xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #456: osx-swapkeys+numlock-v2.patch

File osx-swapkeys+numlock-v2.patch, 2.5 KB (added by Antoine Martin, 8 years ago)

swap control and meta keys and also deal with numlock as per #453 (also emulate numlock state)

  • xpra/platform/darwin/keyboard.py

     
    1111
    1212
    1313class Keyboard(KeyboardBase):
     14    """
     15        Switch Meta_L and Control_L
     16    """
    1417
    1518    def __init__(self):
    16         pass
     19        self.meta_modifier = None
     20        self.control_modifier = None
     21        self.num_lock_modifier = None
     22        self.num_lock_state = False
     23        self.num_lock_keycode = 71      #HARDCODED!
     24
     25    def set_modifier_mappings(self, mappings):
     26        KeyboardBase.set_modifier_mappings(self, mappings)
     27        self.meta_modifier = self.modifier_keys.get("Meta_L")
     28        self.control_modifier = self.modifier_keys.get("Control_L")
     29        self.num_lock_modifier = self.modifier_keys.get("Num_Lock")
     30        log.info("set_modifier_mappings meta=%s, control=%s, numlock=%s", self.meta_modifier, self.control_modifier, self.num_lock_modifier)
     31
     32    def mask_to_names(self, mask):
     33        names = KeyboardBase.mask_to_names(self, mask)
     34        if self.meta_modifier is not None and self.control_modifier is not None:
     35            #we have the modifier names for both keys we may need to switch
     36            if self.meta_modifier in names and self.control_modifier not in names:
     37                names.remove(self.meta_modifier)
     38                names.append(self.control_modifier)
     39            elif self.control_modifier in names and self.meta_modifier not in names:
     40                names.remove(self.control_modifier)
     41                names.append(self.meta_modifier)
     42        if self.num_lock_modifier is not None:
     43            if self.num_lock_state and self.num_lock_modifier not in names:
     44                names.append(self.num_lock_modifier)
     45            elif not self.num_lock_state and self.num_lock_modifier in names:
     46                names.remove(self.num_lock_modifier)
     47        return names
     48
     49    def process_key_event(self, send_key_action_cb, wid, key_event):
     50        if self.meta_modifier is not None and self.control_modifier is not None:
     51            #we have the modifier names for both keys we may need to switch
     52            if key_event.keyname=="Control_L":
     53                key_event.keyname = "Meta_L"
     54            elif key_event.keyname=="Meta_L":
     55                key_event.keyname = "Control_L"
     56        if key_event.keycode==self.num_lock_keycode and not key_event.pressed:
     57            self.num_lock_state = not self.num_lock_state
     58        send_key_action_cb(wid, key_event)