simpler (and dumber) way to position receiver windows initially
This commit is contained in:
parent
79cd52833c
commit
074cafbab1
|
@ -247,37 +247,60 @@ def _make_device_box(index):
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
|
||||||
def _hide(w):
|
def _hide(w, _=None):
|
||||||
position = w.get_position()
|
position = w.get_position()
|
||||||
w.hide()
|
w.hide()
|
||||||
w.move(*position)
|
w.move(*position)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _show(w, status_icon):
|
def _show(w, status_icon=None):
|
||||||
if w.is_visible():
|
if w.get_visible():
|
||||||
return True
|
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()
|
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
|
return True
|
||||||
|
|
||||||
|
@ -320,7 +343,7 @@ def _create(receiver):
|
||||||
window.set_skip_pager_hint(True)
|
window.set_skip_pager_hint(True)
|
||||||
window.set_keep_above(True)
|
window.set_keep_above(True)
|
||||||
# window.set_decorations(Gdk.DECOR_BORDER | Gdk.DECOR_TITLE)
|
# 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
|
_windows[receiver.path] = window
|
||||||
return window
|
return window
|
||||||
|
|
Loading…
Reference in New Issue