diff --git a/CHANGELOG.md b/CHANGELOG.md index 3284f2f5..94ba7ef6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,13 @@ is missing or empty. - The notification center slides down from the top when the clock is clicked, as when it is pulled. - About shows an icon on its renderer line, as on every other. +- The control center and the notification center can be used fully from + the keyboard (Super+Ctrl+1 and Super+Ctrl+2). +- Settings has Date & Time: the time zone, automatic time and a 24-hour + switch for every clock. +- Settings lists every keyboard shortcut (Settings > Keyboard). +- The bar's background and clock format can be changed in Settings, and + rows that do nothing on this device are dimmed. ## [0.3.2] - 2026-11-19 diff --git a/desktop/install-tree b/desktop/install-tree index a05cb994..8fab8168 100755 --- a/desktop/install-tree +++ b/desktop/install-tree @@ -20,7 +20,7 @@ project=$(dirname "$here") shell=$here/shell config=$here/configuration omarchy=$root/usr/share/omarchy for input in "$build/wvkbd-mobintl" "$build/wtype" "$build/wtype.LICENSE" "$upstream/themes" "$upstream/bin" \ - "$upstream/themes/jade-horse/colors.toml" "$upstream/icons/papercraft" "$upstream/applications/foot.desktop" "$dbus_next/dbus_next/__init__.py"; do + "$upstream/themes/jade-horse/colors.toml" "$upstream/icons/papercraft" "$upstream/applications/foot.desktop" "$upstream/default/hypr/toggles/bar-glassy.lua" "$dbus_next/dbus_next/__init__.py"; do [[ -e $input ]] || { echo "Missing input: $input" >&2; exit 1; } done umask 022 @@ -54,6 +54,9 @@ find "$omarchy" \( -name __pycache__ -o -name '*.pyc' \) -prune -exec rm -rf {} cp -RP "$upstream/themes" "$omarchy/themes" # Upstream's app icon sets (Papercraft, the default; Arcade; Original). cp -RP "$upstream/icons" "$omarchy/icons" +# Upstream's glassy-bar toggle: labwc never reads it, but omarchy-bar puts it +# where Hyprland would, and refuses the Glassy background without it. +put "$upstream/default/hypr/toggles/bar-glassy.lua" "$omarchy/default/hypr/toggles/bar-glassy.lua" # Our drawings for the tablet's own apps, in upstream's sets: Firefox, the # default browser, which upstream's sets do not draw. cp -R "$here/icons/." "$omarchy/icons/" diff --git a/desktop/shell/bin/omarchy-shell-config b/desktop/shell/bin/omarchy-shell-config new file mode 100755 index 00000000..d8c20c7d --- /dev/null +++ b/desktop/shell/bin/omarchy-shell-config @@ -0,0 +1,69 @@ +#!/bin/bash + +# omarchy:summary=Shared helpers for editing ~/.config/omarchy-ipad/shell.json (source this, don't run it). +# omarchy:hidden=true + +# Orchard: upstream's, with the tablet shell's own config, which it reads +# instead of ~/.config/omarchy/shell.json (shell.qml userConfigPath), so the +# upstream commands that edit the shell's config (omarchy-bar, ...) edit the +# one the shell reads. +CONFIG_FILE="$HOME/.config/omarchy-ipad/shell.json" +DEFAULTS_FILE="$OMARCHY_PATH/config/omarchy/shell.json" + +fail() { + echo "${0##*/}: $*" >&2 + exit 1 +} + +refresh_shell_config() { + if ! omarchy-shell shell reloadConfig >/dev/null 2>&1; then + omarchy-shell -q shell rescanPlugins >/dev/null 2>&1 || true + fi +} + +source_file() { + if [[ -s $CONFIG_FILE ]]; then + printf '%s\n' "$CONFIG_FILE" + else + printf '%s\n' "$DEFAULTS_FILE" + fi +} + +# jq pipeline that normalizes shell.json into a well-shaped object with +# version=1, bar.layout.{left,centerBegin,center,centerEnd,right} arrays, and +# plugins array. Every mutation pipes through this so downstream jq can assume +# structure. +NORMALIZE=' + def object_or_empty: if type == "object" then . else {} end; + def array_or_empty: if type == "array" then . else [] end; + object_or_empty + | .version = 1 + | .bar = (.bar | object_or_empty) + | .bar.layout = (.bar.layout | object_or_empty) + | .bar.layout.left = (.bar.layout.left | array_or_empty) + | .bar.layout.centerBegin = (.bar.layout.centerBegin | array_or_empty) + | .bar.layout.center = (.bar.layout.center | array_or_empty) + | .bar.layout.centerEnd = (.bar.layout.centerEnd | array_or_empty) + | .bar.layout.right = (.bar.layout.right | array_or_empty) + | .plugins = (.plugins | array_or_empty) +' + +# Apply a jq program to the source file and atomically write the result to the +# user config, then refresh the running shell. Extra args after the program are +# forwarded to jq (e.g. --arg/--argjson). +_SHELL_CONFIG_TMP="" +cleanup_shell_config_tmp() { + if [[ -n $_SHELL_CONFIG_TMP ]]; then rm -f "$_SHELL_CONFIG_TMP"; fi +} +trap cleanup_shell_config_tmp EXIT + +commit() { + local program="$1" + shift + mkdir -p "$(dirname "$CONFIG_FILE")" + _SHELL_CONFIG_TMP=$(mktemp) + jq -S -e "$@" "$program" "$(source_file)" >"$_SHELL_CONFIG_TMP" || fail "could not update shell config" + mv "$_SHELL_CONFIG_TMP" "$CONFIG_FILE" + _SHELL_CONFIG_TMP="" + refresh_shell_config +} diff --git a/desktop/shell/default/i18n/en/shell.json b/desktop/shell/default/i18n/en/shell.json index 04042b3d..93ae710d 100644 --- a/desktop/shell/default/i18n/en/shell.json +++ b/desktop/shell/default/i18n/en/shell.json @@ -733,5 +733,55 @@ "settings.noWifiDevice": "No Wi-Fi on this device", "settings.brightness": "Brightness", "settings.autoBrightness": "Auto-Brightness", - "settings.rotationLock": "Rotation Lock" + "settings.rotationLock": "Rotation Lock", + "settings.dateTime": "Date & Time", + "settings.setAutomatically": "Set Automatically", + "settings.timeZone": "Time Zone", + "settings.timeNow": "Now", + "settings.searchTimeZones": "Search cities and time zones", + "settings.shortcuts": "Keyboard Shortcuts", + "shortcuts.none": "No shortcuts", + "shortcuts.group.shell": "Shell", + "shortcuts.group.apps": "Apps", + "shortcuts.group.windows": "Windows", + "shortcuts.group.screenshots": "Screenshots", + "shortcuts.group.hardware": "Hardware Keys", + "shortcuts.group.other": "Other", + "shortcuts.launcher": "Launcher", + "shortcuts.controlCenter": "Control Center", + "shortcuts.notificationCenter": "Notification Center", + "shortcuts.audio": "Sound", + "shortcuts.bluetooth": "Bluetooth", + "shortcuts.display": "Display", + "shortcuts.network": "Network", + "shortcuts.power": "Battery", + "shortcuts.menu": "Omarchy Menu", + "shortcuts.systemMenu": "Session Menu", + "shortcuts.bar": "Show or Hide the Bar", + "shortcuts.terminal": "Terminal", + "shortcuts.browser": "Browser", + "shortcuts.activity": "Activity", + "shortcuts.screenshot": "Screenshot", + "shortcuts.volumeUp": "Volume Up", + "shortcuts.volumeDown": "Volume Down", + "shortcuts.mute": "Mute", + "shortcuts.brightnessUp": "Brightness Up", + "shortcuts.brightnessDown": "Brightness Down", + "shortcuts.scaleUp": "Larger Display Scale", + "shortcuts.scaleDown": "Smaller Display Scale", + "shortcuts.close": "Close Window", + "shortcuts.fullscreen": "Full Screen", + "shortcuts.maximize": "Maximize or Restore", + "shortcuts.overview": "Exposé", + "shortcuts.nextWindow": "Next Window", + "shortcuts.previousWindow": "Previous Window", + "shortcuts.hideCursor": "Hide Pointer", + "shortcuts.minimize": "Minimize", + "shortcuts.snapUp": "Snap to Top", + "shortcuts.snapDown": "Snap to Bottom", + "shortcuts.snapLeft": "Snap to Left", + "shortcuts.snapRight": "Snap to Right", + "shortcuts.switchWindows": "Switch Windows", + "shortcuts.switchWindowsBack": "Switch Windows Backwards", + "settings.time24": "24-Hour Time" } diff --git a/desktop/shell/shell/Commons/TimeFormat.qml b/desktop/shell/shell/Commons/TimeFormat.qml new file mode 100644 index 00000000..70275668 --- /dev/null +++ b/desktop/shell/shell/Commons/TimeFormat.qml @@ -0,0 +1,26 @@ +pragma Singleton +import QtQuick +import Quickshell +import "TimeFormatModel.js" as Model + +// 24-hour or 12-hour time, for every clock the shell draws (the bar's, the +// lock screen's, the notification center's, a banner's time). The bar's +// clock format in the shell's config says which: Settings' Date & Time +// switch flips that format's hours (keeping its style), and Appearance's +// Clock picks the style; so the two never disagree. +QtObject { + id: root + + readonly property string configPath: (Quickshell.env("HOME") || "") + "/.config/omarchy-ipad/shell.json" + property WatchedFile config: WatchedFile { path: root.configPath } + + // The bar clock's format, "HH:mm" while there is none. + readonly property string barFormat: clockFormat(config.text) + readonly property bool use24: is24(barFormat) + // The time alone, as the clocks show it. + readonly property string time: use24 ? "HH:mm" : "h:mm AP" + + function clockFormat(text) { return Model.clockFormat(text) } + function is24(format) { return Model.is24(format) } + function flipped(format, to24) { return Model.flipped(format, to24) } +} diff --git a/desktop/shell/shell/Commons/TimeFormatModel.js b/desktop/shell/shell/Commons/TimeFormatModel.js new file mode 100644 index 00000000..1385e970 --- /dev/null +++ b/desktop/shell/shell/Commons/TimeFormatModel.js @@ -0,0 +1,27 @@ +// 24-hour or 12-hour time from the bar clock's format (TimeFormat.qml). + +function clockFormat(text) { + try { + var layout = (JSON.parse(text || "{}").bar || {}).layout || {} + for (var section in layout) { + var widgets = layout[section] || [] + for (var i = 0; i < widgets.length; i++) + if (widgets[i] && widgets[i].id === "omarchy.clock" && widgets[i].format) return String(widgets[i].format) + } + } catch (e) {} + return "HH:mm" +} +// Hours as H (0-23) are 24-hour time; h with AP is 12-hour. Quoted text +// ('W') is not a token. A format without hours reads as 24-hour. +function is24(format) { + var tokens = String(format).replace(/'[^']*'/g, "") + return tokens.indexOf("h") < 0 || tokens.indexOf("H") >= 0 +} +// The format with its hours the other way: "dddd HH:mm" ↔ "dddd h:mm AP". +function flipped(format, to24) { + var f = String(format) + if (to24) return f.replace(/\bh(h?)(:mm(:ss)?)\s*(AP|ap|A|a)/, "HH$2") + return f.replace(/\bHH?(:mm(:ss)?)/, "h$1 AP") +} + +if (typeof module !== "undefined") module.exports = { clockFormat: clockFormat, is24: is24, flipped: flipped } diff --git a/desktop/shell/shell/Commons/TimeZone.qml b/desktop/shell/shell/Commons/TimeZone.qml new file mode 100644 index 00000000..e391655c --- /dev/null +++ b/desktop/shell/shell/Commons/TimeZone.qml @@ -0,0 +1,10 @@ +pragma Singleton +import QtQuick + +// A time zone change, for the shell's clocks: each only turns at its next +// minute otherwise, and a new zone moves the hour at once. Settings' Date & +// Time calls changed() when it sets one. +QtObject { + property int revision: 0 + function changed() { revision++ } +} diff --git a/desktop/shell/shell/Commons/qmldir b/desktop/shell/shell/Commons/qmldir index bb773e52..24f4db12 100644 --- a/desktop/shell/shell/Commons/qmldir +++ b/desktop/shell/shell/Commons/qmldir @@ -7,6 +7,8 @@ singleton InputDevices 1.0 InputDevices.qml singleton IpcRegistry 1.0 IpcRegistry.qml singleton InputMethodState 1.0 InputMethodState.qml singleton Style 1.0 Style.qml +singleton TimeZone 1.0 TimeZone.qml +singleton TimeFormat 1.0 TimeFormat.qml singleton UntypedInput 1.0 UntypedInput.qml singleton Util 1.0 Util.qml ShellIpc 1.0 ShellIpc.qml diff --git a/desktop/shell/shell/controlcenter/ControlCenter.qml b/desktop/shell/shell/controlcenter/ControlCenter.qml index a5ae6c36..01bde2a9 100644 --- a/desktop/shell/shell/controlcenter/ControlCenter.qml +++ b/desktop/shell/shell/controlcenter/ControlCenter.qml @@ -272,21 +272,39 @@ Item { { glyph: "󰝚", label: Commons.I18n.t("controlCenter.media") } ] - // Keyboard: the focused cell, or none until the keyboard is used. + // Keyboard: the focused cell, by its name, or none until the keyboard is + // used. By name, since a switch remakes the toggles (their list is + // rebuilt with every state) and the focus stays on the new cell. property var focusables: [] - property int focusIndex: -1 + property string focusKey: "" function registerCell(item) { - var list = root.focusables.slice() + var list = root.focusables.filter(function(c) { return !!c }) if (list.indexOf(item) < 0) list.push(item) root.focusables = list } - function focusedCell() { return focusIndex >= 0 && focusIndex < focusables.length ? focusables[focusIndex] : null } - function visibleCells() { return focusables.filter(function(c) { return c && c.visible && c.focusable }) } + function unregisterCell(item) { + root.focusables = root.focusables.filter(function(c) { return !!c && c !== item }) + } + function focusedCell() { + if (root.focusKey === "") return null + var cells = visibleCells() + for (var i = 0; i < cells.length; i++) if (cells[i].focusKey === root.focusKey) return cells[i] + return null + } + // In reading order: rows top to bottom, each left to right. + function visibleCells() { + var cells = focusables.filter(function(c) { return c && c.visible && c.focusable }) + var at = function(c) { return c.mapToItem(card, 0, 0) } + return cells.sort(function(a, b) { + var p = at(a), q = at(b) + return Math.abs(p.y - q.y) > 4 ? p.y - q.y : p.x - q.x + }) + } function moveFocus(dx, dy) { var cells = visibleCells() if (cells.length === 0) return var current = focusedCell() - if (!current || cells.indexOf(current) < 0) { root.focusIndex = focusables.indexOf(cells[0]); return } + if (!current) { root.focusKey = cells[0].focusKey; return } var a = current.mapToItem(card, current.width / 2, current.height / 2) var best = null, bestScore = 1e9 for (var i = 0; i < cells.length; i++) { @@ -299,14 +317,14 @@ Item { var score = along + across * 2 if (score < bestScore) { bestScore = score; best = c } } - if (best) root.focusIndex = focusables.indexOf(best) + if (best) root.focusKey = best.focusKey } function stepFocus(delta) { var cells = visibleCells() if (cells.length === 0) return var at = cells.indexOf(focusedCell()) var next = at < 0 ? (delta > 0 ? 0 : cells.length - 1) : (at + delta + cells.length) % cells.length - root.focusIndex = focusables.indexOf(cells[next]) + root.focusKey = cells[next].focusKey } // ----------------------------------------------------------- lifecycle @@ -314,7 +332,7 @@ Item { function prepare() { if (!brightnessRead.running) brightnessRead.running = true if (!autoRead.running) autoRead.running = true - root.focusIndex = -1 + root.focusKey = "" } // A bar panel's popup goes first: the control center is never over one. @@ -598,10 +616,13 @@ Item { case Qt.Key_Left: if (cell && cell.adjust) cell.adjust(-0.05); else root.moveFocus(-1, 0); break case Qt.Key_Right: - if (cell && cell.adjust) cell.adjust(0.05) - else if (cell && cell.page) root.openPage(cell.page) - else root.moveFocus(1, 0); break - case Qt.Key_Return: case Qt.Key_Enter: case Qt.Key_Space: + if (cell && cell.adjust) cell.adjust(0.05); else root.moveFocus(1, 0); break + // Enter opens a cell's page, where it has one; Space switches it. + case Qt.Key_Return: case Qt.Key_Enter: + if (cell && cell.page) root.openPage(cell.page) + else if (cell && cell.activate) cell.activate() + break + case Qt.Key_Space: if (cell && cell.activate) cell.activate(); break default: return } @@ -611,7 +632,7 @@ Item { // A pointer clears the keyboard's highlight. PointHandler { - onActiveChanged: if (active) root.focusIndex = -1 + onActiveChanged: if (active) root.focusKey = "" } // Pushed up by a finger, it follows and goes away. Above the card, so it @@ -727,6 +748,7 @@ Item { title: Commons.I18n.t("controlCenter.wifi") subtitle: root.wifiSubtitle on: network.wifiEnabled + focusKey: "wifi" page: "omarchy.network" onActivated: root.toggleWifi() } @@ -737,6 +759,7 @@ Item { subtitle: root.bluetoothSubtitle on: bluetooth.enabled available: !!bluetooth.adapter + focusKey: "bluetooth" page: "omarchy.bluetooth" onActivated: root.toggleBluetooth() } @@ -755,6 +778,8 @@ Item { available: root.brightness >= 0 note: root.autoBrightness ? Commons.I18n.t("controlCenter.auto") : "" pageArrow: true + focusKey: "brightness" + page: "omarchy.monitor" onMoved: function(v) { root.setBrightness(v * 100) } onLongPressed: root.openPage("omarchy.monitor") } @@ -766,6 +791,8 @@ Item { value: root.volume available: !!(root.sink && root.sink.audio) chip: root.outputName + focusKey: "volume" + page: "omarchy.audio" onMoved: function(v) { root.setVolume(v) } onLongPressed: root.openPage("omarchy.audio") } @@ -785,6 +812,7 @@ Item { label: modelData.label on: modelData.on available: modelData.enabled + focusKey: modelData.key onActivated: modelData.act() } } @@ -799,6 +827,7 @@ Item { // Dimmed until its backend exists; then live like the others. on: modelData.on === true available: !!modelData.act && modelData.enabled === true + focusKey: "later:" + modelData.label onActivated: if (modelData.act) modelData.act() } } @@ -857,12 +886,17 @@ Item { property bool on: false property bool available: true property string page: "" - property bool focusable: available - readonly property bool focused: root.focusables[root.focusIndex] === cell + // A cell that can't be used is skipped, unless it has a page: the page + // says why (no adapter, no device), and Enter is the way there. + property bool focusable: available || page !== "" + // Its name for the keyboard (see focusKey). + property string focusKey: "" + readonly property bool focused: focusKey !== "" && root.focusKey === focusKey && visible property bool pressed: false signal activated() function activate() { if (cell.available) cell.activated() } Component.onCompleted: root.registerCell(cell) + Component.onDestruction: root.unregisterCell(cell) radius: Style.cornerRadius color: !available ? "transparent" : (on ? root.onFill : Style.controlFill(false, false, root.text, Commons.Color.accent)) @@ -870,8 +904,20 @@ Item { scale: pressed ? 0.96 : 1 Behavior on scale { NumberAnimation { duration: Style.duration(120); easing.type: Easing.OutCubic } } border.width: Math.max(1, Style.space(1)) - border.color: focused ? Commons.Color.accent : (on && available ? root.onFill : Style.normalBorderColor) + border.color: on && available ? root.onFill : Style.normalBorderColor opacity: available ? 1 : 0.45 + // The keyboard's place: a ring just outside the cell, clear of its fill + // (a lit tile is the accent itself) and of its border. + Rectangle { + z: 100 + visible: cell.focused + anchors.fill: parent + anchors.margins: -Style.space(4) + radius: cell.radius > 0 ? cell.radius + Style.space(4) : 0 + color: "transparent" + border.width: Math.max(2, Style.space(2)) + border.color: Commons.Color.accent + } } component Tile: Cell { @@ -1028,17 +1074,21 @@ Item { onActivated: slider.longPressed() function adjust(delta) { if (slider.available) slider.moved(Math.max(0, Math.min(1, slider.value + delta))) } color: Style.controlFill(false, false, root.text, Commons.Color.accent) - clip: true scale: drag.holding ? 0.96 : 1 Behavior on scale { NumberAnimation { duration: Style.duration(140); easing.type: Easing.OutCubic } } - Rectangle { - x: 0 - y: slider.vertical ? parent.height * (1 - slider.value) : 0 - width: slider.vertical ? parent.width : parent.width * slider.value - height: slider.vertical ? parent.height * slider.value : parent.height - color: root.text - opacity: 0.85 + // The level, clipped to the cell (the focus ring lies outside it). + Item { + anchors.fill: parent + clip: true + Rectangle { + x: 0 + y: slider.vertical ? parent.height * (1 - slider.value) : 0 + width: slider.vertical ? parent.width : parent.width * slider.value + height: slider.vertical ? parent.height * slider.value : parent.height + color: root.text + opacity: 0.85 + } } Text { @@ -1177,8 +1227,9 @@ Item { id: batteryCell visible: root.batteryLine !== "" page: "omarchy.power" + focusKey: "battery" color: "transparent" - border.width: focused ? Math.max(1, Style.space(1)) : 0 + border.width: 0 width: batteryRow.implicitWidth + Style.space(16) height: parent.height onActivated: root.openPage("omarchy.power") diff --git a/desktop/shell/shell/notificationcenter/NotificationCenter.qml b/desktop/shell/shell/notificationcenter/NotificationCenter.qml index 7d0aba8a..4e1ca23d 100644 --- a/desktop/shell/shell/notificationcenter/NotificationCenter.qml +++ b/desktop/shell/shell/notificationcenter/NotificationCenter.qml @@ -114,6 +114,9 @@ Item { if (Math.floor(t / 60000) !== Math.floor(root.now / 60000)) root.now = t } } + // A new time zone moves the hour at once (Settings > Date & Time). + readonly property int zoneRevision: Commons.TimeZone.revision + onZoneRevisionChanged: root.now = Date.now() function ago(ts) { var s = Math.max(0, (root.now - ts * 1000) / 1000) if (s < 60) return I18n.t("agents.durationNow") @@ -197,7 +200,7 @@ Item { root.openGroups = ({}) root.markAllSeen() scroller.contentY = 0 - root.focusIndex = -1 + root.focusRow = "" root.opened = true root.mapped = true if (panel.contentRevealed) root.animateIn() @@ -321,22 +324,83 @@ Item { // ------------------------------------------------------------ keyboard - // Up and Down walk Focus, Clear all and the cards; Enter opens or presses, - // Delete clears a card, Escape closes. - property int focusIndex: -1 - readonly property int focusCount: 2 + root.groups.length - function moveFocus(step) { - if (root.focusCount === 0) return - root.focusIndex = root.focusIndex < 0 ? (step > 0 ? 0 : root.focusCount - 1) - : Math.max(0, Math.min(root.focusCount - 1, root.focusIndex + step)) + // Rows, top to bottom: the header (Focus, Clear all), then each card, an + // open stack's all. Up and Down go between rows, Left and Right along one + // (a card, then its buttons and its reply field). Enter opens or presses, + // Space opens or closes a stack, Delete clears a card, Escape closes. + // The row is a card's notification key, so it stays put as cards come + // and go; "" until the keyboard is used. + property string focusRow: "" + property int focusCol: 0 + property int lastRowIndex: 0 + readonly property var focusRows: { + var rows = ["header"] + for (var i = 0; i < root.groups.length; i++) { + var g = root.groups[i] + if (!g.rows.length) continue + rows.push(String(g.rows[0].key)) + if (root.openGroups[g.key]) for (var j = 1; j < g.rows.length; j++) rows.push(String(g.rows[j].key)) + } + return rows + } + onFocusRowsChanged: { + if (root.focusRow === "" || root.focusRows.indexOf(root.focusRow) >= 0) return + // Its card went: the one now in its place. + root.focusRow = root.focusRows[Math.min(root.lastRowIndex, root.focusRows.length - 1)] + root.focusCol = 0 + } + // The cards on screen, by key, for what only a card knows (its buttons). + property var cardItems: ({}) + function rowParts(row) { + if (row === "header") return root.groups.length > 0 ? 2 : 1 + var card = root.cardItems[row] + return card ? card.parts : 1 + } + function moveRow(step) { + var rows = root.focusRows + var at = rows.indexOf(root.focusRow) + var next = at < 0 ? (step > 0 ? 0 : rows.length - 1) : Math.max(0, Math.min(rows.length - 1, at + step)) + root.lastRowIndex = next + if (rows[next] !== root.focusRow) root.focusCol = 0 + root.focusRow = rows[next] } - function activateFocused() { - if (root.focusIndex === 0) root.toggleFocus() - else if (root.focusIndex === 1) root.clearAll() - else if (root.focusIndex >= 2) root.openGroup(root.groups[root.focusIndex - 2]) + function moveCol(step) { + if (root.focusRow === "") { root.moveRow(1); return } + root.focusCol = Math.max(0, Math.min(root.rowParts(root.focusRow) - 1, root.focusCol + step)) + } + function groupOf(key) { + for (var i = 0; i < root.groups.length; i++) { + var rows = root.groups[i].rows + for (var j = 0; j < rows.length; j++) if (String(rows[j].key) === key) return { group: root.groups[i], entry: rows[j], head: j === 0 } + } + return null + } + function activateFocused(space) { + if (root.focusRow === "header") { + if (root.focusCol === 0) root.toggleFocus(); else root.clearAll() + return + } + var found = root.groupOf(root.focusRow) + if (!found) return + var stack = found.head && found.group.rows.length > 1 + if (space && stack && root.focusCol === 0) { root.toggleGroup(found.group.key); return } + var card = root.cardItems[root.focusRow] + if (card) card.press(root.focusCol) } function forgetFocused() { - if (root.focusIndex >= 2) root.forgetGroup(root.groups[root.focusIndex - 2], false) + var found = root.groupOf(root.focusRow) + if (!found) return + var single = !found.head || !!root.openGroups[found.group.key] + root.forgetGroup(found.group, single, found.entry) + } + // Keeps what the keyboard is on in sight. + function showItem(item) { + if (!item) return + var p = item.mapToItem(scroller.contentItem, 0, 0) + var margin = Style.space(12) + if (p.y - margin < scroller.contentY) scroller.contentY = Math.max(0, p.y - margin) + else if (p.y + item.height + margin > scroller.contentY + scroller.height) + scroller.contentY = Math.min(Math.max(0, scroller.contentHeight - scroller.height), p.y + item.height + margin - scroller.height) } // ------------------------------------------------------------ actions @@ -455,16 +519,19 @@ Item { Keys.onPressed: function(event) { switch (event.key) { case Qt.Key_Escape: root.close(); break - case Qt.Key_Down: case Qt.Key_Tab: root.moveFocus(1); break - case Qt.Key_Up: case Qt.Key_Backtab: root.moveFocus(-1); break - case Qt.Key_Return: case Qt.Key_Enter: case Qt.Key_Space: root.activateFocused(); break + case Qt.Key_Down: case Qt.Key_Tab: root.moveRow(1); break + case Qt.Key_Up: case Qt.Key_Backtab: root.moveRow(-1); break + case Qt.Key_Right: root.moveCol(1); break + case Qt.Key_Left: root.moveCol(-1); break + case Qt.Key_Return: case Qt.Key_Enter: root.activateFocused(false); break + case Qt.Key_Space: root.activateFocused(true); break case Qt.Key_Delete: case Qt.Key_Backspace: root.forgetFocused(); break default: return } event.accepted = true } } - PointHandler { onActiveChanged: if (active) root.focusIndex = -1 } + PointHandler { onActiveChanged: if (active) root.focusRow = "" } // What it shows, sliding down from under the bar: its bottom is where the // finger is. @@ -513,7 +580,7 @@ Item { Text { textFormat: Text.PlainText - text: Qt.locale(I18n.formatLocale).toString(new Date(root.now), "HH:mm") + text: Qt.locale(I18n.formatLocale).toString(new Date(root.now), Commons.TimeFormat.time) color: root.text font.family: Style.font.family font.pixelSize: Style.space(72) @@ -543,7 +610,7 @@ Item { spacing: Style.space(2) Text { textFormat: Text.PlainText - text: Qt.locale(I18n.formatLocale).toString(new Date(root.now), "HH:mm") + text: Qt.locale(I18n.formatLocale).toString(new Date(root.now), Commons.TimeFormat.time) color: root.text font.family: Style.font.family font.pixelSize: Style.space(root.phone ? 34 : 40) @@ -604,13 +671,13 @@ Item { glyph: "󰽥" label: root.focusOn ? I18n.t("notificationCenter.focusOn") : I18n.t("notificationCenter.focusOff") lit: root.focusOn - focused: root.focusIndex === 0 + focused: root.focusRow === "header" && root.focusCol === 0 onActivated: root.toggleFocus() } HeaderButton { label: I18n.t("notificationCenter.clearAll") enabled: root.groups.length > 0 - focused: root.focusIndex === 1 + focused: root.focusRow === "header" && root.focusCol === 1 onActivated: root.clearAll() } } @@ -692,7 +759,6 @@ Item { // The shapes fade and fold away with the opening, not at once. stacked: groupColumn.more shade: 1 - groupColumn.openness - focused: root.focusIndex === groupColumn.index + 2 onOpened: root.openEntry(entry) onSwiped: root.forgetGroup(groupColumn.modelData, groupColumn.open, entry) onMoreToggled: root.toggleGroup(groupColumn.modelData.key) @@ -761,6 +827,16 @@ Item { // ------------------------------------------------------------ parts // The weather, as the weather panel reads it. + // The keyboard's place, as in the control center: a ring just outside. + component FocusRing: Rectangle { + z: 100 + anchors.fill: parent + anchors.margins: -Style.space(4) + color: "transparent" + border.width: Math.max(2, Style.space(2)) + border.color: Commons.Color.accent + } + component WeatherCard: Rectangle { id: weatherCard // Room the text has inside the card as it is laid out. @@ -829,8 +905,10 @@ Item { height: Style.space(30) color: lit ? Util.alpha(Commons.Color.accent, 0.18) : "transparent" border.width: root.hairline - border.color: focused ? Commons.Color.accent : root.outline + border.color: root.outline opacity: enabled ? 1 : 0.45 + onFocusedChanged: if (focused) root.showItem(button) + FocusRing { visible: button.focused } scale: buttonArea.pressed && buttonArea.containsMouse ? 0.96 : 1 Row { id: buttonRow @@ -876,7 +954,29 @@ Item { property int stacked: more > 0 ? more : 0 // How much of a closed stack's shapes behind it shows (1 closed, 0 open). property real shade: 1 - property bool focused: false + // The keyboard: on this card, and on which part of it (0 the card, then + // its buttons, then its reply field). + readonly property string rowKey: String(entry.key || "") + readonly property bool focused: rowKey !== "" && root.focusRow === rowKey + readonly property int part: focused ? root.focusCol : -1 + readonly property int actionCount: (entry.actions || []).length + readonly property bool canReply: String(entry.reply || "") !== "" + readonly property int parts: 1 + actionCount + (canReply ? 1 : 0) + onRowKeyChanged: register() + Component.onCompleted: register() + Component.onDestruction: if (root.cardItems[registered] === card) delete root.cardItems[registered] + property string registered: "" + function register() { + if (registered !== "" && root.cardItems[registered] === card) delete root.cardItems[registered] + registered = rowKey + if (rowKey !== "") root.cardItems[rowKey] = card + } + onFocusedChanged: if (focused) root.showItem(card) + function press(at) { + if (at <= 0) card.opened() + else if (at <= actionCount) card.actionPressed(String(entry.actions[at - 1].id)) + else if (canReply) { root.beginReply(false); replyInput.forceActiveFocus() } + } signal opened() signal swiped() signal moreToggled() @@ -921,8 +1021,9 @@ Item { width: card.width height: content.implicitHeight + Style.space(24) color: root.cardFill - border.width: root.focused ? Math.max(1, root.hairline) : root.hairline - border.color: card.focused ? Commons.Color.accent : root.outline + border.width: root.hairline + border.color: root.outline + FocusRing { visible: card.part === 0 } opacity: Math.max(0, 1 - Math.abs(card.swipeX) / (card.width * 0.5)) layer.enabled: root.gpu && (card.fling !== "" || swipe.active) @@ -1068,6 +1169,7 @@ Item { border.width: index === 0 ? 0 : root.hairline border.color: root.outline scale: actionArea.pressed && actionArea.containsMouse ? 0.96 : 1 + FocusRing { visible: card.part === parent.index + 1 } Text { anchors.centerIn: parent width: parent.width - Style.space(12) @@ -1102,6 +1204,7 @@ Item { color: Util.alpha(Commons.Color.background, 0.7) border.width: replyInput.activeFocus && root.typing ? Math.max(1, root.hairline) : root.hairline border.color: replyInput.activeFocus && root.typing ? Commons.Color.accent : root.outline + FocusRing { visible: card.canReply && card.part === card.parts - 1 && !(replyInput.activeFocus && root.typing) } TextInput { id: replyInput anchors.fill: parent diff --git a/desktop/shell/shell/plugins/lock/LockView.qml b/desktop/shell/shell/plugins/lock/LockView.qml index 27bae92b..fefeefca 100644 --- a/desktop/shell/shell/plugins/lock/LockView.qml +++ b/desktop/shell/shell/plugins/lock/LockView.qml @@ -254,7 +254,7 @@ Item { id: clockTime x: root.landscape ? 0 : (parent.width - width) / 2 textFormat: Text.PlainText - text: Qt.formatTime(root.now, "HH:mm") + text: Qt.formatTime(root.now, TimeFormat.time) color: Commons.Color.lock.text font.family: Style.font.family font.pixelSize: root.pt("time") diff --git a/desktop/shell/shell/plugins/notifications/Toast.qml b/desktop/shell/shell/plugins/notifications/Toast.qml index 4f018f51..e31ca7f0 100644 --- a/desktop/shell/shell/plugins/notifications/Toast.qml +++ b/desktop/shell/shell/plugins/notifications/Toast.qml @@ -60,7 +60,7 @@ Item { var then = new Date(t) var locale = Qt.locale(I18n.formatLocale) var sameDay = new Date(now).toDateString() === then.toDateString() - if (sameDay) return locale.toString(then, "HH:mm") + if (sameDay) return locale.toString(then, TimeFormat.time) var yest = new Date(now - 86400000).toDateString() === then.toDateString() if (yest) return I18n.t("notifications.yesterday") return locale.toString(then, "ddd") diff --git a/desktop/shell/shell/plugins/panels/clock/BarWidget.qml b/desktop/shell/shell/plugins/panels/clock/BarWidget.qml index d4c623c5..c2069650 100644 --- a/desktop/shell/shell/plugins/panels/clock/BarWidget.qml +++ b/desktop/shell/shell/plugins/panels/clock/BarWidget.qml @@ -9,7 +9,7 @@ import "Model.js" as Model // // Left click reveals the calendar — asking "what is the date?" is what a // click on a clock means — right click walks the common label formats, and -// middle click opens the timezone picker. +// middle click opens the time zone (Settings > Date & Time). BarWidget { id: root moduleName: "omarchy.clock" @@ -169,7 +169,8 @@ BarWidget { onPressed: function(b) { if (b === Qt.RightButton) root.cycleFormat() - else if (b === Qt.MiddleButton) { if (root.bar) root.bar.run("omarchy-menu-timezone") } + // Orchard: the time zone is Settings' Date & Time. + else if (b === Qt.MiddleButton) { if (root.bar) root.bar.run("omarchy-settings datetime") } // Orchard: the date and time open the notification center (SHELL-SPEC, // step 3); upstream's calendar panel stays where there is none. else if (root.bar && root.bar.shell && root.bar.shell.notificationCenter) root.bar.shell.notificationCenter.togglePopup() diff --git a/desktop/shell/shell/plugins/panels/clock/WallClock.qml b/desktop/shell/shell/plugins/panels/clock/WallClock.qml index da1f87a7..c8e84742 100644 --- a/desktop/shell/shell/plugins/panels/clock/WallClock.qml +++ b/desktop/shell/shell/plugins/panels/clock/WallClock.qml @@ -1,4 +1,5 @@ import QtQuick +import qs.Commons import "Model.js" as Model // Stands in for Quickshell's SystemClock, which schedules its next tick from @@ -19,6 +20,11 @@ Timer { } onStepChanged: arm() + + // A new time zone (Settings > Date & Time) shows at once, not at the + // next tick. + readonly property int zoneRevision: TimeZone.revision + onZoneRevisionChanged: { date = new Date(); arm() } onTriggered: { date = new Date() arm() diff --git a/desktop/shell/shell/settings/DateTimePage.qml b/desktop/shell/shell/settings/DateTimePage.qml new file mode 100644 index 00000000..1247a765 --- /dev/null +++ b/desktop/shell/shell/settings/DateTimePage.qml @@ -0,0 +1,105 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Commons +import qs.Commons as Commons + +// Date & Time: whether the clock sets itself (NTP) and the time zone, through +// timedatectl. The tablet runs no polkit agent: a polkit rule lets its +// active local session change these two without a password +// (system/overlay/etc/polkit-1/rules.d/60-omarchy-tablet-time.rules). +Item { + id: page + + property var settings: null + + width: parent ? parent.width : 0 + height: column.height + + property string zone: "" + property bool automatic: false + property bool canAutomatic: false + property bool busy: false + + function read() { reader.running = true } + Component.onCompleted: read() + Process { + id: reader + command: ["timedatectl", "show", "-p", "Timezone", "-p", "NTP", "-p", "CanNTP"] + stdout: StdioCollector { + onStreamFinished: { + var lines = String(text).split("\n") + for (var i = 0; i < lines.length; i++) { + var at = lines[i].indexOf("=") + if (at < 0) continue + var key = lines[i].slice(0, at), value = lines[i].slice(at + 1) + if (key === "Timezone") page.zone = value + else if (key === "NTP") page.automatic = value === "yes" + else if (key === "CanNTP") page.canAutomatic = value === "yes" + } + } + } + } + Process { + id: writer + onExited: { page.busy = false; page.read() } + } + function setAutomatic(on) { + if (writer.running) return + page.busy = true + page.automatic = on + writer.command = ["timedatectl", "set-ntp", on ? "true" : "false"] + writer.running = true + } + + // The time now, to the minute, in the zone set. + property date now: new Date() + Timer { interval: 1000; running: true; repeat: true; onTriggered: page.now = new Date() } + + Column { + id: column + width: page.width + spacing: Style.space(14) + + SettingsBox { + settings: page.settings + width: parent.width + SettingsItem { + settings: page.settings + first: true + label: Commons.I18n.t("settings.setAutomatically") + isSwitch: true + switchOn: page.automatic + usable: page.canAutomatic && !page.busy + onActivated: page.setAutomatic(!page.automatic) + } + SettingsItem { + settings: page.settings + label: Commons.I18n.t("settings.timeZone") + value: page.zone.replace(/_/g, " ") + opens: true + onActivated: if (page.settings) page.settings.push({ kind: "native", page: "timezone", title: Commons.I18n.t("settings.timeZone") }) + } + } + + SettingsBox { + settings: page.settings + width: parent.width + // Every clock's hours, through the bar clock's format (TimeFormat). + SettingsItem { + settings: page.settings + first: true + label: Commons.I18n.t("settings.time24") + isSwitch: true + switchOn: Commons.TimeFormat.use24 + onActivated: Quickshell.execDetached(["omarchy-bar", "set", "omarchy.clock", "format", + Commons.TimeFormat.flipped(Commons.TimeFormat.barFormat, !Commons.TimeFormat.use24)]) + } + SettingsItem { + settings: page.settings + label: Commons.I18n.t("settings.timeNow") + value: page.now.toLocaleDateString(Qt.locale(), "d MMMM yyyy") + ", " + Qt.formatTime(page.now, Commons.TimeFormat.time) + } + } + } +} diff --git a/desktop/shell/shell/settings/SettingsLayout.js b/desktop/shell/shell/settings/SettingsLayout.js index 880064eb..2561963d 100644 --- a/desktop/shell/shell/settings/SettingsLayout.js +++ b/desktop/shell/shell/settings/SettingsLayout.js @@ -55,8 +55,9 @@ var SECTIONS = [ groups: [ { label: "", rows: [ { entry: "setup.language" }, - { entry: "update.timezone" }, - { entry: "update.time" } + // The time zone and automatic time, in place of the menu's Timezone + // and Time (which only restarts time sync). + { page: "datetime", label: "settings.dateTime", icon: "󰥔", value: "timedatectl show -p Timezone --value" } ] }, { label: "", rows: [ { entry: "setup.config" }, @@ -89,7 +90,6 @@ var SECTIONS = [ ] }, { label: "settings.bar", rows: [ { toggle: ["appearance.top-bar.show", "appearance.top-bar.hide"], label: "settings.showBar" }, - { entry: "appearance.top-bar.position", value: "omarchy-bar position" }, { entry: "appearance.top-bar.background" }, { toggle: ["appearance.top-bar.indicators.battery-percentage-on", "appearance.top-bar.indicators.battery-percentage-off"], label: "settings.batteryPercentage" }, { entry: "appearance.top-bar.indicators.clock" } @@ -138,6 +138,7 @@ var SECTIONS = [ iconEntry: "setup.keyboard", groups: [ { label: "settings.keyboard", rows: [ + { page: "shortcuts", label: "settings.shortcuts", icon: "󰌌" }, { entry: "setup.keyboard.inputs" }, { entry: "setup.keyboard.input-methods" }, { entry: "setup.keyboard.keybindings" }, @@ -270,7 +271,20 @@ var ELSEWHERE = [ "trigger.transcode", "trigger.share", "trigger.activity", "trigger.toggle.idle-lock-on", "trigger.toggle.idle-lock-off", "system.lock", "system.suspend", "system.hibernate", "system.logout", "system.reboot", - "system.shutdown", "system.screensaver" + "system.shutdown", "system.screensaver", + // The bar stays at the top: a finger pulls the control and notification + // centers down from it, and a phone's bar is laid out for it. + "appearance.top-bar.position", + // Date & Time (General) does what these do. + "update.timezone", "update.time" ] -if (typeof module !== "undefined") module.exports = { SECTIONS: SECTIONS, ELSEWHERE: ELSEWHERE } +// Upstream commands that mention Hyprland but were checked to work under +// labwc: Settings does not dim their rows (SettingsModel.stateScript). +var LABWC_CHECKED = [ + // Bar style, clock format, battery %: the shell's config, through + // omarchy-shell-config; it reloads Hyprland only for a glassy bar's blur. + "omarchy-bar" +] + +if (typeof module !== "undefined") module.exports = { SECTIONS: SECTIONS, ELSEWHERE: ELSEWHERE, LABWC_CHECKED: LABWC_CHECKED } diff --git a/desktop/shell/shell/settings/SettingsModel.js b/desktop/shell/shell/settings/SettingsModel.js index 1b1cb428..ccf242f4 100644 --- a/desktop/shell/shell/settings/SettingsModel.js +++ b/desktop/shell/shell/settings/SettingsModel.js @@ -166,8 +166,10 @@ function resolveRow(spec, ctx, providers, t) { if (!entry || !shown(ctx, entry)) return null var all = entryText(ctx, entry, providers) var gone = missingIn(ctx, all) - // A submenu works as long as something in it does. - var available = gone.length === 0 || (entry.kind === "menu" && !entry.provider && submenuWorks(ctx, entry, providers)) + // A submenu works as long as something in it does, and only then: one + // whose rows are all hidden (no touchpad, say) would open an empty page. + var submenu = entry.kind === "menu" && !entry.provider + var available = submenu ? submenuWorks(ctx, entry, providers) : gone.length === 0 var row = { key: key, entry: entry, label: entry.label, icon: entry.icon || "", iconFont: entry.iconFont || "", value: values[key] || "", available: available, tag: available ? "" : tagFor(gone, all, ctx), @@ -441,9 +443,12 @@ function stateScript(sections, ctx, providers) { if (entry.provider && providers && providers[entry.provider]) names = names.concat(commandsIn(providers[entry.provider].script)) for (var n = 0; n < names.length; n++) commands[names[n]] = true } + var checked = (ctx.labwcChecked || []) var list = Object.keys(commands).sort() - // Missing, or (outside a Hyprland session) calling hyprctl. - if (list.length) lines.push("for c in " + list.join(" ") + "; do p=$(command -v \"$c\" 2>/dev/null) || { printf 'm\\t%s\\n' \"$c\"; continue; }; [[ -z $HYPRLAND_INSTANCE_SIGNATURE ]] && grep -qE '\\bhyprctl\\b|\\bomarchy-hyprland-' \"$p\" 2>/dev/null && printf 'h\\t%s\\n' \"$c\"; done") + // Missing, or (outside a Hyprland session) calling hyprctl: in doubt a row + // stays dimmed. A command checked to work under labwc too (layout's + // LABWC_CHECKED: omarchy-bar reloads Hyprland only for its blur) is not. + if (list.length) lines.push("for c in " + list.join(" ") + "; do p=$(command -v \"$c\" 2>/dev/null) || { printf 'm\\t%s\\n' \"$c\"; continue; }; [[ -z $HYPRLAND_INSTANCE_SIGNATURE ]] && [[ \" " + checked.join(" ") + " \" != *\" $c \"* ]] && grep -qE '\\bhyprctl\\b|\\bomarchy-hyprland-' \"$p\" 2>/dev/null && printf 'h\\t%s\\n' \"$c\"; done") for (var s = 0; s < sections.length; s++) for (var g = 0; g < sections[s].groups.length; g++) for (var r = 0; r < sections[s].groups[g].rows.length; r++) { @@ -480,11 +485,11 @@ function route(path, sections, ctx) { var parts = text.split("/") for (var s = 0; s < sections.length; s++) { if (sections[s].id !== parts[0]) continue - var page = parts.length > 1 ? nativeOrEntry(parts.slice(1).join("/"), ctx) : null + var page = parts.length > 1 ? nativeOrEntry(parts.slice(1).join("/"), ctx, sections) : null return { section: sections[s].id, page: page } } - var native = { theme: "appearance", background: "appearance", icons: "appearance" } - if (native[text]) return { section: native[text], page: { kind: "native", page: text } } + var native = nativePages(sections) + if (native[text]) return { section: native[text].section, page: nativePage(text, native[text]) } var entry = item(ctx, text) if (entry) { var home = sectionFor(sections, ctx, text) @@ -494,8 +499,30 @@ function route(path, sections, ctx) { return { section: "", page: null } } -function nativeOrEntry(rest, ctx) { - if (rest === "theme" || rest === "background" || rest === "icons") return { kind: "native", page: rest } +// The native pages a row opens (Theme, Date & Time, Keyboard Shortcuts, ...), +// by name: the section each lives in and its label, for a deep link. +function nativePages(sections) { + var out = {} + for (var s = 0; s < sections.length; s++) + for (var g = 0; g < sections[s].groups.length; g++) + for (var r = 0; r < sections[s].groups[g].rows.length; r++) { + var spec = sections[s].groups[g].rows[r] + if (spec.page && !out[spec.page]) out[spec.page] = { section: sections[s].id, label: spec.entry ? "" : (spec.label || "") } + } + return out +} + +// A page for the window's stack; its title from its label, where the row has +// one of its own (an entry's page takes the entry's). +function nativePage(name, found) { + var page = { kind: "native", page: name } + if (found.label) page.titleKey = found.label + return page +} + +function nativeOrEntry(rest, ctx, sections) { + var native = nativePages(sections || []) + if (native[rest]) return nativePage(rest, native[rest]) var entry = item(ctx, rest) if (entry && entry.kind === "menu") return { kind: isChoice(ctx, entry) ? "choice" : "menu", id: rest } return null @@ -526,7 +553,7 @@ function swatchesOf(colors) { return out } -if (typeof module !== "undefined") module.exports = { +if (typeof module !== "undefined") module.exports = { nativePages: nativePages, parseColors: parseColors, displayName: displayName, swatchesOf: swatchesOf, commandsIn: commandsIn, resolveRow: resolveRow, resolveRows: resolveRows, menuSpecs: menuSpecs, choiceRows: choiceRows, sectionGroups: sectionGroups, sectionFor: sectionFor, unplaced: unplaced, diff --git a/desktop/shell/shell/settings/SettingsWindow.qml b/desktop/shell/shell/settings/SettingsWindow.qml index e8a8675b..6f090df2 100644 --- a/desktop/shell/shell/settings/SettingsWindow.qml +++ b/desktop/shell/shell/settings/SettingsWindow.qml @@ -55,7 +55,8 @@ FloatingWindow { disabledResults: menu ? menu.disabledResults : ({}), values: values, missing: missing, - hyprland: hyprland + hyprland: hyprland, + labwcChecked: Layout.LABWC_CHECKED }) readonly property var providers: menu ? menu.providers : ({}) function t(key) { return Commons.I18n.t(key) } @@ -186,6 +187,14 @@ FloatingWindow { } } } + // Back to the page shown under it: a native page's pick (a time zone) puts + // its list away. + function backTo(page) { + var at = -1 + for (var i = 0; i < win.stack.length; i++) if (win.stack[i].page === page) at = i + if (at < 0 || at === win.stack.length - 1) return + win.navigate(-1, function() { win.stack = win.stack.slice(0, at + 1); win.cursor = -1 }) + } function back() { if (win.searching) { win.query = ""; searchField.text = ""; return true } if (win.stack.length > 0) { @@ -219,6 +228,8 @@ FloatingWindow { if (win.searching) return win.t("settings.searchResults") if (top) { if (top.kind === "native") { + if (top.title) return top.title + if (top.titleKey) return win.t(top.titleKey) var nativeEntry = { theme: "appearance.theme", background: "appearance.background", icons: "appearance.icons" }[top.page] return nativeEntry && ctx.items[nativeEntry] ? ctx.items[nativeEntry].label : top.page } @@ -233,6 +244,7 @@ FloatingWindow { if (!top) return "" if (stack.length > 1) { var prev = stack[stack.length - 2] + if (prev.kind === "native" && (prev.title || prev.titleKey)) return prev.title || win.t(prev.titleKey) var e = prev.kind === "native" ? null : ctx.items[prev.id] return e ? e.label : "" } @@ -288,7 +300,7 @@ FloatingWindow { if (row.kind === "page") { win.push({ kind: "menu", id: row.entry.id }); return } if (row.kind === "native") { if (sectionById(win.section) && sectionById(win.section).page === row.page && !top) return - win.push({ kind: "native", page: row.page }) + win.push({ kind: "native", page: row.page, title: row.label }) return } if (row.kind === "option" || row.kind === "action") run(row.entry.action) @@ -779,7 +791,10 @@ FloatingWindow { : win.nativePage === "wifi" ? wifiPage : win.nativePage === "bluetooth" ? bluetoothPage : win.nativePage === "sound" ? soundPage - : win.nativePage === "display" ? displayPage : null + : win.nativePage === "display" ? displayPage + : win.nativePage === "datetime" ? dateTimePage + : win.nativePage === "timezone" ? timezonePage + : win.nativePage === "shortcuts" ? shortcutsPage : null } // The section's groups: the card first, then two columns where the @@ -1059,4 +1074,7 @@ FloatingWindow { Component { id: bluetoothPage; BluetoothPage { settings: win } } Component { id: soundPage; SoundPage { settings: win } } Component { id: displayPage; DisplayPage { settings: win } } + Component { id: dateTimePage; DateTimePage { settings: win } } + Component { id: timezonePage; TimezonePage { settings: win } } + Component { id: shortcutsPage; ShortcutsPage { settings: win } } } diff --git a/desktop/shell/shell/settings/ShortcutsModel.js b/desktop/shell/shell/settings/ShortcutsModel.js new file mode 100644 index 00000000..c6a7bdc7 --- /dev/null +++ b/desktop/shell/shell/settings/ShortcutsModel.js @@ -0,0 +1,143 @@ +// Keyboard shortcuts from labwc's rc.xml, named for people: what each does, +// in groups, and its keys as they are written on a keyboard. A binding the +// table does not know shows its command, so an own one is still listed. + +// +function parse(text) { + var out = [] + var source = String(text || "").replace(//g, "") + var re = /]*?)(\/>|>([\s\S]*?)<\/keybind>)/g + var m + while ((m = re.exec(source)) !== null) { + var key = attr(m[1], "key") + if (!key) continue + var actions = [] + var body = m[3] || "" + var are = /]*?)\/?>/g + var a + while ((a = are.exec(body)) !== null) { + actions.push({ name: attr(a[1], "name"), command: unescape(attr(a[1], "command")), + direction: attr(a[1], "direction"), menu: attr(a[1], "menu") }) + } + out.push({ key: key, actions: actions }) + } + return out +} + +function attr(text, name) { + var m = new RegExp("\\b" + name + "=\"([^\"]*)\"").exec(text) + return m ? m[1] : "" +} + +function unescape(text) { + return String(text).replace(/"/g, "\"").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&") +} + +// What a binding does: { group, label } (i18n keys), or null for one that is +// there only to swallow a key (Execute /usr/bin/true). +// groups: shell, apps, windows, screenshots, hardware, other +var COMMANDS = [ + [/omarchy\.dock apps$/, "shell", "shortcuts.launcher"], + [/omarchy\.controlcenter toggle/, "shell", "shortcuts.controlCenter"], + [/omarchy\.notificationcenter toggle/, "shell", "shortcuts.notificationCenter"], + [/toggle omarchy\.audio\b/, "shell", "shortcuts.audio"], + [/toggle omarchy\.bluetooth\b/, "shell", "shortcuts.bluetooth"], + [/toggle omarchy\.monitor\b/, "shell", "shortcuts.display"], + [/toggle omarchy\.network\b/, "shell", "shortcuts.network"], + [/toggle omarchy\.power\b/, "shell", "shortcuts.power"], + [/omarchy\.menu .*"system"/, "shell", "shortcuts.systemMenu"], + [/omarchy\.menu .*"root"/, "shell", "shortcuts.menu"], + [/omarchy-toggle-bar\b/, "shell", "shortcuts.bar"], + [/\bfoot\b|omarchy-launch-terminal/, "apps", "shortcuts.terminal"], + [/\bfirefox\b|omarchy-launch-browser/, "apps", "shortcuts.browser"], + [/omactivity|\bbtop\b/, "apps", "shortcuts.activity"], + [/\bgrim\b|omarchy-capture-screenshot/, "screenshots", "shortcuts.screenshot"], + [/omarchy-volume raise/, "hardware", "shortcuts.volumeUp"], + [/omarchy-volume lower/, "hardware", "shortcuts.volumeDown"], + [/omarchy-volume mute/, "hardware", "shortcuts.mute"], + [/omarchy-brightness-display .*\+/, "hardware", "shortcuts.brightnessUp"], + [/omarchy-brightness-display .*-\d/, "hardware", "shortcuts.brightnessDown"], + [/monitor-scaling up/, "windows", "shortcuts.scaleUp"], + [/monitor-scaling down/, "windows", "shortcuts.scaleDown"] +] +var ACTIONS = { + Close: "shortcuts.close", + ToggleFullscreen: "shortcuts.fullscreen", + ToggleMaximize: "shortcuts.maximize", + ToggleOverview: "shortcuts.overview", + NextWindow: "shortcuts.switchWindows", + PreviousWindow: "shortcuts.switchWindowsBack", + NextWindowImmediate: "shortcuts.nextWindow", + PreviousWindowImmediate: "shortcuts.previousWindow", + HideCursor: "shortcuts.hideCursor", + Iconify: "shortcuts.minimize", + ShowMenu: "shortcuts.menu" +} + +function describe(binding) { + var first = binding.actions[0] + if (!first) return null + if (first.name === "Execute") { + var command = first.command + if (/^\s*(\/usr\/bin\/)?true\s*$/.test(command)) return null + for (var i = 0; i < COMMANDS.length; i++) { + // A window command (display scale) after the window actions. + if (COMMANDS[i][0].test(command)) return { group: COMMANDS[i][1], label: COMMANDS[i][2], rank: COMMANDS[i][1] === "windows" ? 300 + i : i } + } + return { group: "other", label: "", command: command, rank: 1000 } + } + if (first.name === "SnapToEdge") { + var dir = String(first.direction || "") + var dirs = ["up", "down", "left", "right"] + return { group: "windows", label: "shortcuts.snap" + dir.charAt(0).toUpperCase() + dir.slice(1), direction: dir, + rank: 200 + Object.keys(ACTIONS).length + Math.max(0, dirs.indexOf(dir)) } + } + if (ACTIONS[first.name]) return { group: "windows", label: ACTIONS[first.name], rank: 200 + Object.keys(ACTIONS).indexOf(first.name) } + return { group: "other", label: "", command: first.name, rank: 1000 } +} + +var GROUPS = ["shell", "apps", "windows", "screenshots", "hardware", "other"] + +// The bindings in their groups: [{ group, rows: [{ keys, label, command, direction }] }]. +// Two keys for one thing (Super_L, Super_R) are one row. +function groups(text) { + var bindings = parse(text) + var byGroup = {} + for (var i = 0; i < bindings.length; i++) { + var d = describe(bindings[i]) + if (!d) continue + var rows = byGroup[d.group] || (byGroup[d.group] = []) + var same = null + for (var j = 0; j < rows.length; j++) { + if (rows[j].label === d.label && rows[j].command === (d.command || "") && rows[j].direction === (d.direction || "")) same = rows[j] + } + var keys = keyLabel(bindings[i].key) + if (same) { if (same.keys.indexOf(keys) < 0) same.keys.push(keys); continue } + rows.push({ keys: [keys], label: d.label, command: d.command || "", direction: d.direction || "", rank: d.rank }) + } + // In the table's order (the control center beside the notification + // center), not the file's; what the table does not know, as it comes. + for (var key in byGroup) byGroup[key].sort(function(a, b) { return a.rank - b.rank }) + var out = [] + for (var g = 0; g < GROUPS.length; g++) if (byGroup[GROUPS[g]]) out.push({ group: GROUPS[g], rows: byGroup[GROUPS[g]] }) + return out +} + +// "W-S-b" → "Super Shift B"; keysyms as they read. +var MODIFIERS = { W: "Super", S: "Shift", C: "Ctrl", A: "Alt", M: "Alt", H: "Hyper", L: "Mod5" } +var KEYS = { + Super_L: "Super", Super_R: "Super", Return: "Return", space: "Space", Escape: "Esc", + Tab: "Tab", slash: "/", Print: "Print", Up: "↑", Down: "↓", Left: "←", Right: "→", + XF86AudioRaiseVolume: "Volume Up", XF86AudioLowerVolume: "Volume Down", XF86AudioMute: "Mute", + XF86MonBrightnessUp: "Brightness Up", XF86MonBrightnessDown: "Brightness Down", XF86HomePage: "Home" +} +function keyLabel(key) { + var parts = String(key).split("-") + var last = parts.pop() + var out = [] + for (var i = 0; i < parts.length; i++) out.push(MODIFIERS[parts[i]] || parts[i]) + out.push(KEYS[last] || (last.length === 1 ? last.toUpperCase() : last)) + return out.join(" ") +} + +if (typeof module !== "undefined") module.exports = { parse: parse, describe: describe, groups: groups, keyLabel: keyLabel } diff --git a/desktop/shell/shell/settings/ShortcutsPage.qml b/desktop/shell/shell/settings/ShortcutsPage.qml new file mode 100644 index 00000000..2a87ee1e --- /dev/null +++ b/desktop/shell/shell/settings/ShortcutsPage.qml @@ -0,0 +1,62 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Commons +import qs.Commons as Commons +import "ShortcutsModel.js" as Shortcuts + +// Keyboard Shortcuts: what labwc's rc.xml binds, read from the user's own +// file (so a binding added there shows too), named and grouped; read only. +Item { + id: page + + property var settings: null + + width: parent ? parent.width : 0 + height: column.height + + FileView { + id: rc + path: (Quickshell.env("HOME") || "") + "/.config/labwc/rc.xml" + watchChanges: true + printErrors: false + onFileChanged: reload() + } + readonly property var groups: Shortcuts.groups(rc.text()) + + Column { + id: column + width: page.width + spacing: Style.space(14) + + Repeater { + model: page.groups + SettingsBox { + id: box + required property var modelData + settings: page.settings + width: column.width + title: Commons.I18n.t("shortcuts.group." + modelData.group) + Repeater { + model: box.modelData.rows + SettingsItem { + required property var modelData + required property int index + settings: page.settings + first: index === 0 + label: modelData.label ? Commons.I18n.t(modelData.label) : modelData.command + value: modelData.keys.join(" · ") + } + } + } + } + + Text { + visible: page.groups.length === 0 + text: Commons.I18n.t("shortcuts.none") + color: page.settings ? page.settings.faint : "gray" + font.family: Style.font.family + font.pixelSize: Style.font.subtitle + } + } +} diff --git a/desktop/shell/shell/settings/TimezonePage.qml b/desktop/shell/shell/settings/TimezonePage.qml new file mode 100644 index 00000000..421e5201 --- /dev/null +++ b/desktop/shell/shell/settings/TimezonePage.qml @@ -0,0 +1,173 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Commons +import qs.Commons as Commons + +// The time zones: a search over all of them, and under it the regions (Africa, +// America, ...), each opening its own list, so no page holds all six hundred +// rows at once. A pick sets it (timedatectl) and goes back to Date & Time. +Item { + id: page + + property var settings: null + // The region this page lists, or "" for the regions and the search. + readonly property string region: settings && settings.top && settings.top.region ? settings.top.region : "" + + width: parent ? parent.width : 0 + height: column.height + + property var zones: [] + property string current: "" + Process { + running: true + command: ["timedatectl", "list-timezones"] + // The world's regions only, and UTC: the list's old aliases (US/Pacific, + // Brazil/East, Etc/GMT+3, ...) name zones the regions already have. + stdout: StdioCollector { + onStreamFinished: page.zones = String(text).split("\n").filter(function(z) { + return z === "UTC" || page.regionNames.indexOf(z.split("/")[0]) >= 0 && z.indexOf("/") > 0 + }) + } + } + Process { + running: true + command: ["timedatectl", "show", "-p", "Timezone", "--value"] + stdout: StdioCollector { onStreamFinished: page.current = String(text).trim() } + } + + // "America/Argentina/Buenos_Aires": the city, then where it is. + function city(zone) { var p = zone.split("/"); return p[p.length - 1].replace(/_/g, " ") } + function where(zone) { var p = zone.split("/"); return p.slice(0, -1).join(", ").replace(/_/g, " ") } + + readonly property var regionNames: ["Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Australia", "Europe", "Indian", "Pacific"] + readonly property var regions: { + var seen = {}, out = [] + for (var i = 0; i < zones.length; i++) { + var at = zones[i].indexOf("/") + var r = at < 0 ? "" : zones[i].slice(0, at) + if (r === "" || seen[r]) continue + seen[r] = true + out.push(r) + } + return out + } + property string query: "" + readonly property var rows: { + var q = query.trim().toLowerCase().replace(/ /g, "_") + if (region !== "") return zones.filter(function(z) { return z.indexOf(region + "/") === 0 }) + if (q === "") return [] + // The city's start first, then anywhere in the name; at most 60. + var first = [], rest = [] + for (var i = 0; i < zones.length; i++) { + var z = zones[i].toLowerCase(), c = page.city(zones[i]).toLowerCase().replace(/ /g, "_") + if (c.indexOf(q) === 0) first.push(zones[i]) + else if (z.indexOf(q) >= 0) rest.push(zones[i]) + } + return first.concat(rest).slice(0, 60) + } + + Process { + id: writer + stderr: StdioCollector { onStreamFinished: if (text !== "") console.warn("settings: time zone:", text.trim()) } + onExited: function(code) { + if (code !== 0) return + Commons.TimeZone.changed() + if (page.settings) page.settings.backTo("datetime") + } + } + function choose(zone) { + if (writer.running || zone === page.current) return + writer.command = ["timedatectl", "set-timezone", zone] + writer.running = true + } + + Column { + id: column + width: page.width + spacing: Style.space(14) + + // The search, on the first page only. + Rectangle { + visible: page.region === "" + width: parent.width + height: Style.space(40) + color: "transparent" + border.width: 1 + border.color: input.activeFocus && page.settings ? Util.alpha(page.settings.accent, 0.7) : (page.settings ? page.settings.line : "gray") + TextInput { + id: input + x: Style.space(12) + width: parent.width - 2 * x + anchors.verticalCenter: parent.verticalCenter + color: page.settings ? page.settings.text : "white" + font.family: Style.font.family + font.pixelSize: Style.font.subtitle + clip: true + onTextChanged: page.query = text + Keys.onEscapePressed: function(event) { + if (text !== "") { text = ""; event.accepted = true } else event.accepted = false + } + Text { + visible: input.text === "" + text: Commons.I18n.t("settings.searchTimeZones") + color: page.settings ? page.settings.faint : "gray" + font: input.font + } + } + } + + // Matches, or a region's zones. + SettingsBox { + settings: page.settings + width: parent.width + visible: page.rows.length > 0 + Repeater { + model: page.rows + SettingsItem { + required property var modelData + required property int index + settings: page.settings + first: index === 0 + label: page.city(modelData) + detail: page.region === "" ? page.where(modelData) : (page.where(modelData) !== page.region ? page.where(modelData).slice(page.region.length + 2) : "") + checked: modelData === page.current + onActivated: page.choose(modelData) + } + } + } + Text { + visible: page.region === "" && page.query.trim() !== "" && page.rows.length === 0 + text: Commons.I18n.t("settings.noResults") + color: page.settings ? page.settings.faint : "gray" + font.family: Style.font.family + font.pixelSize: Style.font.subtitle + } + + // The regions, while not searching; UTC first. + SettingsBox { + settings: page.settings + width: parent.width + visible: page.region === "" && page.query.trim() === "" + SettingsItem { + settings: page.settings + first: true + label: "UTC" + checked: page.current === "UTC" + onActivated: page.choose("UTC") + } + Repeater { + model: page.regions + SettingsItem { + required property var modelData + required property int index + settings: page.settings + label: modelData.replace(/_/g, " ") + value: page.current.indexOf(modelData + "/") === 0 ? page.city(page.current) : "" + opens: true + onActivated: if (page.settings) page.settings.push({ kind: "native", page: "timezone", title: modelData.replace(/_/g, " "), region: modelData }) + } + } + } + } +} diff --git a/desktop/upstream-commands-held b/desktop/upstream-commands-held index b1e66fae..d3b410c4 100644 --- a/desktop/upstream-commands-held +++ b/desktop/upstream-commands-held @@ -18,7 +18,6 @@ omarchy-audio-output-set-default plugins/panels/audio/Panel.qml plugins/panels/b omarchy-audio-output-sink plugins/panels/audio/Panel.qml omarchy-audio-output-volume plugins/services/media/MediaModel.js plugins/services/media/Service.qml omarchy-audio-sink-availability plugins/panels/audio/Panel.qml -omarchy-bar plugins/bar/Bar.qml omarchy-bar-text-color plugins/bar/Bar.qml omarchy-battery-low plugins/services/battery/Service.qml omarchy-brightness-keyboard plugins/lock/Service.qml @@ -49,8 +48,6 @@ omarchy-network-password plugins/panels/wifiqr/Panel.qml omarchy-network-qr plugins/panels/wifiqr/Model.js plugins/panels/wifiqr/Panel.qml omarchy-reminder plugins/bar/indicators/Reminder.qml omarchy-remove-launcher-entry bin/omarchy-remove-launcher-entry services/AppLibrary.qml -omarchy-restart-hyprctl services/BackgroundSwitch.qml -omarchy-shell-config plugins/bar/BarModel.js omarchy-sudo-passwordless plugins/bar/indicators/PasswordlessSudo.qml omarchy-system-sleep-lock plugins/lock/Service.qml omarchy-tailscale-send plugins/panels/tailscale/Service.qml diff --git a/system/overlay/etc/polkit-1/rules.d/60-omarchy-tablet-time.rules b/system/overlay/etc/polkit-1/rules.d/60-omarchy-tablet-time.rules new file mode 100644 index 00000000..4c8bc9b3 --- /dev/null +++ b/system/overlay/etc/polkit-1/rules.d/60-omarchy-tablet-time.rules @@ -0,0 +1,10 @@ +// The local active tablet session may pick its time zone and whether the +// clock sets itself (Settings > General > Date & Time), as a phone lets its +// owner without a password. Setting the clock by hand, the RTC mode, remote +// or inactive sessions and other users keep the default policy. +polkit.addRule(function(action, subject) { + if ((action.id === "org.freedesktop.timedate1.set-timezone" || + action.id === "org.freedesktop.timedate1.set-ntp") && + subject.user === "tablet" && subject.local && subject.active) + return polkit.Result.YES; +}); diff --git a/tests/package_tree.py b/tests/package_tree.py index d4ac4b72..4f57d2ba 100644 --- a/tests/package_tree.py +++ b/tests/package_tree.py @@ -52,6 +52,8 @@ def inputs(base): (upstream / 'bin').mkdir() for name in ('omarchy-upstream-only', 'omarchy-battery-low', 'omarchy-theme-set'): (upstream / 'bin' / name).write_text('#!/bin/bash\necho upstream\n') + (upstream / 'default/hypr/toggles').mkdir(parents=True) + (upstream / 'default/hypr/toggles/bar-glassy.lua').write_text('-- glassy\n') (upstream / 'applications').mkdir() (upstream / 'applications/foot.desktop').write_text('[Desktop Entry]\nName=Terminal\n') (wheel / 'dbus_next/aio').mkdir(parents=True) diff --git a/tests/test_keyboard_shortcuts.py b/tests/test_keyboard_shortcuts.py index 62ad3f54..d3ca7b59 100644 --- a/tests/test_keyboard_shortcuts.py +++ b/tests/test_keyboard_shortcuts.py @@ -91,3 +91,45 @@ def test_windows_keep_normal_size_and_title_taps_share_a_target(self): tree=ET.parse(PROJECT/'desktop/shell/labwc-rc.xml') self.assertFalse(tree.findall('./windowRules/windowRule/action[@name="Maximize"]')) + + +@unittest.skipUnless(__import__('shutil').which('node'), 'node is required for the shortcuts page') +class ShortcutsPageTests(unittest.TestCase): + # Settings > Keyboard > Keyboard Shortcuts names each binding; a binding + # added to labwc-rc.xml needs a name there (ShortcutsModel.js) and a text. + def test_every_shipped_binding_has_a_name_and_a_text(self): + import json, subprocess + script = r''' +const fs = require('fs'); +const S = require(process.argv[1] + '/desktop/shell/shell/settings/ShortcutsModel.js'); +const texts = JSON.parse(fs.readFileSync(process.argv[1] + '/desktop/shell/default/i18n/en/shell.json', 'utf8')); +const groups = S.groups(fs.readFileSync(process.argv[1] + '/desktop/shell/labwc-rc.xml', 'utf8')); +const unnamed = [], untexted = []; +for (const g of groups) for (const r of g.rows) { + if (!r.label) unnamed.push(r.keys.join(' / ') + ': ' + r.command); + else if (!texts[r.label]) untexted.push(r.label); + if (!texts['shortcuts.group.' + g.group]) untexted.push('shortcuts.group.' + g.group); +} +console.log(JSON.stringify({ unnamed, untexted, groups: groups.length })); +''' + result = subprocess.run(['node', '-e', script, str(PROJECT)], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + found = json.loads(result.stdout) + self.assertEqual(found['unnamed'], []) + self.assertEqual(found['untexted'], []) + self.assertGreater(found['groups'], 3) + + def test_keys_read_as_on_a_keyboard(self): + import subprocess + script = r''' +const S = require(process.argv[1] + '/desktop/shell/shell/settings/ShortcutsModel.js'); +const assert = require('assert'); +assert.equal(S.keyLabel('W-S-b'), 'Super Shift B'); +assert.equal(S.keyLabel('W-C-1'), 'Super Ctrl 1'); +assert.equal(S.keyLabel('XF86AudioMute'), 'Mute'); +// Commented-out bindings are not bindings; a swallowed key is not listed. +const g = S.groups(''); +assert.deepEqual(g.map(x => x.rows.map(r => r.keys[0])), [['Super W']]); +''' + result = subprocess.run(['node', '-e', script, str(PROJECT)], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) diff --git a/tests/test_settings_layout.py b/tests/test_settings_layout.py index 8e719ce8..ab6a50a3 100644 --- a/tests/test_settings_layout.py +++ b/tests/test_settings_layout.py @@ -48,6 +48,28 @@ def test_a_pair_is_one_switch_that_runs_the_shown_entry(self): // A submenu's X On / X Off children become one switch too. const specs = M.menuSpecs(ctx(), 'appearance.top-bar.indicators'); assert.deepEqual(specs[0], { toggle: ['appearance.top-bar.indicators.battery-percentage-on', 'appearance.top-bar.indicators.battery-percentage-off'] }); +''') + + def test_a_command_checked_under_labwc_is_not_taken_for_hyprland(self): + # omarchy-bar mentions Hyprland (a glassy bar's blur) but works here. + self.run_node(r''' +assert.ok(L.LABWC_CHECKED.includes('omarchy-bar')); +const script = M.stateScript(L.SECTIONS, ctx({ labwcChecked: L.LABWC_CHECKED }), {}); +assert.match(script, / omarchy-bar " != \*" \$c "\*/); +''') + + def test_a_page_whose_rows_are_all_hidden_is_dimmed(self): + # Touchpad Haptics on anything but a Dell XPS: every level's guard says no. + self.run_node(r''' +const id = 'trigger.hardware.touchpad-haptics'; +const kids = menu.itemOrder.filter(k => menu.items[k].parent === id); +assert.ok(kids.length > 0); +const hidden = {}; for (const k of kids) hidden[k] = false; +assert.equal(M.resolveRow({ entry: id }, ctx({ whenResults: hidden }), {}).available, false); +// Unanswered yet, or with one level shown, it opens. +assert.equal(M.resolveRow({ entry: id }, ctx(), {}).available, true); +hidden[kids[0]] = true; +assert.equal(M.resolveRow({ entry: id }, ctx({ whenResults: hidden }), {}).available, true); ''') def test_a_row_whose_command_is_missing_is_dimmed_and_tagged(self): @@ -66,6 +88,9 @@ def test_a_row_whose_command_is_missing_is_dimmed_and_tagged(self): def test_deep_links_and_state(self): self.run_node(r''' +// Every native page has a link of its own: Date & Time, Keyboard Shortcuts. +assert.deepEqual(M.route('datetime', L.SECTIONS, ctx()), { section: 'general', page: { kind: 'native', page: 'datetime', titleKey: 'settings.dateTime' } }); +assert.deepEqual(M.route('keyboard/shortcuts', L.SECTIONS, ctx()).page.page, 'shortcuts'); assert.deepEqual(M.route('appearance/theme', L.SECTIONS, ctx()), { section: 'appearance', page: { kind: 'native', page: 'theme' } }); assert.deepEqual(M.route('setup.security', L.SECTIONS, ctx()), { section: 'security', page: { kind: 'menu', id: 'setup.security' } }); assert.deepEqual(M.route('nowhere', L.SECTIONS, ctx()), { section: '', page: null }); diff --git a/tests/test_time_format.py b/tests/test_time_format.py new file mode 100644 index 00000000..12c60063 --- /dev/null +++ b/tests/test_time_format.py @@ -0,0 +1,33 @@ +from pathlib import Path +import shutil +import subprocess +import unittest + +MODEL = Path(__file__).resolve().parents[1] / 'desktop/shell/shell/Commons/TimeFormatModel.js' + + +@unittest.skipUnless(shutil.which('node'), 'node is required for the time format') +class TimeFormatTests(unittest.TestCase): + # Settings > Date & Time's 24-Hour Time flips the bar clock's format, and + # every clock reads 12 or 24 hours from it. + def test_the_switch_flips_hours_and_keeps_the_style(self): + script = r''' +const assert = require('assert'); +const T = require(process.argv[1]); +// Every format upstream's Appearance > Clock offers, both ways. +const pairs = [['dddd HH:mm', 'dddd h:mm AP'], ['dddd HH:mm:ss', 'dddd h:mm:ss AP'], ['HH:mm', 'h:mm AP'], + ['ddd d MMM HH:mm', 'ddd d MMM h:mm AP'], ['yyyy-MM-dd HH:mm', 'yyyy-MM-dd h:mm AP']]; +for (const [h24, h12] of pairs) { + assert.equal(T.is24(h24), true, h24); assert.equal(T.is24(h12), false, h12); + assert.equal(T.flipped(h24, false), h12); assert.equal(T.flipped(h12, true), h24); +} +// No hours at all (the week format) reads as 24-hour and stays as it is. +assert.equal(T.is24("d MMMM 'W'ww yyyy"), true); +assert.equal(T.flipped("d MMMM 'W'ww yyyy", false), "d MMMM 'W'ww yyyy"); +// The clock's format from the shell's config; HH:mm without one. +assert.equal(T.clockFormat(JSON.stringify({ bar: { layout: { center: [{ id: 'omarchy.clock', format: 'h:mm AP' }] } } })), 'h:mm AP'); +assert.equal(T.clockFormat(''), 'HH:mm'); +assert.equal(T.clockFormat('{broken'), 'HH:mm'); +''' + result = subprocess.run(['node', '-e', script, str(MODEL)], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr)