Skip to content

Commit

Permalink
#1195 / #1229: change the default key shortcuts to use the "menu" key…
Browse files Browse the repository at this point in the history
… for both keyboard and pointer grab: with "control" modifier keyboard grabs and "shift" for pointer grabs

git-svn-id: https://xpra.org/svn/Xpra/trunk@13169 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Aug 2, 2016
1 parent b46aa14 commit f22da6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
45 changes: 38 additions & 7 deletions src/xpra/client/keyboard_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
log = Logger("keyboard")

from xpra.keyboard.mask import DEFAULT_MODIFIER_MEANINGS, DEFAULT_MODIFIER_NUISANCE
from xpra.util import nonl, csv
from xpra.util import nonl, csv, print_nested_dict


class KeyboardHelper(object):
Expand Down Expand Up @@ -144,29 +144,60 @@ def parse_shortcuts(self, strs):
continue
#TODO: validate keyname
keyname = keyspec[len(keyspec)-1]
shortcuts[keyname] = (modifiers, action, args)
shortcuts.setdefault(keyname, []).append((modifiers, action, args))
log("shortcut(%s)=%s", keyname, (modifiers, action, args))
log("parse_shortcuts(%s)=%s" % (str(strs), shortcuts))
print_nested_dict(shortcuts, print_fn=log)
return shortcuts

def key_handled_as_shortcut(self, window, key_name, modifiers, depressed):
shortcut = self.key_shortcuts.get(key_name)
if not shortcut:
return False
#find the shortcuts that may match this key:
shortcuts = self.key_shortcuts.get(key_name)
if not shortcuts:
return False
if len(shortcuts)>1:
#sort shortcuts based on how many modifiers are required,
#so that if multiple shortcuts use the same key,
#we will try to match the one with the most modifiers first.
#ie: Num_Lock+Menu will be tested before Menu
#(this is needed because Num_Lock is then discarded when comparing the list of required modifiers!)
shortcuts = sorted(shortcuts, key=lambda x : len(x[0]), reverse=True)
for shortcut in shortcuts:
if self._check_shortcut(window, key_name, modifiers, depressed, shortcut):
return True
return False

def _check_shortcut(self, window, key_name, modifiers, depressed, shortcut):
(req_mods, action, args) = shortcut
extra_modifiers = list(modifiers)
for rm in req_mods:
if rm not in modifiers:
#modifier is missing, bail out
return False
try:
extra_modifiers.remove(rm)
except:
pass #same modifier listed twice?
kmod = self.keyboard.get_keymap_modifiers()[0] #ie: {'ISO_Level3_Shift': 'mod5', 'Meta_L': 'mod1', ...}
log("keymap modifiers: %s", kmod)
ignoremod = ("Caps_Lock", "Num_Lock")
for x in ignoremod:
mod = kmod.get(x)
if mod in extra_modifiers:
extra_modifiers.remove(mod)
if extra_modifiers:
log("skipping partial shortcut match %s, modifiers unmatched: %s", shortcut, extra_modifiers)
return False
log("matched shortcut %s", shortcut)
if not depressed:
""" when the key is released, just ignore it - do NOT send it to the server! """
return True
return True
try:
method = getattr(window, action)
log("key_handled_as_shortcut(%s,%s,%s,%s) found shortcut=%s, will call %s%s", window, key_name, modifiers, depressed, shortcut, method, args)
except AttributeError as e:
log.error("key dropped, invalid method name in shortcut %s: %s", action, e)
return True
return True
try:
method(*args)
log("key_handled_as_shortcut(%s,%s,%s,%s) has been handled: %s", window, key_name, modifiers, depressed, method)
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ def read_xpra_defaults():

def get_default_key_shortcuts():
return [shortcut for e,shortcut in [
(True, "Control_R:toggle_keyboard_grab"),
(True, "Menu:toggle_pointer_grab"),
(True, "Control+Menu:toggle_keyboard_grab"),
(True, "Shift+Menu:toggle_pointer_grab"),
(True, "Meta+Shift+F1:show_menu"),
(True, "Meta+Shift+F2:show_start_new_command"),
(True, "Meta+Shift+F3:show_bug_report"),
Expand Down

0 comments on commit f22da6d

Please sign in to comment.