Skip to content

Commit

Permalink
Don't close the popover when a menu type steals the focus (#863)
Browse files Browse the repository at this point in the history
* Don't close the popover when a menu type steals the focus

* Don't close the popover when a menu type steals the focus
  • Loading branch information
cybre authored and ikeydoherty committed Apr 17, 2017
1 parent 83d57d4 commit 2791fc5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 15 deletions.
67 changes: 52 additions & 15 deletions src/panel/popovers.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
namespace Budgie
{

[DBus (name="org.budgie_desktop.BudgieWM")]
public interface BudgieWM : Object {
public abstract bool IsLastWindowDismissable() throws Error;
}

public class PopoverManagerImpl : PopoverManager, GLib.Object
{
HashTable<Gtk.Widget?,Gtk.Popover?> widgets;
Expand All @@ -22,24 +27,29 @@ public class PopoverManagerImpl : PopoverManager, GLib.Object
bool grabbed = false;
bool mousing = false;

BudgieWM? wm_proxy = null;


public PopoverManagerImpl(Budgie.Panel? owner)
{
this.owner = owner;
widgets = new HashTable<Gtk.Widget?,Gtk.Popover?>(direct_hash, direct_equal);

owner.focus_out_event.connect(()=>{
Bus.watch_name(BusType.SESSION, "org.budgie_desktop.BudgieWM", BusNameWatcherFlags.NONE,
has_wm, lost_wm);

owner.focus_out_event.connect((e)=>{
if (mousing) {
return Gdk.EVENT_PROPAGATE;
}
if (visible_popover != null) {
#if HAVE_GTK_322
visible_popover.popdown();
#else
visible_popover.hide();
#endif
make_modal(visible_popover, false);
visible_popover = null;
if (wm_proxy != null && e.window != null) {
if (wm_proxy.IsLastWindowDismissable()) {
hide_popover();
}
} else {
hide_popover();
}
}
return Gdk.EVENT_PROPAGATE;
});
Expand All @@ -58,20 +68,47 @@ public class PopoverManagerImpl : PopoverManager, GLib.Object
}
if ((e.x < alloc.x || e.x > alloc.x+alloc.width) ||
(e.y < alloc.y || e.y > alloc.y+alloc.height)) {
#if HAVE_GTK_322
visible_popover.popdown();
#else
visible_popover.hide();
#endif
make_modal(visible_popover, false);
visible_popover = null;
hide_popover();
}
return Gdk.EVENT_STOP;

});
owner.add_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.BUTTON_PRESS_MASK);
}

void lost_wm() {
wm_proxy = null;
}

void on_wm_get(GLib.Object? o, GLib.AsyncResult? res)
{
try {
wm_proxy = Bus.get_proxy.end(res);
} catch (Error e) {
warning("Failed to get BudgieWM proxy: %s", e.message);
}
}

void has_wm()
{
if (wm_proxy == null) {
Bus.get_proxy.begin<BudgieWM>(BusType.SESSION,
"org.budgie_desktop.BudgieWM",
"/org/budgie_desktop/BudgieWM", 0, null, on_wm_get);
}
}

void hide_popover()
{
#if HAVE_GTK_322
visible_popover.popdown();
#else
visible_popover.hide();
#endif
make_modal(visible_popover, false);
visible_popover = null;
}

void make_modal(Gtk.Popover? pop, bool modal = true)
{
if (pop == null || pop.get_window() == null || mousing) {
Expand Down
16 changes: 16 additions & 0 deletions src/wm/wm.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,22 @@ public class BudgieWMDBUS : GLib.Object
this.wm.restore_focused();
}

public bool IsLastWindowDismissable()
{
unowned GLib.List<weak Meta.WindowActor>? last = Meta.Compositor.get_window_actors(
this.wm.get_screen()).last();

switch (last.data.get_meta_window().get_window_type()) {
case Meta.WindowType.POPUP_MENU:
case Meta.WindowType.COMBO:
return false;
default:
return true;
}

return true;
}

} /* End BudgieWMDBUS */

} /* End namespace */
Expand Down

0 comments on commit 2791fc5

Please sign in to comment.