Skip to content

Commit

Permalink
[smart-panel@mohammad-sn] Use Flipper/DesktopCube in more cases (#793)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
klangman authored Dec 17, 2024
1 parent 4254454 commit ccf95fb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
50 changes: 41 additions & 9 deletions smart-panel@mohammad-sn/files/smart-panel@mohammad-sn/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand All @@ -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'; };
Expand All @@ -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') {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ccf95fb

Please sign in to comment.