Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
s1hofmann committed Oct 9, 2023
2 parents 6ee31aa + fe7b584 commit 39dd098
Show file tree
Hide file tree
Showing 22 changed files with 5,470 additions and 5,932 deletions.
1 change: 0 additions & 1 deletion .github/workflows/snapshot_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
working-directory: ./test/
run: npm cit
- name: Run window tests
if: ${{matrix.os == 'windows-2019'}}
uses: GabrielBB/xvfb-action@v1
with:
working-directory: ./test/window-integration-tests
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/tagged_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
working-directory: ./test/
run: npm cit
- name: Run window tests
if: ${{matrix.os == 'windows-2019'}}
uses: GabrielBB/xvfb-action@v1
with:
working-directory: ./test/window-integration-tests
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 2.6.0

- Feature: Move/focus/resize window [(#18)](/~https://github.com/nut-tree/libnut-core/issues/18) Contributed by [@ekrenzin](/~https://github.com/ekrenzin)
- Enhancement: Adding support for numpad 'clear' key [PR #166)](/~https://github.com/nut-tree/libnut-core/pull/166) Contributed by [@smithkyle](/~https://github.com/smithkyle)
- Maintenance: Version upgrades, CI updates, etc.

## 2.5.2

- Bugfix: Screen capture broken on macOS 13 [(nut-tree/nut.js#469)](/~https://github.com/nut-tree/nut.js/issues/469)
Expand Down
27 changes: 27 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,31 @@ export function getActiveWindow(): number;
export function getWindowRect(handle: number): Rect;
export function getWindowTitle(handle: number): string;

/**
* Sets the focus to a specific window using its handle.
*
* @param {number} handle - The handle ID of the window to be focused.
* @returns {void}
*/
export function focusWindow(handle: number): void

/**
* Resizes a window by its handle to the given width and height.
* The window is moved to the x & y coordinates if specified.
*
* @param {number} handle - The handle ID of the window to be resized.
* @param {Size} newSize - The new size of the window.
* @returns {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;
87 changes: 46 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libnut",
"version": "2.5.2",
"version": "2.6.0",
"description": "libnut is an N-API module for desktop automation with node",
"main": "index.js",
"typings": "index.d.ts",
Expand All @@ -14,9 +14,9 @@
},
"homepage": "https://nutjs.dev",
"author": {
"name": "Simon Hofmann",
"email": "kontakt@s1h.org",
"url": "https://s1h.org"
"name": "dry Software UG (haftungsbeschränkt)",
"email": "info@dry.software",
"url": "https://dry.software"
},
"bugs": {
"url": "/~https://github.com/nut-tree/nut.js/issues"
Expand Down
2 changes: 2 additions & 0 deletions permissionCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ try {
"getActiveWindow",
"getWindowRect",
"getWindowTitle",
"focusWindow",
"resizeWindow"
];
const screenCaptureAccess = [
"getWindowTitle",
Expand Down
3 changes: 3 additions & 0 deletions src/keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum _MMKeyCode {
K_SUBTRACT = kVK_ANSI_KeypadMinus,
K_DIVIDE = kVK_ANSI_KeypadDivide,
K_MULTIPLY = kVK_ANSI_KeypadMultiply,
K_CLEAR = kVK_ANSI_KeypadClear,

K_NUMPAD_0 = kVK_ANSI_Keypad0,
K_NUMPAD_1 = kVK_ANSI_Keypad1,
Expand Down Expand Up @@ -183,6 +184,7 @@ enum _MMKeyCode {
K_SUBTRACT = XK_KP_Subtract,
K_DIVIDE = XK_KP_Divide,
K_MULTIPLY = XK_KP_Multiply,
K_CLEAR = XK_Clear,

K_NUMPAD_0 = XK_KP_0,
K_NUMPAD_1 = XK_KP_1,
Expand Down Expand Up @@ -284,6 +286,7 @@ enum _MMKeyCode {
K_SUBTRACT = VK_SUBTRACT,
K_DIVIDE = VK_DIVIDE,
K_MULTIPLY = VK_MULTIPLY,
K_CLEAR = VK_CLEAR,

K_NUMPAD_0 = VK_NUMPAD0,
K_NUMPAD_1 = VK_NUMPAD1,
Expand Down
33 changes: 33 additions & 0 deletions src/linux/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,36 @@ MMRect getWindowRect(const WindowHandle windowHandle) {
}
return windowRect;
}

bool focusWindow(const WindowHandle windowHandle) {
Display* display = XGetMainDisplay();
if (display != NULL && windowHandle >= 0) {
// Try to set the window to the foreground
XSetInputFocus(display, windowHandle, RevertToParent, CurrentTime);
XRaiseWindow(display, windowHandle);
XFlush(display);

return true;
}
return false;
}

bool resizeWindow(const WindowHandle windowHandle, const MMSize newSize) {
Display* display = XGetMainDisplay();
if (display != NULL && windowHandle >= 0) {
auto status = XResizeWindow(display, windowHandle, newSize.width, newSize.height);
XFlush(display);
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 39dd098

Please sign in to comment.