Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PanelWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Wingpanel.PanelWindow : Gtk.Window {
private Gtk.CssProvider? style_provider = null;

construct {
popover_manager = new Services.PopoverManager ();
popover_manager = new Services.PopoverManager (this);

panel = new Widgets.Panel (popover_manager);
panel.realize.connect (on_realize);
Expand Down
43 changes: 23 additions & 20 deletions src/Services/PopoverManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,53 @@ public class Wingpanel.Services.PopoverManager : Object {
}

if (_current_indicator == null && value != null) { // First open
indicator_open = true;
_current_indicator = value;

indicator_open = true;
} else if (value == null && _current_indicator != null) { // Close requested
indicator_open = false;
_current_indicator.base_indicator.closed ();
_current_indicator.set_state_flags (NORMAL, true);
_current_indicator = null;
} else if (_current_indicator.base_indicator.code_name == value.base_indicator.code_name) { // Close due to toggle

_current_indicator.set_state_flags (NORMAL, true);
_current_indicator.display_widget.has_tooltip = true;
_current_indicator.base_indicator.closed ();
_current_indicator = null;

popover.popdown ();

indicator_open = false;
} else { // Switch
_current_indicator.set_state_flags (NORMAL, true);
_current_indicator.display_widget.has_tooltip = true;
_current_indicator.base_indicator.closed ();

_current_indicator = value;
popover.unparent ();
}

if (_current_indicator != null) {
popover.child = _current_indicator.indicator_widget;
_current_indicator.display_widget.has_tooltip = false;
popover.set_parent (_current_indicator);
popover.popup ();
_current_indicator.set_state_flags (CHECKED, true);
_current_indicator.display_widget.has_tooltip = false;
_current_indicator.base_indicator.opened ();
} else {
((Widgets.IndicatorEntry)popover.parent).display_widget.has_tooltip = true;
popover.popdown ();

popover.child = _current_indicator.indicator_widget;

Graphene.Point point;
_current_indicator.display_widget.compute_point (_current_indicator.root, { 0.0f, 0.0f }, out point);
popover.pointing_to = {
(int) point.x + _current_indicator.display_widget.get_width () / 2,
(int) point.y + _current_indicator.display_widget.get_height ()
};
popover.popup ();
}
}
}

construct {
public PopoverManager (Gtk.Widget root) {
popover = new Gtk.Popover () {
has_arrow = false,
position = BOTTOM
};
popover.set_parent (root);
popover.add_css_class ("indicator");

popover.closed.connect (() => {
_current_indicator.set_state_flags (NORMAL, true);
current_indicator = null;
popover.unparent ();
});
popover.closed.connect (() => current_indicator = null);
}
}
2 changes: 1 addition & 1 deletion src/Widgets/IndicatorEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class Wingpanel.Widgets.IndicatorEntry : Granite.Bin {
add_controller (gesture_controller);

gesture_controller.pressed.connect ((_gesture_controller, n_press, x, y) => {
popover_manager.current_indicator = this;
popover_manager.current_indicator = popover_manager.current_indicator == this ? null : this;
_gesture_controller.set_state (CLAIMED);
});

Expand Down
9 changes: 8 additions & 1 deletion src/Widgets/Panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,19 @@ public class Wingpanel.Widgets.Panel : Granite.Bin {
}

public void toggle_indicator (string name) {
IndicatorEntry? indicator_entry_to_toggle = null;
for (var i = 0; i < visible_indicator_entries.get_n_items (); i++) {
var indicator_entry = (IndicatorEntry) visible_indicator_entries.get_item (i);
if (indicator_entry.base_indicator.code_name == name) {
popover_manager.current_indicator = indicator_entry;
indicator_entry_to_toggle = indicator_entry;
break;
}
}

popover_manager.current_indicator = (
popover_manager.current_indicator == indicator_entry_to_toggle ?
null :
indicator_entry_to_toggle
);
}
}
Loading