Skip to content

Commit 6d4fa7a

Browse files
dhhclaude
andcommitted
Make the open-panel mark find and fit its module
A center-anchored module is mounted twice: the copy that is drawn, and a zero-size placeholder holding its place in the flow beside the anchor. findPanelWidget returned whichever registered first, and that order is not stable across a live bar reconfiguration, so a panel could open anchored to the invisible copy -- mispositioned, with the drawn slot never lighting up and switchPanelFrom unable to find it again. The mark was also always 55% of the slot, which fits an icon but underlines only a fraction of a text label, and runs the full height of a multi-line module on a vertical bar. Modules can now say how long the mark should be along the bar; anything that does not answer keeps the old proportion. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d4c835a commit 6d4fa7a

4 files changed

Lines changed: 89 additions & 4 deletions

File tree

‎shell/Ui/WidgetButton.qml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Item {
5959
readonly property real scaledHorizontalMargin: Style.spaceReal(horizontalMargin)
6060
readonly property real scaledVerticalPadding: Style.spaceReal(verticalPadding)
6161
readonly property bool tooltipHovered: visible && interactive && !concealed && mouseArea.containsMouse
62+
// Width of the painted label, for bar chrome that wants to line up with the
63+
// text rather than with the slot it sits in. Zero on icon-only buttons.
64+
readonly property real labelWidth: label.visible ? label.implicitWidth : 0
6265

6366
visible: hasVisualContent || keepSpace
6467
opacity: !hasVisualContent || concealed ? 0 : (dimmed ? 0.45 : 1)

‎shell/plugins/bar/Bar.qml‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,19 @@ Item {
406406
function findPanelWidget(pluginId) {
407407
var id = String(pluginId || "")
408408
if (!id) return null
409+
var candidates = []
409410
for (var i = 0; i < moduleSlots.length; i++) {
410411
var slot = moduleSlots[i]
411412
if (!slot || !slot.activeItem) continue
412413
if (slot.moduleName !== id) continue
413414
var item = slot.activeItem
414415
if (typeof item.open !== "function" || typeof item.close !== "function" || item.opened === undefined) continue
415-
return item
416+
candidates.push(slot)
416417
}
417-
return null
418+
// Anchored center modules are mounted twice; only the drawn copy can
419+
// anchor a popup or carry the open-panel mark. See BarModel.pickDrawnSlot.
420+
var chosen = BarModel.pickDrawnSlot(candidates)
421+
return chosen ? chosen.activeItem : null
418422
}
419423

420424
function summonBarWidget(pluginId) {
@@ -1386,6 +1390,16 @@ Item {
13861390
readonly property bool hovered: moduleHover.hovered
13871391
readonly property bool dragSource: root.barDragSource === slot
13881392
readonly property bool panelOpen: root.activePopout === slot.activeItem
1393+
// Modules bigger than the mark they want (a text label in a padded slot,
1394+
// a multi-line stack on a vertical bar) can say how long the open-panel
1395+
// dot should be along the bar, so it tracks what the module paints
1396+
// instead of a fraction of whatever slot it happens to fill.
1397+
readonly property real panelIndicatorExtent: {
1398+
var key = root.vertical ? "openPanelIndicatorHeight" : "openPanelIndicatorWidth"
1399+
var hint = activeItem && key in activeItem ? activeItem[key] : undefined
1400+
if (hint !== undefined && hint !== null && hint > 0) return Math.round(hint)
1401+
return Math.max(Style.space(10), Math.round((root.vertical ? slot.height : slot.width) * 0.55))
1402+
}
13891403
implicitWidth: activeItem && activeItem.visible ? (root.vertical ? root.barSize : activeItem.implicitWidth) : 0
13901404
implicitHeight: activeItem && activeItem.visible ? activeItem.implicitHeight : 0
13911405
width: implicitWidth
@@ -1455,8 +1469,12 @@ Item {
14551469
opacity: slot.panelOpen && !slot.dragSource ? 0.9 : 0
14561470
color: Color.accent
14571471
radius: Math.min(width, height) / 2
1458-
width: root.vertical ? Style.space(2) : Math.max(Style.space(10), Math.round(parent.width * 0.55))
1459-
height: root.vertical ? Math.max(Style.space(10), Math.round(parent.height * 0.55)) : Style.space(2)
1472+
width: root.vertical ? Style.space(2) : slot.panelIndicatorExtent
1473+
height: root.vertical ? slot.panelIndicatorExtent : Style.space(2)
1474+
// The mark sits on the module's inner edge — the one facing the
1475+
// desktop — so it underlines a top bar, overlines a bottom one, and
1476+
// points inward from a left or right one. It reads as pointing at the
1477+
// panel that opens on that side.
14601478
x: root.vertical
14611479
? (root.position === "left" ? parent.width - width - inset : inset)
14621480
: Math.round((parent.width - width) / 2)

‎shell/plugins/bar/BarModel.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,32 @@ function customModulePath(entry, home, configDir) {
9696
return source
9797
}
9898

99+
// A center module is mounted twice once an anchor is set: the copy that is
100+
// actually drawn, and a zero-size placeholder holding its place in the flow
101+
// beside the anchor. Panel routing has to pick the drawn one — it is the only
102+
// one that can anchor a popup, carry the open-panel mark, or be found again
103+
// by switchPanelFrom — and fall back to the placeholder only when nothing is
104+
// on screen. The order the two are registered in is not stable across a live
105+
// bar reconfiguration, so picking the first match is not good enough.
106+
function isDrawnSlot(slot) {
107+
return !!slot && slot.visible === true && slot.width > 0 && slot.height > 0
108+
}
109+
110+
function pickDrawnSlot(slots) {
111+
var placeholder = null
112+
var list = slots || []
113+
for (var i = 0; i < list.length; i++) {
114+
if (!list[i]) continue
115+
if (isDrawnSlot(list[i])) return list[i]
116+
if (!placeholder) placeholder = list[i]
117+
}
118+
return placeholder
119+
}
120+
99121
if (typeof module !== "undefined") {
100122
module.exports = {
123+
isDrawnSlot: isDrawnSlot,
124+
pickDrawnSlot: pickDrawnSlot,
101125
normalizePosition: normalizePosition,
102126
entrySettings: entrySettings,
103127
entryId: entryId,

‎test/shell.d/bar-test.sh‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,47 @@ fi
1515
pass "bar move outline has no post-release settling state"
1616

1717
run_node_test <<'JS'
18+
const fs = require('fs')
1819
const bar = requireFromRoot('shell/plugins/bar/BarModel.js')
20+
const barSource = fs.readFileSync(root + '/shell/plugins/bar/Bar.qml', 'utf8')
21+
22+
// A center module is mounted twice — drawn copy plus zero-size placeholder —
23+
// and the order they register in is not stable across a live reconfiguration,
24+
// so panel routing has to pick the one that is actually on screen.
25+
const drawn = { moduleName: 'omarchy.clock', visible: true, width: 28, height: 81 }
26+
const placeholder = { moduleName: 'omarchy.clock', visible: false, width: 0, height: 0 }
27+
assertEqual(bar.isDrawnSlot(drawn), true, 'bar recognises a drawn slot')
28+
assertEqual(bar.isDrawnSlot(placeholder), false, 'bar recognises a layout placeholder')
29+
assertEqual(bar.pickDrawnSlot([placeholder, drawn]), drawn, 'bar picks the drawn slot when the placeholder registers first')
30+
assertEqual(bar.pickDrawnSlot([drawn, placeholder]), drawn, 'bar picks the drawn slot when it registers first')
31+
assertEqual(bar.pickDrawnSlot([placeholder]), placeholder, 'bar falls back to the placeholder when nothing is drawn')
32+
assertEqual(bar.pickDrawnSlot([]), null, 'bar reports no slot when there are none')
33+
assertEqual(bar.pickDrawnSlot(null), null, 'bar tolerates a missing slot list')
34+
assert(
35+
/BarModel\.pickDrawnSlot\(candidates\)/.test(barSource),
36+
'bar routes panels through the drawn-slot picker'
37+
)
38+
39+
// The open-panel mark sits on the module's desktop-facing edge at every
40+
// position: under a top bar, over a bottom one, inward from left and right.
41+
const indicator = barSource.slice(barSource.indexOf('id: openPanelIndicator'), barSource.indexOf('id: openPanelIndicator') + 1600)
42+
assert(
43+
/x: root\.vertical\s*\n\s*\? \(root\.position === "left" \? parent\.width - width - inset : inset\)/.test(indicator),
44+
'bar pins the open-panel mark to the desktop-facing edge on vertical bars'
45+
)
46+
assert(
47+
/root\.position === "top" \? parent\.height - height - inset : inset/.test(indicator),
48+
'bar pins the open-panel mark to the desktop-facing edge on horizontal bars'
49+
)
50+
assert(
51+
/key in activeItem/.test(barSource),
52+
'bar asks whether a widget declares an indicator hint before reading it'
53+
)
54+
assert(
55+
/width: root\.vertical \? Style\.space\(2\) : slot\.panelIndicatorExtent/.test(indicator) &&
56+
/height: root\.vertical \? slot\.panelIndicatorExtent : Style\.space\(2\)/.test(indicator),
57+
'bar sizes the open-panel mark from the same content hint on both axes'
58+
)
1959
2060
assertEqual(bar.normalizePosition('left'), 'left', 'bar accepts valid positions')
2161
assertEqual(bar.normalizePosition('sideways'), 'top', 'bar defaults invalid positions')

0 commit comments

Comments
 (0)