Skip to content
Closed
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
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ jobs:
env:
DESTDIR: out
run: |
meson build -Ddocumentation=true
meson build -Ddocumentation=true -Dtests=true
ninja -C build
ninja -C build install
- name: Run Tests
run: |
meson test -v -C build

fedora:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -93,3 +96,4 @@ jobs:
io.elementary.vala-lint -d lib
io.elementary.vala-lint -d plugins
io.elementary.vala-lint -d src
io.elementary.vala-lint -d tests
6 changes: 0 additions & 6 deletions lib/Gestures/ActorTarget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
* If a new child (or target via {@link add_target}) is added, its progress will be synced.
*/
public class Gala.ActorTarget : Clutter.Actor, GestureTarget {
public Clutter.Actor? actor {
get {
return this;
}
}

public bool animating { get { return ongoing_animations > 0; } }

private double[] current_progress;
Expand Down
6 changes: 0 additions & 6 deletions lib/Gestures/GestureTarget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,5 @@ public interface Gala.GestureTarget : Object {
END
}

/**
* The actor manipulated by the gesture. The associated frame clock
* will be used for animation timelines.
*/
public abstract Clutter.Actor? actor { get; }

public virtual void propagate (UpdateType update_type, GestureAction action, double progress) { }
}
27 changes: 17 additions & 10 deletions lib/Gestures/PropertyTarget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,34 @@

public class Gala.PropertyTarget : Object, GestureTarget {
public GestureAction action { get; construct; }

//we don't want to hold a strong reference to the actor because we might've been added to it which would form a reference cycle
private weak Clutter.Actor? _actor;
public Clutter.Actor? actor { get { return _actor; } }

// Don't take a reference since we are most of the time owned by the target
public weak Object? target { get; private set; }
public string property { get; construct; }

public Clutter.Interval interval { get; construct; }

public PropertyTarget (GestureAction action, Clutter.Actor actor, string property, Type value_type, Value from_value, Value to_value) {
public PropertyTarget (GestureAction action, Object target, string property, Type value_type, Value from_value, Value to_value) {
Object (action: action, property: property, interval: new Clutter.Interval.with_values (value_type, from_value, to_value));

_actor = actor;
_actor.destroy.connect (() => _actor = null);
this.target = target;
this.target.weak_ref (on_target_disposed);
}

~PropertyTarget () {
if (target != null) {
target.weak_unref (on_target_disposed);
}
}

private void on_target_disposed () {
target = null;
}

public override void propagate (UpdateType update_type, GestureAction action, double progress) {
if (update_type != UPDATE || action != this.action) {
if (target == null || update_type != UPDATE || action != this.action) {
return;
}

actor.set_property (property, interval.compute (progress));
target.set_property (property, interval.compute (progress));
}
}
6 changes: 6 additions & 0 deletions lib/Gestures/RootTarget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
*/

public interface Gala.RootTarget : Object, GestureTarget {
/**
* The actor manipulated by the gesture. The associated frame clock
* will be used for animation timelines.
*/
public abstract Clutter.Actor? actor { get; }

public void add_gesture_controller (GestureController controller) requires (controller.target == null) {
controller.attached (this);
weak_ref (controller.detached);
Expand Down
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ subdir('plugins/template')
if get_option('documentation')
subdir('docs')
endif
if get_option('tests')
subdir('tests')
endif
subdir('po')

vapigen = find_program('vapigen', required: false)
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
option ('documentation', type : 'boolean', value : false)
option ('tests', type : 'boolean', value : false)
option ('systemd', type : 'boolean', value : true)
option ('systemduserunitdir', type : 'string', value : '')
1 change: 1 addition & 0 deletions src/ShellClients/PanelWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class Gala.PanelWindow : ShellWindow, RootTarget {
private static HashTable<Meta.Window, Meta.Strut?> window_struts = new HashTable<Meta.Window, Meta.Strut?> (null, null);

public Clutter.Actor? actor { get { return (Clutter.Actor) window.get_compositor_private (); } }
public WindowManager wm { get; construct; }
public Pantheon.Desktop.Anchor anchor { get; construct set; }

Expand Down
2 changes: 0 additions & 2 deletions src/ShellClients/ShellClientsManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class Gala.ShellClientsManager : Object, GestureTarget {
return instance;
}

public Clutter.Actor? actor { get { return wm.stage; } }

public WindowManager wm { get; construct; }

private NotificationsClient notifications_client;
Expand Down
1 change: 0 additions & 1 deletion src/ShellClients/ShellWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

public class Gala.ShellWindow : PositionedWindow, GestureTarget {
public Clutter.Actor? actor { get { return window_actor; } }
public bool restore_previous_x11_region { private get; set; default = false; }
public bool visible_in_multitasking_view { get; set; default = false; }

Expand Down
1 change: 1 addition & 0 deletions src/Widgets/MultitaskingView/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
private GestureController workspaces_gesture_controller;
private GestureController multitasking_gesture_controller;

public Clutter.Actor? actor { get { return this; } }
public WindowManagerGala wm { get; construct; }

private Meta.Display display;
Expand Down
1 change: 1 addition & 0 deletions src/Widgets/MultitaskingView/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
*/
public signal void request_reposition ();

public Clutter.Actor? actor { get { return this; } }
public WindowManager wm { get; construct; }
public Meta.Window window { get; construct; }

Expand Down
1 change: 1 addition & 0 deletions src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Gala.WindowOverview : ActorTarget, RootTarget, ActivatableComponent
private const int TOP_GAP = 30;
private const int BOTTOM_GAP = 100;

public Clutter.Actor? actor { get { return this; } }
public WindowManager wm { get; construct; }

private GestureController gesture_controller; // Currently not used for actual touchpad gestures but only as controller
Expand Down
82 changes: 82 additions & 0 deletions tests/TestCase.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/**
* A simple test case class. To use it inherit from it and add test methods
* in the constructor using {@link add_test}. Override {@link set_up} and {@link tear_down}
* to provide per-test-method setup and teardown. Then add a `main()` function
* and return the result of {@link run}.
*/
public abstract class Gala.TestCase : Object {
public delegate void TestMethod ();

public string name { get; construct; }

private GLib.TestSuite suite;
private Adaptor[] adaptors = new Adaptor[0];

construct {
suite = new GLib.TestSuite (name);
}

public int run (string[] args) {
Test.init (ref args);
TestSuite.get_root ().add_suite ((owned) suite);
return Test.run ();
}

protected void add_test (string name, owned TestMethod test) {
var adaptor = new Adaptor (name, (owned) test, this);
adaptors += adaptor;

var test_case = new GLib.TestCase (
adaptor.name,
adaptor.set_up,
adaptor.run,
adaptor.tear_down
);

suite.add ((owned) test_case);
}

public virtual void set_up () {
}

public virtual void tear_down () {
}

public void assert_finalize_object<G> (ref G data) {
unowned var weak_pointer = data;
((Object) data).add_weak_pointer (&weak_pointer);
data = null;
assert_null (weak_pointer);
}

private class Adaptor : Object {
public string name { get; construct; }

private TestMethod test;
private TestCase test_case;

public Adaptor (string name, owned TestMethod test, TestCase test_case) {
Object (name: name);

this.test = (owned) test;
this.test_case = test_case;
}

public void set_up (void* fixture) {
test_case.set_up ();
}

public void run (void* fixture) {
test ();
}

public void tear_down (void* fixture) {
test_case.tear_down ();
}
}
}
Loading
Loading