Modules are tiles on a 4-column grid, each 1x1 to 4x4 and adapting its layout to its size. Edit Controls in the panel reorders by dragging, resizes from a corner handle, removes with a badge and adds from a tray. Connectivity splits into Wi-Fi, Bluetooth and Network tiles and Audio into Sound and Microphone; right-clicking Sound extends it with output devices and a volume slider per app. Adds a Caffeine tile. Config version 2 migrates existing layouts in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
292 lines
12 KiB
QML
292 lines
12 KiB
QML
import QtQuick
|
|
import QtTest
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import Quickshell.Networking
|
|
import Quickshell.Bluetooth
|
|
import "../core"
|
|
import "../services"
|
|
|
|
Item {
|
|
id: root
|
|
parent: ShellState.controlCenterWindow ? ShellState.controlCenterWindow.contentItem : null
|
|
TestCase {
|
|
id: input
|
|
name: "ControlInput"
|
|
when: false
|
|
}
|
|
property QtObject audioNode: QtObject {
|
|
property string name: "fixture-output"
|
|
property string description: "Fixture audio"
|
|
property bool isSink: true
|
|
property bool isStream: false
|
|
property QtObject audio: QtObject {
|
|
property real volume: 0.4
|
|
property bool muted: false
|
|
}
|
|
}
|
|
property QtObject audioInput: QtObject {
|
|
property string name: "fixture-input"
|
|
property string description: "Fixture microphone"
|
|
property bool isSink: false
|
|
property bool isStream: false
|
|
property QtObject audio: QtObject {
|
|
property real volume: 0.6
|
|
property bool muted: false
|
|
}
|
|
}
|
|
property var streamNode: QtObject {
|
|
property string name: "fixture-player"
|
|
property string description: ""
|
|
property bool isSink: false
|
|
property bool isStream: true
|
|
property var properties: ({
|
|
"application.name": "Fixture player"
|
|
})
|
|
property QtObject audio: QtObject {
|
|
property real volume: 0.5
|
|
property bool muted: false
|
|
}
|
|
}
|
|
property QtObject audioBackend: QtObject {
|
|
property bool ready: true
|
|
property var defaultAudioSink: root.audioNode
|
|
property var defaultAudioSource: root.audioInput
|
|
property var preferredDefaultAudioSink: root.audioNode
|
|
property var preferredDefaultAudioSource: root.audioInput
|
|
property QtObject nodes: QtObject {
|
|
property var values: [root.audioNode, root.audioInput, root.streamNode]
|
|
}
|
|
}
|
|
property QtObject wifi: QtObject {
|
|
id: fixtureWifi
|
|
property int type: DeviceType.Wifi
|
|
property string name: "fixture-wifi"
|
|
property bool connected: fixtureNetwork.connected
|
|
property bool scannerEnabled: false
|
|
property QtObject networks: QtObject {
|
|
property var values: [root.network]
|
|
}
|
|
}
|
|
property QtObject network: QtObject {
|
|
id: fixtureNetwork
|
|
property string name: "Fixture network"
|
|
property var device: root.wifi
|
|
property bool known: true
|
|
property bool connected: false
|
|
property int state: ConnectionState.Disconnected
|
|
property bool stateChanging: false
|
|
property int security: WifiSecurityType.Wpa2Psk
|
|
signal connectionFailed(int reason)
|
|
function connect() {
|
|
connected = true;
|
|
state = ConnectionState.Connected;
|
|
}
|
|
function disconnect() {
|
|
connected = false;
|
|
state = ConnectionState.Disconnected;
|
|
}
|
|
function connectWithPsk(password) {
|
|
connect();
|
|
}
|
|
}
|
|
property QtObject networkBackend: QtObject {
|
|
property int backend: NetworkBackendType.NetworkManager
|
|
property bool wifiEnabled: true
|
|
property bool wifiHardwareEnabled: true
|
|
property QtObject devices: QtObject {
|
|
property var values: [root.wifi]
|
|
}
|
|
}
|
|
property QtObject btDevice: QtObject {
|
|
property string name: "Fixture headphones"
|
|
property bool connected: false
|
|
property bool paired: true
|
|
property int state: BluetoothDeviceState.Disconnected
|
|
property bool batteryAvailable: true
|
|
property real battery: 0.8
|
|
function connect() {
|
|
connected = true;
|
|
state = BluetoothDeviceState.Connected;
|
|
}
|
|
function disconnect() {
|
|
connected = false;
|
|
state = BluetoothDeviceState.Disconnected;
|
|
}
|
|
}
|
|
property QtObject btAdapter: QtObject {
|
|
property string name: "Fixture Bluetooth"
|
|
property string adapterId: "fixture"
|
|
property bool enabled: true
|
|
property int state: BluetoothAdapterState.Enabled
|
|
property QtObject devices: QtObject {
|
|
property var values: [root.btDevice]
|
|
}
|
|
}
|
|
property QtObject btBackend: QtObject {
|
|
property var defaultAdapter: root.btAdapter
|
|
property QtObject adapters: QtObject {
|
|
property var values: [root.btAdapter]
|
|
}
|
|
}
|
|
function child(name) {
|
|
return input.findChild(ShellState.controlCenterWindow.contentItem, name);
|
|
}
|
|
function reveal(item) {
|
|
let parent = item.parent;
|
|
while (parent) {
|
|
if (parent.contentY !== undefined && parent.contentItem && parent.contentHeight > parent.height) {
|
|
const pos = item.mapToItem(parent.contentItem, 0, 0);
|
|
parent.contentY = Math.max(0, Math.min(parent.contentHeight - parent.height, pos.y - parent.height / 2));
|
|
}
|
|
parent = parent.parent;
|
|
}
|
|
input.wait(40);
|
|
}
|
|
IpcHandler {
|
|
target: "controlTest"
|
|
function inject(): bool {
|
|
if (SystemService.busy)
|
|
return false;
|
|
AudioService.backend = root.audioBackend;
|
|
NetworkService.backend = root.networkBackend;
|
|
BluetoothService.backend = root.btBackend;
|
|
SystemService.helper = "testing/recording_system.py";
|
|
CaffeineService.command = ["sleep", "infinity"];
|
|
SystemService.refresh();
|
|
return true;
|
|
}
|
|
function click(name: string): bool {
|
|
const item = root.child(name);
|
|
if (!item || !item.enabled)
|
|
return false;
|
|
root.reveal(item);
|
|
input.mouseClick(item, item.width / 2, item.height / 2);
|
|
return true;
|
|
}
|
|
function slider(name: string): bool {
|
|
const item = root.child(name);
|
|
if (!item || !item.enabled)
|
|
return false;
|
|
root.reveal(item);
|
|
input.mouseClick(item, item.width * .75, item.height / 2);
|
|
return true;
|
|
}
|
|
function rightClick(name: string): bool {
|
|
const item = root.child(name);
|
|
if (!item || !item.enabled)
|
|
return false;
|
|
root.reveal(item);
|
|
// Near the corner: clear of sliders and buttons on every layout.
|
|
input.mouseClick(item, 14, 14, Qt.RightButton);
|
|
return true;
|
|
}
|
|
// Presses an item and drags it by (dx, dy) in steps.
|
|
function drag(name: string, dx: real, dy: real): bool {
|
|
const item = root.child(name);
|
|
if (!item || !item.visible)
|
|
return false;
|
|
root.reveal(item);
|
|
// Window coordinates, like a real pointer: the item may move or grow.
|
|
const content = ShellState.controlCenterWindow.contentItem;
|
|
const p = item.mapToItem(content, item.width / 2, item.height / 2);
|
|
input.mousePress(content, p.x, p.y);
|
|
for (let i = 1; i <= 8; ++i)
|
|
input.mouseMove(content, p.x + dx * i / 8, p.y + dy * i / 8, 20);
|
|
input.wait(60);
|
|
input.mouseRelease(content, p.x + dx, p.y + dy);
|
|
input.wait(60);
|
|
return true;
|
|
}
|
|
function clickSystem(): bool {
|
|
const pill = ShellState.systemPills.find(p => p.barScreen === ScreenService.active) || ShellState.systemPills[0];
|
|
if (!pill)
|
|
return false;
|
|
input.mouseClick(pill, pill.width / 2, pill.height / 2);
|
|
return true;
|
|
}
|
|
// Drags one module grip onto the lower half of another row.
|
|
function settingsDrag(name: string, target: string): bool {
|
|
const content = ShellState.settingsWindow.contentItem;
|
|
const source = input.findChild(content, name), over = input.findChild(content, target);
|
|
if (!source || !over)
|
|
return false;
|
|
root.reveal(source);
|
|
const end = source.mapFromItem(over, over.width / 2, over.height - 4);
|
|
input.mousePress(source, source.width / 2, source.height / 2);
|
|
input.mouseMove(source, source.width / 2, source.height / 2 + 10, 40);
|
|
input.mouseMove(source, end.x, end.y, 80);
|
|
input.wait(80);
|
|
input.mouseRelease(source, end.x, end.y);
|
|
input.wait(80);
|
|
return true;
|
|
}
|
|
function settingsClick(name: string): bool {
|
|
const item = input.findChild(ShellState.settingsWindow.contentItem, name);
|
|
if (!item || !item.enabled)
|
|
return false;
|
|
root.reveal(item);
|
|
input.mouseClick(item, item.width / 2, item.height / 2);
|
|
return true;
|
|
}
|
|
function value(name: string): real {
|
|
const item = root.child(name);
|
|
return item ? item.value : -1;
|
|
}
|
|
function checked(name: string): bool {
|
|
const item = root.child(name);
|
|
return item ? item.checked : false;
|
|
}
|
|
function pressEscape(): void {
|
|
input.keyClick(Qt.Key_Escape);
|
|
}
|
|
function outside(): void {
|
|
// Outside the panel-sized surface, as Hyprland delivers it.
|
|
input.mouseClick(ShellState.controlCenterWindow.contentItem, -40, ShellState.controlCenterWindow.height / 2);
|
|
}
|
|
function screenshot(path: string): bool {
|
|
return root.child("controlCenterSurface").grabToImage(result => result.saveToFile(path));
|
|
}
|
|
function snapshot(): string {
|
|
const panel = root.child("controlCenterSurface");
|
|
return JSON.stringify({
|
|
settingsVisible: ShellState.settingsWindow.visible,
|
|
modules: ConfigService.data.controlCenter.modules,
|
|
windowVisible: ShellState.controlCenterWindow.visible,
|
|
panelVisible: panel.visible,
|
|
panelOpacity: panel.opacity,
|
|
opened: ShellState.controlCenterOpen,
|
|
state: SystemService.state,
|
|
error: SystemService.error,
|
|
busy: SystemService.busy,
|
|
power: PowerService.pending,
|
|
wifi: NetworkService.enabled,
|
|
bluetooth: BluetoothService.enabled,
|
|
volume: AudioService.sink && AudioService.sink.audio ? AudioService.sink.audio.volume : -1,
|
|
muted: AudioService.sink && AudioService.sink.audio ? AudioService.sink.audio.muted : false,
|
|
microphone: AudioService.source && AudioService.source.audio ? AudioService.source.audio.muted : false,
|
|
scan: fixtureWifi.scannerEnabled,
|
|
editing: ShellState.controlCenterWindow.editing,
|
|
tiles: ShellState.controlCenterWindow.plan.items,
|
|
cellWidth: ShellState.controlCenterWindow.cellWidth,
|
|
extras: ShellState.controlCenterWindow.extras,
|
|
streamVolume: root.streamNode.audio.volume,
|
|
streamMuted: root.streamNode.audio.muted,
|
|
caffeine: CaffeineService.active,
|
|
caffeineRunning: CaffeineService.running,
|
|
active: ScreenService.active.name,
|
|
screens: Quickshell.screens.map(s => s.name),
|
|
x: ShellState.controlCenterWindow.panelScreenX,
|
|
y: ShellState.controlCenterWindow.panelScreenY,
|
|
width: panel.width,
|
|
height: panel.height,
|
|
screenWidth: ShellState.controlCenterWindow.screenWidth,
|
|
screenHeight: ShellState.controlCenterWindow.screenHeight
|
|
});
|
|
}
|
|
function connectFixtures(): bool {
|
|
return NetworkService.connectNetwork(root.network, "") && BluetoothService.connectDevice(root.btDevice);
|
|
}
|
|
}
|
|
}
|