window popup fix for kwin

also, only try to position the window next to the status icon if it has never
been shown before
This commit is contained in:
Daniel Pavel 2013-05-07 05:59:29 +02:00
parent 8d5ca66db7
commit 24ceb8801e
3 changed files with 29 additions and 54 deletions

View File

@ -44,8 +44,8 @@ def _run(args):
ui.notify.init() ui.notify.init()
icon = ui.status_icon.create(ui.main_window.toggle_all) status_icon = ui.status_icon.create(ui.main_window.toggle_all)
assert icon assert status_icon
listeners = {} listeners = {}
from solaar.listener import ReceiverListener from solaar.listener import ReceiverListener
@ -93,8 +93,8 @@ def _run(args):
assert device is not None assert device is not None
# print ("status changed", device, reason) # print ("status changed", device, reason)
GLib.idle_add(ui.status_icon.update, icon, device) GLib.idle_add(ui.status_icon.update, status_icon, device)
GLib.idle_add(ui.main_window.update, device, alert & ALERT.SHOW_WINDOW) GLib.idle_add(ui.main_window.update, device, alert & ALERT.SHOW_WINDOW, status_icon)
if alert & ALERT.NOTIFICATION: if alert & ALERT.NOTIFICATION:
GLib.idle_add(ui.notify.show, device, reason) GLib.idle_add(ui.notify.show, device, reason)

View File

@ -61,7 +61,6 @@ def pair(frame):
from ..ui import error_dialog from ..ui import error_dialog
def _unpair_device(action, frame): def _unpair_device(action, frame):
window = frame.get_toplevel() window = frame.get_toplevel()
# window.present()
device = frame._device device = frame._device
qdialog = Gtk.MessageDialog(window, 0, qdialog = Gtk.MessageDialog(window, 0,
Gtk.MessageType.QUESTION, Gtk.ButtonsType.NONE, Gtk.MessageType.QUESTION, Gtk.ButtonsType.NONE,

View File

@ -255,17 +255,16 @@ def _hide(w, _=None):
def _show(w, status_icon=None): def _show(w, status_icon=None):
if w.get_visible(): if not w.get_visible():
return True w.present()
if not w._was_shown:
# x, y = w.get_position() w._was_shown = True
# w.present() if isinstance(status_icon, Gtk.StatusIcon):
# if x == 0 and y == 0: # if the window hasn't been shown yet, position it relative to
# # if the window hasn't been shown yet, position it relative to # an other window (if it was shown before) or the status icon.
# # an other window (if it was shown before) or the status icon. # TODO: need a more clever positioning algorithm like finding
# # TODO: need a more clever positioning algorithm like finding # the window where space exist on the right, else pick the
# # the window where space exist on the right, else pick the # left-most window.
# # left-most window.
# for win in _windows.values(): # for win in _windows.values():
# x, y = win.get_position() # x, y = win.get_position()
# if win != w and (x, y) != (0, 0): # if win != w and (x, y) != (0, 0):
@ -275,33 +274,8 @@ def _show(w, status_icon=None):
# w.move(x, y) # w.move(x, y)
# break # break
# else: # 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) x, y, _ = Gtk.StatusIcon.position_menu(Gtk.Menu(), status_icon)
w.move(x, y) 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()
return True return True
@ -344,6 +318,7 @@ def _create(receiver):
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', _hide) window.connect('delete-event', _hide)
window._was_shown = False
_windows[receiver.path] = window _windows[receiver.path] = window
return window return window
@ -465,11 +440,12 @@ def _update_device_box(frame, dev):
_config_panel.update(frame) _config_panel.update(frame)
def update(device, popup=False): def update(device, popup=False, status_icon=None):
assert device is not None assert device is not None
# print ("main_window.update", device) # print ("main_window.update", device)
receiver = device if device.kind is None else device.receiver receiver = device if device.kind is None else device.receiver
assert receiver is not None, '%s has no receiver' % device
w = _windows.get(receiver.path) w = _windows.get(receiver.path)
if receiver and not w: if receiver and not w:
w = _create(receiver) w = _create(receiver)
@ -477,7 +453,7 @@ def update(device, popup=False):
if w: if w:
if receiver: if receiver:
if popup: if popup:
w.present() _show(w, status_icon)
vbox = w.get_child() vbox = w.get_child()
frames = list(vbox.get_children()) frames = list(vbox.get_children())