Skip to content

Commit 82ca3e1

Browse files
authored
Feature/9/unicode keyboard (#135)
* (#9) macOS unicode migration: Migrated mouse.c * (#9) macOS unicode migration: Migrated keypress.c * (#9) macOS unicode migration: Migrated mouse.h and keypress.h * (#9) macOS unicode migration: Migrated deadbeef_rand.c * (#9) macOS unicode migration: Removed typeStringDelayed, adjusted signature of typeString * (#9) macOS unicode migration: Adjusted macOS source files * (#9) macOS unicode migration: Limit delays between keypresses so they're only applied in case of two or more characters * (#9) Windows unicode support for typeString * (#9) Switched to using libxdo for typeString * (#9) Switched to using libxdo for typeString * (#9) Install libxkbcommon-dev and libxinerama-dev on Linux build hosts * (#9) Fix typo in packagename libx11-dev * (#9) Convert screen.c and mouse.c * (#9) Migrated screengrab.c * (#9) Converted highlightwindow.c * (#9) Further migration * (#9) macOS C++ migration * (#9) Fixed xdisplay include in window_manager.cc * (#9) Get rid of C-style memory management for image data * (#9) Wire up updated image data handling * (#9) Migrated Linux screengrab implementation * (#9) Windows C++ implementation for screengrab
1 parent 52d9097 commit 82ca3e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3761
-694
lines changed

Diff for: .github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
node-version: ${{matrix.node}}
2323
- name: Configure Linux environment
2424
if: ${{matrix.os == 'ubuntu-latest'}}
25-
run: sudo apt-get install -y cmake libx11-dev zlib1g-dev libpng-dev libxtst-dev build-essential
25+
run: sudo apt-get install -y cmake libx11-dev libxtst-dev libxinerama-dev libxkbcommon-dev build-essential
2626
- name: Install
2727
run: npm run patch && npm i
2828
- name: Build

Diff for: .github/workflows/snapshot_release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
node-version: ${{matrix.node}}
2020
- name: Configure Linux environment
2121
if: ${{matrix.os == 'ubuntu-latest'}}
22-
run: sudo apt-get install -y cmake libx11-dev zlib1g-dev libpng-dev libxtst-dev build-essential
22+
run: sudo apt-get install -y cmake libx11-dev libxtst-dev libxinerama-dev libxkbcommon-dev build-essential
2323
- name: Install
2424
run: npm run patch && npm i
2525
- name: Build

Diff for: .github/workflows/tagged_release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
node-version: ${{matrix.node}}
2020
- name: Configure Linux environment
2121
if: ${{matrix.os == 'ubuntu-latest'}}
22-
run: sudo apt-get install -y cmake libx11-dev zlib1g-dev libpng-dev libxtst-dev build-essential
22+
run: sudo apt-get install -y cmake libx11-dev libxtst-dev libxinerama-dev libxkbcommon-dev build-essential
2323
- name: Install
2424
run: npm run patch && npm i
2525
- name: Build

Diff for: CMakeLists.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
cmake_minimum_required(VERSION 3.20)
22
set(CMAKE_CXX_STANDARD 17)
3+
set(CMAKE_C_STANDARD 99)
34

45
project(libnut)
56

7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8+
69
# Source
7-
set(SOURCE_FILES "src/main.cc" "src/deadbeef_rand.c" "src/MMBitmap.c")
10+
set(SOURCE_FILES "src/main.cc" "src/deadbeef_rand.cc" "src/Bitmap.cc")
811
if (UNIX AND NOT APPLE)
9-
set(SOURCE_FILES "${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")
12+
set(SOURCE_FILES "${SOURCE_FILES}" "src/linux/keycode.cc" "src/linux/keypress.cc" "src/linux/mouse.cc" "src/linux/screen.cc" "src/linux/screengrab.cc" "src/linux/xdisplay.cc" "src/linux/highlightwindow.cc" "src/linux/window_manager.cc" "src/linux/libxdo/xdo.c" "src/linux/libxdo/xdo_search.c")
1013
elseif (UNIX AND APPLE)
11-
set(SOURCE_FILES "${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.c" "src/macos/highlightwindow.m" "src/macos/window_manager.mm")
14+
set(SOURCE_FILES "${SOURCE_FILES}" "src/macos/keycode.cc" "src/macos/keypress.cc" "src/macos/mouse.cc" "src/macos/mouse_utils.mm" "src/macos/screen.cc" "src/macos/screengrab.cc" "src/macos/highlightwindow.mm" "src/macos/window_manager.mm")
1215
elseif (WIN32)
13-
set(SOURCE_FILES "${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")
16+
set(SOURCE_FILES "${SOURCE_FILES}" "src/win32/keycode.cc" "src/win32/keypress.cc" "src/win32/mouse.cc" "src/win32/screen.cc" "src/win32/screengrab.cc" "src/win32/highlightwindow.cc" "src/win32/window_manager.cc")
1417
endif()
1518
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
1619

@@ -28,11 +31,13 @@ elseif (UNIX AND NOT APPLE)
2831
message(STATUS "Linux build")
2932
set(LIBS "${LIBS}" "-lX11")
3033
set(LIBS "${LIBS}" "-lXtst")
34+
set(LIBS "${LIBS}" "-lXinerama")
35+
set(LIBS "${LIBS}" "-lxkbcommon")
3136
endif()
3237

3338
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
3439
message(STATUS "No MSVC compiler in use")
35-
set(CMAKE_CXX_FLAGS "-Wall -Wparentheses -Winline -Wbad-function-cast -Wdisabled-optimization -Wextra")
40+
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wparentheses -Winline -Wdisabled-optimization -Wextra")
3641
else()
3742
message(STATUS "MSVC compiler in use")
3843
set(CMAKE_CXX_FLAGS "/Wall /W4 /EHsc")

Diff for: src/Bitmap.cc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "Bitmap.h"
2+
3+
Bitmap::Bitmap(uint8_t *buffer, size_t width, size_t height, size_t byteWidth,
4+
size_t bitsPerPixel)
5+
: imageBuffer(buffer), width(width), height(height), byteWidth(byteWidth),
6+
bitsPerPixel(bitsPerPixel) {}
7+
8+
Bitmap::~Bitmap() {
9+
delete[] this->imageBuffer;
10+
}
11+
12+
size_t Bitmap::getBufferSize() noexcept {
13+
return this->byteWidth * this->height;
14+
}
15+
16+
uint8_t *Bitmap::getImageBuffer() noexcept { return this->imageBuffer; }
17+
18+
size_t Bitmap::getWidth() noexcept { return this->width; }
19+
20+
size_t Bitmap::getHeight() noexcept { return this->height; }
21+
22+
size_t Bitmap::getByteWidth() noexcept { return this->byteWidth; }
23+
24+
size_t Bitmap::getBitsPerPixel() noexcept { return this->bitsPerPixel; }
25+
26+
size_t Bitmap::getBytesPerPixel() noexcept { return this->bitsPerPixel / 8; }

Diff for: src/Bitmap.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
#ifndef BITMAP_H
3+
#define BITMAP_H
4+
5+
#include <memory>
6+
7+
class Bitmap {
8+
public:
9+
Bitmap(uint8_t* buffer, size_t width, size_t height,
10+
size_t byteWidth, size_t bitsPerPixel);
11+
12+
~Bitmap();
13+
14+
size_t getBufferSize() noexcept;
15+
uint8_t* getImageBuffer() noexcept;
16+
17+
size_t getWidth() noexcept;
18+
size_t getHeight() noexcept;
19+
size_t getByteWidth() noexcept;
20+
size_t getBitsPerPixel() noexcept;
21+
size_t getBytesPerPixel() noexcept;
22+
23+
private:
24+
uint8_t* imageBuffer;
25+
size_t width;
26+
size_t height;
27+
size_t byteWidth;
28+
size_t bitsPerPixel;
29+
};
30+
31+
#endif

Diff for: src/MMBitmap.c

-94
This file was deleted.

Diff for: src/MMBitmap.h

-59
This file was deleted.
File renamed without changes.

Diff for: src/highlightwindow.h

-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22
#ifndef HIGHLIGHT_WINDOW_H
33
#define HIGHLIGHT_WINDOW_H
44

5-
#ifdef __cplusplus
6-
extern "C"
7-
{
8-
#endif
9-
105
#include <stdint.h>
116

127
void showHighlightWindow(int32_t x, int32_t y, int32_t width, int32_t height, long duration, float opacity);
138

14-
#ifdef __cplusplus
15-
}
16-
#endif
17-
189
#endif

Diff for: src/keycode.h

-9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
#include "os.h"
66

7-
#ifdef __cplusplus
8-
extern "C"
9-
{
10-
#endif
11-
127
#if defined(IS_MACOSX)
138

149
#include <Carbon/Carbon.h> /* Really only need <HIToolbox/Events.h> */
@@ -301,9 +296,5 @@ typedef int MMKeyCode;
301296
* given ASCII character. */
302297
MMKeyCode keyCodeForChar(const char c);
303298

304-
#ifdef __cplusplus
305-
}
306-
#endif
307-
308299
#endif /* KEYCODE_H */
309300

Diff for: src/keypress.h

+3-18
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
#include "xdisplay.h"
99
#endif
1010

11+
#include <string>
1112
#include <stdbool.h>
12-
#ifdef __cplusplus
13-
extern "C"
14-
{
15-
#endif
13+
1614
#if defined(IS_MACOSX)
1715

1816
typedef enum {
@@ -68,19 +66,6 @@ void toggleKey(char c, const bool down, MMKeyFlags flags);
6866
void tapKey(char c, MMKeyFlags flags);
6967

7068
/* Sends a UTF-8 string without modifiers. */
71-
void typeString(const char *str);
72-
73-
/* Macro to convert WPM to CPM integers.
74-
* (the average English word length is 5.1 characters.) */
75-
#define WPM_TO_CPM(WPM) (unsigned)(5.1 * WPM)
76-
77-
/* Sends a string with partially random delays between each letter. Note that
78-
* deadbeef_srand() must be called before this function if you actually want
79-
* randomness. */
80-
void typeStringDelayed(const char *str, const unsigned cpm);
81-
82-
#ifdef __cplusplus
83-
}
84-
#endif
69+
void typeString(const std::u16string &str);
8570

8671
#endif /* KEYPRESS_H */

Diff for: src/linux/highlightwindow.c renamed to src/linux/highlightwindow.cc

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
void showHighlightWindow(int32_t x, int32_t y, int32_t width, int32_t height, long duration, float opacity) {
77
Display *d = XOpenDisplay(NULL);
88
Window root = DefaultRootWindow(d);
9-
int default_screen = XDefaultScreen(d);
109

1110
XSetWindowAttributes attrs;
1211
attrs.override_redirect = True;
File renamed without changes.

0 commit comments

Comments
 (0)