Skip to content

Commit

Permalink
feature release
Browse files Browse the repository at this point in the history
- add "activate workspace" settings toggle
- restore active monitor
- restore fullscreen state
- restore above state
- restore on-all-workspaces state
- add tooltips to preferences dialog
  • Loading branch information
khimaros committed May 14, 2023
1 parent 024e1e0 commit dea6f57
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 8 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ack: smart-auto-move@khimaros.com.shell-extension.zip
pack: smart-auto-move@khimaros.com.shell-extension.zip
.PHONY: pack

clean:
Expand Down Expand Up @@ -40,3 +40,7 @@ uninstall:
start: install
MUTTER_DEBUG_DUMMY_MODE_SPECS=1600x900 dbus-run-session -- gnome-shell --nested --wayland
.PHONY: start

start-prefs: install
gnome-extensions prefs smart-auto-move@khimaros.com
.PHONY: start-prefs
39 changes: 37 additions & 2 deletions smart-auto-move@khimaros.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let saveFrequencyMs;
let matchThreshold;
let syncMode;
let freezeSaves;
let activateWorkspace;
let overrides;
let savedWindows;

Expand All @@ -34,6 +35,7 @@ let changedSaveFrequencySignal;
let changedMatchThresholdSignal;
let changedSyncModeSignal;
let changedFreezeSavesSignal;
let changedActivateWorkspaceSignal;
let changedOverridesSignal;
let changedSavedWindowsSignal;

Expand All @@ -52,6 +54,9 @@ function enable() {

restoreSettings();

// maybe Meta.prefs_get_dynamic_workspaces()
// maybe Meta.prefs_set_num_workspaces()

connectSignals();
}

Expand All @@ -78,6 +83,7 @@ function initializeSettings() {
matchThreshold = Common.DEFAULT_MATCH_THRESHOLD;
syncMode = Common.DEFAULT_SYNC_MODE;
freezeSaves = Common.DEFAULT_FREEZE_SAVES;
activateWorkspace = Common.DEFAULT_ACTIVATE_WORKSPACE;
overrides = new Object();
savedWindows = new Object();

Expand All @@ -93,6 +99,7 @@ function cleanupSettings() {
matchThreshold = null;
syncMode = null;
freezeSaves = null;
activateWorkspace = null;
overrides = null;
savedWindows = null;
}
Expand All @@ -106,6 +113,7 @@ function restoreSettings() {
handleChangedMatchThreshold();
handleChangedSyncMode();
handleChangedFreezeSaves();
handleChangedActivateWorkspace();
handleChangedOverrides();
handleChangedSavedWindows();
dumpSavedWindows();
Expand All @@ -119,6 +127,7 @@ function saveSettings() {
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);
settings.set_boolean(Common.SETTINGS_KEY_ACTIVATE_WORKSPACE, activateWorkspace);

let newOverrides = JSON.stringify(overrides);
settings.set_string(Common.SETTINGS_KEY_OVERRIDES, newOverrides);
Expand All @@ -141,15 +150,23 @@ function windowReady(win) {
return true;
}

// https://gjs-docs-experimental.web.app/meta-10/Window/
function windowData(win) {
let win_rect = win.get_frame_rect();
return {
id: win.get_id(),
hash: windowHash(win),
sequence: win.get_stable_sequence(),
title: win.get_title(),
//sandboxed_app_id: win.get_sandboxed_app_id(),
//pid: win.get_pid(),
//user_time: win.get_user_time(),
workspace: win.get_workspace().index(),
maximized: win.get_maximized(),
fullscreen: win.is_fullscreen(),
above: win.is_above(),
monitor: win.get_monitor(),
//on_all_workspaces: win.is_on_all_workspaces(),
x: win_rect.x,
y: win_rect.y,
width: win_rect.width,
Expand Down Expand Up @@ -178,6 +195,7 @@ function windowNewerThan(win, age) {
let wh = windowHash(win);

// TODO: consider using a state machine here: CREATED, MOVED, SAVED, etc.
// TODO: win.get_user_time() might also be useful here.
if (activeWindows.get(wh) === undefined) {
activeWindows.set(wh, Date.now());
}
Expand Down Expand Up @@ -219,7 +237,7 @@ function ensureSavedWindow(win) {

if (freezeSaves) return;

//debug('saveWindow(): ' + win.get_id());
//debug('saveWindow(): ' + windowHash(win);
if (!updateSavedWindow(win)) {
pushSavedWindow(win);
}
Expand All @@ -240,17 +258,28 @@ function findOverrideAction(win, threshold) {

function moveWindow(win, sw) {
//debug('moveWindow(): ' + JSON.stringify(sw));

win.move_to_monitor(sw.monitor);

let ws = global.workspaceManager.get_workspace_by_index(sw.workspace);
win.change_workspace(ws);

win.move_resize_frame(false, sw.x, sw.y, sw.width, sw.height);
if (sw.maximized) win.maximize(sw.maximized);

// NOTE: these additional move/maximize operations were needed in order
// to convince Firefox to stay where we put it.
win.move_resize_frame(false, sw.x, sw.y, sw.width, sw.height);
if (sw.maximized) win.maximize(sw.maximized);
win.move_resize_frame(false, sw.x, sw.y, sw.width, sw.height);

if (sw.fullscreen) win.make_fullscreen();

if (sw.above) win.make_above();

//if (sw.on_all_workspaces) ...

if (activateWorkspace && !ws.active) ws.activate(true)

let nsw = windowData(win);

return nsw;
Expand Down Expand Up @@ -381,6 +410,11 @@ function handleChangedFreezeSaves() {
debug('[smart-auto-move] handleChangedFreezeSaves(): ' + freezeSaves);
}

function handleChangedActivateWorkspace() {
activateWorkspace = settings.get_boolean(Common.SETTINGS_KEY_ACTIVATE_WORKSPACE);
debug('[smart-auto-move] handleChangedActivateWorkspace(): ' + activateWorkspace);
}

function handleChangedOverrides() {
overrides = JSON.parse(settings.get_string(Common.SETTINGS_KEY_OVERRIDES));
debug('handleChangedOverrides(): ' + JSON.stringify(overrides));
Expand Down Expand Up @@ -425,6 +459,7 @@ function connectSettingChangedSignals() {
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);
changedActivateWorkspaceSignal = settings.connect('changed::' + Common.SETTINGS_KEY_ACTIVATE_WORKSPACE, handleChangedActivateWorkspace);
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 @@ -10,6 +10,7 @@ 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_ACTIVATE_WORKSPACE = 'activate-workspace';
var SETTINGS_KEY_OVERRIDES = 'overrides';

// sync mode enum values
Expand All @@ -24,6 +25,7 @@ var DEFAULT_SAVE_FREQUENCY_MS = 1000;
var DEFAULT_MATCH_THRESHOLD = 0.7;
var DEFAULT_SYNC_MODE = SYNC_MODE_RESTORE;
var DEFAULT_FREEZE_SAVES = false;
var DEFAULT_ACTIVATE_WORKSPACE = true;

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": "18",
"version": "19",
"shell-version": ["41", "42", "43", "44"]
}
12 changes: 10 additions & 2 deletions smart-auto-move@khimaros.com/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function buildPrefsWidget() {

builder.add_from_file(Me.path + '/ui/prefs-gtk4.ui');

let notebook = builder.get_object('prefs-notebook');
let root = builder.get_object('prefs-notebook');

/// GENERAL

Expand Down Expand Up @@ -92,6 +92,14 @@ function buildPrefsWidget() {
Gio.SettingsBindFlags.DEFAULT
);

let activate_workspace_widget = builder.get_object('activate-workspace-switch');
settings.bind(
Common.SETTINGS_KEY_ACTIVATE_WORKSPACE,
activate_workspace_widget,
'active',
Gio.SettingsBindFlags.DEFAULT
);

/// SAVED WINDOWS

let saved_windows_list_widget = builder.get_object('saved-windows-listbox');
Expand All @@ -110,7 +118,7 @@ function buildPrefsWidget() {
loadOverridesSetting(overrides_list_widget, overrides_list_objects);
changedOverridesSignal = settings.connect('changed::' + Common.SETTINGS_KEY_OVERRIDES, function () { loadOverridesSetting(overrides_list_widget, overrides_list_objects); });

return notebook;
return root;
}

function loadOverridesSetting(list_widget, list_objects) {
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 @@ -49,5 +49,10 @@
<summary>Freeze Saves</summary>
<description>Do not update saved window data.</description>
</key>
<key name="activate-workspace" type="b">
<default>true</default>
<summary>Activate Workspace</summary>
<description>Follow apps when they are moved to another workspace.</description>
</key>
</schema>
</schemalist>
45 changes: 43 additions & 2 deletions smart-auto-move@khimaros.com/ui.in/prefs-gtk3.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkAdjustment" id="match-threshold-adjustment">
Expand Down Expand Up @@ -38,7 +38,7 @@
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<!-- n-columns=5 n-rows=6 -->
<!-- n-columns=5 n-rows=7 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand All @@ -54,6 +54,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Write detailed logs about extension behavior.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Debug Logging</property>
Expand All @@ -80,6 +81,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Default mode when synchronizing windows.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Default Synchronization Mode</property>
Expand All @@ -94,6 +96,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Minimum threshold for matching restored windows.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Match Threshold</property>
Expand All @@ -108,6 +111,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Frequency in milliseconds to synchronize changes to active windows into the in-memory store.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Sync Frequency (milliseconds)</property>
Expand All @@ -122,6 +126,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Frequency in milliseconds to persist the in-memory store to disk.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Save Frequency (milliseconds)</property>
Expand Down Expand Up @@ -190,6 +195,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Do not update saved window data.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Freeze Saves</property>
Expand All @@ -211,6 +217,41 @@
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Follow apps when they are moved to another workspace.</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Activate Workspace</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="activate-workspace-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">6</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
Expand Down
Loading

0 comments on commit dea6f57

Please sign in to comment.