mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-07 13:08:54 -07:00
fix(overlay): correct Hyprland fullscreen overlay alignment on Linux (#107)
This commit is contained in:
@@ -7,11 +7,56 @@ type ScreenDipConverter = {
|
||||
) => Electron.Rectangle;
|
||||
};
|
||||
|
||||
type ContentBoundsWindow = {
|
||||
isDestroyed: () => boolean;
|
||||
getBounds: () => Electron.Rectangle;
|
||||
getContentBounds: () => Electron.Rectangle;
|
||||
};
|
||||
|
||||
function resolveContentAlignedBounds(
|
||||
geometry: WindowGeometry,
|
||||
window?: ContentBoundsWindow | null,
|
||||
): WindowGeometry {
|
||||
if (!window || window.isDestroyed()) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
let outer: Electron.Rectangle;
|
||||
let content: Electron.Rectangle;
|
||||
try {
|
||||
outer = window.getBounds();
|
||||
content = window.getContentBounds();
|
||||
} catch {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
const leftInset = content.x - outer.x;
|
||||
const topInset = content.y - outer.y;
|
||||
const rightInset = outer.x + outer.width - (content.x + content.width);
|
||||
const bottomInset = outer.y + outer.height - (content.y + content.height);
|
||||
const insets = [leftInset, topInset, rightInset, bottomInset];
|
||||
if (insets.some((inset) => !Number.isFinite(inset) || inset < 0)) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
return {
|
||||
x: geometry.x - leftInset,
|
||||
y: geometry.y - topInset,
|
||||
width: geometry.width + leftInset + rightInset,
|
||||
height: geometry.height + topInset + bottomInset,
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeOverlayWindowBoundsForPlatform(
|
||||
geometry: WindowGeometry,
|
||||
platform: NodeJS.Platform,
|
||||
screen: ScreenDipConverter | null,
|
||||
window?: ContentBoundsWindow | null,
|
||||
): WindowGeometry {
|
||||
if (platform === 'linux') {
|
||||
return resolveContentAlignedBounds(geometry, window);
|
||||
}
|
||||
|
||||
if (platform !== 'win32' || !screen) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user