1

I am making a program that locks my computer by creating a full-screen window and disabling all ways to unfocus the window. For that I need to programmatically disable/enable the Windows key:

enter image description here

Is there a way to catch and stop the windows key event from being passed on to the OS (Ubuntu 21.10) using libX11? From what I understand I am supposed to use XGrabKey but it only blocks Alt-Tab:

XGrabKey(display, ANY_KEY, ANY_MODIFIER, window, False, GRAB_MODE_SYNC,
         GRAB_MODE_SYNC)

Also I don't want to disable the whole keyboard.

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • 1
    What do you mean by ‘passed to the OS’? And why this specific key? – user3840170 Nov 28 '21 at 13:43
  • @user3840170 If you press the windows key when using Ubuntu, a screen with all of open programs will appear. It also allows the user to switch to a different desktop. As I am making a program that is supposed to act as a lock for my computer, I don't want the key to be enabled when the program is running. – TheLizzard Nov 28 '21 at 18:48
  • What if the user runs Xfce, in which arbitrary keyboard shortcuts can be bound to arbitrary actions? – user3840170 Nov 28 '21 at 20:08
  • @user3840170 I am making the program for personal use and only the windows key allows the user to escape the lock that I have now. – TheLizzard Nov 28 '21 at 21:27
  • 1
    Are these any use? https://askubuntu.com/questions/105558/how-do-i-disable-the-super-key – alani Dec 03 '21 at 03:02
  • @alani Sorry but none of them can be done programmatically. Also most of them require `sudo` which I would like to avoid is possible. – TheLizzard Dec 03 '21 at 13:37
  • @TheLizzard the idea was that as this for personal use only, one option might be to keep the windows key disabled in your settings as a one-off operation if you don't need to use the key yourself, and then the question goes away. There's an activities menu at the top-left of the screen that you can click on to access the same thing when needed. – alani Dec 03 '21 at 18:03
  • @alani I use the windows key quite regularly. That is why I asked for a programmatic solution. – TheLizzard Dec 03 '21 at 20:04
  • It could depend upon your particular window manager – Basile Starynkevitch Dec 03 '21 at 20:18
  • @BasileStarynkevitch Do you mean `libX11.so.6`? I am using the default Ubuntu installation. – TheLizzard Dec 03 '21 at 21:20
  • No, I mean your [window manager](https://en.wikipedia.org/wiki/Window_manager). With a little effort, you can configure another one (e.g. [GWM](https://github.com/mnsanghvi/gwm)...). With more efforts, you could write your own one. Read also [ICCCM](https://tronche.com/gui/x/icccm/) – Basile Starynkevitch Dec 04 '21 at 07:59

0 Answers0