From 6b2f14e51ea503fcff5c0544a5d24be21b5740f4 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 7 Nov 2018 15:09:47 +0000 Subject: [PATCH] [GTK] Fix windows not showing topmost on desktop When showing the main_window, Add dialog or file manager windows they would not appear at the top of the display stack, always one below. This is due to needing the windowing timestamp to be passed when making these calls. The recommended Gtk solution to use present_with_time and use an event.time timestamp. However, this does not always work so instead used the lower level Gdk set_user_time and fetch timestamp from X11 server. Notes: - Using int(time.time()) for timestamp is not correct as the windowing timestamp is different. - Gtk.get_current_event_time only works when there is an event being processed. - It might be useful for non-X11 windowing systems to store event timestamps so that we have a value to use instead of 0. --- deluge/ui/gtk3/addtorrentdialog.py | 9 ++++++--- deluge/ui/gtk3/files_tab.py | 4 ++-- deluge/ui/gtk3/mainwindow.py | 13 ++++++++++--- deluge/ui/gtk3/menubar.py | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/deluge/ui/gtk3/addtorrentdialog.py b/deluge/ui/gtk3/addtorrentdialog.py index fd78676a0..4c25f97be 100644 --- a/deluge/ui/gtk3/addtorrentdialog.py +++ b/deluge/ui/gtk3/addtorrentdialog.py @@ -155,14 +155,17 @@ class AddTorrentDialog(component.Component): self.update_core_config(True, focus) def _show(self, focus=False): - if component.get('MainWindow').is_on_active_workspace(): - self.dialog.set_transient_for(component.get('MainWindow').window) + main_window = component.get('MainWindow') + if main_window.is_on_active_workspace(): + self.dialog.set_transient_for(main_window.window) else: self.dialog.set_transient_for(None) + self.dialog.set_position(Gtk.WindowPosition.CENTER) self.dialog.present() if focus: - self.dialog.window.focus() + timestamp = main_window.get_timestamp() + self.dialog.get_window().set_user_time(timestamp) def hide(self): self.dialog.hide() diff --git a/deluge/ui/gtk3/files_tab.py b/deluge/ui/gtk3/files_tab.py index dc5d914da..6c9b5c7fd 100644 --- a/deluge/ui/gtk3/files_tab.py +++ b/deluge/ui/gtk3/files_tab.py @@ -321,7 +321,7 @@ class FilesTab(Tab): path = self.get_file_path(select).split('/') filepath = os.path.join(status['download_location'], *path) log.debug('Open file: %s', filepath) - timestamp = Gtk.get_current_event_time() + timestamp = component.get('MainWindow').get_timestamp() open_file(filepath, timestamp=timestamp) def _on_show_file(self, status): @@ -334,7 +334,7 @@ class FilesTab(Tab): path = self.get_file_path(select).split('/') filepath = os.path.join(status['download_location'], *path) log.debug('Show file: %s', filepath) - timestamp = Gtk.get_current_event_time() + timestamp = component.get('MainWindow').get_timestamp() show_file(filepath, timestamp=timestamp) # The following 3 methods create the folder/file view in the treeview diff --git a/deluge/ui/gtk3/mainwindow.py b/deluge/ui/gtk3/mainwindow.py index 51292e052..8200d9535 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 Gtk +from gi.repository import GdkX11, Gtk from gi.repository.Gdk import DragAction, WindowState from twisted.internet import reactor from twisted.internet.error import ReactorNotRunning @@ -173,6 +173,7 @@ 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()) self.load_window_state() if self.config['lock_tray'] and not self.visible(): @@ -190,6 +191,14 @@ class MainWindow(component.Component): else: restore() + def get_timestamp(self): + """Returns the timestamp for the windowing server.""" + timestamp = 0 + gdk_window = self.window.get_window() + if isinstance(gdk_window, GdkX11.X11Window): + timestamp = GdkX11.x11_get_server_time(gdk_window) + return timestamp + def active(self): """Returns True if the window is active, False if not.""" return self.window.is_active() @@ -351,8 +360,6 @@ class MainWindow(component.Component): if Wnck: self.screen.force_update() - from gi.repository import GdkX11 # NOQA - win = Wnck.Window.get(self.window.get_window().get_xid()) if win: active_wksp = win.get_screen().get_active_workspace() diff --git a/deluge/ui/gtk3/menubar.py b/deluge/ui/gtk3/menubar.py index e98181bbf..e09f394fc 100644 --- a/deluge/ui/gtk3/menubar.py +++ b/deluge/ui/gtk3/menubar.py @@ -313,7 +313,7 @@ class MenuBar(component.Component): log.debug('on_menuitem_open_folder') def _on_torrent_status(status): - timestamp = Gtk.get_current_event_time() + timestamp = component.get('MainWindow').get_timestamp() path = os.path.join( status['download_location'], status['files'][0]['path'].split('/')[0] )