From 4c3ab61c3f5fa1357010e00e642b961592037bbd Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 15 Sep 2010 17:04:23 +0000 Subject: [PATCH] Use a separate socket per workspace on X (patch by Erik de Castro Lopo, thanks). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5232 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ TODO | 1 - doc/geany.html | 18 ++++++++--------- doc/geany.txt | 8 +++++--- src/socket.c | 5 +++-- src/ui_utils.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui_utils.h | 2 ++ 7 files changed, 76 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6935e80a5..b78430ffa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * src/keyfile.c: Save document indent width with the session. + * src/ui_utils.h, src/socket.c, src/ui_utils.c, doc/geany.txt, + doc/geany.html, TODO: + Use a separate socket per workspace on X (patch by Erik de Castro + Lopo, thanks). 2010-09-14 Nick Treleaven diff --git a/TODO b/TODO index f07556fd3..e867db355 100644 --- a/TODO +++ b/TODO @@ -21,7 +21,6 @@ Note: features included in brackets have lower priority. o (sci macro support - as a plugin?) o (parsing tags from a memory buffer instead of a file on disk) o (tango-like icons for the symbol list) - o (per-workspace instances with socket support?) 1.0: diff --git a/doc/geany.html b/doc/geany.html index 0df0e7039..57f07f806 100644 --- a/doc/geany.html +++ b/doc/geany.html @@ -718,9 +718,9 @@ dragging the dividers.

Command line options

---+++ @@ -818,11 +818,11 @@ available if Geany was compiled with support for VTE. @@ -6133,7 +6133,7 @@ USE OR PERFORMANCE OF THIS SOFTWARE.

diff --git a/doc/geany.txt b/doc/geany.txt index 41913d580..f579d2bb9 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -365,10 +365,12 @@ Short option Long option Function available if Geany was compiled with support for VTE. *none* --socket-file Use this socket filename for communication with a - running Geany instance. This can be used with the following - command to execute Geany on the current workspace:: + running Geany instance. By default Geany uses one + socket file per workspace for X Windows, otherwise + only one. - geany --socket-file=/tmp/geany-sock-$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}') + Example: + geany --socket-file=/tmp/geany-sock-2 *none* --vte-lib Specify explicitly the path including filename or only the filename to the VTE library, e.g. diff --git a/src/socket.c b/src/socket.c index f4ccd04e1..fa2e01554 100644 --- a/src/socket.c +++ b/src/socket.c @@ -271,6 +271,7 @@ gint socket_init(gint argc, gchar **argv) return -1; #else gchar *display_name = gdk_get_display(); + gint workspace = ui_get_current_workspace(display_name); gchar *hostname = utils_get_hostname(); gchar *p; @@ -284,8 +285,8 @@ gint socket_init(gint argc, gchar **argv) *p = '_'; if (socket_info.file_name == NULL) - socket_info.file_name = g_strdup_printf("%s%cgeany_socket_%s_%s", - app->configdir, G_DIR_SEPARATOR, hostname, display_name); + socket_info.file_name = g_strdup_printf("%s%cgeany_socket_%s_%s_ws%d", + app->configdir, G_DIR_SEPARATOR, hostname, display_name, workspace); g_free(display_name); g_free(hostname); diff --git a/src/ui_utils.c b/src/ui_utils.c index 9e25bcb91..3c145c35b 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -31,6 +31,14 @@ #include #include +/* For ui_get_current_workspace() */ +#ifdef GDK_WINDOWING_X11 +#include +#include +#include +#include +#endif + #include "ui_utils.h" #include "prefs.h" #include "sciwrappers.h" @@ -2434,3 +2442,48 @@ void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text, g_signal_stop_emission_by_name(editable, "insert-text"); } + +/* Get the current visible workspace number for the given display name. + * + * If the X11 window property isn't found, 0 (the first workspace) + * is returned. + * + * Has been tested and verified to work under GNOME and KDE. Assuming that + * most other X11 desktops will work the same. For non-X11 backends it returns + * a workspace number of 0. + * + * This code is a slightly modified version of code that was ripped from Gedit + * which ripped it from Galeon. */ +gint ui_get_current_workspace(const gchar *display_name) +{ +#ifdef GDK_WINDOWING_X11 + GdkScreen *screen = gdk_screen_get_default(); + GdkWindow *root_win = gdk_screen_get_root_window(screen); + GdkDisplay *display = gdk_display_open(display_name); + Atom type; + gint format; + gulong nitems; + gulong bytes_after; + guint *current_desktop; + gint err, result; + gint ret = 0; + + gdk_error_trap_push(); + result = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XID(root_win), + gdk_x11_get_xatom_by_name_for_display(display, "_NET_CURRENT_DESKTOP"), + 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, + &bytes_after, (gpointer) ¤t_desktop); + err = gdk_error_trap_pop(); + + if (err == Success && result == Success) + { + if (type == XA_CARDINAL && format == 32 && nitems > 0) + ret = current_desktop[0]; + XFree(current_desktop); + } + gdk_display_close(display); + return ret; +#else + return 0; +#endif +} diff --git a/src/ui_utils.h b/src/ui_utils.h index 678a617a8..249b27689 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -318,4 +318,6 @@ gboolean ui_is_keyval_enter_or_return(guint keyval); gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value); +gint ui_get_current_workspace(const gchar *display_name); + #endif
Short option
none --socket-file

Use this socket filename for communication with a -running Geany instance. This can be used with the following -command to execute Geany on the current workspace:

-
-geany --socket-file=/tmp/geany-sock-$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}')
-
+running Geany instance. By default Geany uses one +socket file per workspace for X Windows, otherwise +only one.

+

Example: +geany --socket-file=/tmp/geany-sock-2

none