Last active
October 5, 2022 09:22
-
-
Save ccat3z/1ca8dd27de5cbdf6d7d0bf39f756fc9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Desktop Entry] | |
Name=vscode-right-click-hotfix | |
Type=Application | |
Exec=/usr/bin/env vscode-right-click-hotfix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
from Xlib.display import Display | |
from Xlib import Xatom, X | |
from Xlib.ext.xtest import fake_input | |
def grab_button_3(window): | |
window.grab_button( | |
X.Button3, X.AnyModifier, False, | |
X.ButtonReleaseMask, | |
X.GrabModeAsync, X.GrabModeAsync, | |
X.NONE, X.NONE | |
) | |
def ungrab_button_3(window): | |
window.ungrab_button(X.Button3, X.AnyModifier) | |
def list_vscode_windows(display): | |
root = display.screen().root | |
res = root.get_full_property( | |
display.get_atom('_NET_CLIENT_LIST'), | |
Xatom.WINDOW | |
) | |
if res is None: | |
raise Exception('Cannot get client list') | |
vscode_windows = [] | |
for wid in res.value: | |
w = display.create_resource_object('window', wid) | |
if w.get_wm_class() != ('code', 'Code'): | |
continue | |
vscode_windows.append(w) | |
return vscode_windows | |
if __name__ == '__main__': | |
display = Display() | |
display.screen().root.change_attributes(event_mask=X.PropertyChangeMask) | |
vscode_windows = list_vscode_windows(display) | |
for w in vscode_windows: | |
print('grab window ' + str(w)) | |
grab_button_3(w) | |
while 1: | |
event = display.next_event() | |
if event.type == X.ButtonRelease: | |
print('simulate right click on ' + str(event.window)) | |
ungrab_button_3(event.window) | |
fake_input(display, X.ButtonPress, X.Button3) | |
fake_input(display, X.ButtonRelease, X.Button3) | |
grab_button_3(event.window) | |
elif event.type == X.PropertyNotify \ | |
and event.atom == display.get_atom('_NET_CLIENT_LIST'): | |
new_vscode_windows = list_vscode_windows(display) | |
for w in new_vscode_windows: | |
if w in vscode_windows: | |
continue | |
print('grab window ' + str(w)) | |
grab_button_3(w) | |
vscode_windows = new_vscode_windows |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=VSCode Right Click Hotfix | |
[Service] | |
Type=simple | |
ExecStart=/usr/bin/python3 -u vscode-right-click-hotfix | |
Restart=on-failure | |
RestartSec=5s | |
[Install] | |
WantedBy=gnome-session.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment