From 3cfa39a2ad8ee775a7738188ab7f094c7b01f56a Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Thu, 23 May 2019 12:59:34 +0100 Subject: [PATCH] [macOS] Fix GTK windowing issues On macOS the Quartz windowing is used instead of X11 so make ensure that the X11 window calls are optional. Also if gtkosx_application is not available then don't create osxapp. It would be useful to find out how to pass window timestamps on Quartz. --- deluge/ui/gtk3/addtorrentdialog.py | 6 +++++- deluge/ui/gtk3/gtkui.py | 16 ++++++++++------ deluge/ui/gtk3/mainwindow.py | 11 ++++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/deluge/ui/gtk3/addtorrentdialog.py b/deluge/ui/gtk3/addtorrentdialog.py index e7066f9ba..169703b03 100644 --- a/deluge/ui/gtk3/addtorrentdialog.py +++ b/deluge/ui/gtk3/addtorrentdialog.py @@ -174,7 +174,11 @@ class AddTorrentDialog(component.Component): self.dialog.present() if focus: timestamp = main_window.get_timestamp() - self.dialog.get_window().set_user_time(timestamp) + try: + self.dialog.get_window().set_user_time(timestamp) + except AttributeError: + # Not an X11 windowing system + pass def hide(self): self.dialog.hide() diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index 8feed0e5c..73a329fb7 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -154,17 +154,21 @@ class GtkUI(object): log.debug('OS signal "die" caught with args: %s', args) reactor.stop() + self.osxapp = None if windows_check(): from win32api import SetConsoleCtrlHandler SetConsoleCtrlHandler(on_die, True) log.debug('Win32 "die" handler registered') elif osx_check() and windowing('quartz'): - import gtkosx_application - - self.osxapp = gtkosx_application.gtkosx_application_get() - self.osxapp.connect('NSApplicationWillTerminate', on_die) - log.debug('OSX quartz "die" handler registered') + try: + import gtkosx_application + except ImportError: + pass + else: + self.osxapp = gtkosx_application.gtkosx_application_get() + self.osxapp.connect('NSApplicationWillTerminate', on_die) + log.debug('OSX quartz "die" handler registered') # Set process name again to fix gtk issue setproctitle(getproctitle()) @@ -207,7 +211,7 @@ class GtkUI(object): self.statusbar = StatusBar() self.addtorrentdialog = AddTorrentDialog() - if osx_check() and windowing('quartz'): + if self.osxapp: def nsapp_open_file(osxapp, filename): # Ignore command name which is raised at app launch (python opening main script). diff --git a/deluge/ui/gtk3/mainwindow.py b/deluge/ui/gtk3/mainwindow.py index 3ac8e066c..8896d49a6 100644 --- a/deluge/ui/gtk3/mainwindow.py +++ b/deluge/ui/gtk3/mainwindow.py @@ -13,7 +13,7 @@ import logging import os.path from hashlib import sha1 as sha -from gi.repository import GdkX11, Gtk +from gi.repository import Gtk from gi.repository.Gdk import DragAction, WindowState from twisted.internet import reactor from twisted.internet.error import ReactorNotRunning @@ -35,6 +35,10 @@ try: except ValueError: Wnck = None +try: + from gi.repository import GdkX11 +except ImportError: + GdkX11 = None log = logging.getLogger(__name__) @@ -173,7 +177,8 @@ class MainWindow(component.Component): # Restore the proper x,y coords for the window prior to showing it component.resume(self.child_components) self.window.present() - self.window.get_window().set_user_time(self.get_timestamp()) + if GdkX11: + self.window.get_window().set_user_time(self.get_timestamp()) self.load_window_state() if self.config['lock_tray'] and not self.visible(): @@ -195,7 +200,7 @@ class MainWindow(component.Component): """Returns the timestamp for the windowing server.""" timestamp = 0 gdk_window = self.window.get_window() - if isinstance(gdk_window, GdkX11.X11Window): + if GdkX11 and isinstance(gdk_window, GdkX11.X11Window): timestamp = GdkX11.x11_get_server_time(gdk_window) return timestamp