def test_is_fullscreen_handles_none_wm_states(monkeypatch): class WMStateResponse: def reply(self): return None monkeypatch.setattr("xpybutil.ewmh.get_wm_state", lambda _: WMStateResponse()) win = Window(123) win.is_fullscreen()
def _config_allows_flash(self, window: Window, rule: Dict) -> bool: """Check whether a config parameter disallows a window from flashing. Returns ------- If window should be flashed, this function returns True, else False. """ if self.track_workspaces: self.prev_workspace = self.current_workspace self.current_workspace = get_focused_workspace() if not rule.get("flash_on_focus"): logging.debug( f"flash_on_focus is False for window {window.id}, ignoring...") return False if rule.get("flash_lone_windows") != "always": if len(list_mapped_windows(self.current_workspace)) < 2: if (rule.get("flash_lone_windows") == "never" or (self.current_workspace != self.prev_workspace and rule.get("flash_lone_windows") == "on_open_close") or (self.current_workspace == self.prev_workspace and rule.get("flash_lone_windows") == "on_switch")): logging.debug( "Current workspace has <2 windows, ignoring...") return False if rule.get("flash_fullscreen") is not True: if window.is_fullscreen(): logging.debug("Window is fullscreen, ignoring...") return False return True
def _flash(self, window: Window) -> None: """Flash a window. This function just iterates across `self.flash_series` and modifies the window opacity accordingly. It waits `self.timechunk` between modifications. """ self.progress[window.id] = 0 while self.progress[window.id] < self.ntimepoints: target_opacity = self.flash_series[self.progress[window.id]] window.set_opacity(target_opacity) sleep(self.timechunk) self.progress[window.id] += 1 logging.debug(f"Resetting window {window.id} opacity to default") window.set_opacity(self.default_opacity) del self.progress[window.id]
def _match(self, window: Window) -> Tuple[Dict, Flasher]: """Find a flash rule which matches window.""" for i, (rule, flasher) in enumerate(zip(self.rules, self.flashers)): if window.match(rule): if i < len(self.rules) - 1: logging.debug( f"Window {window.id} matches criteria of rule {i}") return rule, flasher return rule, flasher
def create_blank_window(wm_name=None, wm_class=None): """Create a blank Xorg window.""" setup = xpybutil.conn.get_setup() window = Window(xpybutil.conn.generate_id()) xpybutil.conn.core.CreateWindow( setup.roots[0].root_depth, window.id, setup.roots[0].root, 0, 0, 640, 480, 0, xcffib.xproto.WindowClass.InputOutput, setup.roots[0].root_visual, xcffib.xproto.CW.BackPixel | xcffib.xproto.CW.EventMask, [ setup.roots[0].white_pixel, xcffib.xproto.EventMask.Exposure | xcffib.xproto.EventMask.KeyPress, ], ) xpybutil.conn.core.MapWindow(window.id) xpybutil.conn.flush() if wm_class: window.set_class(wm_class[0], wm_class[1]) if wm_name: window.set_name(wm_name) return window
def test_none_windows_raise_error(): with raises(WMError): Window(None)
def test_window_nonequality_to_none_raises_error(): with raises(TypeError): Window(123) != None
def test_window_raises_wm_error_if_window_is_none(): with raises(WMError): Window(None)
def test_display_handler_handles_focus_shifts(display_handler, windows): with producer_running(display_handler): change_focus(windows[1]) change_focus(windows[0]) queued = queue_to_list(display_handler.queue) assert queued == [ WMEvent(window=windows[1], event_type=WMEventType.FOCUS_SHIFT), WMEvent(window=windows[0], event_type=WMEventType.FOCUS_SHIFT), ] @mark.parametrize( "window1,window2,should_be_equal", [(Window(123), Window(324), False), (Window(23), Window(23), True)], ) def test_window_equality(window1, window2, should_be_equal): assert (window1 == window2) == should_be_equal def test_window_equality_to_none_raises_error(): with raises(TypeError): Window(123) == None def test_window_nonequality_to_none_raises_error(): with raises(TypeError): Window(123) != None
def test_flash_nonexistant_window_ignored(flasher): flasher.flash(Window(0))