From 1220aaf8c6c55a0e0b9eacd9d579557f874cba37 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Mon, 24 Feb 2020 19:03:01 +0100
Subject: [PATCH 5/5] appIcons, windowPreview: Use vfunc instead of signals
Given that now all the UI classes are actors themselves, it's better to use
virtual functions to handle to their own signals
---
appIcons.js | 32 ++++++++------------------------
windowPreview.js | 21 ++++++++++++---------
2 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/appIcons.js b/appIcons.js
index d3d845b..b317267 100644
--- a/appIcons.js
+++ b/appIcons.js
@@ -87,7 +87,6 @@ class MyAppIcon extends Dash.DashIcon {
this._location = appInfo ? appInfo.get_string('XdtdUri') : null;
this._updateIndicatorStyle();
- this._optionalScrollCycleWindows();
// Monitor windows-changes instead of app state.
// Keep using the same Id and function callback (that is extended)
@@ -139,12 +138,6 @@ class MyAppIcon extends Dash.DashIcon {
]);
}
- this._signalsHandler.add([
- Docking.DockManager.settings,
- 'changed::scroll-action',
- this._optionalScrollCycleWindows.bind(this)
- ]);
-
this._numberOverlay();
this._previewMenuManager = null;
@@ -191,20 +184,11 @@ class MyAppIcon extends Dash.DashIcon {
this.onWindowsChanged();
}
- _optionalScrollCycleWindows() {
- if (this._scrollEventHandler) {
- this.disconnect(this._scrollEventHandler);
- this._scrollEventHandler = 0;
- }
-
+ vfunc_scroll_event(scrollEvent) {
let settings = Docking.DockManager.settings;
let isEnabled = settings.get_enum('scroll-action') === scrollAction.CYCLE_WINDOWS;
- if (!isEnabled) return;
- this._scrollEventHandler = this.connect('scroll-event',
- this.onScrollEvent.bind(this));
- }
-
- onScrollEvent(actor, event) {
+ if (!isEnabled)
+ return Clutter.EVENT_PROPAGATE;
// We only activate windows of running applications, i.e. we never open new windows
// We check if the app is running, and that the # of windows is > 0 in
@@ -213,10 +197,10 @@ class MyAppIcon extends Dash.DashIcon {
&& this.getInterestingWindows().length > 0;
if (!appIsRunning)
- return false
+ return Clutter.EVENT_PROPAGATE;
if (this._optionalScrollCycleWindowsDeadTimeId)
- return false;
+ return Clutter.EVENT_PROPAGATE;
else
this._optionalScrollCycleWindowsDeadTimeId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT, 250, () => {
@@ -225,7 +209,7 @@ class MyAppIcon extends Dash.DashIcon {
let direction = null;
- switch (event.get_scroll_direction()) {
+ switch (scrollEvent.direction) {
case Clutter.ScrollDirection.UP:
direction = Meta.MotionDirection.UP;
break;
@@ -233,7 +217,7 @@ class MyAppIcon extends Dash.DashIcon {
direction = Meta.MotionDirection.DOWN;
break;
case Clutter.ScrollDirection.SMOOTH:
- let [dx, dy] = event.get_scroll_delta();
+ let [, dy] = Clutter.get_current_event().get_scroll_delta();
if (dy < 0)
direction = Meta.MotionDirection.UP;
else if (dy > 0)
@@ -257,7 +241,7 @@ class MyAppIcon extends Dash.DashIcon {
}
else
this.app.activate();
- return true;
+ return Clutter.EVENT_STOP;
}
onWindowsChanged() {
diff --git a/windowPreview.js b/windowPreview.js
index 3a5cafd..310353a 100644
--- a/windowPreview.js
+++ b/windowPreview.js
@@ -362,11 +362,6 @@ class DashToDock_WindowPreviewMenuItem extends PopupMenu.PopupBaseMenuItem {
box.add(labelBin);
this.add_actor(box);
- this.connect('enter-event', this._onEnter.bind(this));
- this.connect('leave-event', this._onLeave.bind(this));
- this.connect('key-focus-in', this._onEnter.bind(this));
- this.connect('key-focus-out', this._onLeave.bind(this));
-
this._cloneTexture(window);
this.connect('destroy', this._onDestroy.bind(this));
@@ -478,16 +473,24 @@ class DashToDock_WindowPreviewMenuItem extends PopupMenu.PopupBaseMenuItem {
return n>0;
}
- _onEnter() {
+ vfunc_key_focus_in() {
+ super.vfunc_key_focus_in();
this._showCloseButton();
- return Clutter.EVENT_PROPAGATE;
}
- _onLeave() {
+ vfunc_key_focus_out() {
+ super.vfunc_key_focus_out();
this._hideCloseButton();
}
- return Clutter.EVENT_PROPAGATE;
+ vfunc_enter_event(crossingEvent) {
+ this._showCloseButton();
+ return super.vfunc_enter_event(crossingEvent);
+ }
+
+ vfunc_leave_event(crossingEvent) {
+ this._hideCloseButton();
+ return super.vfunc_leave_event(crossingEvent);
}
_idleToggleCloseButton() {
--
2.24.1