Every time I try to switch to a different desktop environment/window manager, there is just one simple feature which always make me go back to xfce – the possibility to quickly switch back to previous virtual desktop. A simple but extremely addictive feature, which only xfwm4 was offering…
…until yesterday! I became tired on metacity not offering this feature, so I just went ahead and implemented it overnight (learning a lot about gnome development during the process).
So, if anyone out there was missing this feature – feel free to grab this patch and apply it to the metacity source. Basically, it will add one new gconf entry (switch_to_previous_workspace), and will make metacity remember the last workspace. So you can press ctrl-f2 to switch to from workspace 1 workspace 2, and when you press ctrl-f2 again metacity will recognize that you want switch back, to whatever workspace you were before, and will do it.
Once again, this is the beauty of the open source. If there is something you need, but nobody implemented it, you always have the possibility of just doing it yourself. At least, sometimes
.
diff -p -up metacity-2.30.1/src/core/prefs.c.switch metacity-2.30.1/src/core/prefs.c
--- metacity-2.30.1/src/core/prefs.c.switch 2010-03-30 11:35:40.000000000 -0300
+++ metacity-2.30.1/src/core/prefs.c 2010-05-06 17:47:14.000000000 -0300
@@ -97,6 +97,7 @@ static char *cursor_theme = NULL;
static int cursor_size = 24;
static gboolean compositing_manager = FALSE;
static gboolean resize_with_right_button = FALSE;
+static gboolean switch_to_previous_workspace = TRUE;
static gboolean force_fullscreen = TRUE;
static MetaVisualBellType visual_bell_type = META_VISUAL_BELL_FULLSCREEN_FLASH;
@@ -412,6 +413,11 @@ static MetaBoolPreference preferences_bo
&resize_with_right_button,
FALSE,
},
+ { "/apps/metacity/general/switch_to_previous_workspace",
+ META_PREF_SWITCH_TO_PREVIOUS_WORKSPACE,
+ &switch_to_previous_workspace,
+ FALSE,
+ },
{ NULL, 0, NULL, FALSE },
};
@@ -1757,6 +1763,9 @@ meta_preference_to_string (MetaPreferenc
case META_PREF_FORCE_FULLSCREEN:
return "FORCE_FULLSCREEN";
+
+ case META_PREF_SWITCH_TO_PREVIOUS_WORKSPACE:
+ return "SWITCH_TO_PREVIOUS_WORKSPACE";
}
return "(unknown)";
@@ -2719,6 +2728,12 @@ meta_prefs_get_mouse_button_menu (void)
return resize_with_right_button ? 2: 3;
}
+guint
+meta_prefs_switch_to_previous_workspace (void)
+{
+ return switch_to_previous_workspace;
+}
+
gboolean
meta_prefs_get_force_fullscreen (void)
{
diff -p -up metacity-2.30.1/src/core/screen-private.h.switch metacity-2.30.1/src/core/screen-private.h
--- metacity-2.30.1/src/core/screen-private.h.switch 2010-01-14 22:31:32.000000000 -0200
+++ metacity-2.30.1/src/core/screen-private.h 2010-05-06 17:47:14.000000000 -0300
@@ -80,7 +80,7 @@ struct _MetaScreen
MetaUI *ui;
MetaTabPopup *tab_popup;
- MetaWorkspace *active_workspace;
+ MetaWorkspace *active_workspace, *last_workspace;
/* This window holds the focus when we don't want to focus
* any actual clients
diff -p -up metacity-2.30.1/src/core/workspace.c.switch metacity-2.30.1/src/core/workspace.c
--- metacity-2.30.1/src/core/workspace.c.switch 2010-01-14 22:31:32.000000000 -0200
+++ metacity-2.30.1/src/core/workspace.c 2010-05-06 18:00:39.000000000 -0300
@@ -377,7 +377,31 @@ meta_workspace_activate_with_focus (Meta
meta_workspace_index (workspace));
if (workspace->screen->active_workspace == workspace)
- return;
+ {
+ meta_verbose("Switching to same workspace detected, going back to previous one!!\n");
+ if (meta_prefs_switch_to_previous_workspace()) {
+ if (workspace->screen->last_workspace) {
+ meta_verbose("Going to desktop %d\n", meta_workspace_index(workspace));
+ meta_workspace_activate_with_focus(workspace->screen->last_workspace,
+ NULL, timestamp);
+ return;
+ } else {
+ meta_verbose("No old workspace..\n");
+ return;
+ }
+ } else {
+ meta_verbose("Last workspace switching disabled..\n");
+ return;
+ }
+ }
+ else
+ {
+ if (workspace->screen->active_workspace)
+ meta_verbose("Updating last workspace.. current: %d, new: %d\n",
+ meta_workspace_index(workspace->screen->active_workspace),
+ meta_workspace_index(workspace));
+ workspace->screen->last_workspace = workspace->screen->active_workspace;
+ }
if (workspace->screen->active_workspace)
workspace_switch_sound(workspace->screen->active_workspace, workspace);
diff -p -up metacity-2.30.1/src/include/prefs.h.switch metacity-2.30.1/src/include/prefs.h
--- metacity-2.30.1/src/include/prefs.h.switch 2010-01-14 22:31:32.000000000 -0200
+++ metacity-2.30.1/src/include/prefs.h 2010-05-06 17:47:14.000000000 -0300
@@ -60,7 +60,8 @@ typedef enum
META_PREF_CURSOR_SIZE,
META_PREF_COMPOSITING_MANAGER,
META_PREF_RESIZE_WITH_RIGHT_BUTTON,
- META_PREF_FORCE_FULLSCREEN
+ META_PREF_FORCE_FULLSCREEN,
+ META_PREF_SWITCH_TO_PREVIOUS_WORKSPACE
} MetaPreference;
typedef void (* MetaPrefsChangedFunc) (MetaPreference pref,
diff -p -up metacity-2.30.1/src/metacity.schemas.in.in.switch metacity-2.30.1/src/metacity.schemas.in.in
--- metacity-2.30.1/src/metacity.schemas.in.in.switch 2010-05-06 17:47:14.000000000 -0300
+++ metacity-2.30.1/src/metacity.schemas.in.in 2010-05-06 18:01:16.000000000 -0300
@@ -4,6 +4,24 @@
<!-- General preferences -->
<schema>
+ <key>/schemas/apps/metacity/general/switch_to_previous_workspace</key>
+ <applyto>/apps/metacity/general/switch_to_previous_workspace</applyto>
+ <owner>metacity</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>Remember and recall previous workspace when switching via keyboard shortcuts</short>
+ <long>
+ Set this to true to allow to switch to previous workspace when
+ using the current workspace keybinding. For example, if you switched
+ from workspace 2 to workspace 1 by pressing keyboard shortcut for
+ workspace 1, pressing the same shortcut again while on workspace 1
+ will switch to workspace 2.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/metacity/general/mouse_button_modifier</key>
<applyto>/apps/metacity/general/mouse_button_modifier</applyto>
<owner>metacity</owner>
diff -p -up metacity-2.30.1/src/metacity.schemas.in.switch metacity-2.30.1/src/metacity.schemas.in
--- metacity-2.30.1/src/metacity.schemas.in.switch 2010-04-06 07:10:38.000000000 -0300
+++ metacity-2.30.1/src/metacity.schemas.in 2010-05-06 18:01:06.000000000 -0300
@@ -4,6 +4,24 @@
<!-- General preferences -->
<schema>
+ <key>/schemas/apps/metacity/general/switch_to_previous_workspace</key>
+ <applyto>/apps/metacity/general/switch_to_previous_workspace</applyto>
+ <owner>metacity</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>Remember and recall previous workspace when switching via keyboard shortcuts</short>
+ <long>
+ Set this to true to allow to switch to previous workspace when
+ using the current workspace keybinding. For example, if you switched
+ from workspace 2 to workspace 1 by pressing keyboard shortcut for
+ workspace 1, pressing the same shortcut again while on workspace 1
+ will switch to workspace 2.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/metacity/general/mouse_button_modifier</key>
<applyto>/apps/metacity/general/mouse_button_modifier</applyto>
<owner>metacity</owner>
@@ -247,7 +265,7 @@
<applyto>/apps/metacity/general/theme</applyto>
<owner>metacity</owner>
<type>string</type>
- <default>Clearlooks</default>
+ <default>Ia Ora Steel</default>
<locale name="C">
<short>Current theme</short>
<long>












Hi Eugeni! Cool stuff. Please don’t forget put this patch in Gnome bugzilla!
[...] Gnome hacking [...]
[...] Dodonov has asked for a keybinding to return to the previous workspace. For example, if you were on workspace 1 and switched to workspace 2, then pressing this key would [...]
What about getting metacity to open the startup windows in specified Desks? When I log in, I’d like to not only have certain windows open up automatically, but I’d like those windows to be sorted onto specific desks (or workspaces). What you’ve done is great, but not what I was searching for.
Do you know how to do this?