From 8eb5d57dd3f824a11ac521c587e6289a9dfd9785 Mon Sep 17 00:00:00 2001 From: khimaros Date: Mon, 4 Nov 2024 18:31:06 -0800 Subject: [PATCH] add button to cleanup unoccpuied windows --- Makefile | 2 +- smart-auto-move@khimaros.com/extension.js | 6 ++- smart-auto-move@khimaros.com/metadata.json | 2 +- smart-auto-move@khimaros.com/prefs.js | 24 +++++++++ .../ui.in/prefs-gtk3.ui | 49 ++++++++++++++++++- smart-auto-move@khimaros.com/ui/prefs-gtk4.ui | 42 +++++++++++++++- 6 files changed, 119 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 04a40c0..74fd57d 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ test: .PHONY: test log: - journalctl -f /usr/bin/gnome-shell + journalctl -f /usr/bin/gnome-shell /usr/bin/gjs .PHONY: log install: smart-auto-move@khimaros.com.shell-extension.zip diff --git a/smart-auto-move@khimaros.com/extension.js b/smart-auto-move@khimaros.com/extension.js index 8ceed91..7bf4095 100644 --- a/smart-auto-move@khimaros.com/extension.js +++ b/smart-auto-move@khimaros.com/extension.js @@ -528,9 +528,13 @@ function disconnectSettingChangedSignals() { //// DEBUG UTILITIES +function info(message) { + console.log('[smart-auto-move] ' + message); +} + function debug(message) { if (debugLogging) { - console.log('[smart-auto-move] ' + message); + info(message); } } diff --git a/smart-auto-move@khimaros.com/metadata.json b/smart-auto-move@khimaros.com/metadata.json index e1d0bf6..09166bb 100644 --- a/smart-auto-move@khimaros.com/metadata.json +++ b/smart-auto-move@khimaros.com/metadata.json @@ -5,6 +5,6 @@ "description": "Smart Auto Move learns the position, size, and workspace of your application windows and restores them on subsequent launches. Supports Wayland.\n\nNOTE: Optimized for use with static workspaces. For more control, set the default behavior to IGNORE and then selectively RESTORE only desired apps.\n\nKNOWN ISSUES: Multi-monitor is not yet well supported. You may need to manually delete Saved Windows in preferences after adding or removing a display.", "settings-schema": "org.gnome.shell.extensions.smart-auto-move", "original-author": "khimaros", - "version": "27", + "version": "28", "shell-version": ["45", "46", "47"] } diff --git a/smart-auto-move@khimaros.com/prefs.js b/smart-auto-move@khimaros.com/prefs.js index 46f4f17..b030ce8 100644 --- a/smart-auto-move@khimaros.com/prefs.js +++ b/smart-auto-move@khimaros.com/prefs.js @@ -134,6 +134,11 @@ function buildPrefsWidget(extension) { let saved_windows_list_widget = builder.get_object('saved-windows-listbox'); let saved_windows_list_objects = []; + let saved_windows_cleanup_widget = builder.get_object('saved-windows-cleanup-button'); + saved_windows_cleanup_widget.connect('clicked', function () { + //console.log('CLEANUP BUTTON CLICKED'); + deleteNonOccupiedWindows(extension); + }); loadSavedWindowsSetting(extension, saved_windows_list_widget, saved_windows_list_objects); changedSavedWindowsSignal = settings.connect('changed::' + Common.SETTINGS_KEY_SAVED_WINDOWS, function () { loadSavedWindowsSetting(extension, saved_windows_list_widget, saved_windows_list_objects); @@ -241,12 +246,31 @@ function loadOverridesSetting(extension, list_widget, list_objects) { }); } +function deleteNonOccupiedWindows(extension) { + let settings = extension.getSettings(); + + let saved_windows = JSON.parse(settings.get_string(Common.SETTINGS_KEY_SAVED_WINDOWS)); + + Object.keys(saved_windows).forEach(function (wsh) { + let sws = saved_windows[wsh]; + sws.forEach(function (sw, swi) { + if (!sw.occupied) { + sws.splice(swi, 1); + if (sws.length < 1) delete (saved_windows[wsh]); + } + }); + }); + + settings.set_string(Common.SETTINGS_KEY_SAVED_WINDOWS, JSON.stringify(saved_windows)); +} + function loadSavedWindowsSetting(extension, list_widget, list_objects) { let settings = extension.getSettings(); let saved_windows = JSON.parse(settings.get_string(Common.SETTINGS_KEY_SAVED_WINDOWS)); let current_row = list_widget.get_first_child(); + current_row = current_row.get_next_sibling(); // skip the first row while (current_row !== null) { let prev_row = current_row; current_row = current_row.get_next_sibling(); diff --git a/smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui b/smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui index eb48230..7ee785a 100644 --- a/smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui +++ b/smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui @@ -38,7 +38,7 @@ True True - + True False @@ -310,6 +310,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -346,6 +367,32 @@ True none False + + + True + True + + + True + False + True + + + Cleanup Non-occupied Windows + True + True + True + + + False + True + 0 + + + + + + diff --git a/smart-auto-move@khimaros.com/ui/prefs-gtk4.ui b/smart-auto-move@khimaros.com/ui/prefs-gtk4.ui index 881e33b..c783b72 100644 --- a/smart-auto-move@khimaros.com/ui/prefs-gtk4.ui +++ b/smart-auto-move@khimaros.com/ui/prefs-gtk4.ui @@ -217,7 +217,7 @@ - Do not restore windows' position. + Do not restore windows' position. start 1 Ignore Position @@ -240,7 +240,7 @@ - Do not restore windows' workspace. + Do not restore windows' workspace. start 1 Ignore Workspace @@ -276,6 +276,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -307,6 +328,23 @@ 1 none 0 + + + 1 + + + 1 + + + Cleanup Non-occupied Windows + 1 + 1 + + + + + +