Dimitar Zhekov wrote:

> A slight change to your patch:
> 
>       ...
>       if (err == Success && result == Success)
>       {
>               if (type == XA_CARDINAL && format == 32 && nitems > 0)
>                       ret = current_desktop[0];
>               XFree (current_desktop);
>       }
>       gdk_display_close (display);
>       ...
> 
> will avoid the two returns, and close the display on unsuccessful
> operation.

Hood catch Dimitar. An updated version of my patch is attached.

> Under GDK_WINDOWING_WIN32, you can get the current desktop with
> the "Window Station and Desktop Functions". But it's a name, not a
> number.

If anyone wants to work work on this with me let me know. I have an
idea for making this work but I don't have any windows machines handy.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
=== modified file 'src/socket.c'
--- src/socket.c	2010-08-08 07:07:07 +0000
+++ src/socket.c	2010-08-08 07:09:37 +0000
@@ -271,6 +271,7 @@
 		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 @@
 		*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);

=== modified file 'src/ui_utils.c'
--- src/ui_utils.c	2010-08-08 07:07:07 +0000
+++ src/ui_utils.c	2010-08-08 07:09:37 +0000
@@ -31,6 +31,13 @@
 #include <ctype.h>
 #include <gdk/gdkkeysyms.h>
 
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#endif
+
 #include "ui_utils.h"
 #include "prefs.h"
 #include "sciwrappers.h"
@@ -2422,3 +2429,54 @@
 		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;
+	unsigned *current_desktop;
+	int 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) &current_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
+	/* FIXME: on mac etc proably there are native APIs
+	 * to get the current workspace etc */
+	return 0;
+#endif
+}

=== modified file 'src/ui_utils.h'
--- src/ui_utils.h	2010-08-08 07:07:07 +0000
+++ src/ui_utils.h	2010-08-08 07:09:37 +0000
@@ -316,4 +316,6 @@
 
 gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value);
 
+gint ui_get_current_workspace(const gchar *display_name);
+
 #endif

_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to