Skip to content

Commit

Permalink
add button to cleanup unoccpuied windows
Browse files Browse the repository at this point in the history
  • Loading branch information
khimaros committed Nov 5, 2024
1 parent 72156e5 commit 8eb5d57
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion smart-auto-move@khimaros.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion smart-auto-move@khimaros.com/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
24 changes: 24 additions & 0 deletions smart-auto-move@khimaros.com/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
49 changes: 48 additions & 1 deletion smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<!-- n-columns=5 n-rows=7 -->
<!-- n-columns=5 n-rows=9 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -310,6 +310,27 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
Expand Down Expand Up @@ -346,6 +367,32 @@
<property name="vexpand">True</property>
<property name="selection-mode">none</property>
<property name="activate-on-single-click">False</property>
<child>
<object class="GtkListBoxRow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="saved-windows-cleanup-button">
<property name="label" translatable="yes">Cleanup Non-occupied Windows</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
Expand Down
42 changes: 40 additions & 2 deletions smart-auto-move@khimaros.com/ui/prefs-gtk4.ui
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
</child>
<child>
<object class="GtkLabel">
<property name="tooltip-text" translatable="1">Do not restore windows' position.</property>
<property name="tooltip-text" translatable="1">Do not restore windows&apos; position.</property>
<property name="halign">start</property>
<property name="hexpand">1</property>
<property name="label" translatable="1">Ignore Position</property>
Expand All @@ -240,7 +240,7 @@
</child>
<child>
<object class="GtkLabel">
<property name="tooltip-text" translatable="1">Do not restore windows' workspace.</property>
<property name="tooltip-text" translatable="1">Do not restore windows&apos; workspace.</property>
<property name="halign">start</property>
<property name="hexpand">1</property>
<property name="label" translatable="1">Ignore Workspace</property>
Expand Down Expand Up @@ -276,6 +276,27 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</property>
</object>
Expand Down Expand Up @@ -307,6 +328,23 @@
<property name="vexpand">1</property>
<property name="selection-mode">none</property>
<property name="activate-on-single-click">0</property>
<child>
<object class="GtkListBoxRow">
<property name="focusable">1</property>
<property name="child">
<object class="GtkBox">
<property name="homogeneous">1</property>
<child>
<object class="GtkButton" id="saved-windows-cleanup-button">
<property name="label" translatable="1">Cleanup Non-occupied Windows</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
</object>
</child>
</object>
</property>
</object>
</child>
</object>
</property>
</object>
Expand Down

0 comments on commit 8eb5d57

Please sign in to comment.