diff options
| -rw-r--r-- | AGENTS.md | 4 | ||||
| -rw-r--r-- | config.toml | 3 | ||||
| -rw-r--r-- | deckit/modules/windows.py | 3 | ||||
| -rw-r--r-- | static/app.js | 23 | ||||
| -rw-r--r-- | static/modules/windows.js | 10 | ||||
| -rw-r--r-- | tests/test_windows.mjs | 27 |
6 files changed, 68 insertions, 2 deletions
@@ -90,6 +90,10 @@ Keep the server dependency-free apart from that one package. through `Module.image`, only for a window the last state listed; the URL changes every 5s so the browser cache answers in between. Workspace icons come from keystone's `Workspaces.qml` map (`[windows] workspace_icons`). +- A panel may export `peek(state)`; when it returns seconds > 0 `app.js` + shows that tab that long and then goes back, unless the page is touched or + the tab changed meanwhile. `windows.js` peeks on a window id the last poll + lacked, for `[windows] peek` seconds (0 off). - Launchers are `[launch] apps`, desktop ids run with `gtk-launch`; label and icon come from the `.desktop` file. The client sends the id, which must be configured and installed. diff --git a/config.toml b/config.toml index e5bc329..5b84411 100644 --- a/config.toml +++ b/config.toml @@ -91,6 +91,9 @@ face = [] workspace_icons = "~/Programming/GIT/quickshell/shared/Workspaces.qml" # Workspaces shown on the Windows tab, including empty ones. workspaces = [1, 2, 3, 4, 5, 6, 7, 8] +# Seconds the tablet shows this tab when a window opens, then goes back +# unless touched. 0 turns it off. +peek = 8 [icons] # Launcher icons follow the icon theme Keystone sets (gsettings diff --git a/deckit/modules/windows.py b/deckit/modules/windows.py index a15f44c..edca5b5 100644 --- a/deckit/modules/windows.py +++ b/deckit/modules/windows.py @@ -157,6 +157,7 @@ def make(cfg: dict) -> Module: apps = [str(a) for a in cfg.get("launch", {}).get("apps", [])] workspaces = cfg.get("windows", {}).get("workspaces", list(range(1, 11))) ws_icons = workspace_icons(cfg.get("windows", {}).get("workspace_icons", "")) + peek = max(0, int(cfg.get("windows", {}).get("peek", 8))) entries = _desktop_entries() icons = _desktop_icons(entries) shot = cfg.get("shot", _shot) @@ -208,7 +209,7 @@ def make(cfg: dict) -> Module: known = sorted(set(int(n) for n in workspaces) | set(st["workspaces"])) launches = [{"key": a, "icon": entries[a]["icon"], "label": entries[a]["name"] or a} for a in apps if a in entries] - return {**st, "workspaces": known, "launches": launches, + return {**st, "workspaces": known, "launches": launches, "peek": peek, "wsIcons": {str(n): ws_icons[n] for n in known if n in ws_icons}} def image(key): diff --git a/static/app.js b/static/app.js index 79010bf..a15c2de 100644 --- a/static/app.js +++ b/static/app.js @@ -65,6 +65,7 @@ function sortTabs() { } function showTab(name) { + keep(); for (const [n, tab] of Object.entries(tabs)) { tab.section.hidden = n !== name; tab.button.classList.toggle("active", n === name); @@ -74,6 +75,21 @@ function showTab(name) { } catch {} } +// A panel's peek(state) gives seconds when something new turned up: its tab +// comes forward that long, then the page goes back, unless touched first. +let peek = null; // {back, timer} while a tab is shown on its own +function peekTab(name, seconds) { + const now = Object.keys(tabs).find((n) => !tabs[n].section.hidden); + if (now === name && !peek) return; // already there by choice + const back = peek?.back ?? now; + showTab(name); + peek = { back, timer: setTimeout(() => showTab(back), seconds * 1000) }; +} +function keep() { + if (peek) clearTimeout(peek.timer); + peek = null; +} + const dashboard = ensureTab("Dashboard"); dashboard.section.hidden = false; dashboard.button.classList.add("active"); @@ -102,7 +118,11 @@ function mountTab(name, panel, section) { wrap.className = "tab-content"; section.append(wrap); panel.mount?.(wrap); - poll(name, panel.interval ?? 1, (st) => panel.update?.(st, wrap)); + poll(name, panel.interval ?? 1, (st) => { + panel.update?.(st, wrap); + const seconds = panel.peek?.(st); + if (seconds > 0) peekTab(panel.tab, seconds); + }); } // Modules with no panel file: dashboard.js draws them. @@ -151,6 +171,7 @@ function stepTab(dir) { let swipe = null; let swallowClick = false; tabBody.addEventListener("pointerdown", (e) => { + keep(); if (e.pointerType === "mouse" && e.buttons !== 1) return; if (e.target.closest("input, select, textarea")) { swipe = null; diff --git a/static/modules/windows.js b/static/modules/windows.js index 7e2a184..d9f388e 100644 --- a/static/modules/windows.js +++ b/static/modules/windows.js @@ -165,6 +165,16 @@ export default { </div>`; }, + // A window that was not there on the last poll brings the tab forward for + // [windows] peek seconds. + peek(st) { + if (!st.windows) return false; + const ids = new Set(st.windows.map((w) => w.id)); + const fresh = this._ids != null && [...ids].some((id) => !this._ids.has(id)); + this._ids = ids; + return fresh ? st.peek ?? 8 : 0; + }, + update(st, el) { // Polled every second: rebuilding unchanged rows reloads every icon // through its fallbacks, which flickers, so only a change re-renders. diff --git a/tests/test_windows.mjs b/tests/test_windows.mjs new file mode 100644 index 0000000..534fd45 --- /dev/null +++ b/tests/test_windows.mjs @@ -0,0 +1,27 @@ +// deck-it - check for static/modules/windows.js: `node tests/test_windows.mjs` +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import assert from "node:assert/strict"; +globalThis.document = { addEventListener() {} }; // the module wires a listener on load +const { default: windows } = await import("../static/modules/windows.js"); + +const st = (...ids) => ({ windows: ids.map((id) => ({ id })), peek: 5 }); +assert.equal(windows.peek(st("a", "b")), 0); // first poll only learns +assert.equal(windows.peek(st("a", "b")), 0); +assert.equal(windows.peek(st("a")), 0); // a close is not news +assert.equal(windows.peek(st("a", "c")), 5); // a new window is, for [windows] peek seconds +assert.equal(windows.peek({ error: "x" }), false); // an error keeps what it knew +assert.equal(windows.peek(st("a", "c")), 0); |
