def window_unpin() -> None: """unpin window.""" log.misc.debug("window unpin") win = objreg.last_visible_window() win.setWindowFlags( cast( Qt.WindowFlags, win.windowFlags() & ~Qt.WindowStaysOnTopHint, ) ) win.show()
def window_pin() -> None: """pin window to stay always on top.""" log.misc.debug("window pin on top") win = objreg.last_visible_window() win.setWindowFlags( cast( Qt.WindowFlags, win.windowFlags() | Qt.WindowStaysOnTopHint, ) ) win.show()
def get_window(via_ipc, force_window=False, force_tab=False, force_target=None): """Helper function for app.py to get a window id. Args: via_ipc: Whether the request was made via IPC. force_window: Whether to force opening in a window. force_tab: Whether to force opening in a tab. force_target: Override the new-instance-open-target config """ if force_window and force_tab: raise ValueError("force_window and force_tab are mutually exclusive!") if not via_ipc: # Initial main window return 0 window_to_raise = None if force_target is not None: open_target = force_target else: open_target = config.get('general', 'new-instance-open-target') if (open_target == 'window' or force_window) and not force_tab: window = MainWindow() window.show() win_id = window.win_id window_to_raise = window else: try: win_mode = config.get('general', 'new-instance-open-target.window') if win_mode == 'last-focused': window = objreg.last_focused_window() elif win_mode == 'last-opened': window = objreg.last_window() elif win_mode == 'last-visible': window = objreg.last_visible_window() except objreg.NoWindow: # There is no window left, so we open a new one window = MainWindow() window.show() win_id = window.win_id window_to_raise = window win_id = window.win_id if open_target not in ['tab-silent', 'tab-bg-silent']: window_to_raise = window if window_to_raise is not None: window_to_raise.setWindowState( window.windowState() & ~Qt.WindowMinimized | Qt.WindowActive) window_to_raise.raise_() window_to_raise.activateWindow() QApplication.instance().alert(window_to_raise) return win_id
def get_target_window(): """Get the target window for new tabs, or None if none exist.""" try: win_mode = config.val.new_instance_open_target_window if win_mode == 'last-focused': return objreg.last_focused_window() elif win_mode == 'first-opened': return objreg.window_by_index(0) elif win_mode == 'last-opened': return objreg.window_by_index(-1) elif win_mode == 'last-visible': return objreg.last_visible_window() else: raise ValueError("Invalid win_mode {}".format(win_mode)) except objreg.NoWindow: return None
def get_target_window(): """Get the target window for new tabs, or None if none exist.""" try: win_mode = config.get('general', 'new-instance-open-target.window') if win_mode == 'last-focused': return objreg.last_focused_window() elif win_mode == 'first-opened': return objreg.window_by_index(0) elif win_mode == 'last-opened': return objreg.window_by_index(-1) elif win_mode == 'last-visible': return objreg.last_visible_window() else: raise ValueError("Invalid win_mode {}".format(win_mode)) except objreg.NoWindow: return None
def window_pip() -> None: """move window to PIP position.""" log.misc.debug("window move") win = objreg.last_visible_window() screenSize = QtWidgets.QDesktopWidget().screenGeometry(-1) point = screenSize.bottomRight() point.setX(point.x() - 10) point.setY(point.y() - 10) geo = win.geometry() height = 240 width = int(height / 9 * 16) geo.setHeight(height) geo.setWidth(width) geo.moveBottomRight(point) win.setGeometry(geo)