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.patch

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

swap control and meta keys and also deal with numlock as per #453

  • 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
     23    def set_modifier_mappings(self, mappings):
     24        KeyboardBase.set_modifier_mappings(self, mappings)
     25        self.meta_modifier = self.modifier_keys.get("Meta_L")
     26        self.control_modifier = self.modifier_keys.get("Control_L")
     27        self.num_lock_modifier = self.modifier_keys.get("Num_Lock")
     28        log.info("set_modifier_mappings meta=%s, control=%s, numlock=%s", self.meta_modifier, self.control_modifier, self.num_lock_modifier)
     29
     30    def mask_to_names(self, mask):
     31        names = KeyboardBase.mask_to_names(self, mask)
     32        if self.meta_modifier is not None and self.control_modifier is not None:
     33            #we have the modifier names for both keys we may need to switch
     34            if self.meta_modifier in names and self.control_modifier not in names:
     35                names.remove(self.meta_modifier)
     36                names.append(self.control_modifier)
     37            elif self.control_modifier in names and self.meta_modifier not in names:
     38                names.remove(self.control_modifier)
     39                names.append(self.meta_modifier)
     40        if self.num_lock_modifier is not None and self.num_lock_modifier not in names:
     41            names.append(self.num_lock_modifier)
     42        return names
     43
     44    def process_key_event(self, send_key_action_cb, wid, key_event):
     45        if self.meta_modifier is not None and self.control_modifier is not None:
     46            #we have the modifier names for both keys we may need to switch
     47            if key_event.keyname=="Control_L":
     48                key_event.keyname = "Meta_L"
     49            elif key_event.keyname=="Meta_L":
     50                key_event.keyname = "Control_L"
     51        send_key_action_cb(wid, key_event)
  • xpra/platform/keyboard_base.py

     
    2424        return False
    2525
    2626    def set_modifier_mappings(self, mappings):
    27         log("set_modifier_mappings(%s)", mappings)
     27        log.info("set_modifier_mappings(%s)", mappings)
    2828        self.modifier_mappings = mappings
    2929        self.modifier_keys = {}
    3030        self.modifier_keycodes = {}
     
    3434                keycodes = self.modifier_keycodes.setdefault(keyname, [])
    3535                if keycode not in keycodes:
    3636                    keycodes.append(keycode)
    37         log("modifier_keys=%s", self.modifier_keys)
    38         log("modifier_keycodes=%s", self.modifier_keycodes)
     37        log.info("modifier_keys=%s", self.modifier_keys)
     38        log.info("modifier_keycodes=%s", self.modifier_keycodes)
    3939
    4040    def mask_to_names(self, mask):
    4141        return mask_to_names(mask, self.modifier_map)