Skip to content

Remodel GestureController lifetimes #2355

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions src/Gestures/GestureController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class Gala.GestureController : Object {
public GestureAction action { get; construct; }
public WindowManager wm { get; construct; }

private GestureTarget? _target;
public GestureTarget target {
private unowned RootTarget? _target;
public RootTarget target {
get { return _target; }
set {
private set {
_target = value;
target.propagate (UPDATE, action, progress);
_target.propagate (UPDATE, action, progress);
}
}

Expand Down Expand Up @@ -90,8 +90,19 @@ public class Gala.GestureController : Object {

private SpringTimeline? timeline;

public GestureController (GestureAction action, GestureTarget target, WindowManager wm) {
Object (action: action, target: target, wm: wm);
public GestureController (GestureAction action, WindowManager wm) {
Object (action: action, wm: wm);
}

// Do not call this directly, use {@link RooTarget.add_controller} instead.
public void attached (RootTarget target) {
ref ();
this.target = target;
}

public void detached () {
_target = null;
unref ();
}

public void enable_touchpad () {
Expand Down
13 changes: 13 additions & 0 deletions src/Gestures/RootTarget.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Leonhard Kargl <[email protected]>
*/

public interface Gala.RootTarget : Object, GestureTarget {
public void add_gesture_controller (GestureController controller) requires (controller.target == null) {
controller.attached (this);
weak_ref (controller.detached);
}
}
3 changes: 1 addition & 2 deletions src/Gestures/ScrollBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class Gala.ScrollBackend : Object, GestureBackend {
private const double FINISH_DELTA_HORIZONTAL = 40;
private const double FINISH_DELTA_VERTICAL = 30;

public Clutter.Actor actor { get; construct; }
public Clutter.Orientation orientation { get; construct; }
public GestureSettings settings { get; construct; }

Expand All @@ -46,7 +45,7 @@ public class Gala.ScrollBackend : Object, GestureBackend {
}

public ScrollBackend (Clutter.Actor actor, Clutter.Orientation orientation, GestureSettings settings) {
Object (actor: actor, orientation: orientation, settings: settings);
Object (orientation: orientation, settings: settings);

actor.captured_event.connect (on_scroll_event);
actor.leave_event.connect (on_leave_event);
Expand Down
7 changes: 3 additions & 4 deletions src/ShellClients/PanelWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Authored by: Leonhard Kargl <[email protected]>
*/

public class Gala.PanelWindow : ShellWindow {
public class Gala.PanelWindow : ShellWindow, RootTarget {
private const int ANIMATION_DURATION = 250;

private static HashTable<Meta.Window, Meta.Strut?> window_struts = new HashTable<Meta.Window, Meta.Strut?> (null, null);
Expand Down Expand Up @@ -50,8 +50,6 @@ public class Gala.PanelWindow : ShellWindow {
if (window_struts.remove (window)) {
update_struts ();
}

gesture_controller = null; // make it release its reference on us
});

notify["anchor"].connect (() => position = Position.from_anchor (anchor));
Expand All @@ -63,7 +61,8 @@ public class Gala.PanelWindow : ShellWindow {
window.size_changed.connect (update_strut);
window.position_changed.connect (update_strut);

gesture_controller = new GestureController (DOCK, this, wm);
gesture_controller = new GestureController (DOCK, wm);
add_gesture_controller (gesture_controller);

window.display.in_fullscreen_changed.connect (() => {
if (wm.get_display ().get_monitor_in_fullscreen (window.get_monitor ())) {
Expand Down
8 changes: 5 additions & 3 deletions src/Widgets/MultitaskingView/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* preparing the wm, opening the components and holds containers for
* the icon groups, the WorkspaceClones and the MonitorClones.
*/
public class Gala.MultitaskingView : ActorTarget, ActivatableComponent {
public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableComponent {
public const int ANIMATION_DURATION = 250;

private GestureController workspaces_gesture_controller;
Expand Down Expand Up @@ -57,18 +57,20 @@ public class Gala.MultitaskingView : ActorTarget, ActivatableComponent {
opened = false;
display = wm.get_display ();

multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, this, wm);
multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, wm);
multitasking_gesture_controller.enable_touchpad ();
add_gesture_controller (multitasking_gesture_controller);

add_target (ShellClientsManager.get_instance ()); // For hiding the panels

workspaces = new WorkspaceRow (display);

workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, this, wm) {
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, wm) {
overshoot_upper_clamp = 0.1
};
workspaces_gesture_controller.enable_touchpad ();
workspaces_gesture_controller.enable_scroll (this, HORIZONTAL);
add_gesture_controller (workspaces_gesture_controller);

icon_groups = new IconGroupContainer (display.get_monitor_scale (display.get_primary_monitor ()));

Expand Down
5 changes: 3 additions & 2 deletions src/Widgets/MultitaskingView/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A container for a clone of the texture of a MetaWindow, a WindowIcon, a Tooltip with the title,
* a close button and a shadow. Used together with the WindowCloneContainer.
*/
public class Gala.WindowClone : ActorTarget {
public class Gala.WindowClone : ActorTarget, RootTarget {
private const int WINDOW_ICON_SIZE = 64;
private const int ACTIVE_SHAPE_SIZE = 12;
private const int FADE_ANIMATION_DURATION = 200;
Expand Down Expand Up @@ -104,8 +104,9 @@ public class Gala.WindowClone : ActorTarget {
construct {
reactive = true;

gesture_controller = new GestureController (CLOSE_WINDOW, this, wm);
gesture_controller = new GestureController (CLOSE_WINDOW, wm);
gesture_controller.enable_scroll (this, VERTICAL);
add_gesture_controller (gesture_controller);

window.unmanaged.connect (unmanaged);
window.notify["fullscreen"].connect (check_shadow_requirements);
Expand Down
5 changes: 3 additions & 2 deletions src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public class Gala.WindowOverview : ActorTarget, ActivatableComponent {
public class Gala.WindowOverview : ActorTarget, RootTarget, ActivatableComponent {
private const int BORDER = 10;
private const int TOP_GAP = 30;
private const int BOTTOM_GAP = 100;
Expand All @@ -26,9 +26,10 @@ public class Gala.WindowOverview : ActorTarget, ActivatableComponent {
construct {
visible = false;
reactive = true;
gesture_controller = new GestureController (MULTITASKING_VIEW, this, wm) {
gesture_controller = new GestureController (MULTITASKING_VIEW, wm) {
enabled = false
};
add_gesture_controller (gesture_controller);
}


Expand Down
5 changes: 3 additions & 2 deletions src/Widgets/WindowSwitcher/WindowSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public class Gala.WindowSwitcher : CanvasActor, GestureTarget {
public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
public const int ICON_SIZE = 64;
public const int WRAPPER_PADDING = 12;

Expand Down Expand Up @@ -63,13 +63,14 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget {
construct {
style_manager = Drawing.StyleManager.get_instance ();

gesture_controller = new GestureController (SWITCH_WINDOWS, this, wm) {
gesture_controller = new GestureController (SWITCH_WINDOWS, wm) {
overshoot_upper_clamp = int.MAX,
overshoot_lower_clamp = int.MIN,
snap = false
};
gesture_controller.enable_touchpad ();
gesture_controller.notify["recognizing"].connect (recognizing_changed);
add_gesture_controller (gesture_controller);

container = new Clutter.Actor () {
reactive = true,
Expand Down
5 changes: 3 additions & 2 deletions src/Zoom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public class Gala.Zoom : Object, GestureTarget {
public class Gala.Zoom : Object, GestureTarget, RootTarget {
private const float MIN_ZOOM = 1.0f;
private const float MAX_ZOOM = 10.0f;
private const float SHORTCUT_DELTA = 0.5f;
Expand Down Expand Up @@ -34,10 +34,11 @@ public class Gala.Zoom : Object, GestureTarget {
display.add_keybinding ("zoom-in", schema, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) zoom_in);
display.add_keybinding ("zoom-out", schema, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) zoom_out);

gesture_controller = new GestureController (ZOOM, this, wm) {
gesture_controller = new GestureController (ZOOM, wm) {
snap = false
};
gesture_controller.enable_touchpad ();
add_gesture_controller (gesture_controller);

behavior_settings = new GLib.Settings ("io.elementary.desktop.wm.behavior");

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ gala_bin_sources = files(
'Gestures/GestureSettings.vala',
'Gestures/GestureTarget.vala',
'Gestures/PropertyTarget.vala',
'Gestures/RootTarget.vala',
'Gestures/ScrollBackend.vala',
'Gestures/SpringTimeline.vala',
'Gestures/ToucheggBackend.vala',
Expand Down
Loading