11

Is there a way to give a keyboard shortcut defined in an application precedence over a system-wide shortcut with the same key binding?

Desired behaviour: When some keys are pressed, check if the focussed application wants to do anything (and if so, do it). If not, check if there is a system shortcut for some keys and then do that.

What currently happens: I have F11 set as 'toggle fullscreen' in the settings menu for keyboard shortcuts. In Chrome F11 should activate Chrome's own fullscreen mode, but instead is overridden by the system-wide shortcut, i.e. Chrome becomes fullscreen (GNOME panel and title bar vanish) but does not enter Chrome's fullscreen mode (where the tabs, address bar and bookmarks bar also vanish).

(Side note: Firefox does not have the same problem, but this seems to be because FF fullscreen is the same as/is triggered by the window manager fullscreen)

  • The first question that comes to my mind; what talks to the OS about key presses, the application, or X / Wayland? It seems to me that the X will handle a key press, and mangle it if required, before passing it to the window your application is waiting for you on. The second question is how would X know if the application has changed state, and how would it know if a change occurred directly because of a keypress? I'd be inclined to go out on a limb and say that you are out of luck on this. – HellionWisp Nov 16 '17 at 2:04
2

Disclaimer: This is not exactly what you want, but I've spent too much time on this not to post it and maybe someone else can use it.

I got as far as Ctrl + F11 is fullscreen everywhere but Chromium where it is Chromium's fullscreen !

  1. Train of thought

I thought I might be able to trick the window manager if I use xdotool and send the command directly to the chrome window - to no avail.

Then I thought I might be able to change the keyboard shortcut in google chrome, but that seems hardcoded - another dead end.

  1. Which leaves us with this

Install xdotool to simulate keyboard presses

sudo apt-get install xdotool

reconfigure the Ubuntu Keyboard shortcuts to something arbitrary, that we never type but is usable in the script

Settings -> Devices -> Keyboard

Scroll down and edit Toggle fullscreen mode to Ctrl + Alt + 1 and then hit the + and add a custom keyboard shortcut

keyboard shortcuts - fullscreen

and then hit the + and add a custom keyboard shortcut

dialog of custom shortcut

edit the script

nano /home/user/fullscreen.sh


#!/bin/bash
export DISPLAY=:0
windowname=$(xdotool getactivewindow getwindowname | cut -d "-" -f 2)
if [[ $windowname != *"Chromium"* ]]
then
xdotool keydown Ctrl keydown Alt key 1 keyup Alt keyup Ctrl
else
xdotool search --onlyvisible --class "Chromium" windowfocus 
sleep 0.2
xdotool key F11
fi

make it executeable

chmod +x /home/user/fullscreen.sh

  1. Conclusion

It seems impossible to trick the windowmanager and smuggle keystroke by, but there are certainly workarounds possible. In this case Google made the fullscreen keyboard shortcut non-configureable, so it falls just short of the mark

Now with Ctrl + F11 the windowmanager controls the fullscreen behavior except in chromium.

| improve this answer | |
  • 1
    Think you're right that this is the best we can hope for - shame that Chrome/ium doesn't support custom keyboard shortcuts. Worth noting: choice of keyboard shortcut matters for this trick! I already had Ctrl+F11 bound to something else. Tried with Shift+Alt+F11, which didn't work. Alt+F11 worked fine though. (I guess it was attempting to do Shift+Ctrl+Alt+F11) – fred Jan 21 '18 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.