def grab_mouse(self): ''' This method grabs a button and binds to press and realease events ''' mods, button = mousebind.parse_buttonstring(config.mouse_move_string) mousebind.grab_button(self.root.win, mods, button) event.connect('ButtonPress', self.root.win, self.handle_mouse_press) event.connect('ButtonRelease', self.root.win, self.handle_mouse_release)
def register_handlers(self): ''' Adds handlers for no_window_events, binds workspace moving keys and grabs the mouse actions we care about ''' print "Registering Handlers" event.connect('MapRequest', None, self.handle_map_event) event.connect('ConfigureRequest', None, self.handle_configure_event) keybind.bind_global_key('KeyRelease', 'Mod4-Right', self.next_workspace) keybind.bind_global_key('KeyRelease', 'Mod4-Left', self.prev_workspace) keybind.bind_global_key('KeyRelease', 'Mod4-k', self.destroy_window) self.grab_mouse()
def __init__(self, wid): self.wid = wid self.name = ewmh.get_wm_name(self.wid).reply() or "N/A" debug("Connecting to %s" % self) window.listen(self.wid, "PropertyChange", "FocusChange") event.connect("PropertyNotify", self.wid, self.cb_property_notify) event.connect("FocusIn", self.wid, self.cb_focus_in) event.connect("FocusOut", self.wid, self.cb_focus_out) # This connects to the parent window (decorations) # We get all resize AND move events... might be too much self.parentid = window.get_parent_window(self.wid) window.listen(self.parentid, "StructureNotify") event.connect("ConfigureNotify", self.parentid, self.cb_configure_notify) debug("Parent: %s" % str(self.parentid)) # A window should only be floating if that is default self.floating = getattr(config, "floats_default", False) # Not currently in a "moving" state self.moving = False # Load some data self.desk = ewmh.get_wm_desktop(self.wid).reply() debug("Desk: %s" % str(self.desk)) # Add it to this desktop's tilers ret = tile.update_client_add(self) # does this work? debug("Ret: %s" % str(ret)) # First cut at saving client geometry self.save() debug("Init finished and save() called %s" % self)
def __init__(self, wid): self.wid = wid self.name = ewmh.get_wm_name(self.wid).reply() or 'N/A' debug('Connecting to %s' % self) window.listen(self.wid, 'PropertyChange', 'FocusChange') event.connect('PropertyNotify', self.wid, self.cb_property_notify) event.connect('FocusIn', self.wid, self.cb_focus_in) event.connect('FocusOut', self.wid, self.cb_focus_out) # This connects to the parent window (decorations) # We get all resize AND move events... might be too much self.parentid = window.get_parent_window(self.wid) window.listen(self.parentid, 'StructureNotify') event.connect('ConfigureNotify', self.parentid, self.cb_configure_notify) # A window should only be floating if that is default self.floating = config.floats_default # Not currently in a "moving" state self.moving = False # Load some data self.desk = ewmh.get_wm_desktop(self.wid).reply() # Add it to this desktop's tilers tile.update_client_add(self) # First cut at saving client geometry self.save()
def bind_key(event_type, wid, key_string, cb): """ Binds a function ``cb`` to a particular key press ``key_string`` on a window ``wid``. Whether it's a key release or key press binding is determined by ``event_type``. ``bind_key`` will automatically hook into the ``event`` module's dispatcher, so that if you're using ``event.main()`` for your main loop, everything will be taken care of for you. :param event_type: Either 'KeyPress' or 'KeyRelease'. :type event_type: str :param wid: The window to bind the key grab to. :type wid: int :param key_string: A string of the form 'Mod1-Control-a'. Namely, a list of zero or more modifiers separated by '-', followed by a single non-modifier key. :type key_string: str :param cb: A first class function with no parameters. :type cb: function :return: True if the binding was successful, False otherwise. :rtype: bool """ assert event_type in ('KeyPress', 'KeyRelease') mods, kc = parse_keystring(key_string) key = (wid, mods, kc) if not kc: print >> sys.stderr, 'Could not find a keycode for %s' % key_string return False if not __keygrabs[key] and not grab_key(wid, mods, kc): return False __keybinds[key].append(cb) __keygrabs[key] += 1 if not event.is_connected(event_type, wid, __run_keybind_callbacks): event.connect(event_type, wid, __run_keybind_callbacks) return True
def handle_map_event(self, evt): ''' window mapping operations occur here ''' win = self.win_store.get_window(evt.window) if not win: return try: state = win.get_wm_state() if state and state['state'] == icccm.State.Withdrawn: return win.map() except xproto.BadWindow: return self.win_store.add(win) self.current_workspace.update() event.connect('DestroyNotify', win.win, self.handle_unmap_event) event.connect('UnmapNotify', win.win, self.handle_unmap_event) eventmask = [xproto.EventMask.EnterWindow] self.conn.core.ChangeWindowAttributes(win.win, xproto.CW.EventMask, eventmask) event.connect('EnterNotify', win.win, self.handle_enter_event) pointer_pos = self.conn.core.QueryPointer(self.root.win).reply() ifwin = self.win_store.get_window_by_pos(pointer_pos.root_x, pointer_pos.root_y) if ifwin: ifwin.focus()
def scan_windows(self): q = self.conn.core.QueryTree(self.root.win).reply() for item in q.children: win = Window(item, self.conn, self) attrs = win.get_attributes() state = win.get_wm_state() if attrs and attrs.map_state == xproto.MapState.Unmapped: #or attrs.overide_redirect: continue if state and state['state'] == icccm.State.Withdrawn: continue eventmask = [xproto.EventMask.EnterWindow] self.conn.core.ChangeWindowAttributes(win.win, xproto.CW.EventMask, eventmask) if not win.get_wm_transient_for(): event.connect('DestroyNotify', win.win, self.handle_unmap_event) event.connect('UnmapNotify', win.win, self.handle_unmap_event) if win.strut: self.screen.set_strut(win.strut) self.win_store.add(win) event.connect('EnterNotify', win.win, self.handle_enter_event)
if keybind.grab_keyboard(xpybutil.root).status == GS.Success: grabbing = cb def cb_get_letter(e): global grabbing if grabbing is not None: keybind.ungrab_keyboard() sym = keybind.get_keysym(e.detail) letter = keybind.get_keysym_string(sym) if len(letter) == 1 and ord(letter) in range(ord('a'), ord('z') + 1): grabbing(letter.lower()) grabbing = None # This has to come first so it is called first in the event loop event.connect('KeyPress', xpybutil.root, cb_get_letter) for key_str, fun_str in keybinds.iteritems(): if fun_str not in globals(): print >> sys.stderr, 'No such function %s for %s' % (fun_str, key_str) continue fun = globals()[fun_str] if not keybind.bind_global_key('KeyPress', key_str, fun): print >> sys.stderr, 'Could not bind %s to %s' % (key_str, fun_str) event.main()
key = (e.event, mods, kc) for cb in __keybinds.get(key, []): try: cb(e) except TypeError: cb() def __regrab(changes): """ Takes a dictionary of changes (mapping old keycode to new keycode) and regrabs any keys that have been changed with the updated keycode. :param changes: Mapping of changes from old keycode to new keycode. :type changes: dict :rtype: void """ for wid, mods, kc in __keybinds.keys(): if kc in changes: ungrab_key(wid, mods, kc) grab_key(wid, mods, changes[kc]) old = (wid, mods, kc) new = (wid, mods, changes[kc]) __keybinds[new] = __keybinds[old] del __keybinds[old] if conn is not None: update_keyboard_mapping(None) event.connect('MappingNotify', None, update_keyboard_mapping)
d = ewmh.get_wm_desktop(client).reply() if d == 0xffffffff: debug('Ignoring %s because it\'s on all desktops' \ '(not implemented)' % nm) return True return False def cb_property_notify(e): aname = util.get_atom_name(e.atom) if aname == '_NET_CLIENT_LIST_STACKING': update_clients() event.connect('PropertyNotify', xpybutil.root, cb_property_notify) ########NEW FILE######## __FILENAME__ = config import os import os.path import sys xdg = os.getenv('XDG_CONFIG_HOME') or os.path.join(os.getenv('HOME'), '.config') conffile = os.path.join(xdg, 'pytyle3', 'config.py') if not os.access(conffile, os.R_OK): conffile = os.path.join('/', 'etc', 'xdg', 'pytyle3', 'config.py') if not os.access(conffile, os.R_OK): print >> sys.stderr, 'UNRECOVERABLE ERROR: ' \
def setup(): window.listen(xpybutil.root, "PropertyChange") event.connect("PropertyNotify", xpybutil.root, handleEvents) t = Thread(target=event.main) t.start() print("desktops setup")
for cb in __keybinds.get(key, []): try: cb(e) except TypeError: cb() def __regrab(changes): """ Takes a dictionary of changes (mapping old keycode to new keycode) and regrabs any keys that have been changed with the updated keycode. :param changes: Mapping of changes from old keycode to new keycode. :type changes: dict :rtype: void """ for wid, mods, kc in __keybinds.keys(): if kc in changes: ungrab_key(wid, mods, kc) grab_key(wid, mods, changes[kc]) old = (wid, mods, kc) new = (wid, mods, changes[kc]) __keybinds[new] = __keybinds[old] del __keybinds[old] if conn is not None: update_keyboard_mapping(None) event.connect('MappingNotify', None, update_keyboard_mapping)
def cb_get_letter(e): global grabbing if grabbing is not None: keybind.ungrab_keyboard() sym = keybind.get_keysym(e.detail) letter = keybind.get_keysym_string(sym) if len(letter) == 1 and ord(letter) in range(ord("a"), ord("z") + 1): grabbing(letter.lower()) grabbing = None # This has to come first so it is called first in the event loop event.connect("KeyPress", xpybutil.root, cb_get_letter) for key_str, fun_str in keybinds.items(): if fun_str not in globals(): print("No such function %s for %s" % (fun_str, key_str), file=sys.stderr) continue fun = globals()[fun_str] if not keybind.bind_global_key("KeyPress", key_str, fun): print("Could not bind %s to %s" % (key_str, fun_str), file=sys.stderr) event.main()
grabbing = cb def cb_get_letter(e): global grabbing if grabbing is not None: keybind.ungrab_keyboard() sym = keybind.get_keysym(e.detail) letter = keybind.get_keysym_string(sym) if len(letter) == 1 and ord(letter) in range(ord('a'), ord('z') + 1): grabbing(letter.lower()) grabbing = None # This has to come first so it is called first in the event loop event.connect('KeyPress', xpybutil.root, cb_get_letter) for key_str, fun_str in keybinds.iteritems(): if fun_str not in globals(): print >> sys.stderr, 'No such function %s for %s' % (fun_str, key_str) continue fun = globals()[fun_str] if not keybind.bind_global_key('KeyPress', key_str, fun): print >> sys.stderr, 'Could not bind %s to %s' % (key_str, fun_str) event.main()