Skip to content

Commit b22cafa

Browse files
committed
fix(linux): clamp the work area to the screen being positioned on
_NET_WORKAREA describes the whole desktop, not one monitor, so taking it as the bounds let a window opening near a shared edge be placed on the neighbouring monitor. It is intersected with the screen instead, and the monitor is kept where the two do not overlap.
1 parent a5d2cd1 commit b22cafa

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

v3/UNRELEASED_CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ After processing, the content will be moved to the main changelog and this file
2323

2424
## Fixed
2525
<!-- Bug fixes -->
26-
- Fix a system tray window being positioned over the taskbar on Linux by using the desktop work area rather than the full screen
26+
- Fix a system tray window being positioned over the taskbar on Linux by using the desktop work area rather than the full screen (#6019)
2727

2828
## Deprecated
2929
<!-- Soon-to-be removed features -->

v3/pkg/application/systemtray_linux.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,24 @@ func (s *linuxSystemTray) positionWindow(window Window, offset int) error {
257257
// The area panels and docks leave free, so the window is not laid over the
258258
// taskbar. currentScreen.WorkArea is the whole monitor on this backend —
259259
// GTK4 dropped the API it came from — so it is asked for separately.
260+
//
261+
// What comes back describes the whole desktop rather than one monitor, so
262+
// it is intersected with the screen the window is opening on: taking it
263+
// as-is would let a window near a shared edge be placed on the neighbouring
264+
// monitor. An empty intersection means the two disagree, and the monitor
265+
// wins.
260266
screenX := currentScreen.X
261267
screenY := currentScreen.Y
262268
screenWidth := currentScreen.Size.Width
263269
screenHeight := currentScreen.Size.Height
264270
if x, y, width, height, ok := screenWorkArea(); ok {
265-
screenX, screenY, screenWidth, screenHeight = x, y, width, height
271+
left := max(screenX, x)
272+
top := max(screenY, y)
273+
right := min(screenX+screenWidth, x+width)
274+
bottom := min(screenY+screenHeight, y+height)
275+
if right > left && bottom > top {
276+
screenX, screenY, screenWidth, screenHeight = left, top, right-left, bottom-top
277+
}
266278
}
267279

268280
windowWidth := window.Width()

0 commit comments

Comments
 (0)