|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +export const SECONDS_PER_HOUR = 3600; |
| 4 | + |
| 5 | +// D-Bus constants |
| 6 | +export const DBUS_NAME = "org.gnome.shell.extensions.SmartAutoMove"; |
| 7 | +export const DBUS_PATH = "/org/gnome/shell/extensions/SmartAutoMove"; |
| 8 | +export const DBUS_INTERFACE = ` |
| 9 | +<node> |
| 10 | + <interface name="org.gnome.shell.extensions.SmartAutoMove"> |
| 11 | + <method name="ListWindows"> |
| 12 | + <arg type="s" direction="out" name="windows_json"/> |
| 13 | + </method> |
| 14 | + <method name="RefreshFromCurrentActors"> |
| 15 | + </method> |
| 16 | + </interface> |
| 17 | +</node> |
| 18 | +`; |
| 19 | + |
| 20 | +// Settings constants for prefs.js |
| 21 | +export const SETTINGS_KEY_DEBUG_LOGGING = "debug-logging"; |
| 22 | +export const SETTINGS_KEY_CONFIG_VERSION = "config-version"; |
| 23 | +export const SETTINGS_KEY_SAVED_WINDOWS = "saved-windows"; |
| 24 | +export const SETTINGS_KEY_OVERRIDES = "overrides"; |
| 25 | +export const SETTINGS_KEY_MATCH_THRESHOLD = "match-threshold"; |
| 26 | + |
| 27 | +// Sync mode constants |
| 28 | +export const SYNC_MODE_IGNORE = 0; |
| 29 | +export const SYNC_MODE_RESTORE = 1; |
| 30 | +export const SYNC_MODE_DEFAULT = "DEFAULT"; |
| 31 | + |
| 32 | +// Settings configuration for prefs.js binding |
| 33 | +export const SETTINGS_CONFIG = [ |
| 34 | + { |
| 35 | + key: "debug-logging", |
| 36 | + property: "active", |
| 37 | + widgetId: "debug-logging-switch", |
| 38 | + }, |
| 39 | + { |
| 40 | + key: "new-window-max-wait-ms", |
| 41 | + property: "value", |
| 42 | + widgetId: "new-window-max-wait-spin", |
| 43 | + }, |
| 44 | + { |
| 45 | + key: "new-window-title-stability-ms", |
| 46 | + property: "value", |
| 47 | + widgetId: "new-window-title-stability-spin", |
| 48 | + }, |
| 49 | + { |
| 50 | + key: "generic-title-max-length", |
| 51 | + property: "value", |
| 52 | + widgetId: "generic-title-max-length-spin", |
| 53 | + }, |
| 54 | + { |
| 55 | + key: "ambiguity-threshold", |
| 56 | + property: "value", |
| 57 | + widgetId: "ambiguity-threshold-generic-spin", |
| 58 | + }, |
| 59 | + { |
| 60 | + key: "min-score-spread", |
| 61 | + property: "value", |
| 62 | + widgetId: "min-score-spread-spin", |
| 63 | + }, |
| 64 | + { |
| 65 | + key: "generic-title-extended-wait", |
| 66 | + property: "value", |
| 67 | + widgetId: "generic-title-extended-wait-spin", |
| 68 | + }, |
| 69 | + { |
| 70 | + key: "max-unseen-age", |
| 71 | + property: "value", |
| 72 | + widgetId: "max-unseen-age-spin", |
| 73 | + }, |
| 74 | + { |
| 75 | + key: "match-threshold", |
| 76 | + property: "value", |
| 77 | + widgetId: "match-threshold-spin", |
| 78 | + }, |
| 79 | + { |
| 80 | + key: "sync-mode", |
| 81 | + property: "active-id", |
| 82 | + widgetId: "sync-mode-combo", |
| 83 | + }, |
| 84 | + { |
| 85 | + key: "freeze-saves", |
| 86 | + property: "active", |
| 87 | + widgetId: "freeze-saves-switch", |
| 88 | + }, |
| 89 | + { |
| 90 | + key: "activate-workspace", |
| 91 | + property: "active", |
| 92 | + widgetId: "activate-workspace-switch", |
| 93 | + }, |
| 94 | + { |
| 95 | + key: "ignore-position", |
| 96 | + property: "active", |
| 97 | + widgetId: "ignore-position-switch", |
| 98 | + }, |
| 99 | + { |
| 100 | + key: "ignore-workspace", |
| 101 | + property: "active", |
| 102 | + widgetId: "ignore-workspace-switch", |
| 103 | + }, |
| 104 | + { |
| 105 | + key: "ignore-monitor", |
| 106 | + property: "active", |
| 107 | + widgetId: "ignore-monitor-switch", |
| 108 | + }, |
| 109 | +]; |
| 110 | + |
| 111 | +export function getActionId(action) { |
| 112 | + if (action === SYNC_MODE_IGNORE || action === "IGNORE") return "IGNORE"; |
| 113 | + if (action === SYNC_MODE_RESTORE || action === "RESTORE") return "RESTORE"; |
| 114 | + return "DEFAULT"; |
| 115 | +} |
| 116 | + |
| 117 | +export function parseOverrides(overridesStr) { |
| 118 | + try { |
| 119 | + return JSON.parse(overridesStr || "{}"); |
| 120 | + } catch (e) { |
| 121 | + return {}; |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +export function deleteNonOccupiedWindows(savedWindows) { |
| 126 | + Object.keys(savedWindows).forEach((wsh) => { |
| 127 | + savedWindows[wsh] = savedWindows[wsh].filter((sw) => sw.occupied); |
| 128 | + if (savedWindows[wsh].length === 0) { |
| 129 | + delete savedWindows[wsh]; |
| 130 | + } |
| 131 | + }); |
| 132 | +} |
| 133 | + |
| 134 | +export function ignoreSavedWindow( |
| 135 | + savedWindows, |
| 136 | + overrides, |
| 137 | + wsh, |
| 138 | + swi, |
| 139 | + threshold, |
| 140 | + ignoreAny, |
| 141 | +) { |
| 142 | + if (!savedWindows[wsh] || !savedWindows[wsh][swi]) return; |
| 143 | + |
| 144 | + const sw = savedWindows[wsh][swi]; |
| 145 | + |
| 146 | + if (!overrides[wsh]) { |
| 147 | + overrides[wsh] = []; |
| 148 | + } |
| 149 | + |
| 150 | + if (ignoreAny) { |
| 151 | + overrides[wsh].push({ |
| 152 | + action: "IGNORE", |
| 153 | + threshold: threshold, |
| 154 | + }); |
| 155 | + } else { |
| 156 | + overrides[wsh].unshift({ |
| 157 | + title: sw.title, |
| 158 | + action: "IGNORE", |
| 159 | + }); |
| 160 | + } |
| 161 | +} |
0 commit comments