Skip to content

Commit

Permalink
add new "Freeze Saves" preference
Browse files Browse the repository at this point in the history
  • Loading branch information
khimaros committed Mar 5, 2022
1 parent c4b7c0d commit 9edd9e3
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ default **Match Threshold** is probably fine to keep as is.

if you'd like to optimize resource usage, you can change **Sync Frequency** and **Save Frequency**.

once you are happy with your setup, you can **Freeze Saves** to prevent any changes to your saved windows. note, however, that this will pvevent windows from being tracked when their titles change.

### overrides

to create an override, visit the **Saved Windows** tab.
Expand Down
14 changes: 14 additions & 0 deletions smart-auto-move@khimaros.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let syncFrequencyMs;
let saveFrequencyMs;
let matchThreshold;
let syncMode;
let freezeSaves;
let overrides;
let savedWindows;

Expand All @@ -32,6 +33,7 @@ let changedSyncFrequencySignal;
let changedSaveFrequencySignal;
let changedMatchThresholdSignal;
let changedSyncModeSignal;
let changedFreezeSavesSignal;
let changedOverridesSignal;
let changedSavedWindowsSignal;

Expand Down Expand Up @@ -75,6 +77,7 @@ function initializeSettings() {
saveFrequencyMs = Common.DEFAULT_SAVE_FREQUENCY_MS;
matchThreshold = Common.DEFAULT_MATCH_THRESHOLD;
syncMode = Common.DEFAULT_SYNC_MODE;
freezeSaves = Common.DEFAULT_FREEZE_SAVES;
overrides = new Object();
savedWindows = new Object();

Expand All @@ -89,6 +92,7 @@ function cleanupSettings() {
saveFrequencyMs = null;
matchThreshold = null;
syncMode = null;
freezeSaves = null;
overrides = null;
savedWindows = null;
}
Expand All @@ -101,6 +105,7 @@ function restoreSettings() {
handleChangedSaveFrequency();
handleChangedMatchThreshold();
handleChangedSyncMode();
handleChangedFreezeSaves();
handleChangedOverrides();
handleChangedSavedWindows();
dumpSavedWindows();
Expand All @@ -113,6 +118,7 @@ function saveSettings() {
settings.set_int(Common.SETTINGS_KEY_SAVE_FREQUENCY, saveFrequencyMs);
settings.set_double(Common.SETTINGS_KEY_MATCH_THRESHOLD, matchThreshold);
settings.set_enum(Common.SETTINGS_KEY_SYNC_MODE, syncMode);
settings.set_boolean(Common.SETTINGS_KEY_FREEZE_SAVES, freezeSaves);

let newOverrides = JSON.stringify(overrides);
settings.set_string(Common.SETTINGS_KEY_OVERRIDES, newOverrides);
Expand Down Expand Up @@ -211,6 +217,8 @@ function ensureSavedWindow(win) {

if (windowNewerThan(win, startupDelayMs)) return;

if (freezeSaves) return;

//debug('saveWindow(): ' + win.get_id());
if (!updateSavedWindow(win)) {
pushSavedWindow(win);
Expand Down Expand Up @@ -368,6 +376,11 @@ function handleChangedSyncMode() {
debug('handleChangedSyncMode(): ' + syncMode);
}

function handleChangedFreezeSaves() {
freezeSaves = settings.get_boolean(Common.SETTINGS_KEY_FREEZE_SAVES);
debug('[smart-auto-move] handleChangedFreezeSaves(): ' + freezeSaves);
}

function handleChangedOverrides() {
overrides = JSON.parse(settings.get_string(Common.SETTINGS_KEY_OVERRIDES));
debug('handleChangedOverrides(): ' + JSON.stringify(overrides));
Expand Down Expand Up @@ -411,6 +424,7 @@ function connectSettingChangedSignals() {
changedSaveFrequencySignal = settings.connect('changed::' + Common.SETTINGS_KEY_SAVE_FREQUENCY, handleChangedSaveFrequency);
changedMatchThresholdSignal = settings.connect('changed::' + Common.SETTINGS_KEY_MATCH_THRESHOLD, handleChangedMatchThreshold);
changedSyncModeSignal = settings.connect('changed::' + Common.SETTINGS_KEY_SYNC_MODE, handleChangedSyncMode);
changedFreezeSavesSignal = settings.connect('changed::' + Common.SETTINGS_KEY_FREEZE_SAVES, handleChangedFreezeSaves);
changedOverridesSignal = settings.connect('changed::' + Common.SETTINGS_KEY_OVERRIDES, handleChangedOverrides);
changedSavedWindowsSignal = settings.connect('changed::' + Common.SETTINGS_KEY_SAVED_WINDOWS, handleChangedSavedWindows);
}
Expand Down
2 changes: 2 additions & 0 deletions smart-auto-move@khimaros.com/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var SETTINGS_KEY_SYNC_FREQUENCY = 'sync-frequency';
var SETTINGS_KEY_SAVE_FREQUENCY = 'save-frequency';
var SETTINGS_KEY_MATCH_THRESHOLD = 'match-threshold';
var SETTINGS_KEY_SYNC_MODE = 'sync-mode';
var SETTINGS_KEY_FREEZE_SAVES = 'freeze-saves';
var SETTINGS_KEY_OVERRIDES = 'overrides';

// sync mode enum values
Expand All @@ -22,6 +23,7 @@ var DEFAULT_SYNC_FREQUENCY_MS = 100;
var DEFAULT_SAVE_FREQUENCY_MS = 1000;
var DEFAULT_MATCH_THRESHOLD = 0.7;
var DEFAULT_SYNC_MODE = SYNC_MODE_RESTORE;
var DEFAULT_FREEZE_SAVES = false;

function levensteinDistance(a, b) {
var m = [], i, j, min = Math.min;
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 @@ -6,6 +6,6 @@
"settings-schema": "org.gnome.shell.extensions.smart-auto-move",
"settings-path": "/org/gnome/shell/extensions/smart-auto-move/",
"original-author": "khimaros",
"version": "14",
"version": "15",
"shell-version": ["41"]
}
8 changes: 8 additions & 0 deletions smart-auto-move@khimaros.com/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ function buildPrefsWidget() {
Gio.SettingsBindFlags.DEFAULT
);

let freeze_saves_widget = builder.get_object('freeze-saves-switch');
settings.bind(
Common.SETTINGS_KEY_FREEZE_SAVES,
freeze_saves_widget,
'active',
Gio.SettingsBindFlags.DEFAULT
);

/// SAVED WINDOWS

let saved_windows_list_widget = builder.get_object('saved-windows-listbox');
Expand Down
Binary file modified smart-auto-move@khimaros.com/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@
<summary>Overrides</summary>
<description>Overrides for restored window data.</description>
</key>
<key name="freeze-saves" type="b">
<default>false</default>
<summary>Freeze Saves</summary>
<description>Do not update saved window data.</description>
</key>
</schema>
</schemalist>
</schemalist>
36 changes: 35 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 @@ -34,7 +34,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<!-- n-columns=5 n-rows=5 -->
<!-- n-columns=5 n-rows=6 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -180,6 +180,40 @@
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Freeze Saves</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="freeze-saves-switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
Expand Down
31 changes: 31 additions & 0 deletions smart-auto-move@khimaros.com/ui/prefs-gtk4.ui
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,37 @@
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<property name="hexpand">1</property>
<property name="label" translatable="1">Freeze Saves</property>
<layout>
<property name="column">0</property>
<property name="row">5</property>
</layout>
</object>
</child>
<child>
<object class="GtkSwitch" id="freeze-saves-switch">
<property name="focusable">1</property>
<property name="halign">end</property>
<property name="valign">center</property>
<layout>
<property name="column">4</property>
<property name="row">5</property>
</layout>
</object>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</property>
</object>
Expand Down

0 comments on commit 9edd9e3

Please sign in to comment.