Skip to content

Commit 8eb5d57

Browse files
committed
add button to cleanup unoccpuied windows
1 parent 72156e5 commit 8eb5d57

File tree

6 files changed

+119
-6
lines changed

6 files changed

+119
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test:
2525
.PHONY: test
2626

2727
log:
28-
journalctl -f /usr/bin/gnome-shell
28+
journalctl -f /usr/bin/gnome-shell /usr/bin/gjs
2929
.PHONY: log
3030

3131
install: smart-auto-move@khimaros.com.shell-extension.zip

smart-auto-move@khimaros.com/extension.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,13 @@ function disconnectSettingChangedSignals() {
528528

529529
//// DEBUG UTILITIES
530530

531+
function info(message) {
532+
console.log('[smart-auto-move] ' + message);
533+
}
534+
531535
function debug(message) {
532536
if (debugLogging) {
533-
console.log('[smart-auto-move] ' + message);
537+
info(message);
534538
}
535539
}
536540

smart-auto-move@khimaros.com/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"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.",
66
"settings-schema": "org.gnome.shell.extensions.smart-auto-move",
77
"original-author": "khimaros",
8-
"version": "27",
8+
"version": "28",
99
"shell-version": ["45", "46", "47"]
1010
}

smart-auto-move@khimaros.com/prefs.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ function buildPrefsWidget(extension) {
134134

135135
let saved_windows_list_widget = builder.get_object('saved-windows-listbox');
136136
let saved_windows_list_objects = [];
137+
let saved_windows_cleanup_widget = builder.get_object('saved-windows-cleanup-button');
138+
saved_windows_cleanup_widget.connect('clicked', function () {
139+
//console.log('CLEANUP BUTTON CLICKED');
140+
deleteNonOccupiedWindows(extension);
141+
});
137142
loadSavedWindowsSetting(extension, saved_windows_list_widget, saved_windows_list_objects);
138143
changedSavedWindowsSignal = settings.connect('changed::' + Common.SETTINGS_KEY_SAVED_WINDOWS, function () {
139144
loadSavedWindowsSetting(extension, saved_windows_list_widget, saved_windows_list_objects);
@@ -241,12 +246,31 @@ function loadOverridesSetting(extension, list_widget, list_objects) {
241246
});
242247
}
243248

249+
function deleteNonOccupiedWindows(extension) {
250+
let settings = extension.getSettings();
251+
252+
let saved_windows = JSON.parse(settings.get_string(Common.SETTINGS_KEY_SAVED_WINDOWS));
253+
254+
Object.keys(saved_windows).forEach(function (wsh) {
255+
let sws = saved_windows[wsh];
256+
sws.forEach(function (sw, swi) {
257+
if (!sw.occupied) {
258+
sws.splice(swi, 1);
259+
if (sws.length < 1) delete (saved_windows[wsh]);
260+
}
261+
});
262+
});
263+
264+
settings.set_string(Common.SETTINGS_KEY_SAVED_WINDOWS, JSON.stringify(saved_windows));
265+
}
266+
244267
function loadSavedWindowsSetting(extension, list_widget, list_objects) {
245268
let settings = extension.getSettings();
246269

247270
let saved_windows = JSON.parse(settings.get_string(Common.SETTINGS_KEY_SAVED_WINDOWS));
248271

249272
let current_row = list_widget.get_first_child();
273+
current_row = current_row.get_next_sibling(); // skip the first row
250274
while (current_row !== null) {
251275
let prev_row = current_row;
252276
current_row = current_row.get_next_sibling();

smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<property name="hexpand">True</property>
3939
<property name="vexpand">True</property>
4040
<child>
41-
<!-- n-columns=5 n-rows=7 -->
41+
<!-- n-columns=5 n-rows=9 -->
4242
<object class="GtkGrid">
4343
<property name="visible">True</property>
4444
<property name="can-focus">False</property>
@@ -310,6 +310,27 @@
310310
<child>
311311
<placeholder/>
312312
</child>
313+
<child>
314+
<placeholder/>
315+
</child>
316+
<child>
317+
<placeholder/>
318+
</child>
319+
<child>
320+
<placeholder/>
321+
</child>
322+
<child>
323+
<placeholder/>
324+
</child>
325+
<child>
326+
<placeholder/>
327+
</child>
328+
<child>
329+
<placeholder/>
330+
</child>
331+
<child>
332+
<placeholder/>
333+
</child>
313334
</object>
314335
</child>
315336
</object>
@@ -346,6 +367,32 @@
346367
<property name="vexpand">True</property>
347368
<property name="selection-mode">none</property>
348369
<property name="activate-on-single-click">False</property>
370+
<child>
371+
<object class="GtkListBoxRow">
372+
<property name="visible">True</property>
373+
<property name="can-focus">True</property>
374+
<child>
375+
<object class="GtkBox">
376+
<property name="visible">True</property>
377+
<property name="can-focus">False</property>
378+
<property name="homogeneous">True</property>
379+
<child>
380+
<object class="GtkButton" id="saved-windows-cleanup-button">
381+
<property name="label" translatable="yes">Cleanup Non-occupied Windows</property>
382+
<property name="visible">True</property>
383+
<property name="can-focus">True</property>
384+
<property name="receives-default">True</property>
385+
</object>
386+
<packing>
387+
<property name="expand">False</property>
388+
<property name="fill">True</property>
389+
<property name="position">0</property>
390+
</packing>
391+
</child>
392+
</object>
393+
</child>
394+
</object>
395+
</child>
349396
</object>
350397
</child>
351398
</object>

smart-auto-move@khimaros.com/ui/prefs-gtk4.ui

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
</child>
218218
<child>
219219
<object class="GtkLabel">
220-
<property name="tooltip-text" translatable="1">Do not restore windows' position.</property>
220+
<property name="tooltip-text" translatable="1">Do not restore windows&apos; position.</property>
221221
<property name="halign">start</property>
222222
<property name="hexpand">1</property>
223223
<property name="label" translatable="1">Ignore Position</property>
@@ -240,7 +240,7 @@
240240
</child>
241241
<child>
242242
<object class="GtkLabel">
243-
<property name="tooltip-text" translatable="1">Do not restore windows' workspace.</property>
243+
<property name="tooltip-text" translatable="1">Do not restore windows&apos; workspace.</property>
244244
<property name="halign">start</property>
245245
<property name="hexpand">1</property>
246246
<property name="label" translatable="1">Ignore Workspace</property>
@@ -276,6 +276,27 @@
276276
<child>
277277
<placeholder/>
278278
</child>
279+
<child>
280+
<placeholder/>
281+
</child>
282+
<child>
283+
<placeholder/>
284+
</child>
285+
<child>
286+
<placeholder/>
287+
</child>
288+
<child>
289+
<placeholder/>
290+
</child>
291+
<child>
292+
<placeholder/>
293+
</child>
294+
<child>
295+
<placeholder/>
296+
</child>
297+
<child>
298+
<placeholder/>
299+
</child>
279300
</object>
280301
</property>
281302
</object>
@@ -307,6 +328,23 @@
307328
<property name="vexpand">1</property>
308329
<property name="selection-mode">none</property>
309330
<property name="activate-on-single-click">0</property>
331+
<child>
332+
<object class="GtkListBoxRow">
333+
<property name="focusable">1</property>
334+
<property name="child">
335+
<object class="GtkBox">
336+
<property name="homogeneous">1</property>
337+
<child>
338+
<object class="GtkButton" id="saved-windows-cleanup-button">
339+
<property name="label" translatable="1">Cleanup Non-occupied Windows</property>
340+
<property name="focusable">1</property>
341+
<property name="receives-default">1</property>
342+
</object>
343+
</child>
344+
</object>
345+
</property>
346+
</object>
347+
</child>
310348
</object>
311349
</property>
312350
</object>

0 commit comments

Comments
 (0)