def __init__(self, wsid, x, y, width, height, color=0x000000): if x < 0 or y < 0 or width < 1 or height < 1: self.wid = 0 return self._root_depth = connection.setup.roots[0].root_depth self._root_visual = connection.setup.roots[0].root_visual self._pixel = color self.wid = connection.conn.generate_id() connection.get_core().CreateWindow( self._root_depth, self.wid, XROOT.wid, x, y, width, height, 0, xcb.xproto.WindowClass.InputOutput, self._root_visual, xcb.xproto.CW.BackPixel, [self._pixel] ) self.set_override_redirect(True) self._set_property('_NET_WM_NAME', 'Internal PyTyle Window') connection.get_core().MapWindow(self.wid) connection.push()
def set_override_redirect(self, override_redirect): try: connection.get_core().ChangeWindowAttributes( self.wid, xcb.xproto.CW.OverrideRedirect, [override_redirect] ) except: print traceback.format_exc()
def stack(self, above): try: connection.get_core().ConfigureWindow( self.wid, xcb.xproto.ConfigWindow.StackMode, [xcb.xproto.StackMode.Above if above else xcb.xproto.StackMode.Below] ) except: return False
def set_event_masks(self, event_masks): try: connection.get_core().ChangeWindowAttributes( self.wid, xcb.xproto.CW.EventMask, [event_masks] ) except: print traceback.format_exc()
def build_cache(): if Atom._cache: return for atom in atoms: Atom._cache[atom] = connection.get_core().InternAtom(False, len(atom), atom).reply().atom if atoms[atom][0] is not None and atoms[atom][0] not in Atom._cache: Atom._cache[atoms[atom][0]] = ( connection.get_core().InternAtom(False, len(atoms[atom][0]), atoms[atom][0]).reply().atom )
def _get_geometry(self): try: raw = connection.get_core().GetGeometry(self.wid).reply() return (raw.x, raw.y, raw.width, raw.height) except: return False
def _get_property(self, atom_name): try: if not Atom.get_type_name(atom_name): return '' rsp = connection.get_core().GetProperty( False, self.wid, Atom.get_atom(atom_name), Atom.get_atom_type(atom_name), 0, (2 ** 32) - 1 ).reply() if Atom.get_type_name(atom_name) in ('UTF8_STRING', 'STRING'): if atom_name == 'WM_CLASS': return Atom.null_terminated_to_strarray(rsp.value) else: return Atom.ords_to_str(rsp.value) elif Atom.get_type_name(atom_name) in ('UTF8_STRING[]', 'STRING[]'): return Atom.null_terminated_to_strarray(rsp.value) else: return list(struct.unpack('I' * (len(rsp.value) / 4), rsp.value.buf())) except: pass
def query_tree_children(self): try: children = connection.get_core().QueryTree(self.wid).reply().children return [wid for wid in children] except: return False
def get_atom(name): if not Atom._cache: raise Exception("Atom cache has not been built") if name not in Atom._cache: Atom._cache[name] = connection.get_core().InternAtom(True, len(name), name).reply().atom return Atom._cache[name]
def _set_property(self, atom_name, value): try: if isinstance(value, list): data = struct.pack(len(value) * 'I', *value) data_len = len(value) else: value = str(value) data_len = len(value) data = value connection.get_core().ChangeProperty( xcb.xproto.PropMode.Replace, self.wid, Atom.get_atom(atom_name), Atom.get_atom_type(atom_name), Atom.get_atom_length(atom_name), data_len, data ) except: print traceback.format_exc()
def _send_client_event_exec(self, to_wid, message_type, data, format=32, event_mask=xcb.xproto.EventMask.SubstructureRedirect): try: data = data + ([0] * (5 - len(data))) packed = struct.pack( 'BBH7I', events['ClientMessageEvent'], format, 0, to_wid, message_type, data[0], data[1], data[2], data[3], data[4] ) connection.get_core().SendEvent( False, self.wid, event_mask, packed ) except: print traceback.format_exc()
def __init__(self, wsid, x, y, width, height, color=0x000000): self._root_depth = connection.setup.roots[0].root_depth self._root_visual = connection.setup.roots[0].root_visual self._pixel = color self.wid = connection.conn.generate_id() connection.get_core().CreateWindow( self._root_depth, self.wid, XROOT.wid, x, y, width, height, 0, xcb.xproto.WindowClass.InputOutput, self._root_visual, xcb.xproto.CW.BackPixel, [self._pixel] ) self._set_property('_NET_WM_NAME', 'Place holder') self.set_desktop(wsid) self._set_property('WM_NAME', 'pytyle-internal-window') self._set_property('WM_PROTOCOLS', [Atom.get_atom('WM_DELETE_WINDOW')]) self._set_property( '_PYTYLE_TYPE', [ Atom.get_atom('_PYTYLE_TYPE_PLACE_HOLDER') ] ) #self.set_override_redirect(True) connection.get_core().MapWindow(self.wid) connection.push() self._moveresize(x, y, width, height) connection.push() #self.set_override_redirect(False) connection.push()
def ungrab_key(self, key, modifiers): try: addmods = [ 0, xcb.xproto.ModMask.Lock, xcb.xproto.ModMask._2, xcb.xproto.ModMask._2 | xcb.xproto.ModMask.Lock ] for mod in addmods: cook = connection.get_core().UngrabKeyChecked( key, self.wid, modifiers | mod, ) cook.check() except: print traceback.format_exc() print 'Could not ungrab key:', modifiers, '---', key
def grab_key(self, key, modifiers): try: addmods = [ 0, xcb.xproto.ModMask.Lock, xcb.xproto.ModMask._2, xcb.xproto.ModMask._2 | xcb.xproto.ModMask.Lock ] for mod in addmods: cook = connection.get_core().GrabKeyChecked( True, self.wid, modifiers | mod, key, xcb.xproto.GrabMode.Async, xcb.xproto.GrabMode.Async ) cook.check() return True except xcb.xproto.BadAccess: return False
def close(self): connection.get_core().UnmapWindow(self.wid)
def get_atom_name(num): return Atom.ords_to_str(connection.get_core().GetAtomName(num).reply().name)
def close(self): connection.get_core().DestroyWindow(self.wid)
def query_tree_parent(self): try: return Window(connection.get_core().QueryTree(self.wid).reply().parent) except: return False
def query_pointer(self): return connection.get_core().QueryPointer(self.wid).reply()