From de01f56cc424ef05f56fd65189a58344345b4bd5 Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 14:24:14 +0700 Subject: [PATCH 01/14] Update to gnome 45 --- extension.js | 23 +++++++++++++---------- metadata.json | 4 +--- prefs.js | 12 ++++++++---- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/extension.js b/extension.js index 39a604d..e5b4f59 100644 --- a/extension.js +++ b/extension.js @@ -1,9 +1,11 @@ "use strict"; -const { Shell, Meta, Gio, GObject } = imports.gi; -const Main = imports.ui.main; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); +import Shell from "gi://Shell"; +import Meta from "gi://Meta"; +import Gio from "gi://Gio"; +import GObject from "gi://GObject"; +import * as Main from 'resource:///org/gnome/shell/ui/main.js'; +import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; @@ -71,8 +73,9 @@ const KeyboardShortcuts = GObject.registerClass( } ); -class Extension { - constructor() { +export default class FocusWindowExtensions extends Extension { + constructor(metadata) { + super(metadata); this.shortcuts = null; this.settingsListener = null; this.settings = null; @@ -81,7 +84,7 @@ class Extension { enable() { this.shortcuts = new KeyboardShortcuts(); - this.settings = ExtensionUtils.getSettings(SETTINGS_ID); + this.settings = this.getSettings(SETTINGS_ID); this.settingsListener = this.settings.connect( `changed::${SETTINGS_KEY}`, @@ -175,8 +178,8 @@ class Extension { return false; } catch (error) { - log("setting trigger failed: "); - log(error); + Console.log("setting trigger failed: "); + Console.log(error); } }); } @@ -194,5 +197,5 @@ class Extension { } function init() { - return new Extension(); + return new FocusWindowExtensions(); } diff --git a/metadata.json b/metadata.json index 93ac039..797bae1 100644 --- a/metadata.json +++ b/metadata.json @@ -3,9 +3,7 @@ "description": "This extension allows one to create various shortcuts for applications, enabling the ability to have one shortcut that triggers both the launch and focus of an application window.", "uuid": "focus-window@chris.al", "shell-version": [ - "42", - "43", - "44" + "45" ], "url": "https://github.com/pcbowers/focus-window", "version": 1 diff --git a/prefs.js b/prefs.js index bf0eba5..ea42cf0 100644 --- a/prefs.js +++ b/prefs.js @@ -1,7 +1,11 @@ -const { GObject, GLib, Gio, Adw, Gtk, Gdk } = imports.gi; +import Adw from "gi://Adw"; +import Gtk from "gi://Gtk"; +import Gdk from "gi://Gdk"; +import GLib from "gi://GLib"; +import Gio from "gi://Gio"; +import GObject from "gi://GObject"; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); +import * as Me from './extension.js'; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; @@ -377,7 +381,7 @@ function fillPreferencesWindow(window) { const focusWidgets = []; // get settings - const extensionSettings = ExtensionUtils.getSettings(SETTINGS_ID); + const extensionSettings = Me.getSettings(SETTINGS_ID); const { getAllSettings, setSettings } = generateSettings(extensionSettings); // create preference pages From 73230f10120804a9ac553fb15e04dbf04be7486b Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 15:29:55 +0700 Subject: [PATCH 02/14] More changes --- prefs.js | 163 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 83 insertions(+), 80 deletions(-) diff --git a/prefs.js b/prefs.js index ea42cf0..752279d 100644 --- a/prefs.js +++ b/prefs.js @@ -6,6 +6,7 @@ import Gio from "gi://Gio"; import GObject from "gi://GObject"; import * as Me from './extension.js'; +import {ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; @@ -376,88 +377,90 @@ const FocusWidget = GObject.registerClass( } ); -function fillPreferencesWindow(window) { - // stores all focusWidgets - const focusWidgets = []; - - // get settings - const extensionSettings = Me.getSettings(SETTINGS_ID); - const { getAllSettings, setSettings } = generateSettings(extensionSettings); - - // create preference pages - const page = new Adw.PreferencesPage(); - const group = new Adw.PreferencesGroup(); - page.add(group); - window.add(page); - window.set_margin_bottom(10); - window.set_margin_top(10); - window.set_margin_start(5); - window.set_margin_end(5); - - // generate 'Add Application' button - const button = new Gtk.Button({ valign: Gtk.Align.CENTER }); - const buttonContent = new Adw.ButtonContent({ - "icon-name": "list-add-symbolic", - label: "Add Application", - }); - button.add_css_class("suggested-action"); - group.set_header_suffix(button); - button.set_child(buttonContent); - - // sets the title and description of group - const setTitleAndDescription = () => { - group.set_title( - `${focusWidgets.length} Shortcut${ - focusWidgets.length === 1 ? "" : "s Created" - }` - ); - - const configured = focusWidgets.filter( - (item) => - item.widget.settings && - item.widget.settings.applicationToFocus && - item.widget.settings.keyboardShortcut - ).length; - - group.set_description( - `${ - configured === focusWidgets.length ? "All" : configured - } of which are fully configured` - ); - }; +export default class FocusWindowPreferences extends ExtensionPreferences { + fillPreferencesWindow(window) { + // stores all focusWidgets + const focusWidgets = []; + + // get settings + const extensionSettings = Me.getSettings(SETTINGS_ID); + const {getAllSettings, setSettings} = generateSettings(extensionSettings); + + // create preference pages + const page = new Adw.PreferencesPage(); + const group = new Adw.PreferencesGroup(); + page.add(group); + window.add(page); + window.set_margin_bottom(10); + window.set_margin_top(10); + window.set_margin_start(5); + window.set_margin_end(5); + + // generate 'Add Application' button + const button = new Gtk.Button({valign: Gtk.Align.CENTER}); + const buttonContent = new Adw.ButtonContent({ + "icon-name": "list-add-symbolic", + label: "Add Application", + }); + button.add_css_class("suggested-action"); + group.set_header_suffix(button); + button.set_child(buttonContent); + + // sets the title and description of group + const setTitleAndDescription = () => { + group.set_title( + `${focusWidgets.length} Shortcut${ + focusWidgets.length === 1 ? "" : "s Created" + }` + ); - // removes focus widget from page and memory, updates count label - const onDelete = (id) => () => { - const index = focusWidgets.findIndex((i) => i.id === id); - if (index < 0) return; + const configured = focusWidgets.filter( + (item) => + item.widget.settings && + item.widget.settings.applicationToFocus && + item.widget.settings.keyboardShortcut + ).length; + + group.set_description( + `${ + configured === focusWidgets.length ? "All" : configured + } of which are fully configured` + ); + }; + + // removes focus widget from page and memory, updates count label + const onDelete = (id) => () => { + const index = focusWidgets.findIndex((i) => i.id === id); + if (index < 0) return; + + group.remove(focusWidgets[index].widget); + focusWidgets.splice(index, 1); + setTitleAndDescription(); + }; + + // add focus widgets from settings + getAllSettings().forEach((settings) => { + const newWidget = new FocusWidget( + {"margin-top": 0}, + setSettings(settings.id), + onDelete(settings.id), + settings.id, + settings, + false + ); + focusWidgets.push({id: settings.id, widget: newWidget}); + group.add(newWidget); + }); - group.remove(focusWidgets[index].widget); - focusWidgets.splice(index, 1); setTitleAndDescription(); - }; - // add focus widgets from settings - getAllSettings().forEach((settings) => { - const newWidget = new FocusWidget( - { "margin-top": 0 }, - setSettings(settings.id), - onDelete(settings.id), - settings.id, - settings, - false - ); - focusWidgets.push({ id: settings.id, widget: newWidget }); - group.add(newWidget); - }); - - setTitleAndDescription(); - - // add focus widgets when 'Add Application' button is clicked - button.connect("clicked", () => { - const id = createId(); - const newWidget = new FocusWidget({}, setSettings(id), onDelete(id), id); - focusWidgets.push({ id, widget: newWidget }); - group.add(newWidget); - setTitleAndDescription(); - }); + // add focus widgets when 'Add Application' button is clicked + button.connect("clicked", () => { + const id = createId(); + const newWidget = new FocusWidget({}, setSettings(id), onDelete(id), id); + focusWidgets.push({id, widget: newWidget}); + group.add(newWidget); + setTitleAndDescription(); + }); + } } From 489040c9f128d4687c8f925c82d39ec7ec98eea0 Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 15:41:06 +0700 Subject: [PATCH 03/14] more fix --- extension.js | 3 +-- prefs.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/extension.js b/extension.js index e5b4f59..915adf8 100644 --- a/extension.js +++ b/extension.js @@ -7,7 +7,6 @@ import GObject from "gi://GObject"; import * as Main from 'resource:///org/gnome/shell/ui/main.js'; import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; -const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; @@ -84,7 +83,7 @@ export default class FocusWindowExtensions extends Extension { enable() { this.shortcuts = new KeyboardShortcuts(); - this.settings = this.getSettings(SETTINGS_ID); + this.settings = this.getSettings(); this.settingsListener = this.settings.connect( `changed::${SETTINGS_KEY}`, diff --git a/prefs.js b/prefs.js index 752279d..349727a 100644 --- a/prefs.js +++ b/prefs.js @@ -8,7 +8,6 @@ import GObject from "gi://GObject"; import * as Me from './extension.js'; import {ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; -const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; @@ -383,7 +382,7 @@ export default class FocusWindowPreferences extends ExtensionPreferences { const focusWidgets = []; // get settings - const extensionSettings = Me.getSettings(SETTINGS_ID); + const extensionSettings = Me.getSettings(); const {getAllSettings, setSettings} = generateSettings(extensionSettings); // create preference pages From 5d8e6086c5b524b244db1fdea0d29fb1f60e0f03 Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 15:41:55 +0700 Subject: [PATCH 04/14] More fix --- extension.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/extension.js b/extension.js index 915adf8..b29a8fb 100644 --- a/extension.js +++ b/extension.js @@ -177,8 +177,6 @@ export default class FocusWindowExtensions extends Extension { return false; } catch (error) { - Console.log("setting trigger failed: "); - Console.log(error); } }); } From f950c42fa9f1aa3167c1b6659463e9c7f1942e3c Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 15:44:53 +0700 Subject: [PATCH 05/14] Revert "more fix" This reverts commit 489040c9f128d4687c8f925c82d39ec7ec98eea0. --- extension.js | 3 ++- prefs.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/extension.js b/extension.js index b29a8fb..7cd2293 100644 --- a/extension.js +++ b/extension.js @@ -7,6 +7,7 @@ import GObject from "gi://GObject"; import * as Main from 'resource:///org/gnome/shell/ui/main.js'; import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; +const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; @@ -83,7 +84,7 @@ export default class FocusWindowExtensions extends Extension { enable() { this.shortcuts = new KeyboardShortcuts(); - this.settings = this.getSettings(); + this.settings = this.getSettings(SETTINGS_ID); this.settingsListener = this.settings.connect( `changed::${SETTINGS_KEY}`, diff --git a/prefs.js b/prefs.js index 349727a..752279d 100644 --- a/prefs.js +++ b/prefs.js @@ -8,6 +8,7 @@ import GObject from "gi://GObject"; import * as Me from './extension.js'; import {ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; +const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; @@ -382,7 +383,7 @@ export default class FocusWindowPreferences extends ExtensionPreferences { const focusWidgets = []; // get settings - const extensionSettings = Me.getSettings(); + const extensionSettings = Me.getSettings(SETTINGS_ID); const {getAllSettings, setSettings} = generateSettings(extensionSettings); // create preference pages From 31f6399570ed98d776e1d0cd190ff81cd9ef8118 Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 16:21:11 +0700 Subject: [PATCH 06/14] More fix --- prefs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prefs.js b/prefs.js index 752279d..3697552 100644 --- a/prefs.js +++ b/prefs.js @@ -6,7 +6,7 @@ import Gio from "gi://Gio"; import GObject from "gi://GObject"; import * as Me from './extension.js'; -import {ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; +import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; @@ -100,7 +100,7 @@ function init() {} const FocusWidget = GObject.registerClass( { GTypeName: "FocusWidget", - Template: Me.dir.get_child("prefs.ui").get_uri(), + Template: `resource://${Me.app_path}/ui/prefs/about.ui`, InternalChildren: [ "application_to_focus", "application_list", @@ -383,7 +383,7 @@ export default class FocusWindowPreferences extends ExtensionPreferences { const focusWidgets = []; // get settings - const extensionSettings = Me.getSettings(SETTINGS_ID); + const extensionSettings = this.getSettings(SETTINGS_ID); const {getAllSettings, setSettings} = generateSettings(extensionSettings); // create preference pages From 0398ca20f2522c3423c493180193f29881ec263c Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 18:00:54 +0700 Subject: [PATCH 07/14] importing extension.js fix --- prefs.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prefs.js b/prefs.js index 3697552..4bf22ac 100644 --- a/prefs.js +++ b/prefs.js @@ -5,13 +5,14 @@ import GLib from "gi://GLib"; import Gio from "gi://Gio"; import GObject from "gi://GObject"; -import * as Me from './extension.js'; import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; +const APP_UUID = "focus-window@chris.al"; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; +const Me = ExtensionPreferences.lookupByUUID(APP_UUID); // Helper Functions // creates a simple unique ID based on date @@ -100,7 +101,7 @@ function init() {} const FocusWidget = GObject.registerClass( { GTypeName: "FocusWidget", - Template: `resource://${Me.app_path}/ui/prefs/about.ui`, + Template: `resource://${Me.path}/ui/prefs/about.ui`, InternalChildren: [ "application_to_focus", "application_list", From 88b27ef1c64e4977a1e28bcab430e46d5dba7b2e Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 18:04:36 +0700 Subject: [PATCH 08/14] Path fix --- prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefs.js b/prefs.js index 4bf22ac..af29198 100644 --- a/prefs.js +++ b/prefs.js @@ -101,7 +101,7 @@ function init() {} const FocusWidget = GObject.registerClass( { GTypeName: "FocusWidget", - Template: `resource://${Me.path}/ui/prefs/about.ui`, + Template: `resource://${Me.path}/prefs.ui`, InternalChildren: [ "application_to_focus", "application_list", From 64a388ad27e50806e9ce820bad410013a68e0cef Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 18:41:25 +0700 Subject: [PATCH 09/14] Test app Path --- prefs.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/prefs.js b/prefs.js index af29198..adbc4dd 100644 --- a/prefs.js +++ b/prefs.js @@ -7,12 +7,11 @@ import GObject from "gi://GObject"; import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; -const APP_UUID = "focus-window@chris.al"; +const APP_PATH= "/org/gnome/shell/extensions/focus-window"; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; -const Me = ExtensionPreferences.lookupByUUID(APP_UUID); // Helper Functions // creates a simple unique ID based on date @@ -101,7 +100,7 @@ function init() {} const FocusWidget = GObject.registerClass( { GTypeName: "FocusWidget", - Template: `resource://${Me.path}/prefs.ui`, + Template: `resource://${APP_PATH}/prefs.ui`, InternalChildren: [ "application_to_focus", "application_list", From c792903331804ef55aa0b0d0c5d227d5978d6f0f Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 18:50:25 +0700 Subject: [PATCH 10/14] test more --- prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefs.js b/prefs.js index adbc4dd..996080d 100644 --- a/prefs.js +++ b/prefs.js @@ -179,7 +179,7 @@ const FocusWidget = GObject.registerClass( })); // make them choosable - this.allApplications.forEach((a) => this.applicationList.append(a.name)); + this.allApplications.forEach((a) => this.applicationList?.append(a.name)); } addDeleteButton() { From 993531513bf0599390df627424446efd4938c7aa Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 19:10:45 +0700 Subject: [PATCH 11/14] Revert "test more" This reverts commit c792903331804ef55aa0b0d0c5d227d5978d6f0f. --- prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefs.js b/prefs.js index 996080d..adbc4dd 100644 --- a/prefs.js +++ b/prefs.js @@ -179,7 +179,7 @@ const FocusWidget = GObject.registerClass( })); // make them choosable - this.allApplications.forEach((a) => this.applicationList?.append(a.name)); + this.allApplications.forEach((a) => this.applicationList.append(a.name)); } addDeleteButton() { From 4f6ac389f5dc1ff9042cb217e08a1a8e8f9d8cb0 Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 19:24:54 +0700 Subject: [PATCH 12/14] Simple fix --- prefs.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prefs.js b/prefs.js index adbc4dd..a27e71f 100644 --- a/prefs.js +++ b/prefs.js @@ -179,6 +179,7 @@ const FocusWidget = GObject.registerClass( })); // make them choosable + this.applicationList ??= []; this.allApplications.forEach((a) => this.applicationList.append(a.name)); } @@ -384,6 +385,7 @@ export default class FocusWindowPreferences extends ExtensionPreferences { // get settings const extensionSettings = this.getSettings(SETTINGS_ID); + console.error(JSON.stringify(extensionSettings)); const {getAllSettings, setSettings} = generateSettings(extensionSettings); // create preference pages From e0ad975634c52b4145f217a87353052cefc181ae Mon Sep 17 00:00:00 2001 From: popemkt Date: Thu, 1 Feb 2024 20:17:33 +0700 Subject: [PATCH 13/14] Fix --- prefs.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/prefs.js b/prefs.js index a27e71f..31ad95e 100644 --- a/prefs.js +++ b/prefs.js @@ -7,7 +7,6 @@ import GObject from "gi://GObject"; import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; -const APP_PATH= "/org/gnome/shell/extensions/focus-window"; const SETTINGS_ID = "org.gnome.shell.extensions.focus-window"; const SETTINGS_KEY = "app-settings"; const SETTINGS_VARIANT = "aa{sv}"; @@ -100,7 +99,7 @@ function init() {} const FocusWidget = GObject.registerClass( { GTypeName: "FocusWidget", - Template: `resource://${APP_PATH}/prefs.ui`, + Template: GLib.uri_resolve_relative(import.meta.url, './prefs.ui', GLib.UriFlags.NONE), InternalChildren: [ "application_to_focus", "application_list", @@ -179,7 +178,6 @@ const FocusWidget = GObject.registerClass( })); // make them choosable - this.applicationList ??= []; this.allApplications.forEach((a) => this.applicationList.append(a.name)); } From 0fa725416a91e0de5317f02a648c3a4c874f07aa Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Thu, 19 Feb 2026 12:13:32 +0700 Subject: [PATCH 14/14] Add "Move to Current Desktop" toggle and GNOME 46 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New per-app toggle to move windows to the active workspace before focusing, instead of always doing it unconditionally - Add GNOME 46 to supported shell-version in metadata.json - Add .gitignore for IDE artifacts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .gitignore | 2 ++ extension.js | 19 +++++++++++-------- metadata.json | 6 +++++- prefs.js | 12 ++++++++++++ prefs.ui | 14 ++++++++++++++ 5 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d801d6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +*.DotSettings.user diff --git a/extension.js b/extension.js index 7cd2293..1a0a2bc 100644 --- a/extension.js +++ b/extension.js @@ -161,18 +161,21 @@ export default class FocusWindowExtensions extends Extension { return appWindows[0].minimize(); } + // Draw focus to the window if it is not already focused if (appWindows.length === 1) { - // Get the currently active workspace const appWindow = appWindows[0]; - const activeWorkspace = global.workspace_manager.get_active_workspace(); - const windowWorkspaceIndex = appWindow.get_workspace().index(); - // If the window is not in the active workspace, move it - // Move the window to the active workspace - if (activeWorkspace.index() !== windowWorkspaceIndex){ - appWindow.change_workspace(activeWorkspace); + if (setting.moveToCurrentDesktop){ + // Get the currently active workspace + const activeWorkspace = global.workspace_manager.get_active_workspace(); + const windowWorkspaceIndex = appWindow.get_workspace().index(); + // If the window is not in the active workspace, move it + // Move the window to the active workspace + if (activeWorkspace.index() !== windowWorkspaceIndex){ + appWindow.change_workspace(activeWorkspace); + } } - + return Main.activateWindow(appWindow); } diff --git a/metadata.json b/metadata.json index 797bae1..918b5a9 100644 --- a/metadata.json +++ b/metadata.json @@ -3,7 +3,11 @@ "description": "This extension allows one to create various shortcuts for applications, enabling the ability to have one shortcut that triggers both the launch and focus of an application window.", "uuid": "focus-window@chris.al", "shell-version": [ - "45" + "45", + "46", + "47", + "48", + "49" ], "url": "https://github.com/pcbowers/focus-window", "version": 1 diff --git a/prefs.js b/prefs.js index 31ad95e..ed61e9f 100644 --- a/prefs.js +++ b/prefs.js @@ -106,6 +106,7 @@ const FocusWidget = GObject.registerClass( "title_to_match", "exact_title_match", "launch_application", + "move_to_current_desktop", "command_line_arguments", "keyboard_shortcut_row", "keyboard_shortcut", @@ -123,6 +124,7 @@ const FocusWidget = GObject.registerClass( titleToMatch: "", exactTitleMatch: false, launchApplication: true, + moveToCurrentDesktop: true, commandLineArguments: "", keyboardShortcut: "", }, @@ -140,6 +142,7 @@ const FocusWidget = GObject.registerClass( this.titleToMatch = this._title_to_match; this.exactTitleMatch = this._exact_title_match; this.launchApplication = this._launch_application; + this.moveToCurrentDesktop = this._move_to_current_desktop; this.commandLineArguments = this._command_line_arguments; this.keyboardShortcutRow = this._keyboard_shortcut_row; this.keyboardShortcut = this._keyboard_shortcut; @@ -162,6 +165,7 @@ const FocusWidget = GObject.registerClass( this.titleToMatch.set_text(this.settings.titleToMatch); this.exactTitleMatch.set_active(this.settings.exactTitleMatch); this.launchApplication.set_active(this.settings.launchApplication); + this.moveToCurrentDesktop.set_active(this.settings.moveToCurrentDesktop); this.commandLineArguments.set_text(this.settings.commandLineArguments); this.keyboardShortcut.set_accelerator(this.settings.keyboardShortcut); } @@ -327,6 +331,14 @@ const FocusWidget = GObject.registerClass( this.settings.launchApplication = !!active; this.saveSettings(); } + + // saves launch application state + // bound by signal in UI + onMoveToCurrentDesktopToggled(swtch) { + const active = swtch.get_active(); + this.settings.moveToCurrentDesktop = !!active; + this.saveSettings(); + } // saves written command lines // bound by signal in UI diff --git a/prefs.ui b/prefs.ui index ff23379..8f02f83 100644 --- a/prefs.ui +++ b/prefs.ui @@ -91,5 +91,19 @@ Press Esc to cancel or Backspace to unbind the shortcut. + + + Move to current Desktop + Toggle this on if you want to move the + move_to_current_desktop + + + center + true + + + + + \ No newline at end of file