diff --git a/.gitignore b/.gitignore index 19d78b0..c489766 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,9 @@ strata-daemon/target/ # Bundled binary (no longer shipped - daemon must be installed separately) strata@edu4rdshl.dev/bin/ -# Screenshots / scratch images +# Screenshots / scratch images (project assets under assets/ are kept) *.png +!assets/*.png # External reference code (not part of this project) external_sources/ diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 965a80c..134058f 100755 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -295,38 +295,24 @@ image. ## Theming -St's CSS engine has no custom properties (`var()`) and no reliable -`!important`, so the light theme is not a runtime-generated stylesheet. -Instead `stylesheet.css` is the dark theme (default, auto-loaded by GNOME), -and `light.css` carries light overrides with every rule scoped under a -`.strata-theme-light` ancestor class -- e.g. dark `.strata-panel { ... }` is -overridden by `.strata-panel.strata-theme-light { ... }`. That scoping makes -each light rule strictly more specific than its dark counterpart, so it wins -deterministically regardless of stylesheet load order. +Light and dark are handled by GNOME Shell's built-in per-variant stylesheet +loading, not by any code in the extension. When it enables an extension the +Shell loads `stylesheet-.css`, where the variant comes from +`Main.getStyleVariant()` (the shell's own light/dark), and falls back to +`stylesheet.css`; it reloads that sheet when the color scheme changes. -The switch between themes is a single class. `extension.js` loads `light.css` -into the St theme context once at `enable()` (and unloads it on `disable()`), -but loading it changes nothing on screen: its rules are present in the engine -yet match no actors, because nothing carries `.strata-theme-light` yet. The -panel resolves the effective theme from the `theme` setting (`auto` consults -`org.gnome.desktop.interface color-scheme`) and adds or removes that one class -on its root box. With the class present the more-specific light rules win and -the panel is light; with it absent only the base dark rules apply. So -switching is one class toggle on an existing subtree -- instant, off the -ingest/render hot paths, and needing no reload. +Strata ships two sheets and no `stylesheet.css`: -`light.css` is loaded exactly once and the theme context's `changed` signal is -deliberately not used: `load_stylesheet` itself emits `changed`, so reloading -on it feeds back into itself and hits "too much recursion" (it fired on screen -unlock, which restyles widgets). The one caveat of loading once is a full -GNOME Shell *theme* switch (the User Themes extension swapping the whole Shell -theme), which replaces the theme object and drops every dynamically loaded -sheet, including `light.css`. After that, light mode falls back to the dark -base rules until the extension is re-enabled; dark mode is unaffected because -GNOME re-loads `stylesheet.css` itself. This is rare and recoverable, and far -preferable to re-subscribing to `changed`. The ordinary light/dark switch -(including the system Settings light/dark that `auto` follows) is just the -class toggle and is unaffected. +- `stylesheet-dark.css` is the full dark theme (the base). +- `stylesheet-light.css` does `@import url("stylesheet-dark.css")` and then + overrides the colors for a light panel. Its rules follow the import, so they + win by load order. + +This is the structure the built-in `window-list` extension uses. Because the +variant tracks the *shell* style, the panel matches the shell chrome: a normal +session prefers dark, so the panel is dark, and it turns light only when the +shell itself is light (a `prefer-light` color scheme, the Classic session, or +high contrast). There is no theme setting and no manual stylesheet loading. ## Wayland clipboard monitor diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cc5027..9e13186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,35 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). --- +## [0.11.0] - 2026-07-02 + +The daemon is unchanged from 0.10.0; all changes are in the GNOME Shell extension. + +### Changed + +- Light and dark styling follows the GNOME Shell style variant via + `stylesheet-dark.css` and `stylesheet-light.css`, loaded automatically by the + Shell, instead of loading `light.css` into the theme context by hand. The + manual theme setting and its preferences row are gone; the panel matches the + shell. +- Signal connections use `connectObject`/`disconnectObject`. + +### Fixed + +- `disable()` stops the daemon synchronously with `SIGTERM` instead of deferring + the kill to a timeout. +- The daemon-restart timeout is cleared before a new one is scheduled. +- Removed the `try`/`catch` around `send_signal`, which does not throw. + +### Performance + +- The thumbnail cache is cleared asynchronously in batches instead of a + synchronous enumerate and delete on the compositor thread. +- The thumbnail path cache is pruned on delete and clear-all. +- Each row computes its type (image, URL, color) once. + +--- + ## [0.10.0] - 2026-06-25 The daemon is unchanged from 0.9.0; all changes are in the GNOME Shell extension. diff --git a/Makefile b/Makefile index 3ab6d3f..3d5d025 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,6 @@ pack: schemas --extra-source=ui \ --extra-source=dbus.js \ --extra-source=util.js \ - --extra-source=light.css \ --force @echo "Packed: $(EXTENSION_UUID).shell-extension.zip" diff --git a/README.md b/README.md index f51be73..0a57f20 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,15 @@ All heavy work (hashing, decoding, storage, search, thumbnails) lives in a Rust daemon. The GNOME Shell extension only renders UI and forwards events over D-Bus, so the compositor is never blocked, even with thousands of items. +

+ + Download from extensions.gnome.org + +

+ +> **Requires a companion daemon.** Installing from GNOME Extensions is only half +> the setup. See [Installing the daemon](#installing-the-daemon). + The motivation behind this is explained in the technical blog post [Rethinking the GNOME clipboard issues](https://edu4rdshl.dev/posts/rethinking-the-gnome-clipboard-issues/) ## Features @@ -34,8 +43,8 @@ Unknown MIME types are ignored (a strict allowlist). **Appearance.** -- Automatic light/dark theme: `Auto` follows the system color scheme; `Light` - and `Dark` force one. +- Light and dark styling follows the GNOME Shell automatically, matching the + rest of the shell UI. - Configurable panel position (top/center/bottom by left/center/right), width, and maximum height. - Optional "move an item to the top" when you paste it. @@ -78,12 +87,6 @@ Unknown MIME types are ignored (a strict allowlist). - Keyboard navigation (arrow keys, `Esc` to close), click-outside to dismiss, per-row delete, and "Clear all". -## How it looks - -The idea is to have a simple but responsive UI that fits into the project's goals. Actually, Strata looks like it: - -image - ## Architecture Strata is **two components**, and you need **both** for it to work: @@ -104,6 +107,32 @@ GNOME Shell (GJS) ──D-Bus──▶ strata-daemon ──▶ SQLite (~/.lo └──▶ thumbnails (~/.cache/strata) ``` +## Installing the daemon + +Strata is two parts: the GNOME Shell extension and a small background daemon +(`strata-daemon`) that does the storage, search, and thumbnailing. Installing +the extension from [GNOME Extensions](https://extensions.gnome.org/extension/10291/strata/) +is only half the setup; **without the daemon the extension does nothing.** + +Install the daemon with whichever fits your system: + +- **Arch (AUR):** `paru -S strata-daemon` (or `strata-daemon-git` for the latest `main`). +- **From source** (needs Rust/Cargo 1.74+): + + ```sh + git clone https://github.com/Edu4rdSHL/Strata.git + cd Strata + make install-daemon # builds and installs to ~/.local/bin + ``` + + Make sure `~/.local/bin` is in your `$PATH`. + +Then log out and back in (Wayland) or `Alt+F2` → `r` (X11). The extension finds +`strata-daemon` in `$PATH` and starts it automatically; no separate service is +needed. + +For distro packages and the systemd user service, see [Install](#install). + ## Requirements - GNOME Shell 50. Older releases may work if built from source but are not tested or supported. @@ -197,6 +226,19 @@ the wire protocol and a `busctl` example. The shipped UI is a GNOME Shell extension. Ports to other desktops only need a new front-end against the same D-Bus interface. +## How it looks + +A responsive panel that drops down from the top bar and follows the GNOME +shell's look. + +

+ Strata's clipboard panel open on the GNOME desktop +

+ +

+ Close-up of the Strata panel: a URL with its hostname, an image thumbnail, color swatches, and text entries +

+ ## Deeper reading - [`ARCHITECTURE.md`](ARCHITECTURE.md): design goals, process model, diff --git a/assets/ego.svg b/assets/ego.svg new file mode 100644 index 0000000..57aaff3 --- /dev/null +++ b/assets/ego.svg @@ -0,0 +1,170 @@ + + + Download From EGO Logo + + + + + + + + + + + + image/svg+xml + + Download From EGO Logo + 2021 + + + Javad Rahmatzadeh + + + + + Javad Rahmatzadeh + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/panel-desktop.png b/assets/panel-desktop.png new file mode 100644 index 0000000..3b971ab Binary files /dev/null and b/assets/panel-desktop.png differ diff --git a/assets/panel.png b/assets/panel.png new file mode 100644 index 0000000..a514e1e Binary files /dev/null and b/assets/panel.png differ diff --git a/strata-daemon/Cargo.lock b/strata-daemon/Cargo.lock index b49ad70..a94967b 100644 --- a/strata-daemon/Cargo.lock +++ b/strata-daemon/Cargo.lock @@ -1205,7 +1205,7 @@ dependencies = [ [[package]] name = "strata-daemon" -version = "0.10.0" +version = "0.11.0" dependencies = [ "anyhow", "blake3", diff --git a/strata-daemon/Cargo.toml b/strata-daemon/Cargo.toml index 269fc0c..ef3fe61 100644 --- a/strata-daemon/Cargo.toml +++ b/strata-daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strata-daemon" -version = "0.10.0" +version = "0.11.0" edition = "2021" description = "Strata clipboard manager backend daemon" diff --git a/strata@edu4rdshl.dev/extension.js b/strata@edu4rdshl.dev/extension.js index 4d4d571..8bfa070 100644 --- a/strata@edu4rdshl.dev/extension.js +++ b/strata@edu4rdshl.dev/extension.js @@ -22,7 +22,6 @@ export default class StrataExtension extends Extension { _daemonRestartAttempts = 0; _shuttingDown = false; _daemonRestartTimerId = null; - _daemonKillTimerId = null; /** True while a GetNameOwner check before spawning is in flight, so an * overlapping respawn attempt can't spawn a second daemon. */ _spawnPending = false; @@ -36,18 +35,12 @@ export default class StrataExtension extends Extension { _itemDeletedId = null; _historyClearedId = null; - /** @type {number | null} focused-window signal connection ID */ - _focusSignalId = null; - /** @type {string} WM class of the currently focused app (lower-cased) */ _currentFocusedApp = ''; /** @type {object | null} PanelMenu.Button indicator */ _indicator = null; - /** @type {number | null} Meta.Selection owner-changed signal ID */ - _selectionChangedId = null; - /** @type {number | null} Debounce timer for clipboard reads */ _clipboardDebounceId = null; @@ -64,29 +57,16 @@ export default class StrataExtension extends Extension { enable() { this._shuttingDown = false; this._daemonRestartAttempts = 0; - // Cancel any pending force-kill timer left over from a previous disable - // (enable→disable→enable within 1.5s) so it can't outlive this cycle. - if (this._daemonKillTimerId) { - GLib.Source.remove(this._daemonKillTimerId); - this._daemonKillTimerId = null; - } this._settings = this.getSettings(); - this._excludedApps = this._settings.get_strv('excluded-apps'); - this._excludedAppsChangedId = this._settings.connect('changed::excluded-apps', () => { - this._excludedApps = this._settings.get_strv('excluded-apps'); - }); - + this._excludedApps = this._readExcluded(); this._readSizeLimits(); - this._configChangedIds = [ - this._settings.connect('changed::max-history', () => { this._readSizeLimits(); this._pushConfig(); }), - this._settings.connect('changed::max-text-mb', () => { this._readSizeLimits(); this._pushConfig(); }), - this._settings.connect('changed::max-image-mb', () => { this._readSizeLimits(); this._pushConfig(); }), - ]; - - // Load the light theme overrides into the Shell theme context. They stay - // inert until the panel toggles the `.strata-theme-light` class (panel.js). - this._loadThemeStylesheet(); + this._settings.connectObject( + 'changed::excluded-apps', () => { this._excludedApps = this._readExcluded(); }, + 'changed::max-history', () => { this._readSizeLimits(); this._pushConfig(); }, + 'changed::max-text-mb', () => { this._readSizeLimits(); this._pushConfig(); }, + 'changed::max-image-mb', () => { this._readSizeLimits(); this._pushConfig(); }, + this); this._addIndicator(); this._spawnDaemon(); @@ -108,27 +88,13 @@ export default class StrataExtension extends Extension { this._disconnectFocusTracking(); this._disconnectSignals(); this._clearIdleSources(); - if (this._proxyOwnerId && this._proxy) { - this._proxy.disconnect(this._proxyOwnerId); - this._proxyOwnerId = 0; - } - if (this._configChangedIds && this._settings) { - for (const id of this._configChangedIds) this._settings.disconnect(id); - this._configChangedIds = null; - } - if (this._excludedAppsChangedId && this._settings) { - this._settings.disconnect(this._excludedAppsChangedId); - this._excludedAppsChangedId = null; - } + this._proxy?.disconnectObject(this); + this._settings?.disconnectObject(this); this._panel?.destroy(); this._panel = null; - if (this._indicatorClickId && this._indicator) { - this._indicator.disconnect(this._indicatorClickId); - this._indicatorClickId = null; - } + this._indicator?.disconnectObject(this); this._indicator?.destroy(); this._indicator = null; - this._unloadThemeStylesheet(); this._stopDaemon(); this._proxy = null; this._settings = null; @@ -143,20 +109,19 @@ export default class StrataExtension extends Extension { style_class: 'system-status-icon', }); this._indicator.add_child(icon); - this._indicatorClickId = this._indicator.connect('button-press-event', () => { + this._indicator.connectObject('button-press-event', () => { this._panel?.toggle(); return false; // EVENT_PROPAGATE - }); + }, this); Main.panel.addToStatusArea('strata', this._indicator); } _connectClipboardMonitor() { - const selection = global.display.get_selection(); - this._selectionChangedId = selection.connect('owner-changed', (_sel, type) => { + global.display.get_selection().connectObject('owner-changed', (_sel, type) => { if (type !== Meta.SelectionType.SELECTION_CLIPBOARD) return; this._scheduleClipboardRead(); - }); + }, this); } _disconnectClipboardMonitor() { @@ -167,10 +132,7 @@ export default class StrataExtension extends Extension { this._clipboardDebounceId = null; } this._clipboardTransferPending = false; - if (this._selectionChangedId !== null) { - global.display.get_selection().disconnect(this._selectionChangedId); - this._selectionChangedId = null; - } + global.display.get_selection().disconnectObject(this); } /** Debounce entry point - coalesces rapid clipboard changes (e.g. from @@ -347,6 +309,10 @@ export default class StrataExtension extends Extension { _scheduleDaemonRestart() { if (this._shuttingDown) return; + if (this._daemonRestartTimerId !== null) { + GLib.Source.remove(this._daemonRestartTimerId); + this._daemonRestartTimerId = null; + } // Exponential backoff: 1s, 2s, 4s, 8s, 16s const backoffMs = 1000 * Math.pow(2, Math.max(0, this._daemonRestartAttempts - 1)); this._daemonRestartTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, backoffMs, () => { @@ -358,20 +324,9 @@ export default class StrataExtension extends Extension { _stopDaemon() { if (!this._daemon) return; - // Capture reference immediately so the timer doesn't kill a newly-spawned daemon. - const daemonToStop = this._daemon; + const daemon = this._daemon; this._daemon = null; - try { - // Graceful shutdown via D-Bus first. - this._proxy?.ShutdownRemote(() => {}); - } catch { /* proxy may already be gone */ } - // Give it 1.5s then force-terminate. Track the source so a re-enable - // within that window can cancel it (see enable()). - this._daemonKillTimerId = GLib.timeout_add(GLib.PRIORITY_LOW, 1500, () => { - this._daemonKillTimerId = null; - try { daemonToStop.send_signal(15); } catch { /* already exited */ } // SIGTERM - return GLib.SOURCE_REMOVE; - }); + daemon.send_signal(15); // SIGTERM } @@ -393,8 +348,8 @@ export default class StrataExtension extends Extension { // again on every owner transition so a respawned // daemon picks up the latest values. this._pushConfig(); - this._proxyOwnerId = proxy.connect('notify::g-name-owner', - () => { if (proxy.g_name_owner) this._pushConfig(); }); + proxy.connectObject('notify::g-name-owner', + () => { if (proxy.g_name_owner) this._pushConfig(); }, this); } ); } catch (e) { @@ -437,23 +392,50 @@ export default class StrataExtension extends Extension { this._historyClearedId = this._proxy.connectSignal('HistoryCleared', () => { - try { - const dir = `${GLib.get_user_cache_dir()}/strata/thumbnails`; - const d = Gio.File.new_for_path(dir); - if (d.query_exists(null)) { - const en = d.enumerate_children( - 'standard::name', Gio.FileQueryInfoFlags.NONE, null); - let info; - while ((info = en.next_file(null))) { - try { d.get_child(info.get_name()).delete(null); } catch { /* best-effort cleanup */ } - } - en.close(null); - } - } catch (e) { logError('cache clear failed', e); } + this._clearThumbnailCache(); this._addIdleSource(() => this._panel?.clearItems()); }); } + /** Delete every cached thumbnail without blocking the compositor: + * enumerate and unlink asynchronously in batches. */ + _clearThumbnailCache() { + const dir = Gio.File.new_for_path( + `${GLib.get_user_cache_dir()}/strata/thumbnails`); + dir.enumerate_children_async( + 'standard::name', Gio.FileQueryInfoFlags.NONE, + GLib.PRIORITY_DEFAULT, null, + (d, res) => { + let en; + try { + en = d.enumerate_children_finish(res); + } catch { + return; // dir missing or unreadable + } + const step = () => { + en.next_files_async(32, GLib.PRIORITY_DEFAULT, null, (e, r) => { + let infos; + try { + infos = e.next_files_finish(r); + } catch { + infos = []; + } + if (infos.length === 0) { + e.close_async(GLib.PRIORITY_DEFAULT, null, () => {}); + return; + } + for (const info of infos) { + e.get_child(info).delete_async( + GLib.PRIORITY_DEFAULT, null, + (f, rr) => { try { f.delete_finish(rr); } catch { /* best-effort */ } }); + } + step(); + }); + }; + step(); + }); + } + _disconnectSignals() { if (this._itemAddedId && this._proxy) { this._proxy.disconnectSignal(this._itemAddedId); @@ -504,24 +486,25 @@ export default class StrataExtension extends Extension { }); } + _readExcluded() { + return this._settings.get_strv('excluded-apps').map(s => s.toLowerCase()); + } + _isExcluded(appClass) { if (!appClass) return false; - return this._excludedApps.some(ex => appClass.includes(ex.toLowerCase())); + return this._excludedApps.some(ex => appClass.includes(ex)); } _connectFocusTracking() { - this._focusSignalId = global.display.connect('notify::focus-window', () => { + global.display.connectObject('notify::focus-window', () => { const win = global.display.focus_window; this._currentFocusedApp = (win?.get_wm_class() ?? '').toLowerCase(); - }); + }, this); } _disconnectFocusTracking() { - if (this._focusSignalId !== null) { - global.display.disconnect(this._focusSignalId); - this._focusSignalId = null; - } + global.display.disconnectObject(this); } @@ -542,29 +525,4 @@ export default class StrataExtension extends Extension { _unregisterShortcut() { Main.wm.removeKeybinding('keyboard-shortcut'); } - - - /** Load light.css once. It is scoped under `.strata-theme-light` and stays - * inert until the panel adds that class. We do not subscribe to the theme - * context's 'changed' signal because load_stylesheet itself emits it. */ - _loadThemeStylesheet() { - try { - const themeContext = St.ThemeContext.get_for_stage(global.stage); - this._lightCssFile = this.dir.get_child('light.css'); - this._stTheme = themeContext.get_theme(); - this._stTheme.load_stylesheet(this._lightCssFile); - } catch (e) { - logError('Failed to load light.css', e); - } - } - - _unloadThemeStylesheet() { - try { - this._stTheme?.unload_stylesheet(this._lightCssFile); - } catch (e) { - logError('Failed to unload light.css', e); - } - this._stTheme = null; - this._lightCssFile = null; - } } diff --git a/strata@edu4rdshl.dev/light.css b/strata@edu4rdshl.dev/light.css deleted file mode 100644 index 6d14993..0000000 --- a/strata@edu4rdshl.dev/light.css +++ /dev/null @@ -1,143 +0,0 @@ -/* Strata light theme. - * - * Loaded into the Shell theme context by extension.js and activated by toggling - * the `.strata-theme-light` class on the panel root box (see ui/panel.js). - * Every rule is scoped under `.strata-theme-light` so it is strictly more - * specific than its counterpart in stylesheet.css and wins deterministically, - * regardless of stylesheet load order. The dark theme (stylesheet.css) is left - * untouched: with no class present, none of these rules apply. - * - * Colors follow GNOME Adwaita (blue #3584e4, link #1a5fb4, amber #b5830a, - * red #e01b24) and are picked for contrast on a light panel. - * - * Performance rule (same as stylesheet.css): NO `transition: all`, NO - * Clutter/CSS animations. Only background-color transitions on hover. - */ - -/* ── Panel container ────────────────────────────────────────────────────── */ -.strata-panel.strata-theme-light { - background-color: rgba(250, 250, 250, 0.98); - border-color: rgba(0, 0, 0, 0.14); - box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28); -} - -/* ── Header ─────────────────────────────────────────────────────────────── */ -.strata-theme-light .strata-title { - color: rgba(0, 0, 0, 0.87); -} - -.strata-theme-light .strata-clear-btn { - border-color: rgba(0, 0, 0, 0.18); - color: rgba(0, 0, 0, 0.55); -} - -.strata-theme-light .strata-clear-btn:hover { - background-color: rgba(0, 0, 0, 0.07); - color: rgba(0, 0, 0, 0.85); -} - -/* ── Search box ─────────────────────────────────────────────────────────── */ -.strata-theme-light .strata-search { - background-color: rgba(0, 0, 0, 0.05); - border-color: rgba(0, 0, 0, 0.14); - color: rgba(0, 0, 0, 0.87); - caret-color: rgba(0, 0, 0, 0.8); -} - -.strata-theme-light .strata-search:focus { - border-color: rgba(53, 132, 228, 0.8); - background-color: rgba(0, 0, 0, 0.035); -} - -/* Placeholder ("Search...") text - legible dim gray on the light panel. */ -.strata-theme-light .strata-search-hint { - color: rgba(0, 0, 0, 0.55); -} - -/* ── Clipboard item: hover / focus (Adwaita blue) ───────────────────────── */ -.strata-theme-light .strata-item:hover, -.strata-theme-light .strata-item-hovered { - background-color: rgba(53, 132, 228, 0.14); - border-color: rgba(53, 132, 228, 0.45); -} - -.strata-theme-light .strata-item:focus, -.strata-theme-light .strata-item-focused { - background-color: rgba(53, 132, 228, 0.16); - border-color: rgba(53, 132, 228, 0.65); -} - -.strata-theme-light .strata-item:hover:focus, -.strata-theme-light .strata-item-focused.strata-item-hovered { - background-color: rgba(53, 132, 228, 0.24); - border-color: rgba(53, 132, 228, 0.78); -} - -.strata-theme-light .strata-item:focus .strata-item-text, -.strata-theme-light .strata-item-focused .strata-item-text { - color: rgba(0, 0, 0, 0.95); -} - -/* ── Active item (warm amber, darkened for light bg) ────────────────────── */ -.strata-theme-light .strata-item-active { - background-color: rgba(181, 131, 10, 0.16); - border-color: rgba(181, 131, 10, 0.50); -} - -.strata-theme-light .strata-item-active .strata-item-text { - color: rgba(120, 82, 0, 1.0); -} - -.strata-theme-light .strata-item-active.strata-item-hovered { - background-color: rgba(181, 131, 10, 0.24); -} - -.strata-theme-light .strata-item-active.strata-item-focused, -.strata-theme-light .strata-item-active:focus { - background-color: rgba(53, 132, 228, 0.20); - border-color: rgba(53, 132, 228, 0.65); -} - -.strata-theme-light .strata-item-active.strata-item-focused .strata-item-text, -.strata-theme-light .strata-item-active:focus .strata-item-text { - color: rgba(0, 0, 0, 0.95); -} - -.strata-theme-light .strata-item:active { - background-color: rgba(0, 0, 0, 0.10); -} - -/* ── Item icon / thumbnail ──────────────────────────────────────────────── */ -.strata-theme-light .strata-item-icon { - color: rgba(0, 0, 0, 0.55); -} - -.strata-theme-light .strata-item-thumb { - border-color: rgba(0, 0, 0, 0.15); -} - -/* ── Text content ───────────────────────────────────────────────────────── */ -.strata-theme-light .strata-item-text { - color: rgba(0, 0, 0, 0.85); -} - -.strata-theme-light .strata-item-url { - color: rgba(26, 95, 180, 1.0); -} - -.strata-theme-light .strata-item-subtext { - color: rgba(0, 0, 0, 0.55); -} - -/* ── Delete button (Adwaita red) ────────────────────────────────────────── */ -.strata-theme-light .strata-item:hover .strata-item-delete, -.strata-theme-light .strata-item:focus .strata-item-delete, -.strata-theme-light .strata-item-focused .strata-item-delete, -.strata-theme-light .strata-item-hovered .strata-item-delete { - color: rgba(224, 27, 36, 0.75); -} - -.strata-theme-light .strata-item-delete:hover { - background-color: rgba(224, 27, 36, 0.13); - color: rgba(224, 27, 36, 1.0); -} diff --git a/strata@edu4rdshl.dev/metadata.json b/strata@edu4rdshl.dev/metadata.json index 54b2d96..35d6102 100644 --- a/strata@edu4rdshl.dev/metadata.json +++ b/strata@edu4rdshl.dev/metadata.json @@ -2,7 +2,7 @@ "name": "Strata", "description": "A fast clipboard manager. Storage, search and image decoding run in a separate Rust daemon.", "uuid": "strata@edu4rdshl.dev", - "version": 10, + "version": 11, "shell-version": ["50"], "settings-schema": "org.gnome.shell.extensions.strata", "url": "https://github.com/Edu4rdSHL/Strata" diff --git a/strata@edu4rdshl.dev/prefs.js b/strata@edu4rdshl.dev/prefs.js index 6acb5a8..1db163e 100644 --- a/strata@edu4rdshl.dev/prefs.js +++ b/strata@edu4rdshl.dev/prefs.js @@ -79,29 +79,6 @@ export default class StrataPreferences extends ExtensionPreferences { const appearanceGroup = new Adw.PreferencesGroup({ title: 'Appearance' }); - const themes = [ - { id: 'auto', label: 'Automatic' }, - { id: 'light', label: 'Light' }, - { id: 'dark', label: 'Dark' }, - ]; - const themeRow = new Adw.ComboRow({ - title: 'Theme', - subtitle: 'Automatic follows the system light/dark preference', - model: Gtk.StringList.new(themes.map(t => t.label)), - }); - const currentTheme = settings.get_string('theme'); - const currentThemeIdx = themes.findIndex(t => t.id === currentTheme); - themeRow.selected = currentThemeIdx >= 0 ? currentThemeIdx : 0; - themeRow.connect('notify::selected', () => { - settings.set_string('theme', themes[themeRow.selected].id); - }); - settings.connect('changed::theme', () => { - const idx = themes.findIndex(t => t.id === settings.get_string('theme')); - if (idx >= 0 && themeRow.selected !== idx) - themeRow.selected = idx; - }); - appearanceGroup.add(themeRow); - const panelWidthRow = new Adw.SpinRow({ title: 'Panel width', subtitle: 'Width of the clipboard panel in pixels', diff --git a/strata@edu4rdshl.dev/schemas/org.gnome.shell.extensions.strata.gschema.xml b/strata@edu4rdshl.dev/schemas/org.gnome.shell.extensions.strata.gschema.xml index 0c51ab5..ad37c85 100644 --- a/strata@edu4rdshl.dev/schemas/org.gnome.shell.extensions.strata.gschema.xml +++ b/strata@edu4rdshl.dev/schemas/org.gnome.shell.extensions.strata.gschema.xml @@ -52,17 +52,6 @@ When enabled, clicking or pressing Enter on a history item moves it to position 1 in the list. - - - - - - - 'auto' - Panel color theme - Auto follows the system light/dark color scheme (org.gnome.desktop.interface color-scheme). Light and Dark force a fixed theme. - - diff --git a/strata@edu4rdshl.dev/stylesheet.css b/strata@edu4rdshl.dev/stylesheet-dark.css similarity index 98% rename from strata@edu4rdshl.dev/stylesheet.css rename to strata@edu4rdshl.dev/stylesheet-dark.css index 0808909..c0f073d 100644 --- a/strata@edu4rdshl.dev/stylesheet.css +++ b/strata@edu4rdshl.dev/stylesheet-dark.css @@ -1,4 +1,4 @@ -/* Strata clipboard manager stylesheet. +/* Strata dark theme (the default; loaded when the system color scheme is dark). * * Performance rule: NO `transition: all`, NO Clutter/CSS animations. * Only background-color transitions on hover (GPU-composited, zero JS). diff --git a/strata@edu4rdshl.dev/stylesheet-light.css b/strata@edu4rdshl.dev/stylesheet-light.css new file mode 100644 index 0000000..37ef1de --- /dev/null +++ b/strata@edu4rdshl.dev/stylesheet-light.css @@ -0,0 +1,129 @@ +/* Strata light theme. + * + * GNOME Shell loads this instead of stylesheet-dark.css when the system color + * scheme is light. It imports the dark base and overrides the colors below, so + * the overrides win by load order. Colors follow GNOME Adwaita (blue #3584e4, + * link #1a5fb4, amber, red #e01b24), picked for contrast on a light panel. + */ + +@import url("stylesheet-dark.css"); + +.strata-panel { + background-color: rgba(250, 250, 250, 0.98); + border-color: rgba(0, 0, 0, 0.14); + box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28); +} + +.strata-title { + color: rgba(0, 0, 0, 0.87); +} + +.strata-clear-btn { + border-color: rgba(0, 0, 0, 0.18); + color: rgba(0, 0, 0, 0.55); +} + +.strata-clear-btn:hover { + background-color: rgba(0, 0, 0, 0.07); + color: rgba(0, 0, 0, 0.85); +} + +.strata-search { + background-color: rgba(0, 0, 0, 0.05); + border-color: rgba(0, 0, 0, 0.14); + color: rgba(0, 0, 0, 0.87); + caret-color: rgba(0, 0, 0, 0.8); +} + +.strata-search:focus { + border-color: rgba(53, 132, 228, 0.8); + background-color: rgba(0, 0, 0, 0.035); +} + +/* Placeholder ("Search...") text - legible dim gray on the light panel. */ +.strata-search-hint { + color: rgba(0, 0, 0, 0.55); +} + +.strata-item:hover, +.strata-item-hovered { + background-color: rgba(53, 132, 228, 0.14); + border-color: rgba(53, 132, 228, 0.45); +} + +.strata-item:focus, +.strata-item-focused { + background-color: rgba(53, 132, 228, 0.16); + border-color: rgba(53, 132, 228, 0.65); +} + +.strata-item:hover:focus, +.strata-item-focused.strata-item-hovered { + background-color: rgba(53, 132, 228, 0.24); + border-color: rgba(53, 132, 228, 0.78); +} + +.strata-item:focus .strata-item-text, +.strata-item-focused .strata-item-text { + color: rgba(0, 0, 0, 0.95); +} + +.strata-item-active { + background-color: rgba(181, 131, 10, 0.16); + border-color: rgba(181, 131, 10, 0.50); +} + +.strata-item-active .strata-item-text { + color: rgba(120, 82, 0, 1.0); +} + +.strata-item-active.strata-item-hovered { + background-color: rgba(181, 131, 10, 0.24); +} + +.strata-item-active.strata-item-focused, +.strata-item-active:focus { + background-color: rgba(53, 132, 228, 0.20); + border-color: rgba(53, 132, 228, 0.65); +} + +.strata-item-active.strata-item-focused .strata-item-text, +.strata-item-active:focus .strata-item-text { + color: rgba(0, 0, 0, 0.95); +} + +.strata-item:active { + background-color: rgba(0, 0, 0, 0.10); +} + +.strata-item-icon { + color: rgba(0, 0, 0, 0.55); +} + +.strata-item-thumb { + border-color: rgba(0, 0, 0, 0.15); +} + +.strata-item-text { + color: rgba(0, 0, 0, 0.85); +} + +.strata-item-url { + color: rgba(26, 95, 180, 1.0); +} + +.strata-item-subtext { + color: rgba(0, 0, 0, 0.55); +} + +.strata-item:hover .strata-item-delete, +.strata-item:focus .strata-item-delete, +.strata-item-focused .strata-item-delete, +.strata-item-hovered .strata-item-delete { + color: rgba(224, 27, 36, 0.75); +} + +.strata-item-delete:hover { + background-color: rgba(224, 27, 36, 0.13); + color: rgba(224, 27, 36, 1.0); +} diff --git a/strata@edu4rdshl.dev/ui/clipboardItem.js b/strata@edu4rdshl.dev/ui/clipboardItem.js index 76a8787..56e6639 100644 --- a/strata@edu4rdshl.dev/ui/clipboardItem.js +++ b/strata@edu4rdshl.dev/ui/clipboardItem.js @@ -57,8 +57,11 @@ export const ClipboardItem = GObject.registerClass({ x_expand: true, }); - row.add_child(this._buildLeading(mimeType, preview)); - row.add_child(this._buildContent(mimeType, preview)); + const isImage = mimeType.startsWith('image/'); + const urlLike = !isImage && isUrl(preview ?? ''); + const colorLike = !isImage && !urlLike && isColor(preview ?? ''); + row.add_child(this._buildLeading(mimeType, preview, isImage, colorLike)); + row.add_child(this._buildContent(preview, isImage, urlLike, colorLike)); const deleteBtn = new St.Button({ style_class: 'strata-item-delete', @@ -88,11 +91,11 @@ export const ClipboardItem = GObject.registerClass({ }); } - _buildLeading(mimeType, preview) { - if (mimeType.startsWith('image/')) { + _buildLeading(mimeType, preview, isImage, colorLike) { + if (isImage) { return this._buildThumbnail(this._id); } - if (isColor(preview)) { + if (colorLike) { return this._buildColorSwatch(preview); } const icon = new St.Icon({ @@ -197,7 +200,7 @@ export const ClipboardItem = GObject.registerClass({ }); } - _buildContent(mimeType, preview) { + _buildContent(preview, isImage, urlLike, colorLike) { preview = preview ?? ''; const box = new St.BoxLayout({ vertical: true, @@ -208,17 +211,17 @@ export const ClipboardItem = GObject.registerClass({ let mainText; let subText = ''; - if (mimeType.startsWith('image/')) { + if (isImage) { // Generic label - the thumbnail identifies the image, and the // on-clipboard format (often PNG even for a copied GIF/WebP) is an // implementation detail that misleads more than it informs. mainText = 'Image'; - } else if (isUrl(preview)) { + } else if (urlLike) { mainText = preview.trim(); try { subText = GLib.Uri.parse(preview.trim(), GLib.UriFlags.NONE).get_host() ?? ''; } catch { /* not a parseable URI */ } - } else if (isColor(preview)) { + } else if (colorLike) { mainText = preview.trim().toUpperCase(); subText = 'Color'; } else { @@ -230,7 +233,7 @@ export const ClipboardItem = GObject.registerClass({ const labelMain = new St.Label({ text: mainText || '(empty)', - style_class: `strata-item-text${isUrl(preview) ? ' strata-item-url' : ''}`, + style_class: `strata-item-text${urlLike ? ' strata-item-url' : ''}`, x_expand: true, y_align: Clutter.ActorAlign.CENTER, }); diff --git a/strata@edu4rdshl.dev/ui/panel.js b/strata@edu4rdshl.dev/ui/panel.js index dad7cc2..cc99f3e 100644 --- a/strata@edu4rdshl.dev/ui/panel.js +++ b/strata@edu4rdshl.dev/ui/panel.js @@ -1,7 +1,6 @@ /* panel.js - Strata clipboard popup panel. */ import GLib from 'gi://GLib'; -import Gio from 'gi://Gio'; import St from 'gi://St'; import Clutter from 'gi://Clutter'; import Meta from 'gi://Meta'; @@ -19,8 +18,8 @@ export class StrataPanel { this._proxy = proxy; this._settings = settings; this._pageSize = settings.get_int('page-size'); - this._pageSizeChangedId = settings.connect('changed::page-size', - () => { this._pageSize = settings.get_int('page-size'); }); + settings.connectObject('changed::page-size', + () => { this._pageSize = settings.get_int('page-size'); }, this); /** @type {{ id: string, mimeType: string, preview: string }[]} */ this._items = []; /** @type {Map} id → widget */ @@ -46,16 +45,6 @@ export class StrataPanel { this._buildUI(); - // Theme: apply light/dark to the panel box and react to changes. - // The light.css overrides (loaded by extension.js) only take effect - // while the `.strata-theme-light` class is present on `_box`. - this._interfaceSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' }); - this._applyTheme(); - this._themeChangedId = this._settings.connect('changed::theme', - () => this._applyTheme()); - this._colorSchemeChangedId = this._interfaceSettings.connect('changed::color-scheme', - () => this._applyTheme()); - // Trigger the initial load as soon as the daemon owns its bus name. // At extension boot the daemon may still be starting (its D-Bus name // not yet owned); the proxy fires notify::g-name-owner when that @@ -63,25 +52,8 @@ export class StrataPanel { // and only then issue GetHistory. If the daemon is already up, the // owner is already set and we load immediately. this._tryInitialLoad(); - this._nameOwnerId = this._proxy.connect('notify::g-name-owner', - () => this._tryInitialLoad()); - } - - /** True when the effective theme is light. `auto` follows the system - * color-scheme (anything other than prefer-dark counts as light). */ - _effectiveIsLight() { - const mode = this._settings.get_string('theme'); - if (mode === 'light') return true; - if (mode === 'dark') return false; - return this._interfaceSettings.get_string('color-scheme') !== 'prefer-dark'; - } - - _applyTheme() { - if (!this._box) return; - if (this._effectiveIsLight()) - this._box.add_style_class_name('strata-theme-light'); - else - this._box.remove_style_class_name('strata-theme-light'); + this._proxy.connectObject('notify::g-name-owner', + () => this._tryInitialLoad(), this); } _tryInitialLoad() { @@ -306,6 +278,7 @@ export class StrataPanel { removeItem(id) { this._items = this._items.filter(i => i.id !== id); + this._thumbCache.delete(id); // Keep the search snapshot in sync so a deleted/pruned item sitting in // the not-yet-rendered tail can't be re-created as a phantom row when // scrolling appends the next page. Adjust _searchRendered if the removed @@ -338,27 +311,13 @@ export class StrataPanel { this._hoveredWidget = null; this._activeWidget = null; this._widgets.clear(); + this._thumbCache.clear(); this._itemList.destroy_all_children(); } destroy() { - if (this._pageSizeChangedId) { - this._settings.disconnect(this._pageSizeChangedId); - this._pageSizeChangedId = 0; - } - if (this._themeChangedId) { - this._settings.disconnect(this._themeChangedId); - this._themeChangedId = 0; - } - if (this._colorSchemeChangedId && this._interfaceSettings) { - this._interfaceSettings.disconnect(this._colorSchemeChangedId); - this._colorSchemeChangedId = 0; - } - this._interfaceSettings = null; - if (this._nameOwnerId) { - this._proxy.disconnect(this._nameOwnerId); - this._nameOwnerId = 0; - } + this._settings.disconnectObject(this); + this._proxy.disconnectObject(this); if (this._searchDebounceId) { GLib.Source.remove(this._searchDebounceId); this._searchDebounceId = null;