consolidate logic
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import QtQuick
|
||||
|
||||
// Base item every bar widget extends. Codifies the three properties the
|
||||
// bar host injects into each widget slot:
|
||||
// bar - the host Bar instance (foreground/background/run/etc).
|
||||
// moduleName - widget's canonical id, used by the host registry to look
|
||||
// up settings and to disambiguate inline IPC routes.
|
||||
// settings - per-widget overrides read from shell.json's layout entry.
|
||||
//
|
||||
// Widgets are free to add their own properties, signals, and child items.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property QtObject bar: null
|
||||
property string moduleName: ""
|
||||
property var settings: ({})
|
||||
}
|
||||
@@ -45,6 +45,14 @@ PanelWindow {
|
||||
property bool open: false
|
||||
property int gap: Style.gapsOut // distance between bar edge and panel
|
||||
|
||||
// Item that should take keyboard focus once the panel maps. Typically a
|
||||
// PanelKeyCatcher inside the panel content. Layer-shell grants focus to
|
||||
// the surface at map time, but Qt still needs an active-focus target
|
||||
// inside the surface for Keys.onPressed handlers to fire. Schedule the
|
||||
// focus through Qt.callLater so it runs after the surface is fully
|
||||
// mapped and child items have completed layout.
|
||||
property Item focusTarget: null
|
||||
|
||||
default property alias contentItem: contentHolder.children
|
||||
|
||||
readonly property var coordinatorKey: owner || root
|
||||
@@ -187,6 +195,9 @@ PanelWindow {
|
||||
// Coordinate on `open`, not `visible`. `visible` lags into the fade-out
|
||||
// animation, which made ownership transfer to a sibling popup race.
|
||||
onOpenChanged: {
|
||||
if (open && focusTarget) Qt.callLater(function() {
|
||||
if (root.open && root.focusTarget) root.focusTarget.forceActiveFocus()
|
||||
})
|
||||
if (!bar) return
|
||||
if (open) bar.requestPopout(coordinatorKey)
|
||||
else if (bar.activePopout === coordinatorKey) bar.releasePopout(coordinatorKey)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// Owns the open/close lifecycle for a bar panel widget. Wraps the
|
||||
// repetitive popupOpen + closePopout + toggle/show/hide IpcHandler triplet
|
||||
// so each panel just declares one of these and binds its WidgetButton +
|
||||
// KeyboardPanel to the exposed `open` property.
|
||||
//
|
||||
// Usage:
|
||||
// PanelController { id: ctrl; ipcTarget: "audioPanel" }
|
||||
//
|
||||
// WidgetButton { onPressed: ctrl.toggle() }
|
||||
// KeyboardPanel { open: ctrl.open; owner: ctrl; focusTarget: keyCatcher }
|
||||
//
|
||||
// The bar popout coordinator uses `owner` as a registry key, so each
|
||||
// PanelController instance doubles as that key. KeyboardPanel calls
|
||||
// `owner.closePopout()` when another panel grabs the slot.
|
||||
//
|
||||
// Set `manageIpc: false` when the panel needs to declare its own IpcHandler
|
||||
// for additional methods on the same target (monitorPanel adds brightness +
|
||||
// state). Quickshell only honors one IpcHandler per target, so the panel's
|
||||
// handler must then also delegate toggle/show/hide to this controller.
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
// IPC target name. The bar pairs this with the bar widget's filename so a
|
||||
// Hyprland keybind (`omarchy-shell <target> toggle`) summons the panel.
|
||||
property string ipcTarget: ""
|
||||
property bool manageIpc: true
|
||||
|
||||
property bool open: false
|
||||
|
||||
function toggle() { open = !open }
|
||||
function show() { if (!open) open = true }
|
||||
function hide() { open = false }
|
||||
function closePopout() { open = false }
|
||||
|
||||
property IpcHandler _ipc: manageIpc ? ipcComponent.createObject(root) : null
|
||||
|
||||
property Component ipcComponent: Component {
|
||||
IpcHandler {
|
||||
target: root.ipcTarget
|
||||
function toggle(): void { root.toggle() }
|
||||
function show(): void { root.show() }
|
||||
function hide(): void { root.hide() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
module qs.Ui
|
||||
|
||||
BarWidget 1.0 BarWidget.qml
|
||||
Button 1.0 Button.qml
|
||||
ButtonGroup 1.0 ButtonGroup.qml
|
||||
CursorSurface 1.0 CursorSurface.qml
|
||||
@@ -7,6 +8,7 @@ Dropdown 1.0 Dropdown.qml
|
||||
KeyboardPanel 1.0 KeyboardPanel.qml
|
||||
NumberField 1.0 NumberField.qml
|
||||
PanelActionButton 1.0 PanelActionButton.qml
|
||||
PanelController 1.0 PanelController.qml
|
||||
PanelKeyCatcher 1.0 PanelKeyCatcher.qml
|
||||
PanelSectionHeader 1.0 PanelSectionHeader.qml
|
||||
PanelSeparator 1.0 PanelSeparator.qml
|
||||
|
||||
Reference in New Issue
Block a user