From 4acf36c97b79730b40ded2bbb050fd18eb3f3b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 25 Mar 2019 20:01:01 +0100 Subject: [PATCH] Add method to determine window manager --- gajim/common/app.py | 14 ++++++++++++++ gajim/common/const.py | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/gajim/common/app.py b/gajim/common/app.py index 15b6f1187..8da6ae6f5 100644 --- a/gajim/common/app.py +++ b/gajim/common/app.py @@ -39,12 +39,14 @@ from distutils.version import LooseVersion as V from collections import namedtuple import nbxmpp +from gi.repository import Gdk import gajim from gajim.common import config as c_config from gajim.common import configpaths from gajim.common import ged as ged_module from gajim.common.i18n import LANG +from gajim.common.const import Display from gajim.common.contacts import LegacyContactsAPI from gajim.common.events import Events from gajim.common.types import NetworkEventsControllerT # pylint: disable=unused-import @@ -212,6 +214,18 @@ def is_installed(dependency): def is_flatpak(): return gajim.IS_FLATPAK +def is_display(display): + # XWayland reports as Display X11, so try with env var + is_wayland = os.environ.get('XDG_SESSION_TYPE') == 'wayland' + if is_wayland and display == Display.WAYLAND: + return True + + default = Gdk.Display.get_default() + if default is None: + log('gajim').warning('Could not determine window manager') + return False + return default.__class__.__name__ == display.value + def disable_dependency(dependency): _dependencies[dependency] = False diff --git a/gajim/common/const.py b/gajim/common/const.py index 58a870116..d9d030408 100644 --- a/gajim/common/const.py +++ b/gajim/common/const.py @@ -199,6 +199,7 @@ class MUCUser(IntEnum): AFFILIATION = 3 AFFILIATION_TEXT = 4 + @unique class Trust(IntEnum): UNTRUSTED = 0 @@ -206,6 +207,14 @@ class Trust(IntEnum): BLIND = 2 VERIFIED = 3 + +class Display(Enum): + X11 = 'X11Display' + WAYLAND = 'GdkWaylandDisplay' + WIN32 = 'GdkWin32Display' + QUARTZ = 'GdkQuartzDisplay' + + EME_MESSAGES = { 'urn:xmpp:otr:0': _('This message was encrypted with OTR '