Repository navigation
fix(linux): open Notes at the top edge on Wayland, clear of the HUD bar #1586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
ad03462
fix(linux): open Notes at the top edge on Wayland, clear of the HUD bar
EtienneLescot afdab0e
fix(linux): size Wayland Notes from the HUD's reported bar top
EtienneLescot f28d174
fix(linux): read the Wayland Notes size when it shrinks, minimum incl…
EtienneLescot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { | ||
| PLACEMENT_FALLBACK_MS, | ||
| type PlacedWindow, | ||
| shrinkOncePlaced, | ||
| topEdgeOpeningHeight, | ||
| } from "./notesPlacement"; | ||
|
|
||
| const SIZE = { width: 400, height: 417 }; | ||
| const MAX = { width: 640, height: 720 }; | ||
|
|
||
| function fakeWindow({ destroyed = false } = {}) { | ||
| let configure: (() => void) | undefined; | ||
| const win = { | ||
| configure: () => configure?.(), | ||
| isDestroyed: () => destroyed, | ||
| once: vi.fn((_event: "resize", listener: () => void) => { | ||
| configure = listener; | ||
| }), | ||
| setSize: vi.fn(), | ||
| setMaximumSize: vi.fn(), | ||
| }; | ||
| return win satisfies PlacedWindow; | ||
| } | ||
|
|
||
| describe("topEdgeOpeningHeight", () => { | ||
| it("is taller than every display, so the compositor has to clamp it", () => { | ||
| expect(topEdgeOpeningHeight([1080, 1440])).toBe(1441); | ||
| expect(topEdgeOpeningHeight([])).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe("shrinkOncePlaced (GNOME Wayland Notes)", () => { | ||
| beforeEach(() => vi.useFakeTimers()); | ||
| afterEach(() => vi.useRealTimers()); | ||
|
|
||
| it("waits for the compositor's first configure, then shrinks on the next turn", () => { | ||
| const win = fakeWindow(); | ||
| shrinkOncePlaced(win, SIZE, MAX); | ||
| expect(win.setSize).not.toHaveBeenCalled(); | ||
|
|
||
| win.configure(); | ||
| // Not inside the configure itself: a resize sent before the compositor placed the | ||
| // window is overwritten (rc.3 probe: Notes stayed full height). | ||
| expect(win.setSize).not.toHaveBeenCalled(); | ||
| vi.advanceTimersByTime(0); | ||
|
|
||
| expect(win.setSize).toHaveBeenCalledWith(400, 417); | ||
| expect(win.setMaximumSize).toHaveBeenCalledWith(640, 720); | ||
| }); | ||
|
|
||
| it("shrinks anyway when no configure comes, and only once", () => { | ||
| const win = fakeWindow(); | ||
| shrinkOncePlaced(win, SIZE, MAX); | ||
|
|
||
| vi.advanceTimersByTime(PLACEMENT_FALLBACK_MS - 1); | ||
| expect(win.setSize).not.toHaveBeenCalled(); | ||
| vi.advanceTimersByTime(1); | ||
| expect(win.setSize).toHaveBeenCalledTimes(1); | ||
|
|
||
| win.configure(); | ||
| vi.runAllTimers(); | ||
| expect(win.setSize).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("leaves a window closed before it was placed alone", () => { | ||
| const win = fakeWindow({ destroyed: true }); | ||
| shrinkOncePlaced(win, SIZE, MAX); | ||
| win.configure(); | ||
| vi.runAllTimers(); | ||
| expect(win.setSize).not.toHaveBeenCalled(); | ||
| expect(win.setMaximumSize).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Opening Notes clear of the HUD bar on GNOME Wayland. | ||
| // | ||
| // A Wayland client cannot place its windows. mutter opens a new one 50px down-right of each | ||
| // window whose top-left corner sits on its diagonal from the work area's corner, and the HUD | ||
| // sits on that diagonal from launch. How many steps Notes takes depends on the other windows on | ||
| // the desktop, so no opening height keeps it off the bar: in rc.3, at 402px, three steps put it | ||
| // 48px over the bar. | ||
| // | ||
| // What mutter does not vary is where a window as tall as the work area goes: its top edge. A | ||
| // cascade step would push it off the bottom, so mutter starts the next cascade along the top | ||
| // edge, and its first-fit search must fit the whole window too. A resize then keeps the window's | ||
| // top-left. So Notes opens that tall and shrinks once the compositor has placed it. The HUD's | ||
| // window cannot rise above that edge, and everything it draws sits at least | ||
| // WAYLAND_HUD_BAR_TOP below its own top, so a Notes window shorter than that ends above the bar | ||
| // wherever the HUD is. Measured on GNOME 46 (v2.3.0-rc.3): Notes at x 50–450, y 32–433 with the | ||
| // bar at y 535, where it had opened at y 183–583. | ||
|
|
||
| /** The slice of `BrowserWindow` this needs, so the rule can be tested without Electron. */ | ||
| export type PlacedWindow = { | ||
| isDestroyed(): boolean; | ||
| once(event: "resize", listener: () => void): unknown; | ||
| setSize(width: number, height: number): void; | ||
| setMaximumSize(width: number, height: number): void; | ||
| }; | ||
|
|
||
| type Size = { width: number; height: number }; | ||
|
|
||
| /** | ||
| * How long to wait for the compositor's first configure before shrinking anyway, for a | ||
| * compositor that does not clamp the window to its work area and so never sends one. | ||
| */ | ||
| export const PLACEMENT_FALLBACK_MS = 1000; | ||
|
|
||
| /** | ||
| * Taller than any display, so the compositor has to clamp the window to its work area: that | ||
| * clamp is the configure `shrinkOncePlaced` waits for. | ||
| */ | ||
| export function topEdgeOpeningHeight(displayHeights: readonly number[]): number { | ||
| return Math.max(0, ...displayHeights) + 1; | ||
| } | ||
|
|
||
| /** | ||
| * For a window just shown at `topEdgeOpeningHeight`: brings it to `size`, and its maximum back | ||
| * to `max`, once the compositor has placed it. Its first configure, the `resize` that clamps it | ||
| * to the work area, tells when. A resize sent before it is overwritten (measured: 16ms after | ||
| * `show()`, Notes stayed full height), so the shrink waits for it and goes out on the next turn. | ||
| */ | ||
| export function shrinkOncePlaced(win: PlacedWindow, size: Size, max: Size): void { | ||
| let done = false; | ||
| const shrink = () => { | ||
| if (done || win.isDestroyed()) return; | ||
| done = true; | ||
| win.setSize(size.width, size.height); | ||
| win.setMaximumSize(max.width, max.height); | ||
| }; | ||
| win.once("resize", () => setTimeout(shrink, 0)); | ||
| setTimeout(shrink, PLACEMENT_FALLBACK_MS); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.