Erik de Castro Lopo wrote:
> Erik de Castro Lopo wrote:
>
> > I still think this functionality can be improved on to do the right
> > thing for most people most of the time.
>
> Ah, its in the TODO list anyway:
>
> o (per-workspace instances with socket support?)
>
> Since I have already figured out the basic mechanics of how to do
> this using nothing more than GTK/GDK and X11 libs, I'll roll a
> patch and send it in.
I've been running the attached patch for two days now and its
worked flawlessly on Debian Testing, Ubuntu Lucid and Ubuntu Hardy.
I've been careful to try and make sure the code compiles on windows
and mac, but I haven't tested it. There is code in place for these
systems so that if it can't determine the workspace number it just
returns a default of 0. This means that windows/mac behaviour will
be unchanged after this patch.
Cheers,
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
=== modified file 'src/socket.c'
--- src/socket.c 2010-04-25 17:43:39 +0000
+++ src/socket.c 2010-08-04 05:45:18 +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-07-09 17:15:16 +0000
+++ src/ui_utils.c 2010-08-04 05:45:18 +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"
@@ -2396,3 +2403,53 @@
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) ¤t_desktop);
+ err = gdk_error_trap_pop ();
+
+ if (err != Success || result != Success)
+ return ret;
+
+ if (type == XA_CARDINAL && format == 32 && nitems > 0)
+ ret = current_desktop[0];
+
+ gdk_display_close (display);
+ XFree (current_desktop);
+ 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-07-09 17:15:16 +0000
+++ src/ui_utils.h 2010-08-04 05:45:18 +0000
@@ -317,4 +317,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