Toggle workspace patch

Vebjorn Ljosa ljosa-lists-xfce at ljosa.com
Mon Jun 14 18:53:02 CEST 2004


I have implemented a tiny, new feature in xfwm4.  First a little
background:

I always keep my web browser in workspace 3, and my keyboard has some
extra keys, one of which is labelled with a symbol for the web.  I
would like the web key to always switch to workspace 3---except if I'm
already there, in which case I want it to switch back to the previous
workspace.  This is useful, for example, when I'm working in a
different workspace and want to take a quick look at the page that is
open in the web browser.  I press the web key to take me to the
browser, and then press it again to take me back.

I could of course instead have pressed C-F3 to take me to the browser,
but in order to switch back, I would have had to remember which
workspace I was working in.  Normally I don't, and I end up going
through all the workspaces looking for whatever window I was working
in.

I have attached a diff against the CVS version.  I would appreciate if
somebody could test it before I submit it to the xfce developers.
Save it to, say, /tmp/foo, go into the xfce4/xfwm4 source code
directory that you got from CVS, and type `patch -p0 < /tmp/foo`.

The patch updates the default keythemerc file, but if you have you
own, you will need to add a few lines.  I have the following:

toggle_workspace_1_key=F17
toggle_workspace_2_key=none
toggle_workspace_3_key=F18
toggle_workspace_4_key=none
toggle_workspace_5_key=none
toggle_workspace_6_key=none
toggle_workspace_7_key=none
toggle_workspace_8_key=none
toggle_workspace_9_key=none

My special keys are called F17 and F18.  Use xev to find out what
yours are called.

Vebjorn
-------------- next part --------------
Index: src/client.c
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/src/client.c,v
retrieving revision 1.383
diff -u -r1.383 client.c
--- src/client.c	5 Jun 2004 08:56:22 -0000	1.383
+++ src/client.c	14 Jun 2004 16:34:38 -0000
@@ -314,6 +314,15 @@
     grabKey (c->md->dpy, &params.keys[KEY_SHORTCUT_8], c->window);
     grabKey (c->md->dpy, &params.keys[KEY_SHORTCUT_9], c->window);
     grabKey (c->md->dpy, &params.keys[KEY_SHORTCUT_10], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_1], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_2], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_3], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_4], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_5], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_6], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_7], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_8], c->window);
+    grabKey (c->md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_9], c->window);
 }
 
 void
Index: src/events.c
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/src/events.c,v
retrieving revision 1.223
diff -u -r1.223 events.c
--- src/events.c	5 Jun 2004 08:56:22 -0000	1.223
+++ src/events.c	14 Jun 2004 16:34:38 -0000
@@ -435,6 +435,17 @@
         case KEY_SHORTCUT_10:
             spawn_shortcut (key - KEY_SHORTCUT_1);
             break;
+        case KEY_TOGGLE_WORKSPACE_1:
+        case KEY_TOGGLE_WORKSPACE_2:
+        case KEY_TOGGLE_WORKSPACE_3:
+        case KEY_TOGGLE_WORKSPACE_4:
+        case KEY_TOGGLE_WORKSPACE_5:
+        case KEY_TOGGLE_WORKSPACE_6:
+        case KEY_TOGGLE_WORKSPACE_7:
+        case KEY_TOGGLE_WORKSPACE_8:
+        case KEY_TOGGLE_WORKSPACE_9:
+           toggleWorkspace (md, key - KEY_TOGGLE_WORKSPACE_1);
+           break;
         default:
             break;
     }
Index: src/settings.c
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/src/settings.c,v
retrieving revision 1.94
diff -u -r1.94 settings.c
--- src/settings.c	5 Jun 2004 08:56:22 -0000	1.94
+++ src/settings.c	14 Jun 2004 16:34:39 -0000
@@ -912,6 +912,24 @@
         getValue ("raise_window_key", rc));
     parseKeyString (md->dpy, &params.keys[KEY_LOWER_WINDOW],
         getValue ("lower_window_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_1],
+        getValue ("toggle_workspace_1_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_2],
+        getValue ("toggle_workspace_2_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_3],
+        getValue ("toggle_workspace_3_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_4],
+        getValue ("toggle_workspace_4_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_5],
+        getValue ("toggle_workspace_5_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_6],
+        getValue ("toggle_workspace_6_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_7],
+        getValue ("toggle_workspace_7_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_8],
+        getValue ("toggle_workspace_8_key", rc));
+    parseKeyString (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_9],
+        getValue ("toggle_workspace_9_key", rc));
     ungrabKeys (md->dpy, md->gnome_win);
     grabKey (md->dpy, &params.keys[KEY_CYCLE_WINDOWS], md->gnome_win);
     grabKey (md->dpy, &params.keys[KEY_NEXT_WORKSPACE], md->gnome_win);
@@ -937,6 +955,15 @@
     grabKey (md->dpy, &params.keys[KEY_SHORTCUT_8], md->gnome_win);
     grabKey (md->dpy, &params.keys[KEY_SHORTCUT_9], md->gnome_win);
     grabKey (md->dpy, &params.keys[KEY_SHORTCUT_10], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_1], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_2], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_3], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_4], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_5], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_6], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_7], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_8], md->gnome_win);
+    grabKey (md->dpy, &params.keys[KEY_TOGGLE_WORKSPACE_9], md->gnome_win);
 
     return TRUE;
 }
@@ -1066,6 +1093,15 @@
         {"shortcut_10_exec", NULL, FALSE},
         {"raise_window_key", NULL, TRUE},
         {"lower_window_key", NULL, TRUE},
+        {"toggle_workspace_1_key", NULL, TRUE},
+        {"toggle_workspace_2_key", NULL, TRUE},
+        {"toggle_workspace_3_key", NULL, TRUE},
+        {"toggle_workspace_4_key", NULL, TRUE},
+        {"toggle_workspace_5_key", NULL, TRUE},
+        {"toggle_workspace_6_key", NULL, TRUE},
+        {"toggle_workspace_7_key", NULL, TRUE},
+        {"toggle_workspace_8_key", NULL, TRUE},
+        {"toggle_workspace_9_key", NULL, TRUE},
         {NULL, NULL, FALSE}
     };
     GValue tmp_val = { 0, };
Index: src/settings.h
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/src/settings.h,v
retrieving revision 1.36
diff -u -r1.36 settings.h
--- src/settings.h	4 Jun 2004 22:08:34 -0000	1.36
+++ src/settings.h	14 Jun 2004 16:34:39 -0000
@@ -114,7 +114,16 @@
 #define KEY_SHORTCUT_10                 49
 #define KEY_LOWER_WINDOW                50
 #define KEY_RAISE_WINDOW                51
-#define KEY_COUNT                       52
+#define KEY_TOGGLE_WORKSPACE_1          52
+#define KEY_TOGGLE_WORKSPACE_2          53
+#define KEY_TOGGLE_WORKSPACE_3          54
+#define KEY_TOGGLE_WORKSPACE_4          55
+#define KEY_TOGGLE_WORKSPACE_5          56
+#define KEY_TOGGLE_WORKSPACE_6          57
+#define KEY_TOGGLE_WORKSPACE_7          58
+#define KEY_TOGGLE_WORKSPACE_8          59
+#define KEY_TOGGLE_WORKSPACE_9          60
+#define KEY_COUNT                       61
 #define NB_KEY_SHORTCUTS                10
 
 #define ALIGN_LEFT                      0
Index: src/workspaces.c
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/src/workspaces.c,v
retrieving revision 1.74
diff -u -r1.74 workspaces.c
--- src/workspaces.c	4 Jun 2004 22:08:34 -0000	1.74
+++ src/workspaces.c	14 Jun 2004 16:34:39 -0000
@@ -40,6 +40,8 @@
 #include "stacking.h"
 #include "hints.h"
 
+static int previous_workspace = 0;
+
 void
 workspaceSwitch (ScreenData *md, int new_ws, Client * c2)
 {
@@ -72,6 +74,7 @@
     XGrabPointer (md->dpy, md->gnome_win, FALSE, EnterWindowMask, GrabModeAsync,
                        GrabModeAsync, None, None, GDK_CURRENT_TIME);
 
+    previous_workspace = md->current_ws;
     md->current_ws = new_ws;
     if (c2)
     {
@@ -268,3 +271,12 @@
                              md->margins);
     }
 }
+
+void
+toggleWorkspace (ScreenData *md, int ws)
+{
+     if (ws == md->current_ws)
+          workspaceSwitch(md, previous_workspace, NULL);
+     else
+          workspaceSwitch(md, ws, NULL);
+}
Index: src/workspaces.h
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/src/workspaces.h,v
retrieving revision 1.17
diff -u -r1.17 workspaces.h
--- src/workspaces.h	4 Jun 2004 22:08:34 -0000	1.17
+++ src/workspaces.h	14 Jun 2004 16:34:39 -0000
@@ -35,5 +35,6 @@
 void workspaceSetNames (char *, int);
 void workspaceSetCount (ScreenData *, int);
 void workspaceUpdateArea (ScreenData *);
+void toggleWorkspace (ScreenData *, int);
 
 #endif /* INC_WORKSPACES_H */
Index: themes/default.keys/keythemerc
===================================================================
RCS file: /cvsroot/xfce/xfce4/xfwm4/themes/default.keys/keythemerc,v
retrieving revision 1.6
diff -u -r1.6 keythemerc
--- themes/default.keys/keythemerc	13 Oct 2003 16:21:04 -0000	1.6
+++ themes/default.keys/keythemerc	14 Jun 2004 16:34:39 -0000
@@ -53,3 +53,12 @@
 shortcut_8_key=none
 shortcut_9_key=none
 shortcut_10_key=none
+toggle_workspace_1_key=none
+toggle_workspace_2_key=none
+toggle_workspace_3_key=none
+toggle_workspace_4_key=none
+toggle_workspace_5_key=none
+toggle_workspace_6_key=none
+toggle_workspace_7_key=none
+toggle_workspace_8_key=none
+toggle_workspace_9_key=none


More information about the Xfce mailing list