Skip to content

Commit

Permalink
GTK4 prep: Use event controllers for click and scrubbing
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 authored and danirabbit committed Jul 12, 2024
1 parent d49b0c5 commit 0278654
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 43 deletions.
27 changes: 2 additions & 25 deletions src/Services/PopoverManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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 Gee.HashMap<string, Wingpanel.Widgets.IndicatorEntry> registered_indicators;
private Wingpanel.Widgets.IndicatorPopover popover;
Expand Down Expand Up @@ -95,10 +94,6 @@ public class Wingpanel.Services.PopoverManager : Object {
});

owner.focus_out_event.connect ((e) => {
if (mousing) {
return Gdk.EVENT_PROPAGATE;
}

if (current_indicator != null && e.window == null) {
current_indicator = null;
}
Expand Down Expand Up @@ -175,7 +170,7 @@ public class Wingpanel.Services.PopoverManager : Object {
}

private void make_modal (Gtk.Popover? pop, bool modal = true) {
if (pop == null || pop.get_window () == null || mousing) {
if (pop == null || pop.get_window () == null) {
return;
}

Expand Down Expand Up @@ -210,26 +205,8 @@ public class Wingpanel.Services.PopoverManager : Object {

registered_indicators.set (widg.base_indicator.code_name, widg);

widg.enter_notify_event.connect ((w, e) => {
if (mousing) {
return Gdk.EVENT_PROPAGATE;
}

if (grabbed) {
if (!get_visible (widg) && e.mode != Gdk.CrossingMode.TOUCH_BEGIN) {
mousing = true;
current_indicator = widg;
mousing = false;
}

return Gdk.EVENT_STOP;
}

return Gdk.EVENT_PROPAGATE;
});

widg.notify["visible"].connect (() => {
if (mousing || grabbed) {
if (grabbed) {
return;
}

Expand Down
34 changes: 16 additions & 18 deletions src/Widgets/IndicatorEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.EventBox {

private Gtk.Revealer revealer;

private Gtk.GestureMultiPress gesture_controller;
private Gtk.EventControllerMotion motion_controller;

public IndicatorEntry (Indicator base_indicator, Services.PopoverManager popover_manager) {
Object (
base_indicator: base_indicator,
Expand All @@ -54,9 +57,10 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.EventBox {
return;
}

revealer = new Gtk.Revealer ();
revealer = new Gtk.Revealer () {
child = display_widget
};
revealer.get_style_context ().add_class ("composited-indicator");
revealer.add (display_widget);

add (revealer);

Expand Down Expand Up @@ -97,26 +101,20 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.EventBox {
return Gdk.EVENT_PROPAGATE;
});

touch_event.connect ((e) => {
if (e.type == Gdk.EventType.TOUCH_BEGIN) {
popover_manager.current_indicator = this;
return Gdk.EVENT_STOP;
}
button_press_event.connect ((e) => display_widget.button_press_event (e));

return Gdk.EVENT_PROPAGATE;
});
gesture_controller = new Gtk.GestureMultiPress (this);
gesture_controller.pressed.connect (() => popover_manager.current_indicator = this);

motion_controller = new Gtk.EventControllerMotion (this) {
propagation_phase = CAPTURE
};

button_press_event.connect ((e) => {
if ((e.button == Gdk.BUTTON_PRIMARY || e.button == Gdk.BUTTON_SECONDARY)
&& e.type == Gdk.EventType.BUTTON_PRESS) {
motion_controller.enter.connect (() => {
// If something is open and it's not us, open us. This implements the scrubbing behavior
if (popover_manager.current_indicator != null && !popover_manager.get_visible (this)) {
popover_manager.current_indicator = this;
return Gdk.EVENT_STOP;
}

/* Call button press on the indicator display widget */
display_widget.button_press_event (e);

return Gdk.EVENT_STOP;
});

set_reveal (base_indicator.visible);
Expand Down

0 comments on commit 0278654

Please sign in to comment.