[GTK] Improve detecting X11 display server

GdkX11 still imports on Wayland so check display server is X11 before
importing.
This commit is contained in:
Calum Lind 2019-06-12 15:44:44 +01:00
parent 7a54db3179
commit a2dee79439
4 changed files with 21 additions and 19 deletions

View File

@ -34,7 +34,12 @@ from deluge.httpdownloader import download_file
from deluge.ui.client import client from deluge.ui.client import client
from deluge.ui.common import TorrentInfo from deluge.ui.common import TorrentInfo
from .common import get_clipboard_text, listview_replace_treestore, reparent_iter from .common import (
get_clipboard_text,
listview_replace_treestore,
reparent_iter,
windowing,
)
from .dialogs import ErrorDialog from .dialogs import ErrorDialog
from .edittrackersdialog import trackers_tiers_from_text from .edittrackersdialog import trackers_tiers_from_text
from .path_chooser import PathChooser from .path_chooser import PathChooser
@ -174,11 +179,8 @@ class AddTorrentDialog(component.Component):
self.dialog.present() self.dialog.present()
if focus: if focus:
timestamp = main_window.get_timestamp() timestamp = main_window.get_timestamp()
try: if windowing('X11'):
self.dialog.get_window().set_user_time(timestamp) self.dialog.get_window().set_user_time(timestamp)
except AttributeError:
# Not an X11 windowing system
pass
def hide(self): def hide(self):
self.dialog.hide() self.dialog.hide()

View File

@ -16,7 +16,7 @@ import shutil
import sys import sys
import six.moves.cPickle as pickle # noqa: N813 import six.moves.cPickle as pickle # noqa: N813
from gi.repository.Gdk import SELECTION_CLIPBOARD from gi.repository.Gdk import SELECTION_CLIPBOARD, Display
from gi.repository.GdkPixbuf import Colorspace, Pixbuf from gi.repository.GdkPixbuf import Colorspace, Pixbuf
from gi.repository.GLib import GError from gi.repository.GLib import GError
from gi.repository.Gtk import ( from gi.repository.Gtk import (
@ -389,3 +389,7 @@ def get_clipboard_text():
) )
if text: if text:
return text.strip() return text.strip()
def windowing(like):
return like.lower() in str(type(Display.get_default())).lower()

View File

@ -22,7 +22,6 @@ gi.require_version('Gtk', '3.0') # NOQA: E402
gi.require_version('Gdk', '3.0') # NOQA: E402 gi.require_version('Gdk', '3.0') # NOQA: E402
# isort:imports-thirdparty # isort:imports-thirdparty
from gi.repository.Gdk import Display
from gi.repository.GLib import set_prgname from gi.repository.GLib import set_prgname
from gi.repository.Gtk import Builder, ResponseType from gi.repository.Gtk import Builder, ResponseType
from twisted.internet import defer, gtk3reactor from twisted.internet import defer, gtk3reactor
@ -55,7 +54,7 @@ from deluge.ui.tracker_icons import TrackerIcons
# isort:imports-localfolder # isort:imports-localfolder
from .addtorrentdialog import AddTorrentDialog from .addtorrentdialog import AddTorrentDialog
from .common import associate_magnet_links from .common import associate_magnet_links, windowing
from .connectionmanager import ConnectionManager from .connectionmanager import ConnectionManager
from .dialogs import YesNoDialog from .dialogs import YesNoDialog
from .filtertreeview import FilterTreeView from .filtertreeview import FilterTreeView
@ -139,10 +138,6 @@ DEFAULT_PREFS = {
} }
def windowing(like):
return like.lower() in str(type(Display.get_default())).lower()
class GtkUI(object): class GtkUI(object):
def __init__(self, args): def __init__(self, args):
# Setup gtkbuilder/glade translation # Setup gtkbuilder/glade translation

View File

@ -24,17 +24,18 @@ from deluge.common import decode_bytes, fspeed, resource_filename
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
from deluge.ui.client import client from deluge.ui.client import client
from .common import get_deluge_icon from .common import get_deluge_icon, windowing
from .dialogs import PasswordDialog from .dialogs import PasswordDialog
from .ipcinterface import process_args from .ipcinterface import process_args
try: GdkX11 = None
from gi.repository import GdkX11
except ImportError:
GdkX11 = None
Wnck = None Wnck = None
if GdkX11: if windowing('X11'):
try:
from gi.repository import GdkX11
except ImportError:
pass
try: try:
gi.require_version('Wnck', '3.0') gi.require_version('Wnck', '3.0')
from gi.repository import Wnck from gi.repository import Wnck