Fix window positioning of main windows

Previously, the intent was likely to position the receiver window near the
status icon. It did so by calling move followed by present. According to the
Gtk documentation, move() may fail if the window is hidden before.

Therefore present the window *after* determining the position, but *before*
moving it. (presenting the window before getting the position gives a Gtk
warning and has unpredictable behavior wrt. the window position).

As window positioning is now enabled, add additional logic to prevent overlap
of windows: position the first window near the status icon and others on the
left. This is not idea, e.g. when the status icon is on the left side of the
screen, but the idea of positioning windows near to each other is broken anyway.
This commit is contained in:
Peter Wu 2013-05-05 11:10:07 +02:00
parent a2bad425f6
commit dded8504e6
1 changed files with 24 additions and 7 deletions

View File

@ -254,14 +254,31 @@ def _hide(w):
return True
def _show(w, trigger=None):
if trigger and isinstance(trigger, Gtk.StatusIcon):
x, y = w.get_position()
if x == 0 and y == 0:
# if the window hasn't been shown yet, position it next to the status icon
x, y, _ = Gtk.StatusIcon.position_menu(Gtk.Menu(), trigger)
w.move(x, y)
def _show(w, status_icon):
if w.is_visible():
return True
x, y = w.get_position()
w.present()
if x == 0 and y == 0:
# if the window hasn't been shown yet, position it relative to
# an other window (if it was shown before) or the status icon.
# TODO: need a more clever positioning algorithm like finding
# the window where space exist on the right, else pick the
# left-most window.
for win in _windows.values():
x, y = win.get_position()
if win != w and (x, y) != (0, 0):
# position left plus some window decoration
w_width, w_height = w.get_size()
x -= w_width + 10
w.move(x, y)
break
else:
if isinstance(status_icon, Gtk.StatusIcon):
x, y, _ = Gtk.StatusIcon.position_menu(Gtk.Menu(), status_icon)
w.move(x, y)
return True