← easystroke

Add interface to enable/disable, show about dialog and quit

57661b549d5595fa55b17c23031fcc7654488a34 · Thomas Jaeger · Sep 6, 2012 18:44

If users add an icon to their dock, they should be able to access the
functionality previously provided by the status icon.

+52 −7 · 6 files changed

  • dbus-server.cc +18 −0
  • dbus.xml +3 −0
  • easystroke.desktop.in +12 −0
  • main.cc +16 −4
  • win.cc +2 −2
  • win.h +1 −1
diff --git a/dbus-server.cc b/dbus-server.cc
index a65dbc5..98c99f6 100644
--- a/dbus-server.cc
+++ b/dbus-server.cc
@@ -18,6 +18,7 @@
 #include <dbus/dbus-glib-bindings.h>
 
 #include <stdio.h>
+#include "win.h"
 
 #define SERVER_OBJECT_TYPE (server_object_get_type())
 
@@ -36,6 +37,23 @@ static gboolean server_send(ServerObject *obj, const char *str, GError **error)
 	return TRUE;
 }
 
+extern Source<bool> disabled;
+static gboolean server_enable(ServerObject *obj, GError **error) {
+	disabled.set(!disabled.get());
+	return TRUE;
+}
+
+static gboolean server_about(ServerObject *obj, GError **error) {
+	win->show_about();
+	return TRUE;
+}
+
+extern void quit();
+static gboolean server_quit(ServerObject *obj, GError **error) {
+	quit();
+	return TRUE;
+}
+
 #include "dbus-server.h"
 
 static void server_object_class_init(ServerObjectClass *klass) {
diff --git a/dbus.xml b/dbus.xml
index e8c89dc..8055b4d 100644
--- a/dbus.xml
+++ b/dbus.xml
@@ -5,6 +5,9 @@
 		<method name="send">
 			<arg type="s" name="action" direction="in" />
 		</method>
+		<method name="enable" />
+		<method name="about" />
+		<method name="quit" />
 	</interface>
 </node>
 
diff --git a/easystroke.desktop.in b/easystroke.desktop.in
index 754e874..d8f3465 100644
--- a/easystroke.desktop.in
+++ b/easystroke.desktop.in
@@ -7,3 +7,15 @@ Exec=easystroke
 Icon=easystroke
 Categories=GTK;Utility;Accessibility;
 _Comment=Control your desktop using mouse gestures
+
+[Desktop Action About]
+_Name=About
+Exec=easystroke about
+
+[Desktop Action Enable]
+_Name=Enable/Disable
+Exec=easystroke enable
+
+[Desktop Action Quit]
+_Name=Quit
+Exec=easystroke quit
diff --git a/main.cc b/main.cc
index 757ddd9..4dae25c 100644
--- a/main.cc
+++ b/main.cc
@@ -1130,7 +1130,7 @@ static void link_button_hook(Gtk::LinkButton *, const Glib::ustring& uri) { xdg_
 static void about_dialog_hook(Gtk::AboutDialog &, const Glib::ustring& url) { xdg_open(url); }
 
 // dbus-send --type=method_call --dest=org.easystroke /org/easystroke org.easystroke.send string:"foo"
-static void send_dbus(const char *str) {
+static void send_dbus(bool action, const char *str) {
 	GError *error = 0;
 	DBusGConnection *bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
 	if (!bus) {
@@ -1138,7 +1138,10 @@ static void send_dbus(const char *str) {
 		exit(EXIT_FAILURE);
 	}
 	DBusGProxy *proxy = dbus_g_proxy_new_for_name(bus, "org.easystroke", "/org/easystroke", "org.easystroke");
-	dbus_g_proxy_call_no_reply(proxy, "send", G_TYPE_STRING, str, G_TYPE_INVALID);
+	if (action)
+		dbus_g_proxy_call_no_reply(proxy, "send", G_TYPE_STRING, str, G_TYPE_INVALID);
+	else
+		dbus_g_proxy_call_no_reply(proxy, str, G_TYPE_INVALID);
 }
 
 int start_dbus();
@@ -1156,7 +1159,13 @@ Main::Main() : kit(0) {
 		if (argc == 2)
 			usage(argv[0], false);
 		gtk_init(&argc, &argv);
-		send_dbus(argv[2]);
+		send_dbus(true, argv[2]);
+		exit(EXIT_SUCCESS);
+	}
+
+	if (argc > 1 && (!strcmp(argv[1], "enable") || !strcmp(argv[1], "about") || !strcmp(argv[1], "quit"))) {
+		gtk_init(&argc, &argv);
+		send_dbus(false, argv[1]);
 		exit(EXIT_SUCCESS);
 	}
 
@@ -1177,7 +1186,7 @@ Main::Main() : kit(0) {
 	}
 	if (!no_dbus && start_dbus() < 0) {
 		printf(_("Easystroke is already running, showing configuration window instead.\n"));
-		send_dbus("");
+		send_dbus(true, "");
 		exit(EXIT_SUCCESS);
 	}
 	ROOT = DefaultRootWindow(dpy);
@@ -1233,6 +1242,9 @@ void Main::usage(char *me, bool good) {
 	printf("\n");
 	printf("Usage: %s [OPTION]...\n", me);
 	printf("or:    %s send <action_name>\n", me);
+	printf("       %s enable\n", me);
+	printf("       %s about\n", me);
+	printf("       %s quit\n", me);
 	printf("\n");
 	printf("Options:\n");
 	printf("  -c, --config-dir       Directory for config files\n");
diff --git a/win.cc b/win.cc
index 2d6d3bd..0dc4e78 100644
--- a/win.cc
+++ b/win.cc
@@ -170,7 +170,7 @@ Win::Win() : actions(new Actions), prefs_tab(new Prefs), stats(new Stats) {
 
 	WIDGET(Gtk::ImageMenuItem, menu_about, Gtk::Stock::ABOUT);
 	menu.append(menu_about);
-	menu_about.signal_activate().connect(sigc::mem_fun(*this, &Win::on_about));
+	menu_about.signal_activate().connect(sigc::mem_fun(*this, &Win::show_about));
 
 	WIDGET(Gtk::SeparatorMenuItem, menu_sep);
 	menu.append(menu_sep);
@@ -229,7 +229,7 @@ void Win::show_popup(guint button, guint32 activate_time) {
 }
 
 extern const char *version_string;
-void Win::on_about() {
+void Win::show_about() {
 	Gtk::AboutDialog *about;
 	widgets->get_widget("aboutdialog", about);
 	about->set_logo(Stroke::trefoil()->draw(96, 4.0));
diff --git a/win.h b/win.h
index be215de..b64fd8e 100644
--- a/win.h
+++ b/win.h
@@ -59,13 +59,13 @@ public:
 	boost::shared_ptr<Stats> stats;
 	void show_hide();
 	void set_icon(RStroke stroke, bool invert);
+	void show_about();
 private:
 	bool on_icon_size_changed(int);
 	virtual void timeout();
 	void on_help_toggled();
 	void show_popup(guint, guint32);
 	void show_hide_icon();
-	void on_about();
 
 	Gtk::Window *win;