Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 77 additions & 26 deletions desktop/shell/shell/controlcenter/ControlCenter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -299,22 +317,22 @@ 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

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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -737,6 +759,7 @@ Item {
subtitle: root.bluetoothSubtitle
on: bluetooth.enabled
available: !!bluetooth.adapter
focusKey: "bluetooth"
page: "omarchy.bluetooth"
onActivated: root.toggleBluetooth()
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -785,6 +812,7 @@ Item {
label: modelData.label
on: modelData.on
available: modelData.enabled
focusKey: modelData.key
onActivated: modelData.act()
}
}
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -857,21 +886,38 @@ 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))
// Pressed, it only shrinks a little: no tint.
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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
Loading
Loading