Wednesday, April 9, 2008

Windows+L to Lock Screen.

Aka L or L. For the past several releases Gnome/Metacity have an issue with setting certain keyboard binding shortcuts involving the WinKey.

There are really normally two bugs involved. The first bug is that Gnome doesn't think the Win key is a modifier, so it registers as Super_L (meaning the Left Super Key as a standalone) whenever you try to bind a shortcut using that key. This can be fixed through System -> Preferences -> Keyboard -> Layout Options -> Alt/Win Key Behavior. Choose the option labeled "Super is mapped to the Win-keys (default)" Yes, I know it says default, but it isn't really. You'll notice that one or two other options in the same series are also labeled default.

The second bug is that there are two separate shortcut managers, metacity and gnome-settings-daemon, and one of them (gnome-settings-daemon) happens before gnome does its magic modifier mappings, the other happens after. Basically this means that when you set the key bindings under Keyboard Shortcuts in preferences, you are using a certain key layout when you make your selection, but when the keys actually get interpreted, they are using a different (and defective) layout, which lacks certain keys -- such as the Windows key. So far, there's not really a good way to fix the problem, but there is a way to work around it. Instead of letting gnome-settings-daemon handle the task you are trying to assign, find an alternate way to perform the task using metacity (or compiz). Open up gconf-editor from a terminal, then go to /apps/metacity/global_keybindings where you will find a series of run_command_X options from 1 to 12. Fill in one of them with the value l (you actually type it like that, with the angle brackets, etc.) then fill in the corresponding command_X item in /apps/metacity/keybinding_commands with the command you are trying to launch, which - if you are trying to bind Windows+L is most likely:

/usr/bin/gnome-screensaver-command --lock

This will launch the gnome screensaver and lock the screen.

I know this isn't perfect, but a workaround is better than nothing. I hope it was helpful!

2 comments:

Anonymous said...

Argh, I've tried this solution, both by adding the keybindings under /apps/metacity/global_keybindings and under /apps/compiz/general/allscreens/options and still I can't get windows+L to be performing any action. (And that while I was hopeful that _finally_ having found someone describing the problem I was facing, I'd actually have a solution as well...)

It's very curious; every single windows+key combination works, except for +E, +F and +L.

Any chance you might have any insight in what could be preventing this from working for me? I'm on a laptop here (a Toshiba Portege R500), with a "general 105 key (intl) keyboard layout - but I just can't see that mattering for standard keys like E, F and L...

Anonymous said...

I think i found a workaround for win+e not working, it's kinda long but it works, install xbindkeys and xbindkeys-config

follow this instructions:
http://www.modeemi.fi/~tuomov/ion/faq/entries/Modifier_releases.html

and in xbindkeys-config use
m:0x50 + c:26 for win+e (change 26 for other letters)

dalaidakkarATgmailDOTcom
blog.dakkar.tk