Fix window position restore on multi-head setups

Gajim stopped to properly restore roster and dialogs windows positions
after restart with more than one monitor attached.

Gajim saves the absolute window positions, i.e. based on the total screen size
of all monitors attached. Despite Gtk deprecated Gdk.Screen.width() and height(),
we cannot just use width() and height() for one monitor, as recommended.
We still need the total screen size, which was the base for saving the positions.

[1] https://stackoverflow.com/questions/30207586/gdk-screen-vs-monitor-vs-display
This commit is contained in:
Andrey Gursky 2018-03-16 16:59:54 +01:00 committed by Philipp Hörist
parent 8d583a1801
commit c6172c86ad
2 changed files with 8 additions and 9 deletions

View File

@ -3179,7 +3179,7 @@ class PopupNotificationWindow:
window_width, self.window_height = self.window.get_size() window_width, self.window_height = self.window.get_size()
app.interface.roster.popups_notification_height += self.window_height app.interface.roster.popups_notification_height += self.window_height
pos_x = app.config.get('notification_position_x') pos_x = app.config.get('notification_position_x')
screen_w, screen_h = gtkgui_helpers.get_display_geometry() screen_w, screen_h = gtkgui_helpers.get_total_screen_geometry()
if pos_x < 0: if pos_x < 0:
pos_x = screen_w - window_width + pos_x + 1 pos_x = screen_w - window_width + pos_x + 1
pos_y = app.config.get('notification_position_y') pos_y = app.config.get('notification_position_y')
@ -3216,7 +3216,7 @@ class PopupNotificationWindow:
current_index += 1 current_index += 1
window_width, window_height = window_instance.window.get_size() window_width, window_height = window_instance.window.get_size()
app.interface.roster.popups_notification_height += window_height app.interface.roster.popups_notification_height += window_height
screen_w, screen_h = gtkgui_helpers.get_display_geometry() screen_w, screen_h = gtkgui_helpers.get_total_screen_geometry()
window_instance.window.move(screen_w - window_width, window_instance.window.move(screen_w - window_width,
screen_h - \ screen_h - \
app.interface.roster.popups_notification_height) app.interface.roster.popups_notification_height)

View File

@ -100,11 +100,10 @@ if os.name == 'nt':
from gajim.common import helpers from gajim.common import helpers
def get_display_geometry(): def get_total_screen_geometry():
display = Gdk.Display.get_default() screen = Gdk.Screen.get_default()
monitor = display.get_monitor(0) window = Gdk.Screen.get_root_window(screen)
geometry = monitor.get_geometry() return window.get_width(), window.get_height()
return geometry.width, geometry.height
def add_image_to_button(button, icon_name): def add_image_to_button(button, icon_name):
img = Gtk.Image() img = Gtk.Image()
@ -175,7 +174,7 @@ def move_window(window, x, y):
""" """
Move the window, but also check if out of screen Move the window, but also check if out of screen
""" """
screen_w, screen_h = get_display_geometry() screen_w, screen_h = get_total_screen_geometry()
if x < 0: if x < 0:
x = 0 x = 0
if y < 0: if y < 0:
@ -191,7 +190,7 @@ def resize_window(window, w, h):
""" """
Resize window, but also checks if huge window or negative values Resize window, but also checks if huge window or negative values
""" """
screen_w, screen_h = get_display_geometry() screen_w, screen_h = get_total_screen_geometry()
if not w or not h: if not w or not h:
return return
if w > screen_w: if w > screen_w: