omarchy: on Hyprland the tray panel opens under the click on a monitor that isn't at 0,0, not off the screen (#1785)

PanelAt answered where the panel goes in coordinates across the whole
layout (the cursor's, from hyprctl cursorpos), and PlacePanel handed them
to Hyprland's move rule. Hyprland counts a move from the corner of the
window's monitor (CDefaultFloatingAlgorithm::newTarget in 0.56.2:
COMPUTED + MONITOR_POS), so the monitor's place was added twice. The
reporter's click on the right of two 1920-wide monitors asked for
3238,40 and got 5158,40, off every screen. The monitor at 0,0 hid it,
and the only setup tried before (bf25a3ae8) had one monitor.

PanelAt now answers from the corner of the monitor under the cursor and
names it. The rule says monitor = that name, so the move counts from the
monitor clicked, not whichever one Hyprland would have opened the panel
on. The panel is still kept PanelGap inside that monitor's work area,
and the room below it is unchanged. ClickedOutside compares the cursor
with the clients' places, both across the layout, and stays as it was.
niri's placement already moves within the working area of the output and
doesn't share this. The fix follows laojianzi's draft (laojianzi/magpie#1).

Run:
- internal/omarchy TestPanelAtMonitorOffScreenOrigin (new), with the
  reporter's two 1920x1080 side by side, the right edge, a monitor left
  of and above 0,0, and a scaled one below. It plays Hyprland's sum and
  checks where the panel lands and that it's inside the clicked
  monitor's work area. With the old sum put back by hand it goes red,
  landing at 5158,40 for the reporter's case. TestPanelAt's turned
  monitor had the old global x written into it, and now has 6.
  TestPanelRule checks the rule's text.
- On the omarchy VM (Hyprland 0.56.2), with a headless second output at
  1600,0 made for the try and removed after, the same Lua rule on a
  throwaway foot window titled magpie-1785-probe (not magpie's rule
  name):
  - monitor = "PROBE-1785", move = { 100, 40 } landed at 1700,40;
  - the old global 1700,40 landed at 3300,40, off the screen;
  - monitor = "Virtual-1", move = { 100, 40 } landed at 100,40.
- go vet (darwin, windows; internal/omarchy for linux with nogui).
  gofmt is clean.

Not tried: magpie itself on two real monitors under Hyprland. The Linux
GUI build needs cgo and wasn't built here, so placePanel's two changed
lines are covered by the darwin and windows builds (app.go has no OS
tag).
This commit is contained in:
yetone
2026-10-12 22:21:52 +08:00
parent 632b14ec8d
commit 0db8112afe
4 changed files with 133 additions and 32 deletions
+1 -1
View File
@@ -162,7 +162,7 @@ retry after a failed read. See `TestRecentCallBodiesOnDemand` and
- The page must work in Chromium (Windows' WebView2) and WebKit (macOS, and WebKitGTK on Linux). GUI tests run in both engines.
- On Linux the panel is frameless and the main window has a hidden title bar (`plainTitlebar`). GTK 3 asks KDE's Wayland session (KWin's decoration protocol) for a frame drawn by KWin on any window without client-side decorations, an undecorated one too, so `ownFrame` tells KWin the panel draws its own on each realize (#1283). GTK 4 builds ask for none themselves. With no KWin title bar, and with a Wayland window placed by the compositor rather than by the icon, the panel's header is its drag handle on Linux, as the window's is (`--wails-draggable` in `app.js`; `panel-drag-linux.test.cjs`); on the Mac and Windows the panel isn't dragged (#1430).
- On Linux the panel is a solid window, as the main window is, and its page paints `--bg` whole (`panelOptions`, `body.linux.panel` in `app.css`). The Mac's and Windows' panels stay translucent. A see-through panel is an RGBA, app-paintable GTK window under a transparent webview, and on KDE Plasma 6 its page, painted at 93%, left a fainter copy of the old scroll position as it scrolled (Wayland and XWayland, compositing mode on or off) while the main window never did (#1803, `TestPanelSolidOnLinux`, `panel-linux-opaque.test.cjs`). Xvfb with picom on WebKitGTK 2.54 doesn't show the ghost either way, so the fix rests on the reporter's machine.
- A Wayland window can't place itself, so under Hyprland and niri the compositor is asked to put the panel under the bar. Under Hyprland `placePanel` gives it a window rule at the cursor (`omarchy.PlacePanel`) and closes it on a click outside (`omarchy.ReportClicks`). niri (`omarchy.Niri`, `NIRI_SOCKET` set) takes no rules at runtime and doesn't report the cursor. There `omarchy.NiriPanel` watches niri's event stream and moves the panel each time it opens: the window of magpie's pid titled `panelTitle`, moved with `MoveFloatingWindow` (after `MoveWindowToFloating` if it was tiled). It goes 6 px under the working area's top, centred on the x the tray host passed to `Activate(x, y)`. Wails keeps that x in its Linux tray (`trayClick`, `TestTrayClickIsWails`), and it is taken across the bar, since that's all a Wayland bar knows. With no click (`magpie panel`), or with one off the output, it goes top right. Wails' `HideOnFocusLost` closes it, since a click on another window takes niri's focus. It still opens in the middle and slides up, and a bar at the bottom or the side isn't accounted for (#1670).
- A Wayland window can't place itself, so under Hyprland and niri the compositor is asked to put the panel under the bar. Under Hyprland `placePanel` gives it a window rule at the cursor (`omarchy.PlacePanel`) and closes it on a click outside (`omarchy.ReportClicks`). The rule names the monitor under the cursor and moves the panel to x, y from that monitor's corner (`omarchy.PanelAt`): Hyprland adds the window's monitor's place to a `move`, so a position across the whole layout put the panel off a monitor not at 0,0 (#1785, `TestPanelAtMonitorOffScreenOrigin`). The cursor and the clients' places that `omarchy.ClickedOutside` compares are both across the layout. niri (`omarchy.Niri`, `NIRI_SOCKET` set) takes no rules at runtime and doesn't report the cursor. There `omarchy.NiriPanel` watches niri's event stream and moves the panel each time it opens: the window of magpie's pid titled `panelTitle`, moved with `MoveFloatingWindow` (after `MoveWindowToFloating` if it was tiled). It goes 6 px under the working area's top, centred on the x the tray host passed to `Activate(x, y)`. Wails keeps that x in its Linux tray (`trayClick`, `TestTrayClickIsWails`), and it is taken across the bar, since that's all a Wayland bar knows. With no click (`magpie panel`), or with one off the output, it goes top right. Wails' `HideOnFocusLost` closes it, since a click on another window takes niri's focus. It still opens in the middle and slides up, and a bar at the bottom or the side isn't accounted for (#1670).
- Wails calls the tray's click handler both for the icon's click (`Activate`) and when the tray host opens the icon's menu (dbusmenu's "opened" event). KDE opens the menu on a right-click, and the panel that click opened took the focus and shut the menu on Wayland. On Linux the handler ignores the call when it comes from the menu opening (`menuOpening` in [`trayclick.go`](../../internal/gui/trayclick.go), which looks for Wails' `(*linuxSystemTray).Event` among its callers; `TestTrayMenuOpenFrameIsWails` fails if Wails renames it or stops calling the handler there) (#1430).
- On GTK 3 builds, the app gives GDK a font DPI before the first webview when it has none (`fontDPI`, [`fontdpi_gtk3.h`](../../internal/gui/fontdpi_gtk3.h)). GDK's unset value is -1, and WebKitGTK 2.54's GTK 3 settings reader multiplies it by 1024 unchecked, so every page lays out at a negative width with a 9000000px font (#1371). An unset DPI takes `gtk-xft-dpi`, or 96, times a valid `GDK_DPI_SCALE`; a positive one is left alone. Wails initialises GTK (its GtkApplication) only inside `Run` and makes each window from a default-idle-priority callback on the main loop, so `fontDPI`, called just before `Run`, queues the check as a `G_PRIORITY_HIGH` idle: it runs on the main thread after GTK's own start, before the first window. `TestFontDPIUnset` opens a real WebKitGTK page through `magpie_font_dpi` and needs a display (Xvfb).
- Tests never touch a live agent config. The package's `TestMain` runs under `testenv`'s home of its own. A macOS test that shows windows runs them in a process of its own through `runAppKit` ([`appkit_darwin_test.go`](../../internal/gui/appkit_darwin_test.go)). AppKit and WebKit take their home from the account, not from HOME, so `runAppKit` gives them a temporary one with `CFFIXED_USER_HOME`; appearance, contrast and languages still come from the account. The test fails when that process leaves a folder in the real `~/Library/WebKit` or `~/Library/Caches`. Playwright tests serve `assets/` with isolated `/api` fixtures.
+2 -2
View File
@@ -734,11 +734,11 @@ func (h *host) togglePanelNow() {
// click, the way Omarchy's own drop-downs sit: a Wayland window can't place
// itself, so Hyprland is given a rule for it (see omarchy.PlacePanel).
func (h *host) placePanel() {
x, y, room, ok := omarchy.PanelAt(h.panelW())
mon, x, y, room, ok := omarchy.PanelAt(h.panelW())
if !ok {
return
}
if err := omarchy.PlacePanel(panelTitle, x, y); err != nil {
if err := omarchy.PlacePanel(panelTitle, mon, x, y); err != nil {
log.Println("hyprland:", err)
return
}
+36 -18
View File
@@ -29,6 +29,7 @@ func Hyprland() bool {
const PanelGap = 6
type hyprMonitor struct {
Name string
X, Y int
Width, Height int
Scale float64
@@ -52,40 +53,57 @@ func (m hyprMonitor) size() (w, h int) {
// PanelAt is where a drop-down panel width wide goes: under the bar, its
// middle at the cursor (which has just clicked the icon it drops from),
// kept PanelGap inside the monitor the cursor is on. maxH is the room it has
// down to the bottom of that monitor's work area.
func PanelAt(width int) (x, y, maxH int, ok bool) {
// kept PanelGap inside the monitor the cursor is on. mon is that monitor's
// name, and x, y are from its top left corner, as Hyprland's move rule
// takes them: it adds the monitor's own place to them, so a monitor not at
// 0,0 was counted twice and the panel opened off the screen (#1785). maxH
// is the room it has down to the bottom of that monitor's work area.
func PanelAt(width int) (mon string, x, y, maxH int, ok bool) {
var cur struct{ X, Y int }
var mons []hyprMonitor
if hyprJSON("cursorpos", &cur) != nil || hyprJSON("monitors", &mons) != nil {
return 0, 0, 0, false
return "", 0, 0, 0, false
}
return panelAt(width, cur.X, cur.Y, mons)
}
func panelAt(width, cx, cy int, mons []hyprMonitor) (x, y, maxH int, ok bool) {
// panelAt takes the cursor in layout coordinates, across every monitor (as
// hyprctl cursorpos gives it), and answers from the corner of the one it is
// on.
func panelAt(width, cx, cy int, mons []hyprMonitor) (mon string, x, y, maxH int, ok bool) {
for _, m := range mons {
w, h := m.size()
if cx < m.X || cx >= m.X+w || cy < m.Y || cy >= m.Y+h {
continue
}
left, right := m.X+m.Reserved[0]+PanelGap, m.X+w-m.Reserved[2]-PanelGap
x = max(left, min(right-width, cx-width/2))
y = m.Y + m.Reserved[1] + PanelGap
return x, y, m.Y + h - m.Reserved[3] - PanelGap - y, true
left, right := m.Reserved[0]+PanelGap, w-m.Reserved[2]-PanelGap
x = max(left, min(right-width, cx-m.X-width/2))
y = m.Reserved[1] + PanelGap
return m.Name, x, y, h - m.Reserved[3] - PanelGap - y, true
}
return 0, 0, 0, false
return "", 0, 0, 0, false
}
// PlacePanel gives the window titled title a rule of its own (replacing
// the last one, by name): floating, pinned to every workspace, at x, y, with
// no border and fully opaque — the page draws its own frame, in the border's
// colour. It is asked each time the panel opens, as where it goes follows
// the click, and a config reload drops rules made this way.
func PlacePanel(title string, x, y int) error {
lua := fmt.Sprintf(`hl.window_rule({ name = "magpie-panel", match = { title = %s }, tag = "-default-opacity", float = true, pin = true, border_size = 0, no_shadow = true, opacity = "1 1", no_anim = true, move = { %d, %d } })`,
strconv.Quote("^"+regexpQuote(title)+"$"), x, y)
return hyprctl("eval", lua)
// the last one, by name): floating, pinned to every workspace, on monitor
// mon at x, y from its corner, with no border and fully opaque — the page
// draws its own frame, in the border's colour. It is asked each time the
// panel opens, as where it goes follows the click, and a config reload
// drops rules made this way.
func PlacePanel(title, mon string, x, y int) error {
return hyprctl("eval", panelRule(title, mon, x, y))
}
// panelRule is PlacePanel's rule. The monitor is named so that the move
// counts from the corner of the one clicked, not from whichever Hyprland
// would have opened the panel on.
func panelRule(title, mon string, x, y int) string {
on := ""
if mon != "" {
on = "monitor = " + strconv.Quote(mon) + ", "
}
return fmt.Sprintf(`hl.window_rule({ name = "magpie-panel", match = { title = %s }, tag = "-default-opacity", float = true, pin = true, border_size = 0, no_shadow = true, opacity = "1 1", no_anim = true, %smove = { %d, %d } })`,
strconv.Quote("^"+regexpQuote(title)+"$"), on, x, y)
}
// Clicks are how the panel closes on a click outside it, as Omarchy's own
+94 -11
View File
@@ -1,33 +1,116 @@
package omarchy
import "testing"
import (
"strings"
"testing"
)
func TestPanelAt(t *testing.T) {
// 2528x960 at 1.6 is 1580x600 in layout coordinates; Omarchy's bar
// takes 26 at the top. A second monitor to its right, turned, at 1.
mons := []hyprMonitor{
{Width: 2528, Height: 960, Scale: 1.6, Reserved: [4]int{0, 26, 0, 0}},
{X: 1580, Width: 1920, Height: 1080, Scale: 1, Transform: 1},
{Name: "Virtual-1", Width: 2528, Height: 960, Scale: 1.6, Reserved: [4]int{0, 26, 0, 0}},
{Name: "DP-1", X: 1580, Width: 1920, Height: 1080, Scale: 1, Transform: 1},
}
for _, c := range []struct {
name string
cx, cy int
mon string
x, y, room int
ok bool
}{
{"middle", 800, 10, 580, 32, 562, true},
{"right edge", 1570, 10, 1580 - 6 - 440, 32, 562, true},
{"left edge", 20, 10, 6, 32, 562, true},
{"turned monitor", 1700, 1500, 1586, 6, 1920 - 12, true},
{"off every monitor", -5, 10, 0, 0, 0, false},
{"middle", 800, 10, "Virtual-1", 580, 32, 562, true},
{"right edge", 1570, 10, "Virtual-1", 1580 - 6 - 440, 32, 562, true},
{"left edge", 20, 10, "Virtual-1", 6, 32, 562, true},
// from DP-1's corner, which Hyprland adds (#1785)
{"turned monitor", 1700, 1500, "DP-1", 6, 6, 1920 - 12, true},
{"off every monitor", -5, 10, "", 0, 0, 0, false},
} {
x, y, room, ok := panelAt(440, c.cx, c.cy, mons)
if x != c.x || y != c.y || room != c.room || ok != c.ok {
t.Errorf("%s: %d,%d room %d %v; want %d,%d room %d %v", c.name, x, y, room, ok, c.x, c.y, c.room, c.ok)
mon, x, y, room, ok := panelAt(440, c.cx, c.cy, mons)
if mon != c.mon || x != c.x || y != c.y || room != c.room || ok != c.ok {
t.Errorf("%s: %q %d,%d room %d %v; want %q %d,%d room %d %v", c.name, mon, x, y, room, ok, c.mon, c.x, c.y, c.room, c.ok)
}
}
}
// landed is where Hyprland 0.56 puts a floating window that its move rule
// places at x, y: from the corner of the window's monitor
// (CDefaultFloatingAlgorithm::newTarget, COMPUTED + MONITOR_POS). The rule
// names that monitor.
func landed(mons []hyprMonitor, mon string, x, y int) (gx, gy int) {
for _, m := range mons {
if m.Name == mon {
return m.X + x, m.Y + y
}
}
return x, y
}
// A click on the tray of a monitor that isn't at 0,0 opens the panel on
// that monitor, under the click and inside its work area. With the
// monitor's place counted in the move as well as by Hyprland, the
// reporter's panel at 3238,40 went to 5158,40, off every screen (#1785).
func TestPanelAtMonitorOffScreenOrigin(t *testing.T) {
const width = 440
for _, c := range []struct {
name string
mons []hyprMonitor
cx, cy int
gx, gy int // where the panel's corner lands across the layout
}{
// the reporter's: two 1920x1080 side by side, a bar of 34 on each
{"right of two", []hyprMonitor{
{Name: "DP-1", Width: 1920, Height: 1080, Scale: 1, Reserved: [4]int{0, 34, 0, 0}},
{Name: "HDMI-A-1", X: 1920, Width: 1920, Height: 1080, Scale: 1, Reserved: [4]int{0, 34, 0, 0}},
}, 3458, 17, 3238, 40},
{"right of two, at its right edge", []hyprMonitor{
{Name: "DP-1", Width: 1920, Height: 1080, Scale: 1, Reserved: [4]int{0, 34, 0, 0}},
{Name: "HDMI-A-1", X: 1920, Width: 1920, Height: 1080, Scale: 1, Reserved: [4]int{0, 34, 0, 0}},
}, 3835, 17, 3840 - 6 - width, 40},
{"left of two, the other at 0,0", []hyprMonitor{
{Name: "eDP-1", Width: 1920, Height: 1080, Scale: 1, Reserved: [4]int{0, 34, 0, 0}},
{Name: "DP-2", X: -2560, Y: -360, Width: 2560, Height: 1440, Scale: 1, Reserved: [4]int{0, 34, 0, 0}},
}, -1000, -350, -1000 - width/2, -360 + 40},
{"below, scaled", []hyprMonitor{
{Name: "eDP-1", Width: 2880, Height: 1800, Scale: 2, Reserved: [4]int{0, 30, 0, 0}},
{Name: "DP-3", Y: 900, Width: 3840, Height: 2160, Scale: 1.5, Reserved: [4]int{0, 30, 0, 0}},
}, 20, 910, 6, 900 + 36},
} {
mon, x, y, room, ok := panelAt(width, c.cx, c.cy, c.mons)
if !ok {
t.Fatalf("%s: not placed", c.name)
}
gx, gy := landed(c.mons, mon, x, y)
if gx != c.gx || gy != c.gy {
t.Errorf("%s: the panel lands at %d,%d (%q %d,%d), want %d,%d", c.name, gx, gy, mon, x, y, c.gx, c.gy)
}
// on the monitor clicked, inside its work area
var on hyprMonitor
for _, m := range c.mons {
if w, h := m.size(); c.cx >= m.X && c.cx < m.X+w && c.cy >= m.Y && c.cy < m.Y+h {
on = m
}
}
w, h := on.size()
if mon != on.Name || gx < on.X+on.Reserved[0] || gx+width > on.X+w-on.Reserved[2] || gy < on.Y+on.Reserved[1] || gy+room > on.Y+h-on.Reserved[3] {
t.Errorf("%s: %d,%d %dx%d on %q isn't inside %q's work area", c.name, gx, gy, width, room, mon, on.Name)
}
}
}
func TestPanelRule(t *testing.T) {
got := panelRule("magpie panel", "HDMI-A-1", 1318, 40)
for _, want := range []string{`match = { title = "^magpie panel$" }`, `monitor = "HDMI-A-1", move = { 1318, 40 }`, `float = true`, `pin = true`} {
if !strings.Contains(got, want) {
t.Errorf("rule %s\nhas no %s", got, want)
}
}
// no monitor known: no monitor named, rather than an empty one
if got := panelRule("magpie panel", "", 6, 32); strings.Contains(got, "monitor") || !strings.Contains(got, "move = { 6, 32 }") {
t.Errorf("rule with no monitor: %s", got)
}
}
func TestRegexpQuote(t *testing.T) {
for in, want := range map[string]string{
"magpie panel": "magpie panel",