[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.
This commit is contained in:
Calum Lind 2019-05-23 12:59:34 +01:00
parent a3b6d8d8e5
commit 3cfa39a2ad
3 changed files with 23 additions and 10 deletions

View File

@ -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()

View File

@ -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).

View File

@ -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