Files
magpie/internal/omarchy/hypr_test.go
T
yetone 0db8112afe 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).
2026-10-12 22:21:52 +08:00

145 lines
5.2 KiB
Go

package omarchy
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{
{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, "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},
} {
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",
"a.b(c)": `a\.b\(c\)`,
"x+y*": `x\+y\*`,
} {
if got := regexpQuote(in); got != want {
t.Errorf("regexpQuote(%q) = %q, want %q", in, got, want)
}
}
}
func TestOutside(t *testing.T) {
at, size := [2]int{1134, 32}, [2]int{440, 520}
for _, c := range []struct {
name string
x, y int
want bool
}{
{"on the panel", 1300, 300, false},
{"on its top-left corner", 1134, 32, false},
{"left of it", 900, 300, true},
{"under it", 1300, 560, true},
{"on the bar", 1400, 10, false},
{"in the gap under the bar", 900, 28, true},
} {
if got := outside(c.x, c.y, at, size); got != c.want {
t.Errorf("%s: %v, want %v", c.name, got, c.want)
}
}
}