mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-30 05:28:15 +03:00
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:
parent
8ec4765a5b
commit
ffa1e4aaff
4 changed files with 70 additions and 3 deletions
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue