2

Mint 17.2, Cinnamon.

I use dconf editor to set up my hot keys to switch between workspaces. Here is the relevant portion of my workspace key bindings:

enter image description here

What I want is a key binding that switches back to the last workspace I was on. This feature is available in the windows desktop manager "dexpot" as shown here:

enter image description here

So under windows, when I type "Ctrl-Alt-L" it takes me to the last workspace I was in. If you hit it repeatedly, it then toggle between the two active workspaces.

I know this question has been asked before, as I found it once several years ago (and the answer was "no you can't"), but unfortunately I can't find anything dealing with this under google anymore, so I apologize in advance if this has already been answered. I also know it's a function of the window manager (e.g cinnamon) and not gnome.

I'm hoping there's some way to do it now, as I really miss this functionality, especially since I've been context switching between windows and linux a lot lately.

Many Thanks!

1 Answer 1

3

Since no one has come up with anything (and indeed, I can't find anything myself), I assume the answer to this question is "No, you can't do it". Thus I opened an issue on cinnamon github requesting this as a feature.

Since I've had no response there either, I'm looking into implementing it myself. In examining the cinnamon code base, it looks like the back-end "engine" is written in c (difficult to fix), but a lot of the front-end user-interface stuff is handled in JavaScript (easier to fix). So there might be a reasonable chance I can hack something together, so I can at least patch my system if not create an actual fix that is incorporated into Cinnamon itself.

If I come up with a solution, I will post the result here.

Update: I did a code hack. It's not an official solution, but if you refer to the previously mentioned ticket, you can find the details. I reproduce my write-up here as well:

Solution

Limitations

Ok, after setting up a test image, looking at the code, and doing some research, I came up with a solution to fix this. Note: this is currently just a workaround that involves manually editing a few files. In order to submit this as an "official" fix I would need to:

  1. add support for a new keyword "switch-to-workspace-last" so that it's visible in, at least dconf-editor, if not in the Keyboard->Shortcuts gui in the control panel.
  2. Write any unit tests (although, I don't see any uts for the files I touched under /tests (?)).
  3. Deal with creating an actual build of .deb of the cinnamon package (or is this not necessary to submit a fix ?).

  4. Get a little more feedback on if the way I did it is a "good" way to do it.

For now, I'm just going to stick with the workaround. I'm actually just so happy that I have a workaround, and that it's just a couple of lines to implement. This allows me I to get started using this right away (and boy is it great to have).

Anyway, in another comment, I will write-up a detailed posting with some background: what files are important, how I figured it out, and what exactly needs to be done as I propagate the fix into my production image.

How to add hot-key support for "visit last workspace" in Cinnamon 17.2 (2.6.13+rafaela).

Overview:

We will hijack the functionality of a rarely used key binding of your choice (I used 'move-to-workspace-left') with the functionality to implement "move-to-workspace-last". This involves adding a few lines to '/usr/share/cinnamon/js/ui/windowManger.js'. We will need to add a new state variable 'global.screen.penultimate_workspace' to the 'global' js variable, and then utilize function 'global.screen.get_workspace_by_index(new_index)' to activate the 'last' workspace, and then call 'activate' to switch to it.

A good example of an existing file that does something simliar is the workspace-switcher applet, which is located at '/usr/share/cinnamon/applets/[email protected]/applet.js'. You have to add this applet to the panel in order to see the file.

Fortunately, this can be done entirely in the JavaScript portion of Cinnamon.

Detail

Code changes

see here for a full copy of the Mint 17.3 patched file. Search on 'vt' (my initials) to see the relevant portions of code. This is much easier to follow than the small snippets of code I give next.

Edit file '/usr/share/cinnamon/js/ui/windowManger.js' like so:

1) Init new global var 'screen.penultimate_workspace':

WindowManager.prototype = {                                                                   
          _init : function() {                                                                      
         this._cinnamonwm =  global.window_manager;  
         ...
         //fix add
        global.screen.penultimate_workspace = 1;
        //fix end

2) update the penultimate_workspace whenever someone manually switches to a workspace via the 'switch-to-workspace-' key. This is function _switchWorkspace in windowManager.js ;

   _switchWorkspace : function(cinnamonwm, from, to, direction) {
        //fix add
        global.screen.penultimate_workspace = from;
        //fix end
        if (!this._shouldAnimate()) {
            cinnamonwm.completed_switch_workspace();
            return;
        }

3) overlay your selected key-binding handler:

   _moveWindowToWorkspaceLeft : function(display, screen, window, binding) {
        //original code
        //this._shiftWindowToWorkspace(window, Meta.MotionDirection.LEFT);
        //end original code
        //fix add
        // get workspace object for 'last' workspace
        let metaWorkspace = global.screen.get_workspace_by_index(global.screen.penultimate_workspace);
        // save current workspace index into penultimate_workspace
        global.screen.penultimate_workspace = global.screen.get_active_workspace_index();

        // and switch to penultimate workspace
        metaWorkspace.activate(global.get_current_time() );
        //fix end
    },

dconf-editor changes:

1) I chose to use "Ctrl-Alt-l" (that's lower case 'ell) as my 'switch-to-workspace-last' command. Unfortunately, this was already in use as screen lock. a) so goto control panel->Keyboard->Shortcuts->System->LockScreen and change to Ctrl-Alt-Shift-l (or whatever you want)

2) using dconf editor change 'move-to-workspace-left' to be 'Control -Alt-l' in schema org.cinnamon.desktop.keybindings.wm

Activate changes

1) type "Ctrl-Alt-Esc" to refresh the cinnamon window manager. This is somewhat like logging off and logging on, except all your windows and editing sessions will still be in effect.

Note: sometimes your terminal may hang after doing this. If this happens, just restart your image.

That's it. After doing this pressing "Ctrl-Alt-l" should take you to the last visited window.

Debuging help:

1) use Ctrl-Alt-Esc to refresh if window manager if you change a file. Any changes you make will not take effect until you do this.

2) use global.log("vt: windowManger. blah");

to see debug mesages. Do tail -f on ~/.cinnamon/glass.log to see the messages:

tail -f glass.log

Note: you have to kill any prior tail -f sessions and start anew everytime you do a "Ctrl-Alt-Esc" to refresh the window manager.

1
  • Same requirement as yours here. I am also very surprised to not find more people asking for this feature, as it's the complement of our old "alt-tab" friend to switch b/w windows. Your solution is, unfortunately, at least for the moment, too complex for me, as I can't fiddle that much with settings at my work machine. Maybe there's some other solution after all this time? Thanks Mar 1 at 16:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .