From 074cafbab117706d63ed338a1b24a19014916d34 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Mon, 6 May 2013 17:39:27 +0200 Subject: [PATCH] simpler (and dumber) way to position receiver windows initially --- lib/solaar/ui/main_window.py | 69 ++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/lib/solaar/ui/main_window.py b/lib/solaar/ui/main_window.py index 9242ddd5..b98dc145 100644 --- a/lib/solaar/ui/main_window.py +++ b/lib/solaar/ui/main_window.py @@ -247,37 +247,60 @@ def _make_device_box(index): return frame -def _hide(w): +def _hide(w, _=None): position = w.get_position() w.hide() w.move(*position) return True -def _show(w, status_icon): - if w.is_visible(): +def _show(w, status_icon=None): + if w.get_visible(): return True - x, y = w.get_position() + # 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) + + # Nah. It's a bit more complicated than that. + # If the first window is already at the right edge, this would place the + # second window out-of-bounds -- if the status icon is in the top-right + # corner. It might be in any of the other corners. Depending on the window + # manager and its settings, it might also have its own ideas of there the + # window should be when first shown. Etc... + + # Trying to cover all the bases would ridiculously complicate this code. + # The current way all receiver windows may be overlapped initially, and the + # user will have to move some out of the way, but I think it's a good + # compromise betwen simplicity of code and covering 99% of users, that have + # a single receiver. + + if status_icon and isinstance(status_icon, 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(), status_icon) + w.move(x, y) + # Show the window only after it's been moved to its location, otherwise + # the user might get to see it moving from (0, 0) to the location. 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 @@ -320,7 +343,7 @@ def _create(receiver): window.set_skip_pager_hint(True) window.set_keep_above(True) # window.set_decorations(Gdk.DECOR_BORDER | Gdk.DECOR_TITLE) - window.connect('delete-event', lambda widget, event: _hide(widget)) + window.connect('delete-event', _hide) _windows[receiver.path] = window return window