Wayland windows sizing

- improved `Window` class. Added:
  + `Window.isWayland()` to check if the system runs under wayland
  + `Window.upscaleSize()` to fix sizing of the window if the system uses wayland
- removed ability to resize windows (mistakenly added in the prev commit)
This commit is contained in:
Observer KRypt0n_ 2022-01-08 17:55:17 +02:00
parent 8ec4765a5b
commit ffa1e4aaff
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
4 changed files with 70 additions and 3 deletions

View file

@ -174,7 +174,13 @@
// Do some stuff when all the content will be loaded
onMount(() => {
Window.current.show();
Window.current.setSize({ width: 900, height: 600 });
Window.current.setSize({
width: 900,
height: 600,
resizable: false
});
Window.current.center(900, 600);
});

View file

@ -20,7 +20,13 @@
onMount(() => {
Window.current.show();
Window.current.setSize({ width: 300, height: 400 });
Window.current.setSize({
width: 300,
height: 400,
resizable: false
});
Window.current.center(300, 400);
});

View file

@ -87,7 +87,13 @@ export default class State
IPC.write('launcher-loaded');
Window.current.show();
Window.current.setSize({ width: 1280, height: 700 });
Window.current.setSize({
width: 1280,
height: 700,
resizable: false
});
Window.current.center(1280, 700);
});
}

View file

@ -36,6 +36,15 @@ declare const Neutralino;
class Window
{
public static waylandUpscales = {
width: 46,
height: 74
};
public static upscaleOnWayland = true;
protected static isWaylandSession?: boolean;
public static get current(): any
{
return {
@ -44,6 +53,11 @@ class Window
center(windowWidth: number, windowHeight: number)
{
Neutralino.window.move(Math.round((window.screen.width - windowWidth) / 2), Math.round((window.screen.height - windowHeight) / 2));
},
setSize(size: WindowSize)
{
Window.upscaleSize(size).then(Neutralino.window.setSize);
}
};
}
@ -71,6 +85,41 @@ class Window
});
});
}
public static isWayland(): Promise<boolean>
{
return new Promise((resolve) => {
if (this.isWaylandSession !== undefined)
resolve(this.isWaylandSession);
else Neutralino.os.getEnv('XDG_SESSION_TYPE').then((value) => {
this.isWaylandSession = value === 'wayland';
resolve(this.isWaylandSession);
});
});
}
public static upscaleSize(size: WindowSize): Promise<WindowSize>
{
return new Promise(async (resolve) => {
// Upscale is required only if the window is not resizable
if (Window.upscaleOnWayland && size.resizable !== undefined && !size.resizable && await Window.isWayland())
{
// Upscale width
for (const prop of ['minWidth', 'maxWidth', 'width'])
if (size[prop] !== undefined)
size[prop] += Window.waylandUpscales.width;
// Upscale height
for (const prop of ['minHeight', 'maxHeight', 'height'])
if (size[prop] !== undefined)
size[prop] += Window.waylandUpscales.height;
}
resolve(size);
});
}
}
export type {