def parse_output(self, data): groups = self.GROUP_RE.split(data) devs = [] for g in groups: m = self.DEVICE_RE.search(g) if not m or not self.FROM_ALSA.has_key(m.group(1)): continue dev = self.FROM_ALSA[m.group(1)] mono = None left = None right = None for channel, volume in self.VOLUME_RE.findall(g): if channel == 'Mono': mono = int(volume) elif channel == 'Front Left': left = int(volume) elif channel == 'Front Right': right = int(volume) wmanager.debug('mixer', 'dev %s: %s,%s or %s', dev, left, right, mono) if left is not None and right is not None: devs.append((dev, (left, right))) elif mono is not None: devs.append((dev, mono)) return devs
def M5_n(self, evt): wmanager.debug('keys', 'Moving window to new view') if self.wm.current_client: c = self.wm.current_client c.iconify() self.wm.current_screen.view_new() c.deiconify()
def S_Pause(self, evt): wmanager.debug('keys', 'dropping keygrabs temporarily') # First release all our grabs. They will be reinstalled # by BypassHandler when it exits self._ungrab() BypassHandler(self)
def __wm_init__(self): for ifclass in INTERFACE_CLASSES: interface = ifclass() status = self.system(interface.probe_cmd(), fg=1) # Probe OK? if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0: wmanager.debug('mixer', 'using interface %s', ifclass.__name__) self.mixer_interface = interface break else: wmanager.debug('mixer', 'could not find any interface to use') self.mixer_interface = None return self.dispatch.add_handler(MixerIOEventType, self.mixer_io_event) self.dispatch.add_handler(MixerTimeoutEventType, self.mixer_timout) self.mixer_devs = {} self.mixer_mute_devs = {} self.mixer_status_msg = None self.mixer_timer_event = None self.mixer_cmd_out = None self.mixer_update_settings()
def __client_init__(self): self.traceim_message = None filters = None for f in self.traceim_filters: if f.enable(self): if filters is None: wmanager.debug( 'traceim', 'Enabling IM tracing for %s' % self.get_title()) self.dispatch.add_handler(X.PropertyNotify, self.traceim_handle_property) self.dispatch.add_handler(wmevents.ClientIconified, self.traceim_handle_iconified) self.dispatch.add_handler(wmevents.ClientDeiconified, self.traceim_handle_iconified) self.dispatch.add_handler(wmevents.RemoveClient, self.traceim_handle_removed) filters = [f] else: filters.append(f) if filters: self.traceim_filters = filters self.traceim_message = None self.traceim_update()
def mixer_set(self, dev, val1, val2=None): if self.mixer_interface is None: wmanager.debug('mixer', 'no mixer interface') return try: values = self.mixer_devs[dev] except KeyError: return assert val1 >= 0 and val1 <= 100 assert val2 is None or (val2 >= 0 and val2 <= 100) if type(values) is types.TupleType: if val2 is None: val2 = val1 self.mixer_devs[dev] = (val1, val2) cmd = self.mixer_interface.set_cmd(dev, val1, val2) else: self.mixer_devs[dev] = val1 cmd = self.mixer_interface.set_cmd(dev, val1, None) if cmd: self.system(cmd, fg=1) try: del self.mixer_mute_devs[dev] except KeyError: pass
def __screen_client_init__(self): "Create the initial pane object for this screen." wmanager.debug('panesScreen', 'Initializing screen %d', self.number) self.dispatch.add_handler(X.ConfigureRequest, self.panes_configure) pane = Pane(self, 0, 0, self.root_width, self.root_height) self.panes_fullscreen(pane) self.wm.panes_add(pane)
def KP_Begin(self, event): wmanager.debug('keys', 'Entering move-resize mode') if self.wm.focus_client: try: mv = MoveResizeKeys(self.wm, self.dispatch, self.wm.focus_client, event.time) except keys.error, status: wmanager.debug('keys', 'Grabbing keyboard failed: %d', status)
def next_window(self): "Move to the next window in this pane." wmanager.debug('Pane', 'next window') clients = self.screen.query_clients(panefilter(self), 1) if len(clients) > 1: self.deactivate() self.window = clients[0] self.activate()
def add_units(self, cls): for unit, path in self.find_units(cls.PROC_DIR): try: b = cls(unit, path) self.infos.append(b) self.units[(cls.EVENT, unit)] = b except (IOError, BadInfo), e: wmanager.debug('acpi', 'could not add %s %s: %s', cls.__name__, unit, e)
def panes_prev(self): "Move to the previous pane." if len(self.panes_list) > 1: wmanager.debug('panesManager', 'previous pane') self.panes_list[self.panes_current].deactivate() self.panes_current = self.panes_current - 1 if self.panes_current < 0: self.panes_current = len(self.panes_list) - 1 self.panes_list[self.panes_current].activate()
def panes_next(self): "Move to the next pane." if len(self.panes_list) > 1: wmanager.debug('panesManager', 'next pane') self.panes_list[self.panes_current].deactivate() self.panes_current = self.panes_current + 1 if self.panes_current == len(self.panes_list): self.panes_current = 0 self.panes_list[self.panes_current].activate()
def mw_clock_update(self): t = time.localtime(time.time()) s = time.strftime(self.mw_clock_format, t) self.mw_clock_message.set_text(s) wmanager.debug('clock', 'updated to "%s", rescheduling in %d seconds', s, 61 - t[5]) # Trig a timer when minute change self.events.add_timer(event.TimerEvent(ClockEventType, after=61 - t[5]))
def prev_window(self): "Move to the previous window in this pane." wmanager.debug('Pane', 'previous window') clients = self.screen.query_clients(panefilter(self), 1) if len(clients) > 1: self.deactivate() # Lower the old window to make it the "next" window. self.window.lowerwindow() self.window = clients[len(clients) - 2] self.activate()
def __wm_screen_init__(self): "Create the list of panes with no current pane." global WM_TRANSIENT_FOR wmanager.debug('panesManager', 'inited') # Warning - if we manage more than one display, this breaks! if not WM_TRANSIENT_FOR: WM_TRANSIENT_FOR = self.display.intern_atom("WM_TRANSIENT_FOR") self.panes_list = [] self.panes_current = None
def Pause(self, evt): wmanager.debug('keys', 'reinstalling keygrabs') self._screen.modewindow_remove_message(self._message) # Delete ourself, and reinstall the callee grabs self._cleanup() self._keyhandler._buildmap() # Remove it, just to be sure there are no circular references del self._keyhandler del self._screen
def S_Pause(self, evt): """Drop all keygrabs until Scroll_Lock is pressed again. Allows clients to recieve keys used by plwm. """ wmanager.debug('keys', 'dropping keygrabs temporarily') # First release all our grabs. They will be reinstalled # when BypassHandler exits self._ungrab() BypassHandler(self)
def add_window(self, window): "Add a window to this pane." wmanager.debug('Pane', 'Adding window %s to pane %s', window, self) if window == self.window: return old = window.panes_pane if old != self: if old: old.remove_window(window) self.place_window(window) window.panes_pane = self if self.window: self.deactivate() self.window = window self.activate()
def mixer_mute(self, dev): """Toggle muteness of DEV.""" if self.mixer_interface is None: wmanager.debug('mixer', 'no mixer interface') return if self.mixer_mute_devs.has_key(dev): old = self.mixer_mute_devs[dev] self.mixer_set(dev, old) else: old = self.mixer_get(dev) self.mixer_set(dev, 0) self.mixer_mute_devs[dev] = old
def mixer_get(self, dev, stereo=0): if self.mixer_interface is None: wmanager.debug('mixer', 'no mixer interface') return None try: values = self.mixer_devs[dev] if type(values) is types.TupleType: return values[0] else: return values except KeyError: return None
def remove_window(self, window): "Tag a window as not belonging to me." wmanager.debug('Pane', 'Removing window %s from pane %s' % (window, self)) window.panes_pane = None if self.window == window: self.deactivate() clients = self.screen.query_clients(panefilter(self), 1) if not clients: self.window = None else: self.window = clients[len(clients) - 1] if self.wm.panes_list[self.wm.panes_current] == self: self.activate()
def do_activate(self): "Activate whatever is currently my window." self.wm.current_screen = self.screen if self.window and not self.window.withdrawn: wmanager.debug( 'Pane', 'Activating window %s in pane %s' % (self.window, self)) # Will raise window and give focus self.window.activate() pos = self.window.panes_pointer_pos if pos: self.window.warppointer(pos[0], pos[1])
def __screen_client_init__(self): "Create the initial pane object for this screen." global WM_TRANSIENT_FOR # Warning - if we manage more than one display, this breaks! if not WM_TRANSIENT_FOR: WM_TRANSIENT_FOR = self.wm.display.intern_atom("WM_TRANSIENT_FOR") self.panes_list = [] self.current_pane = None wmanager.debug('panesScreen', 'Initializing screen %d', self.number) self.dispatch.add_handler(X.ConfigureRequest, self.panes_configure) pane = Pane(self, 0, 0, self.root_width, self.root_height) self.panes_fullscreen(pane) self.panes_add(pane)
def activate(self): "Activate whatever is currently my window." self.wm.current_screen = self.screen if self.screen.current_pane != self: self.screen.current_pane.deactivate() self.screen.current_pane = self if self.window and not self.window.withdrawn: wmanager.debug('Pane', 'Activating window %s in pane %s' % (self.window, self)) self.window.activate() self.window.warppointer() event = paneFocus() event.pane = self self.wm.misc_dispatch.dispatch_event(event)
def add_window(self, window): "Add a window to this pane." if window in self.window_list: return wmanager.debug('Pane', 'Adding window %s to pane %s', window, self) self.window_list.append(window) prev_pane = window.pane if prev_pane != self: if prev_pane: prev_pane.remove_window(window) self.place_window(window) window.pane = self self.window = window self.activate()
class UnixLoad: loadcmd = "/usr/bin/uptime" load_re = re.compile(r'(\d+.\d\d)[, ]+(\d+.\d\d)[, ]+(\d+.\d\d)') def probe(self): return os.path.isfile(self.loadcmd) def get(self, wm): pipes = wm.system(self.loadcmd, redirect = 1) out = pipes[1] try: s = out.readline() except IOError, err: if err.errno == errno.EINTR: s = out.readline() out.close() wmanager.debug('mw_load', 'output: %s', s) m = self.load_re.search(s) if m: return string.join(m.groups(), ' ') else: return ''
def mw_acpi_handle_socket_event(self, evt): if evt.state & event.FileEvent.READ: try: data = self.mw_acpi_socket.recv(200) except socket.error, e: wmanager.debug('acpi', 'failed to receive from event socket: %s', e) data = '' if data: newstatus = self.mw_acpi_interface.handle_event_socket(data) self.mw_acpi_update(newstatus) else: wmanager.debug('acpi', 'event socket closed') self.mw_acpi_socket.close() self.mw_acpi_socket = None self.mw_acpi_socket_event.cancel()
def place_window(self, window = None): "Figure out where the window should be put." if window is None: window = self.window if window is None: return wmanager.debug('Pane', 'Placing window %s for pane %s' % (window, self)) # Bypassing size hints/gravity, they seem useless for tiles. width = self.width - 2 * window.border_width height = self.height - 2 * window.border_width x, y = self.x, self.y x, y, width, height = window.keep_on_screen(x, y, width, height) wmanager.debug('Pane-configure', 'Resizing window from %d, %d to %d, %d' % (window.width, window.height, width, height)) window.moveresize(x, y, width, height)
def mixer_update_settings(self): if self.mixer_interface is None: wmanager.debug('mixer', 'no mixer interface') return if self.mixer_cmd_out is not None: wmanager.debug('mixer', 'previous update command has not finished yet') return pipes = self.system(self.mixer_interface.get_cmd(), redirect=1) self.mixer_cmd_out = pipes[1] self.mixer_cmd_data = '' self.mixer_cmd_event = event.FileEvent(MixerIOEventType, self.mixer_cmd_out, event.FileEvent.READ) self.events.add_file(self.mixer_cmd_event)
def handle_event(self, eventstr): m = self.event_re.match(eventstr) if not m: wmanager.debug('acpi', 'could parse event, closing socket:', eventstr) self.socket.close() return event = m.group(1).replace('/', '_') arg = m.group(2) try: unit = self.units[(event, arg)] except KeyError: wmanager.debug('acpi', 'unknown event: %s', eventstr) return if unit.update(): self.status_changed = 1
def traceim_update(self): m = [] for f in self.traceim_filters: if f.unseen(self): m.append(f.message) if m: m = ' '.join(m) if m != self.traceim_message: wmanager.debug('traceim', 'Unseen IM for %s: %s', self.get_title(), m) self.traceim_message = m self.wm.traceim_add_message(self, m) else: if self.traceim_message: wmanager.debug('traceim', 'No longer unseen IM for %s', self.get_title()) self.traceim_message = None self.wm.traceim_remove_message(self)
def __client_init__(self): "Arrange to open in the current pane." wmanager.debug('Pane', 'Initing client %s', self) # Set this clients gravity if self.window.get_property(WM_TRANSIENT_FOR, Xatom.WINDOW, 0, 1) is not None: self.panes_gravity = self.screen.panes_transient_gravity elif self.sizehints and self.sizehints.flags & Xutil.PMaxSize: self.panes_gravity = self.screen.panes_maxsize_gravity else: self.panes_gravity = self.screen.panes_window_gravity self.pane = None pane = self.screen.current_pane if pane.screen != self.screen: pane = filter(lambda p, m=self.screen: p.screen == m, self.screen.panes_list)[0] pane.add_window(self) self.dispatch.add_handler(X.UnmapNotify, self.panes_unmap) self.dispatch.add_handler(X.DestroyNotify, self.panes_unmap)
def __client_init__(self): "Arrange to open in the current pane." wmanager.debug('Pane', 'Initing client %s', self) # Set this clients gravity if self.window.get_property(WM_TRANSIENT_FOR, Xatom.WINDOW, 0, 1) is not None: self.panes_gravity = self.wm.panes_transient_gravity elif self.sizehints and self.sizehints.flags & Xutil.PMaxSize: self.panes_gravity = self.wm.panes_maxsize_gravity else: self.panes_gravity = self.wm.panes_window_gravity self.panes_pointer_pos = self.panes_pane = None pane = self.wm.panes_list[self.wm.panes_current] if pane.screen != self.screen: pane = filter(lambda p, m=self.screen: p.screen == m, self.wm.panes_list)[0] pane.add_window(self) self.dispatch.add_handler(X.UnmapNotify, self.panes_unmap) self.dispatch.add_handler(X.DestroyNotify, self.panes_unmap)
def mixer_status_view(self, devs=None, stereo=0, timeout=5): if self.mixer_interface is None: wmanager.debug('mixer', 'no mixer interface') return if devs is None: devs = self.mixer_devs.keys() msg = '' for dev in devs: try: val = self.mixer_mute_devs[dev] valstr = 'MUTE:%s' % val except KeyError: try: values = self.mixer_devs[dev] if type(values) is types.TupleType: if stereo: valstr = '%s:%s' % values else: valstr = str(values[0]) else: valstr = str(values) except KeyError: valstr = 'N/A' msg = '%s [%s %s]' % (msg, dev, valstr) if self.mixer_status_msg is None: self.mixer_status_msg = self.current_screen.modestatus_new(msg) else: self.mixer_status_msg.set(msg) if self.mixer_timer_event is not None: self.mixer_timer_event.cancel() self.mixer_timer_event = event.TimerEvent(MixerTimeoutEventType, after=timeout) self.events.add_timer(self.mixer_timer_event)
def place_window(self, window=None): "Figure out where the window should be put." if not window: window = self.window wmanager.debug('Pane', 'Placing window %s for pane %s' % (window, self)) width, height = window.follow_size_hints( self.width - 2 * window.border_width, self.height - 2 * window.border_width) # If it doesn't fit, just force it. if width > self.width - 2 * window.border_width: width = self.width - 2 * window.border_width if height > self.height - 2 * window.border_width: height = self.height - 2 * window.border_width if window.panes_gravity in (X.NorthEastGravity, X.EastGravity, X.SouthEastGravity): x = self.x elif window.panes_gravity in (X.NorthGravity, X.CenterGravity, X.SouthGravity): x = self.x + (self.width - width) / 2 - window.border_width else: x = self.x + self.width - width - (2 * window.border_width) if window.panes_gravity in (X.NorthEastGravity, X.NorthGravity, X.NorthWestGravity): y = self.y elif window.panes_gravity in (X.EastGravity, X.CenterGravity, X.WestGravity): y = self.y + (self.height - height) / 2 - window.border_width else: y = self.y + self.height - height - (2 * window.border_width) x, y, width, height = window.keep_on_screen(x, y, width, height) wmanager.debug( 'Pane-configure', 'Resizing window from %d, %d to %d, %d' % (window.width, window.height, width, height)) window.moveresize(x, y, width, height)
def remove_window(self, window): "Disown a window and cycle a new one into focus." if window.pane != self or window not in self.window_list: return wmanager.debug('Pane', 'Removing window %s from pane %s' % (window, self)) window.pane = None windex = self.window_list.index(window) self.window_list.remove(window) if self.window == window: # Jump back towards the beginning of the window list. if windex > 0: windex -= 1 elif self.window_list != []: windex = 0 else: self.window = None if self.screen.current_pane == self: self.wm.set_current_client(None) return self.window = self.window_list[windex] if self.screen.current_pane == self: self.activate()
def panes_add(self, pane): "Add the given pane to the list of all panes." wmanager.debug('panesManager', 'added pane %s', `pane`) self.panes_list.append(pane) if self.current_pane is None: self.current_pane = self.panes_list[0]
def __screen_client_init__( self ): log.debug( "tritiumScreen. __screen_client_init__" ) "Create the initial pane object for this screen." wmanager.debug( 'panesScreen', 'Initializing screen %d', self.number ) self.dispatch.add_handler( X.ConfigureRequest, self.configure_frame )