From d9abcf8aa5902bdfce68c77dac560e7aac3af28f Mon Sep 17 00:00:00 2001 From: infirit Date: Sat, 8 Nov 2014 01:36:31 +0100 Subject: Properly get the workarea for positioning the labels Based on gnome-desktop commit: b4b3fbe614c245e5e2cc4ca431d0f5310eca6ed1 From: Matthias Clasen Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=641996 --- libmate-desktop/mate-rr-labeler.c | 43 +++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'libmate-desktop/mate-rr-labeler.c') diff --git a/libmate-desktop/mate-rr-labeler.c b/libmate-desktop/mate-rr-labeler.c index d498520..fa0db03 100644 --- a/libmate-desktop/mate-rr-labeler.c +++ b/libmate-desktop/mate-rr-labeler.c @@ -67,6 +67,38 @@ static void mate_rr_labeler_finalize (GObject *object); static void create_label_windows (MateRRLabeler *labeler); static void setup_from_config (MateRRLabeler *labeler); +static int +get_current_desktop (GdkScreen *screen) +{ + Display *display; + Window win; + Atom current_desktop, type; + int format; + unsigned long n_items, bytes_after; + unsigned char *data_return = NULL; + int workspace = 0; + + display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); + win = XRootWindow (display, GDK_SCREEN_XNUMBER (screen)); + + current_desktop = XInternAtom (display, "_NET_CURRENT_DESKTOP", True); + + XGetWindowProperty (display, + win, + current_desktop, + 0, G_MAXLONG, + False, XA_CARDINAL, + &type, &format, &n_items, &bytes_after, + &data_return); + + if (type == XA_CARDINAL && format == 32 && n_items > 0) + workspace = (int) data_return[0]; + if (data_return) + XFree (data_return); + + return workspace; +} + static gboolean get_work_area (MateRRLabeler *labeler, GdkRectangle *rect) @@ -82,6 +114,7 @@ get_work_area (MateRRLabeler *labeler, long *workareas; int result; int disp_screen; + int desktop; Display *display; display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (labeler->priv->screen)); @@ -120,11 +153,13 @@ get_work_area (MateRRLabeler *labeler, return FALSE; } + desktop = get_current_desktop (labeler->priv->screen); + workareas = (long *) ret_workarea; - rect->x = workareas[disp_screen * 4]; - rect->y = workareas[disp_screen * 4 + 1]; - rect->width = workareas[disp_screen * 4 + 2]; - rect->height = workareas[disp_screen * 4 + 3]; + rect->x = workareas[desktop * 4]; + rect->y = workareas[desktop * 4 + 1]; + rect->width = workareas[desktop * 4 + 2]; + rect->height = workareas[desktop * 4 + 3]; XFree (ret_workarea); -- cgit v1.2.1