Skip to content

Commit

Permalink
Feature/18/focus window (#173)
Browse files Browse the repository at this point in the history
* (#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
  • Loading branch information
s1hofmann authored Oct 9, 2023
1 parent 901f5aa commit b4ef2bc
Show file tree
Hide file tree
Showing 9 changed files with 4,838 additions and 4,734 deletions.
13 changes: 11 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,18 @@ export function focusWindow(handle: number): void
* The window is moved to the x & y coordinates if specified.
*
* @param {number} handle - The handle ID of the window to be resized.
* @param {Rect} rect - The new size of the window.
* @param {Size} newSize - The new size of the window.
* @returns {void}
*/
export function resizeWindow(handle: number, rect: Rect): void
export function resizeWindow(handle: number, newSize: Size): void

/**
* Moves a window by its handle to the given x and y coordinates.
*
* @param {number} handle - The handle ID of the window to be resized.
* @param {Point} newOrigin - The new size of the window.
* @returns {void}
*/
export function moveWindow(handle: number, newOrigin: Point): void

export const screen: Screen;
28 changes: 13 additions & 15 deletions src/linux/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,22 @@ bool focusWindow(const WindowHandle windowHandle) {
return false;
}

bool resizeWindow(const WindowHandle windowHandle, const MMRect& rect) {
bool resizeWindow(const WindowHandle windowHandle, const MMSize newSize) {
Display* display = XGetMainDisplay();
if (display != NULL && windowHandle >= 0) {
XWindowChanges changes;

//size
changes.width = rect.size.width;
changes.height = rect.size.height;

//origin
changes.x = rect.origin.x;
changes.y = rect.origin.y;

// Resize and move the window
XConfigureWindow(display, windowHandle, CWX | CWY | CWWidth | CWHeight, &changes);
auto status = XResizeWindow(display, windowHandle, newSize.width, newSize.height);
XFlush(display);

return true;
return status;
}
return false;
}

bool moveWindow(const WindowHandle windowHandle, const MMPoint newOrigin) {
Display* display = XGetMainDisplay();
if (display != NULL && windowHandle >= 0) {
auto status = XMoveWindow(display, windowHandle, newOrigin.x, newOrigin.y);
XFlush(display);
return status;
}
return false;
}
Loading

0 comments on commit b4ef2bc

Please sign in to comment.