Exemple #1
0
def test_display_manager_is_not_wayland(monkeypatch):
    monkeypatch.setenv("WAYLAND_DISPLAY", "")
    monkeypatch.setenv("XDG_SESSION_TYPE", "x11")
    system_info.display_manager_is_wayland.cache_clear()
    assert not system_info.display_manager_is_wayland()

    monkeypatch.setenv("WAYLAND_DISPLAY", "something")
    monkeypatch.setenv("XDG_SESSION_TYPE", "something")
    system_info.display_manager_is_wayland.cache_clear()
    assert not system_info.display_manager_is_wayland()
Exemple #2
0
    def _show_windows(self):
        """Initialize child windows with method depending on system."""
        if not system_info.display_manager_is_wayland():
            for index in system_info.screens():
                self._create_window(index)

        elif system_info.desktop_environment() in [
            DesktopEnvironment.GNOME,
            DesktopEnvironment.KDE,
        ]:
            self._create_next_window()
Exemple #3
0
    def changeEvent(self, event) -> None:
        """Update position on Wayland."""
        if (
            event.type() == QtCore.QEvent.Type.ActivationChange
            and system_info.display_manager_is_wayland()
            and self.isActiveWindow()
            and not self.is_positioned
        ):
            self._position_windows_on_wayland()
            self.tray.com.on_window_positioned.emit()

        return super().changeEvent(event)
Exemple #4
0
def main():
    """Start main application logic."""
    logger = logging.getLogger("normcap")
    sys.excepthook = utils.hook_exceptions

    # Allow closing QT app with CTRL+C in terminal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    args = create_argparser().parse_args()

    logger.setLevel(args.verbosity.upper())
    logger.info("Start NormCap v%s", __version__)

    if system_info.display_manager_is_wayland():
        # QT has 32 as default cursor size on wayland, while it should be 24
        if "XCURSOR_SIZE" not in os.environ:
            logger.debug("Set XCURSOR_SIZE=24")
            os.environ["XCURSOR_SIZE"] = "24"
        # Select wayland extension for better rendering
        if "QT_QPA_PLATFORM" not in os.environ:
            logger.debug("Set QT_QPA_PLATFORM=wayland")
            os.environ["QT_QPA_PLATFORM"] = "wayland"

    # Wrap QT logging output
    QtCore.qInstallMessageHandler(utils.qt_log_wrapper)

    if system_info.is_briefcase_package():
        utils.copy_tessdata_files_to_config_dir()

    app = QtWidgets.QApplication(sys.argv)
    app.setQuitOnLastWindowClosed(False)

    logger.debug("System info:\n%s", system_info.to_dict())

    tray = SystemTray(app, vars(args))
    tray.setVisible(True)

    sys.exit(app.exec_())