Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK4 prep: Use event controllers for open and scrubbing #544

Merged
merged 7 commits into from
Sep 10, 2024
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 Gtk.GestureMultiPress owner_gesture_controller;

Expand Down Expand Up @@ -98,10 +97,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 @@ -147,7 +142,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 @@ -182,26 +177,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
35 changes: 18 additions & 17 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 @@ -95,26 +99,23 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.EventBox {
return display_widget.scroll_event (e);
});

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;
gesture_controller.set_state (CLAIMED);
});

button_press_event.connect ((e) => {
if ((e.button == Gdk.BUTTON_PRIMARY || e.button == Gdk.BUTTON_SECONDARY)
&& e.type == Gdk.EventType.BUTTON_PRESS) {
motion_controller = new Gtk.EventControllerMotion (this) {
propagation_phase = CAPTURE
};

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
9 changes: 6 additions & 3 deletions src/Widgets/Panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox {
private unowned Gtk.StyleContext style_context;
private Gtk.CssProvider? style_provider = null;

private Gtk.GestureMultiPress gesture_controller;
private Gtk.EventControllerScroll scroll_controller;
private double current_scroll_delta = 0;

Expand Down Expand Up @@ -77,9 +78,11 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox {

Services.BackgroundManager.get_default ().background_state_changed.connect (update_background);

button_press_event.connect ((event) => {
begin_drag (event.x_root, event.y_root);
return Gdk.EVENT_PROPAGATE;
gesture_controller = new Gtk.GestureMultiPress (this);
gesture_controller.pressed.connect ((n_press, x, y) => {
begin_drag (x, y);
gesture_controller.set_state (CLAIMED);
gesture_controller.reset ();
});

scroll_controller = new Gtk.EventControllerScroll (this, BOTH_AXES);
Expand Down
2 changes: 1 addition & 1 deletion wingpanel-interface/FocusManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class WingpanelInterface.FocusManager : Object {

ulong handler = 0;
handler = stage.captured_event.connect ((event) => {
if (event.get_type () == LEAVE) {
if (event.get_type () == LEAVE || event.get_type () == ENTER) { // We need to filter ENTER for X because reasons I don't understand :( (I think something with pushing modal)
/* We get leave emitted when beginning a grab op, so we have
to filter it in order to avoid disconnecting and popping twice */
return Clutter.EVENT_PROPAGATE;
Expand Down
Loading