コード例 #1
0
ファイル: test_bencode.py プロジェクト: rudresh2319/Xpra
def test_large_dict():
    import gtk.gdk
    from wimpiggy.lowlevel import get_keycode_mappings          #@UnresolvedImport
    mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
    b = bencode(mappings)
    print("bencode(%s)=%s" % (mappings, b))
    d = bdecode(b)
    print("bdecode(%s)=%s" % (b, d))
コード例 #2
0
def keys_changed(*args):
	global keycode_mappings, modifier_mappings
	print("keys_changed(%s)" % str(args))
	new_keycode_mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
	new_modifier_mappings = get_modifier_mappings()
	if new_keycode_mappings!=keycode_mappings:
		print("modifier mappings have changed: %s" % new_modifier_mappings)
		modifier_mappings = new_modifier_mappings
	if new_keycode_mappings!=keycode_mappings:
		print("keycode mappings have changed: %s" % new_keycode_mappings)
		keycode_mappings = new_keycode_mappings
コード例 #3
0
def keys_changed(*args):
    global keycode_mappings, modifier_mappings
    print("keys_changed(%s)" % str(args))
    new_keycode_mappings = get_keycode_mappings(
        gtk.gdk.get_default_root_window())
    new_modifier_mappings = get_modifier_mappings()
    if new_keycode_mappings != keycode_mappings:
        print("modifier mappings have changed: %s" % new_modifier_mappings)
        modifier_mappings = new_modifier_mappings
    if new_keycode_mappings != keycode_mappings:
        print("keycode mappings have changed: %s" % new_keycode_mappings)
        keycode_mappings = new_keycode_mappings
コード例 #4
0
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

from wimpiggy.lowlevel import get_keycode_mappings  #@UnresolvedImport
from wimpiggy.lowlevel import get_modifier_mappings  #@UnresolvedImport

keycode_mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
modifier_mappings = get_modifier_mappings()


def keys_changed(*args):
    global keycode_mappings, modifier_mappings
    print("keys_changed(%s)" % str(args))
    new_keycode_mappings = get_keycode_mappings(
        gtk.gdk.get_default_root_window())
    new_modifier_mappings = get_modifier_mappings()
    if new_keycode_mappings != keycode_mappings:
        print("modifier mappings have changed: %s" % new_modifier_mappings)
        modifier_mappings = new_modifier_mappings
    if new_keycode_mappings != keycode_mappings:
        print("keycode mappings have changed: %s" % new_keycode_mappings)
        keycode_mappings = new_keycode_mappings


def main():
    keymap = gtk.gdk.keymap_get_default()
    print("keymap=%s" % keymap)
    keymap.connect("keys-changed", keys_changed)
コード例 #5
0
ファイル: xkbhelper.py プロジェクト: svn2github/Xpra
def set_all_keycodes(xkbmap_x11_keycodes, xkbmap_keycodes, preserve_server_keycodes, modifiers):
    """
        Clients that have access to raw x11 keycodes should provide
        an xkbmap_x11_keycodes map, we otherwise fallback to using
        the xkbmap_keycodes gtk keycode list.
        We try to preserve the initial keycodes if asked to do so,
        we retrieve them from the current server keymap and combine
        them with the given keycodes.
        The modifiers dict can be obtained by calling
        get_modifiers_from_meanings or get_modifiers_from_keycodes.
        We use it to ensure that two modifiers are not
        mapped to the same keycode (which is not allowed).
        We return a translation map for keycodes after setting them up,
        the key is (keycode, keysym) and the value is the server keycode.
    """
    debug("set_all_keycodes(%s.., %s.., %s.., %s)", str(xkbmap_x11_keycodes)[:60], str(xkbmap_keycodes)[:60], str(preserve_server_keycodes)[:60], modifiers)

    #so we can validate entries:
    keysym_to_modifier = {}
    for modifier, keysyms in modifiers.items():
        for keysym in keysyms:
            existing_mod = keysym_to_modifier.get(keysym)
            if existing_mod and existing_mod!=modifier:
                log.error("ERROR: keysym %s is mapped to both %s and %s !", keysym, modifier, existing_mod)
            else:
                keysym_to_modifier[keysym] = modifier
    debug("keysym_to_modifier=%s", keysym_to_modifier)

    def modifiers_for(entries):
        """ entries can only point to a single modifier - verify """
        modifiers = set()
        for keysym, _ in entries:
            modifier = keysym_to_modifier.get(keysym)
            if modifier:
                modifiers.add(modifier)
        return modifiers

    def filter_mappings(mappings):
        filtered = {}
        for keycode, entries in mappings.items():
            mods = modifiers_for(entries)
            if len(mods)>1:
                log.warn("keymapping removed invalid keycode entry %s pointing to more than one modifier (%s): %s", keycode, mods, entries)
                continue
            #now remove entries for keysyms we don't have:
            f_entries = set([(keysym, index) for keysym, index in entries if parse_keysym(keysym) is not None])
            if len(f_entries)==0:
                log("keymapping removed invalid keycode entry %s pointing to only unknown keysyms: %s", keycode, entries)
                continue
            filtered[keycode] = f_entries
        return filtered

    #get the list of keycodes (either from x11 keycodes or gtk keycodes):
    if xkbmap_x11_keycodes and len(xkbmap_x11_keycodes)>0:
        debug("using x11 keycodes: %s", xkbmap_x11_keycodes)
        dump_dict(xkbmap_x11_keycodes)
        keycodes = indexed_mappings(xkbmap_x11_keycodes)
    else:
        debug("using gtk keycodes: %s", xkbmap_keycodes)
        keycodes = gtk_keycodes_to_mappings(xkbmap_keycodes)
    #filter to ensure only valid entries remain:
    debug("keycodes=%s", keycodes)
    keycodes = filter_mappings(keycodes)

    #now lookup the current keycodes (if we need to preserve them)
    preserve_keycode_entries = {}
    if preserve_server_keycodes:
        import gtk.gdk
        preserve_keycode_entries = get_keycode_mappings(gtk.gdk.get_default_root_window())
        debug("preserved mappings:")
        dump_dict(preserve_keycode_entries)
        debug("preserve_keycode_entries=%s", preserve_keycode_entries)
        preserve_keycode_entries = filter_mappings(indexed_mappings(preserve_keycode_entries))

    kcmin, kcmax = get_minmax_keycodes()
    for try_harder in (False, True):
        trans, new_keycodes, missing_keycodes = translate_keycodes(kcmin, kcmax, keycodes, preserve_keycode_entries, keysym_to_modifier, try_harder)
        if len(missing_keycodes)==0:
            break
    instructions = keymap_to_xmodmap(new_keycodes)
    unset = apply_xmodmap(instructions)
    debug("unset=%s", unset)
    return trans
コード例 #6
0
ファイル: xkbhelper.py プロジェクト: rudresh2319/Xpra
def set_all_keycodes(xkbmap_x11_keycodes, xkbmap_keycodes,
                     preserve_server_keycodes, modifiers):
    """
        Clients that have access to raw x11 keycodes should provide
        an xkbmap_x11_keycodes map, we otherwise fallback to using
        the xkbmap_keycodes gtk keycode list.
        We try to preserve the initial keycodes if asked to do so,
        we retrieve them from the current server keymap and combine
        them with the given keycodes.
        The modifiers dict can be obtained by calling
        get_modifiers_from_meanings or get_modifiers_from_keycodes.
        We use it to ensure that two modifiers are not
        mapped to the same keycode (which is not allowed).
        We return a translation map for keycodes after setting them up,
        the key is (keycode, keysym) and the value is the server keycode.
    """
    debug("set_all_keycodes(%s.., %s.., %s.., %s)",
          str(xkbmap_x11_keycodes)[:60],
          str(xkbmap_keycodes)[:60],
          str(preserve_server_keycodes)[:60], modifiers)

    #so we can validate entries:
    keysym_to_modifier = {}
    for modifier, keysyms in modifiers.items():
        for keysym in keysyms:
            existing_mod = keysym_to_modifier.get(keysym)
            if existing_mod and existing_mod != modifier:
                log.error("ERROR: keysym %s is mapped to both %s and %s !",
                          keysym, modifier, existing_mod)
            else:
                keysym_to_modifier[keysym] = modifier
    debug("keysym_to_modifier=%s", keysym_to_modifier)

    def modifiers_for(entries):
        """ entries can only point to a single modifier - verify """
        modifiers = set()
        for keysym, _ in entries:
            modifier = keysym_to_modifier.get(keysym)
            if modifier:
                modifiers.add(modifier)
        return modifiers

    def filter_mappings(mappings):
        filtered = {}
        for keycode, entries in mappings.items():
            mods = modifiers_for(entries)
            if len(mods) > 1:
                log.warn(
                    "keymapping removed invalid keycode entry %s pointing to more than one modifier (%s): %s",
                    keycode, mods, entries)
                continue
            #now remove entries for keysyms we don't have:
            f_entries = set([(keysym, index) for keysym, index in entries
                             if parse_keysym(keysym) is not None])
            if len(f_entries) == 0:
                log(
                    "keymapping removed invalid keycode entry %s pointing to only unknown keysyms: %s",
                    keycode, entries)
                continue
            filtered[keycode] = f_entries
        return filtered

    #get the list of keycodes (either from x11 keycodes or gtk keycodes):
    if xkbmap_x11_keycodes and len(xkbmap_x11_keycodes) > 0:
        debug("using x11 keycodes: %s", xkbmap_x11_keycodes)
        dump_dict(xkbmap_x11_keycodes)
        keycodes = indexed_mappings(xkbmap_x11_keycodes)
    else:
        debug("using gtk keycodes: %s", xkbmap_keycodes)
        keycodes = gtk_keycodes_to_mappings(xkbmap_keycodes)
    #filter to ensure only valid entries remain:
    debug("keycodes=%s", keycodes)
    keycodes = filter_mappings(keycodes)

    #now lookup the current keycodes (if we need to preserve them)
    preserve_keycode_entries = {}
    if preserve_server_keycodes:
        import gtk.gdk
        preserve_keycode_entries = get_keycode_mappings(
            gtk.gdk.get_default_root_window())
        debug("preserved mappings:")
        dump_dict(preserve_keycode_entries)
        debug("preserve_keycode_entries=%s", preserve_keycode_entries)
        preserve_keycode_entries = filter_mappings(
            indexed_mappings(preserve_keycode_entries))

    kcmin, kcmax = get_minmax_keycodes()
    for try_harder in (False, True):
        trans, new_keycodes, missing_keycodes = translate_keycodes(
            kcmin, kcmax, keycodes, preserve_keycode_entries,
            keysym_to_modifier, try_harder)
        if len(missing_keycodes) == 0:
            break
    instructions = keymap_to_xmodmap(new_keycodes)
    unset = apply_xmodmap(instructions)
    debug("unset=%s", unset)
    return trans
コード例 #7
0
def main():
    mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
    print("mappings=%s" % mappings)
    print("")
    for k, v in mappings.items():
        print("%s\t\t:\t%s" % (k, v))
コード例 #8
0
def main():
	mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
	print("mappings=%s" % mappings)
	print("")
	for k,v in mappings.items():
		print("%s\t\t:\t%s" % (k, v))
コード例 #9
0
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk


from wimpiggy.lowlevel import get_keycode_mappings		#@UnresolvedImport
from wimpiggy.lowlevel import get_modifier_mappings		#@UnresolvedImport

keycode_mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
modifier_mappings = get_modifier_mappings()

def keys_changed(*args):
	global keycode_mappings, modifier_mappings
	print("keys_changed(%s)" % str(args))
	new_keycode_mappings = get_keycode_mappings(gtk.gdk.get_default_root_window())
	new_modifier_mappings = get_modifier_mappings()
	if new_keycode_mappings!=keycode_mappings:
		print("modifier mappings have changed: %s" % new_modifier_mappings)
		modifier_mappings = new_modifier_mappings
	if new_keycode_mappings!=keycode_mappings:
		print("keycode mappings have changed: %s" % new_keycode_mappings)
		keycode_mappings = new_keycode_mappings

def main():
	keymap = gtk.gdk.keymap_get_default()
	print("keymap=%s" % keymap)
	keymap.connect("keys-changed", keys_changed)

	gtk.main()