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

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

swap control and meta keys

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