Skip to content

Commit

Permalink
Fix #32 (#34)
Browse files Browse the repository at this point in the history
* ✏️ Fixed typo

Fixed typo on line 313

* 🙈 Add executable to gitignore

* 🩹 Uses active window

[LINUX] Now uses active foregroud window instead of whatever window is below the cursor

* 🩹 Fix #32

Fixed mouse not being aligned correctly with cursor position.

Added comments explaining variables and changes some variable names

* 🔨 Changed output directory

Compiled binaries now output to the source directory as opposed to ./build/bin/
  • Loading branch information
KeithBrown39423 authored Jul 5, 2023
1 parent cf02cf1 commit 5d17dd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ CMakeFiles
bongo
build
NOTE
SFML
SFML
bongocat
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/")

set(CMAKE_CXX_STANDARD 17)
Expand Down
27 changes: 17 additions & 10 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,43 +295,50 @@ std::pair<double, double> get_xy() {
}
CFRelease(windows);
#elif defined(__unix__) || defined(__unix)
double letter_x = 0;
double letter_y = 0;
int x_pos = 0;
int y_pos = 0;
double s_height = horizontal;
double s_width = vertical;

s_width = horizontal;
s_height = vertical;
letter_x = 0;
letter_y = 0;

double x = 0, y = 0;
int px = 0, py = 0;

if (xdo_get_mouse_location(xdo, &px, &py, NULL) == 0) {
Window window_under_cursor;
if (xdo_get_window_at_mouse(xdo, &window_under_cursor) == 0) {
if (xdo_get_active_window(xdo, &window_under_cursor) == 0) {
unsigned int width_ret, height_ret;
if (xdo_get_window_size(xdo, window_under_cursor, &width_ret, &height_ret) == 0) {
s_width = width_ret;
s_height = height_ret;
}
}

double fx = (1.0 * px - letter_x) / s_width;
xdo_get_window_location(xdo, window_under_cursor, &x_pos, &y_pos, NULL);

/**
* Ratio of the mouse position to the window size on the x axis
*/
double fx = (1.0 * px - x_pos) / s_width;

if (is_left_handed) {
fx = 1 - fx;
}

double fy = (1.0 * py - letter_y) / s_height;

/**
* Ratio of the mouse position to the window size on the y axis
*/
double fy = (1.0 * py - y_pos) / s_height;

fx = std::min(fx, 1.0);
fx = std::max(fx, 0.0);

fy = std::min(fy, 1.0);
fy = std::max(fy, 0.0);

/**
* Magic numbers to position the mouse cursor on the mouse pad correctly
*/
x = -97 * fx + 44 * fy + 184;
y = -76 * fx - 40 * fy + 324;
}
Expand Down

0 comments on commit 5d17dd4

Please sign in to comment.