Skip to content
29 changes: 29 additions & 0 deletions src/Services/PopoverManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
* Boston, MA 02110-1301 USA.
*/

[DBus (name = "org.pantheon.gala")]
public interface WMDBus : GLib.Object {
public abstract void offset_notifications (int32 offset) throws DBusError, Error;
}

public class Wingpanel.Services.PopoverManager : Object {
private unowned Wingpanel.PanelWindow? owner;

private bool grabbed = false; // whether the wingpanel grabbed focus
private bool mousing = false;

private WMDBus? wm = null;

private Gee.HashMap<string, Wingpanel.Widgets.IndicatorEntry> registered_indicators;
private Wingpanel.Widgets.IndicatorPopover popover;
private Wingpanel.Widgets.IndicatorEntry? _current_indicator = null;
Expand Down Expand Up @@ -59,10 +66,12 @@ public class Wingpanel.Services.PopoverManager : Object {
owner.present ();
popover.popup ();
popover.show_all ();
offset_notifications (popover);
_current_indicator.base_indicator.opened ();
} else {
update_has_tooltip (((Wingpanel.Widgets.IndicatorEntry)popover.get_relative_to ()).display_widget);
popover.popdown ();
offset_notifications ();
}
}
}
Expand All @@ -72,6 +81,12 @@ public class Wingpanel.Services.PopoverManager : Object {

this.owner = owner;

try {
this.wm = Bus.get_proxy_sync (BusType.SESSION, "org.pantheon.gala", "/org/pantheon/gala");
} catch (Error e) {
warning ("Could not connect to dbus org.pantheon.gala");
}

popover = new Wingpanel.Widgets.IndicatorPopover ();

popover.leave_notify_event.connect ((e) => {
Expand Down Expand Up @@ -238,4 +253,18 @@ public class Wingpanel.Services.PopoverManager : Object {
}
});
}

private void offset_notifications(Wingpanel.Widgets.IndicatorPopover? popover = null) {
int offset = 0;
if (popover != null) {
int minimum_height, natural_height;
popover.get_preferred_height (out minimum_height, out natural_height);
offset = natural_height;
}
try {
wm.offset_notifications (offset);
} catch (Error e) {
warning ("Could not offset notifications: %s", e.message);
}
}
}