tests: setters for full screen and frame geometry

This commit is contained in:
Peter Fajdiga
2024-09-15 17:41:10 +02:00
parent 79571146be
commit d239ac24b3
5 changed files with 121 additions and 10 deletions

View File

@@ -4,10 +4,23 @@
Workspace = workspaceMock;
const world = new World(getDefaultConfig());
workspaceMock.createWindow(new Mocks.KwinClient(
const kwinClient = new Mocks.KwinClient(
1,
"app1",
"Application 1",
new Mocks.QmlRect(0, 0, 200, 200),
));
);
workspaceMock.createWindow(kwinClient);
kwinClient.fullScreen = true;
{
const frame = kwinClient.frameGeometry;
assert(frame.width === Mocks.screenWidth && frame.height === Mocks.screenHeight);
}
kwinClient.fullScreen = false;
{
const frame = kwinClient.frameGeometry;
assert(frame.width === 200 && frame.height === 200);
}
}

View File

@@ -18,7 +18,7 @@ namespace Mocks {
public readonly managed: boolean = false;
public readonly popupWindow: boolean = false;
public fullScreen: boolean = false;
private _fullScreen: boolean = false;
public activities: string[] = [];
public skipSwitcher: boolean = false;
public keepAbove: boolean = false;
@@ -40,12 +40,17 @@ namespace Mocks {
public readonly interactiveMoveResizeFinished: QSignal<[]> = new QSignal();
public readonly frameGeometryChanged: QSignal<[oldGeometry: QmlRect]> = new QSignal();
private windowedFrameGeometry: QmlRect;
private windowed: boolean = false;
constructor(
public readonly pid: number,
public readonly resourceClass: string,
public readonly caption: string,
public frameGeometry: QmlRect,
) {}
private _frameGeometry: QmlRect,
) {
this.windowedFrameGeometry = _frameGeometry.clone();
}
setMaximize(vertically: boolean, horizontally: boolean) {
this.maximizedAboutToChange.fire(
@@ -58,6 +63,10 @@ namespace Mocks {
}
public get clientGeometry() {
if (this._fullScreen) {
return this.frameGeometry;
}
return new QmlRect(
this.frameGeometry.x + KwinClient.borderThickness,
this.frameGeometry.y + KwinClient.borderThickness,
@@ -65,5 +74,40 @@ namespace Mocks {
this.frameGeometry.height - 2 * KwinClient.borderThickness,
);
}
public get fullScreen() {
return this._fullScreen;
}
public set fullScreen(fullScreen: boolean) {
this.windowed = !fullScreen;
this._fullScreen = fullScreen;
this.fullScreenChanged.fire();
if (fullScreen) {
this.frameGeometry = new QmlRect(0, 0, screenWidth, screenHeight);
} else {
this.frameGeometry = this.windowedFrameGeometry;
}
}
public get frameGeometry() {
return this._frameGeometry;
}
public set frameGeometry(frameGeometry: QmlRect) {
const oldFrameGeometry = this._frameGeometry;
this._frameGeometry = new QmlRect(
frameGeometry.x,
frameGeometry.y,
frameGeometry.width,
frameGeometry.height,
this.frameGeometryChanged.fire,
);
if (this.windowed) {
this.windowedFrameGeometry = this._frameGeometry.clone();
}
this.frameGeometryChanged.fire(oldFrameGeometry);
}
}
}

View File

@@ -1,12 +1,53 @@
namespace Mocks {
export class QmlRect {
constructor(
public x: number,
public y: number,
public width: number,
public height: number,
private _x: number,
private _y: number,
private _width: number,
private _height: number,
private readonly onChanged: (oldRect: QmlRect) => void = () => {},
) {}
public get x() {
return this._x;
}
public set x(x: number) {
const oldRect = this.clone();
this._x = x;
this.onChanged(oldRect);
}
public get y() {
return this._y;
}
public set y(y: number) {
const oldRect = this.clone();
this._y = y;
this.onChanged(oldRect);
}
public get width() {
return this._width;
}
public set width(width: number) {
const oldRect = this.clone();
this._width = width;
this.onChanged(oldRect);
}
public get height() {
return this._height;
}
public set height(height: number) {
const oldRect = this.clone();
this._height = height;
this.onChanged(oldRect);
}
public get top() {
return this.y;
}
@@ -22,5 +63,14 @@ namespace Mocks {
public get right() {
return this.x + this.width;
}
public clone() {
return new QmlRect(
this._x,
this._y,
this._width,
this._height,
);
}
}
}

View File

@@ -21,7 +21,7 @@ namespace Mocks {
public readonly virtualScreenSizeChanged = new Mocks.QSignal<[]>();
public clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop) {
return new QmlRect(0, 0, 800, 600);
return new QmlRect(0, 0, Mocks.screenWidth, Mocks.screenHeight);
}
public createWindow(kwinClient: KwinClient) {

View File

@@ -0,0 +1,4 @@
namespace Mocks {
export const screenWidth = 800;
export const screenHeight = 600;
}