Sublime Forum

Alt+F4 reassign doesn't work

#1

In ST3 b3180 under Ubuntu 18.04 reassigning Alt+F4 shortcut doesn’t work for me. Does anyone experience the same issue.

0 Likes

#2

I would check to see if that key is used by your window manager. If it is you need to get the WM to ignore it so that Sublime can see it. If I recall correctly, in XFCE it’s used for switching to other desktops, for example.

0 Likes

#3

Yes, it’s used by WM (GNOME) to close a program window (and I’d like to keep it). Does it mean that “Alt+F4” keypress event is not passed to ST at all?

0 Likes

#4

Generally speaking, yes; for keys that the OS (or WM, etc depending on platform) use, they consume the key and don’t pass it on to applications, so Sublime never gets to even know the key was pressed. In that case unless you can somehow change that key on an application by application basis, I don’t think you can bind it directly.

1 Like

#5

Many thanks, now the reason for this issue is clear too

1 Like

#6

It seems I found a solution by using ST “Chain of Command” package, xdotool and wmctrl:

Install “Chain of Command” package in ST.

Assign user shortcut in ST (it must be other than Alt+F4):

{ "keys": ["alt+x"], "command": "chain", "args": { "commands": [ ["close_workspace"], ["close_window"] ] } }

Create bash script:

#!/usr/bin/env bash

if [[ $(xdotool getwindowfocus getwindowname) == *" - Sublime Text" ]]; then # Match end of window title
    sleep 0.1 # Without this delay "xdotool key" doesn't work
    xdotool key alt+x
else
    wmctrl -c :ACTIVE: # Close active window gracefully
fi

Disable “Alt+F4” system keyboard shortcut in your OS.

Create “Alt+F4” user keyboard shortcut in your OS and assign it to running the bash script

I think “Chain of Command” package is optional as one should be able to assign shortcuts to “close_workspace” and “close_window” actions and then call them from the bash script.

0 Likes