From ccee4464ec2950dc6bedb7c738cdec7adea9962a Mon Sep 17 00:00:00 2001 From: jderose9 Date: Mon, 6 Feb 2017 22:23:24 -0500 Subject: [PATCH] Cancel timers rather than using flags Previously using flags in the event handlers to decide whether they should handle the timeout event, rather than just cancelling the timeout. --- Settings.ui | 2 +- taskbar.js | 2 -- windowPreview.js | 51 +++++++++++++++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Settings.ui b/Settings.ui index ca59390..5d9dec7 100644 --- a/Settings.ui +++ b/Settings.ui @@ -305,7 +305,7 @@ True False True - If set too low, the window preview of running applications may seem to close too quickly when trying to enter the popup. If set too high, the taskbar may feel slow to highlight applications. + If set too low, the window preview of running applications may seem to close too quickly when trying to enter the popup. If set too high, the preview may linger too long when moving to an adjacent icon. True 40 0 diff --git a/taskbar.js b/taskbar.js index 7b90164..b264795 100644 --- a/taskbar.js +++ b/taskbar.js @@ -1368,7 +1368,6 @@ const taskbarAppIcon = new Lang.Class({ this.emit('menu-state-changed', true); - this.windowPreview.shouldOpen = false; this.windowPreview.close(); this.actor.set_hover(true); @@ -1413,7 +1412,6 @@ const taskbarAppIcon = new Lang.Class({ }, activate: function(button) { - this.windowPreview.shouldOpen = false; this.windowPreview.requestCloseMenu(); let event = Clutter.get_current_event(); diff --git a/windowPreview.js b/windowPreview.js index cba438a..b836745 100644 --- a/windowPreview.js +++ b/windowPreview.js @@ -56,8 +56,6 @@ const thumbnailPreviewMenu = new Lang.Class({ this._source = source; this._app = this._source.app; - this.shouldOpen = true; - this.shouldClose = false; this.actor.add_style_class_name('app-well-menu'); this.actor.set_style("max-width: " + (Main.layoutManager.primaryMonitor.width - 22) + "px;"); @@ -107,8 +105,7 @@ const thumbnailPreviewMenu = new Lang.Class({ }, _onMenuEnter: function () { - this.shouldOpen = true; - this.shouldClose = false; + this.cancelClose(); // This grab is usually called when the menu is opened. However, there seems to be a bug in the // underlying gnome-shell that causes the window contents to freeze if the grab and ungrab occur @@ -121,35 +118,51 @@ const thumbnailPreviewMenu = new Lang.Class({ }, _onMenuLeave: function () { - this.shouldOpen = false; - this.shouldClose = true; - Mainloop.timeout_add(Taskbar.DASH_ITEM_HOVER_TIMEOUT, Lang.bind(this, this.hoverClose)); + this.cancelOpen(); + this.cancelClose(); + + this._hoverCloseTimeoutId = Mainloop.timeout_add(Taskbar.DASH_ITEM_HOVER_TIMEOUT, Lang.bind(this, this.hoverClose)); }, _onEnter: function () { - this.shouldOpen = true; - this.shouldClose = false; + this.cancelOpen(); + this.cancelClose(); - Mainloop.timeout_add(this._dtpSettings.get_int('show-window-previews-timeout'), Lang.bind(this, this.hoverOpen)); + this._hoverOpenTimeoutId = Mainloop.timeout_add(this._dtpSettings.get_int('show-window-previews-timeout'), Lang.bind(this, this.hoverOpen)); }, _onLeave: function () { - this.shouldClose = true; - this.shouldOpen = false; + this.cancelOpen(); + this.cancelClose(); - Mainloop.timeout_add(this._dtpSettings.get_int('leave-timeout'), Lang.bind(this, this.hoverClose)); + this._hoverCloseTimeoutId = Mainloop.timeout_add(this._dtpSettings.get_int('leave-timeout'), Lang.bind(this, this.hoverClose)); + }, + + cancelOpen: function () { + if(this._hoverOpenTimeoutId) { + Mainloop.source_remove(this._hoverOpenTimeoutId); + log("cancelled open"); + this._hoverOpenTimeoutId = null; + } + }, + + cancelClose: function () { + if(this._hoverCloseTimeoutId) { + Mainloop.source_remove(this._hoverCloseTimeoutId); + log("cancelled close"); + this._hoverCloseTimeoutId = null; + } }, hoverOpen: function () { - if (this.shouldOpen && !this.isOpen && this._dtpSettings.get_boolean("show-window-previews")) { + this._hoverOpenTimeoutId = null; + if (!this.isOpen && this._dtpSettings.get_boolean("show-window-previews")) this.popup(); - } }, hoverClose: function () { - if (this.shouldClose) { - this.close(~0); - } + this._hoverCloseTimeoutId = null; + this.close(~0); }, destroy: function () { @@ -173,6 +186,8 @@ const thumbnailPreviewMenu = new Lang.Class({ }, close: function(animate) { + this.cancelOpen(); + if (this.isOpen) this.emit('open-state-changed', false); if (this._activeMenuItem)