Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
muwoo committed Sep 26, 2023
2 parents 6ee31aa + ee0e04a commit 4305481
Show file tree
Hide file tree
Showing 60 changed files with 639 additions and 11,101 deletions.
22 changes: 3 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 17)

project(libnut)
project(rubick-addon)

# Source
set(SOURCE_FILES
src/main.cc
src/deadbeef_rand.c
src/MMBitmap.c
)

if (UNIX AND NOT APPLE)
list(APPEND SOURCE_FILES
src/linux/keycode.c
src/linux/keypress.c
src/linux/mouse.c
src/linux/screen.c
src/linux/screengrab.c
src/linux/xdisplay.c
src/linux/highlightwindow.c
src/linux/window_manager.cc
)
elseif (UNIX AND APPLE)
list(APPEND SOURCE_FILES
src/macos/keycode.c
src/macos/keypress.c
src/macos/mouse.c
src/macos/mouse_utils.mm
src/macos/screen.c
src/macos/screengrab.m
src/macos/highlightwindow.m
src/macos/window_manager.mm
src/macos/clipboard.mm
)
elseif (WIN32)
list(APPEND SOURCE_FILES
src/win32/keycode.c
src/win32/keypress.c
src/win32/mouse.c
src/win32/screen.c
src/win32/screengrab.c
src/win32/highlightwindow.c
src/win32/window_manager.cc
src/win32/clipboard.cc
)
endif()

Expand Down
32 changes: 19 additions & 13 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@ export function keyToggle(
): void;
export function typeString(string: string): void;
export function typeStringDelayed(string: string, cpm: number): void;
export function setMouseDelay(delay: number): void;
export function moveMouse(x: number, y: number): void;
export function moveMouseSmooth(x: number, y: number): void;
export function mouseClick(button?: string, double?: boolean): void;
export function mouseToggle(down?: string, button?: string): void;
export function dragMouse(x: number, y: number): void;
export function scrollMouse(x: number, y: number): void;
export function getMousePos(): Point;
export function getScreenSize(): Size;
export function getWindows(): number[];
export function getActiveWindow(): number;
export function getWindowRect(handle: number): Rect;
export function getWindowTitle(handle: number): string;
export function readFilePaths(): 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 {Rect} rect - The new size of the window.
* @returns {void}
*/
export function resizeWindow(handle: number, rect: Rect): void

export const screen: Screen;
52 changes: 5 additions & 47 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
let libnut;
let rubickAddon;

if (process.platform === 'darwin') {
libnut = require("./permissionCheck");
rubickAddon = require("./permissionCheck");
} else {
libnut = require("bindings")("libnut");
}

module.exports = libnut;

module.exports.screen = {};

function bitmap(width, height, byteWidth, bitsPerPixel, bytesPerPixel, image) {
this.width = width;
this.height = height;
this.byteWidth = byteWidth;
this.bitsPerPixel = bitsPerPixel;
this.bytesPerPixel = bytesPerPixel;
this.image = image;
rubickAddon = require("bindings")("rubick-addon");
}

module.exports.screen.highlight = function (x, y, width, height, duration, opacity) {
let highlightOpacity = (opacity < 0) ? 0 : opacity;
highlightOpacity = (highlightOpacity > 1) ? 1 : highlightOpacity;
const highlightDuration = (duration < 0) ? 0 : duration;

libnut.highlight(x, y, width, height, highlightDuration, highlightOpacity);
}

module.exports.screen.capture = function (x, y, width, height) {
let b;
//If coords have been passed, use them.
if (
typeof x !== "undefined" &&
typeof y !== "undefined" &&
typeof width !== "undefined" &&
typeof height !== "undefined"
) {
b = libnut.captureScreen(x, y, width, height);
} else {
b = libnut.captureScreen();
}

return new bitmap(
b.width,
b.height,
b.byteWidth,
b.bitsPerPixel,
b.bytesPerPixel,
b.image
);
};
module.exports = rubickAddon;
Loading

0 comments on commit 4305481

Please sign in to comment.