예제 #1
0
 def compute_modifier_keynames(self):
     self.keycodes_for_modifier_keynames = {}
     self.xkbmap_mod_nuisance = set(DEFAULT_MODIFIER_NUISANCE)
     keymap = get_default_keymap()
     gdk = import_gdk()
     if self.keynames_for_mod:
         for modifier, keynames in self.keynames_for_mod.items():
             for keyname in keynames:
                 if keyname in DEFAULT_MODIFIER_NUISANCE_KEYNAMES:
                     self.xkbmap_mod_nuisance.add(modifier)
                 keyval = gdk.keyval_from_name(keyname)
                 if keyval == 0:
                     log.error(
                         "Error: no keyval found for keyname '%s' (modifier '%s')",
                         keyname, modifier)
                     return []
                 entries = keymap.get_entries_for_keyval(keyval)
                 if entries:
                     keycodes = []
                     if is_gtk3():
                         if entries[0] is True:
                             keycodes = [
                                 entry.keycode for entry in entries[1]
                             ]
                     else:
                         keycodes = [entry[0] for entry in entries]
                     for keycode in keycodes:
                         l = self.keycodes_for_modifier_keynames.setdefault(
                             keyname, [])
                         if keycode not in l:
                             l.append(keycode)
     log("compute_modifier_keynames: keycodes_for_modifier_keynames=%s",
         self.keycodes_for_modifier_keynames)
예제 #2
0
 def __init__(self, *args):
     KeyboardHelper.__init__(self, *args)
     #used for delaying the sending of keymap changes
     #(as we may be getting dozens of such events at a time)
     self._keymap_changing = False
     self._keymap_change_handler_id = None
     self._keymap = get_default_keymap()
     self.update()
     if self._keymap:
         self._keymap_change_handler_id = self._keymap.connect("keys-changed", self.keymap_changed)
예제 #3
0
파일: keymap.py 프로젝트: rudresh2319/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3
    gdk = import_gdk()
    keymap = get_default_keymap()
    keycodes = []
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("%s.get_entries_for_keycode(%s)=%s", keymap, i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                name = gdk.keyval_name(keyval)
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(key.keycode),
                                     nn(key.group), nn(key.level)))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                #ugly workaround for "period" key on win32 (see ticket 588)
                #which is reported as "period" instead of "KP_Decimal",
                #despite being on the numeric keypad just like all the other KP_* keys...
                if name == "period" and keyval == 46 and keycode == 110:
                    name = "KP_Decimal"
                elif name == "dead_tilde" and keyval == 65107 and keycode == 50:
                    name = "asciitilde"
                elif name == "dead_grave" and keyval == 65104 and keycode == 55:
                    name = "grave"
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(keycode),
                                     nn(group), nn(level)))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #4
0
파일: keymap.py 프로젝트: svn2github/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol", "0xffffff"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3

    gdk = import_gdk()
    keymap = get_default_keymap()
    log(
        "get_default_keymap()=%s, direction=%s, bidirectional layouts: %s",
        keymap,
        keymap.get_direction(),
        keymap.have_bidi_layouts(),
    )
    keycodes = []
    for i in range(0, 2 ** 8):
        entries = keymap.get_entries_for_keycode(i)
        log("get_entries_for_keycode(%s)=%s", i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                keycode = key.keycode
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode or 0, key.group or 0, key.level or 0))
        else:
            # gtk2:
            for keyval, keycode, group, level in entries:
                # assert keycode==i
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode or 0, group or 0, level or 0))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #5
0
파일: keymap.py 프로젝트: svn2github/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3
    gdk = import_gdk()
    keymap = get_default_keymap()
    keycodes=[]
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("%s.get_entries_for_keycode(%s)=%s", keymap, i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                name = gdk.keyval_name(keyval)
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(key.keycode), nn(key.group), nn(key.level)))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                #ugly workaround for "period" key on win32 (see ticket 588)
                #which is reported as "period" instead of "KP_Decimal",
                #despite being on the numeric keypad just like all the other KP_* keys...
                if name=="period" and keyval==46 and keycode==110:
                    name = "KP_Decimal"
                elif name=="dead_tilde" and keyval==65107 and keycode==50:
                    name = "asciitilde"
                elif name=="dead_grave" and keyval==65104 and keycode==55:
                    name = "grave"
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(keycode), nn(group), nn(level)))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #6
0
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol", "0xffffff"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3
    gdk = import_gdk()
    keymap = get_default_keymap()
    log("get_default_keymap()=%s, direction=%s, bidirectional layouts: %s",
        keymap, keymap.get_direction(), keymap.have_bidi_layouts())
    keycodes = []
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("get_entries_for_keycode(%s)=%s", i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                keycode = key.keycode
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                group = key.group or 0
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode
                                     or 0, group, key.level or 0))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode
                                     or 0, group or 0, level or 0))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #7
0
 def keymap_changed(self, *args):
     log("keymap_changed%s", args)
     if self._keymap_change_handler_id:
         self._keymap.disconnect(self._keymap_change_handler_id)
         self._keymap_change_handler_id = None
     self._keymap = get_default_keymap()
     if self._keymap_changing:
         #timer due already
         return
     self._keymap_changing = True
     def do_keys_changed():
         #re-register the change handler:
         self._keymap_change_handler_id = self._keymap.connect("keys-changed", self.keymap_changed)
         self._keymap_changing = False
         if self.locked:
             #automatic changes not allowed!
             log.info("ignoring keymap change: layout is locked to '%s'", self.layout_str())
             return
         if self.update():
             log.info("keymap has been changed to '%s', sending updated mappings to the server", self.layout_str())
             if self.xkbmap_layout:
                 self.send_layout()
             self.send_keymap()
     glib.timeout_add(500, do_keys_changed)
예제 #8
0
 def watch_keymap_changes(self):
     ### Set up keymap change notification:
     keymap = get_default_keymap()
     keymap.connect("keys-changed", self._keys_changed)