From ccf95fbc7ca7ca39fc8209570e9dea1240139361 Mon Sep 17 00:00:00 2001 From: Kevin Langman Date: Tue, 17 Dec 2024 10:51:13 -0500 Subject: [PATCH] [smart-panel@mohammad-sn] Use Flipper/DesktopCube in more cases (#793) Use a new API that will be added to Flipper & DesktopCube for switching the workspace. This API will allow switching to arbitrary workspaces rather than just to workspaces that are adjacent to the current one. The change checks if the new API exists (which it does not currently, but Flipper & DesktopCube updates will follow soon) and uses the API if it exists. If the API is not found, the code will use DesktopCube/Flipper as it did before (in a slightly more limited way then what is possible using the API). --- .../smart-panel@mohammad-sn/extension.js | 50 +++++++++++++++---- .../smart-panel@mohammad-sn/metadata.json | 2 +- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/extension.js b/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/extension.js index 4581da15..96632fb7 100644 --- a/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/extension.js +++ b/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/extension.js @@ -208,10 +208,11 @@ SmartPanelExt.prototype = { let limit = this._lastScroll + this.scroll_delay; if (this.no_fast_scroll && currentTime < limit && currentTime >= this._lastScroll) { } else if (this.scrl_action == 'switch_workspace') { - if (ExtensionSystem.runningExtensions.indexOf('DesktopCube@yare') > -1 ) { + this._updateWorkspaceSwitcherExt(); + // If we didn't find the workspace switcher extension APIs, check if we have older versions of DesktopCube or Flipper + if (!this.workspaceSwitcherExt && ExtensionSystem.runningExtensions.indexOf('DesktopCube@yare') > -1 ) { //~ global.log("DesktopCube@yare DETECTED!!!"); - if (this.DesktopCube) {} - else { + if (!this.DesktopCube) { //~ global.log("ExtensionSystem.extensions['DesktopCube@yare']['5.4']['extension']: "+Object.keys(ExtensionSystem.extensions['DesktopCube@yare']['5.4']['extension'])); this.DesktopCube = ExtensionSystem.extensions['DesktopCube@yare']['5.4']['extension']; } @@ -228,10 +229,11 @@ SmartPanelExt.prototype = { } } else - if (ExtensionSystem.runningExtensions.indexOf('Flipper@connerdev') > -1) { + if (!this.workspaceSwitcherExt && ExtensionSystem.runningExtensions.indexOf('Flipper@connerdev') > -1) { //~ global.log("Flipper@connerdev DETECTED!!!"); - if (this.Flipper){} - else { this.Flipper = ExtensionSystem.extensions['Flipper@connerdev']['5.4']['extension']; } + if (!this.Flipper) { + this.Flipper = ExtensionSystem.extensions['Flipper@connerdev']['5.4']['extension']; + } let binding = []; binding.get_mask = function(){ return 0x0; }; if (scrollDirection == 1) binding.get_name = function(){ return 'switch-to-workspace-left'; }; @@ -257,8 +259,12 @@ SmartPanelExt.prototype = { if (reqWsInex < 0) reqWsInex = first; else if (reqWsInex > last) reqWsInex = flast; let reqWs = global.screen.get_workspace_by_index(reqWsInex); - reqWs.activate(global.get_current_time()); - this.showWorkspaceOSD(); + if (this.workspaceSwitcherExt) { + this.workspaceSwitcherExt.ExtSwitchToWorkspace(reqWs); + } else { + reqWs.activate(global.get_current_time()); + this.showWorkspaceOSD(); + } } } else if (this.scrl_action == 'switch-windows') { @@ -366,7 +372,15 @@ SmartPanelExt.prototype = { break; } - if (reqWs) { reqWs.activate(global.get_current_time()); this.showWorkspaceOSD(); } + if (reqWs) { + this._updateWorkspaceSwitcherExt(); + if (this.workspaceSwitcherExt) { + this.workspaceSwitcherExt.ExtSwitchToWorkspace(reqWs); + } else { + reqWs.activate(global.get_current_time()); + this.showWorkspaceOSD(); + } + } }, showWorkspaceOSD : function() { @@ -445,6 +459,24 @@ SmartPanelExt.prototype = { this._workspace_osd = null; } }, + + _updateWorkspaceSwitcherExt : function() { + // Check if one of the workspace switcher extensions are installed or if the state has changed since we last checked + if (ExtensionSystem.runningExtensions.indexOf('DesktopCube@yare') > -1 ) { + if (!this.workspaceSwitcherExt || this.workspaceSwitcherExt !== ExtensionSystem.extensions['DesktopCube@yare']['5.4']['extension']) { + this.workspaceSwitcherExt = ExtensionSystem.extensions['DesktopCube@yare']['5.4']['extension']; + } + } else if (ExtensionSystem.runningExtensions.indexOf('Flipper@connerdev') > -1) { + if (!this.workspaceSwitcherExt || this.workspaceSwitcherExt !== ExtensionSystem.extensions['Flipper@connerdev']['5.4']['extension']) { + this.workspaceSwitcherExt = ExtensionSystem.extensions['Flipper@connerdev']['5.4']['extension']; + } + } + // Make sure the switcher extension has the required API to allow us to change to any arbitrary workspace + if (this.workspaceSwitcherExt && typeof this.workspaceSwitcherExt.ExtSwitchToWorkspace !== "function") + { + this.workspaceSwitcherExt = null; + } + }, } function myClassicSwitcher() { diff --git a/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/metadata.json b/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/metadata.json index 5c39b160..0fcae676 100644 --- a/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/metadata.json +++ b/smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/metadata.json @@ -23,7 +23,7 @@ ], "description": "Switch between workspaces, show desktop, activate overview or expo, ... by scrolling, double click, mouse gestures etc on free space of the panel.", "name": "Smart Panel", - "version": "1.4.1", + "version": "1.4.2", "uuid": "smart-panel@mohammad-sn", "url": "https://cinnamon-spices.linuxmint.com/extensions/view/80", "author": "mohammad-sn"