Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: Fn+F2 to lock screen on ThinkPad X220 (Read 700 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Fn+F2 to lock screen on ThinkPad X220

Hi everyone,

I am trying to map Fn+F2 to lock the screen on my thinkpad X220. I looked for some instruction online and found this topic (although regarding Arch).

I followed the instructions, namely:

1) installed both acpid and dbus

2) created the mentioned scripts:

/etc/acpi/events/fn-f2.sh:

Code: [Select]
event=ibm/hotkey HKEY 00000080 00001002
action=/etc/acpi/dbus-lock-screen.sh %e

/etc/acpi/dbus-lock-screen.sh:

Code: [Select]
#!/bin/bash

users=$(who|grep '^\w\w* *:'|awk '{print $1}'|sort|uniq)
for user in $users; do
        userhome=$(grep "^$user:" /etc/passwd|awk -F : '{print $6}')
        cd "$userhome/.dbus/session-bus/"
        for sf in $(ls); do
                source $sf
                export DBUS_SESSION_BUS_ADDRESS
                export DBUS_SESSION_BUS_PID
                export DBUS_SESSION_BUS_WINDOWID

                su $user -c 'qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock'
        done
done

It's quite clear to me that the first script aims to basically link the Fn+F2 "event" to lock the screen through the second script. However, I could not complete step 5) of the tutorial since there is no /etc/rc.d/ directory in my system. According to one of the replies in the abovementioned topic, the error might be in regex for grep in $users in the second script, although I don't really understand what do I need to edit. May someone give me a hand? Is this the problem, or do I need to also install acpid-runit and/or dbus-runit and enable them to make it work? Also, reading the second script I cannot understand what is actually used for locking the screen (I would like to edit this to make it slock, since I already use it to lock my screen on suspend).

Thank you in advance and sorry for the newbie question :)

Re: Fn+F2 to lock screen on ThinkPad X220

Reply #1
Install i3lock-fancy and program your F2 key to launch i3lock-fancy. The key shortcut def is up to your DE/WM.

Re: Fn+F2 to lock screen on ThinkPad X220

Reply #2
Thanks @calvinh. Since I use dwm I originally thought about that, but I have no idea how I should refer to the Fn+F2 key combination in my config.def.h (keybindings section). I tried to look for it in /usr/include/X11/keysymdef.h but could not find it. After some googling I found this this: if I got it right, it's not possible to map it in dwm with the conventional method. Am I right?
In fatc, interestingly, some Fn+FX key combinations (X ∈ [1, 12]) were working out-of-the-box when I first installed X and dwm, while some others (like the abovementioned Fn+F2) weren't. Maybe someone else managed to do it and can give me some clues?

Re: Fn+F2 to lock screen on ThinkPad X220

Reply #3
Thanks @calvinh. Since I use dwm I originally thought about that, but I have no idea how I should refer to the Fn+F2 key combination in my config.def.h (keybindings section). I tried to look for it in /usr/include/X11/keysymdef.h but could not find it. After some googling I found this this: if I got it right, it's not possible to map it in dwm with the conventional method. Am I right?
In fatc, interestingly, some Fn+FX key combinations (X ∈ [1, 12]) were working out-of-the-box when I first installed X and dwm, while some others (like the abovementioned Fn+F2) weren't. Maybe someone else managed to do it and can give me some clues?


If I remember right, Lenovo laptops use "Fn + Escape" to toggle function keys, for example brightness, volume, etc. Once function keys are enable, if you press brightness increase key (F2 on my mac laptop), X actually only sees key "F2". You can use xev to monitor the X events and play around.

If it's indeed "F2" key in your system, you could define an entry in config.def.h, something like this,

Code: [Select]
{0,                       XK_F2,      spawn,          {.v = scrlockcmd } },


 

Re: Fn+F2 to lock screen on ThinkPad X220

Reply #5
So from there, showkey might be helpful? showkey gives some output when pressing my function key while xev doesn't.

Nah, for me also showkey does not give me any output. Guess I'll just map Super+F2 to lock the screen or something like this in my config.def.h for the moment... Although I wanted to make use of that Fn key