Skip to content

Commit b4ef2bc

Browse files
authoredOct 9, 2023
Feature/18/focus window (#173)
* (#18) Refactored moving/resizing of windows into two dedicated functions * Fixed Windows implementation * (#18) Updated Linux implementation * (#18) Code cleanup on Linux * (#18) Updated tests to use new functions for resizing and moving of windows * (#18) Adapt tests which require accessibility permissions to not execute on macOS. Verified locally during development * (#18) Migrating window tests to playwright, WIP * (#18) Fixed error in moveWindow on macOS caused by not passing a CGPoint, updated window tests
1 parent 901f5aa commit b4ef2bc

File tree

9 files changed

+4838
-4734
lines changed

9 files changed

+4838
-4734
lines changed
 

‎index.d.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,18 @@ export function focusWindow(handle: number): void
6565
* The window is moved to the x & y coordinates if specified.
6666
*
6767
* @param {number} handle - The handle ID of the window to be resized.
68-
* @param {Rect} rect - The new size of the window.
68+
* @param {Size} newSize - The new size of the window.
6969
* @returns {void}
7070
*/
71-
export function resizeWindow(handle: number, rect: Rect): void
71+
export function resizeWindow(handle: number, newSize: Size): void
72+
73+
/**
74+
* Moves a window by its handle to the given x and y coordinates.
75+
*
76+
* @param {number} handle - The handle ID of the window to be resized.
77+
* @param {Point} newOrigin - The new size of the window.
78+
* @returns {void}
79+
*/
80+
export function moveWindow(handle: number, newOrigin: Point): void
7281

7382
export const screen: Screen;

‎src/linux/window_manager.cc

+13-15
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,22 @@ bool focusWindow(const WindowHandle windowHandle) {
8282
return false;
8383
}
8484

85-
bool resizeWindow(const WindowHandle windowHandle, const MMRect& rect) {
85+
bool resizeWindow(const WindowHandle windowHandle, const MMSize newSize) {
8686
Display* display = XGetMainDisplay();
8787
if (display != NULL && windowHandle >= 0) {
88-
XWindowChanges changes;
89-
90-
//size
91-
changes.width = rect.size.width;
92-
changes.height = rect.size.height;
93-
94-
//origin
95-
changes.x = rect.origin.x;
96-
changes.y = rect.origin.y;
97-
98-
// Resize and move the window
99-
XConfigureWindow(display, windowHandle, CWX | CWY | CWWidth | CWHeight, &changes);
88+
auto status = XResizeWindow(display, windowHandle, newSize.width, newSize.height);
10089
XFlush(display);
101-
102-
return true;
90+
return status;
91+
}
92+
return false;
93+
}
94+
95+
bool moveWindow(const WindowHandle windowHandle, const MMPoint newOrigin) {
96+
Display* display = XGetMainDisplay();
97+
if (display != NULL && windowHandle >= 0) {
98+
auto status = XMoveWindow(display, windowHandle, newOrigin.x, newOrigin.y);
99+
XFlush(display);
100+
return status;
103101
}
104102
return false;
105103
}

0 commit comments

Comments
 (0)
Please sign in to comment.