diff --git a/.gitignore b/.gitignore index 34a9c9f..9526061 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ CMakeFiles bongo build NOTE -SFML \ No newline at end of file +SFML +bongocat \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c754a21..0f59938 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/input.cpp b/src/input.cpp index a21f12e..d2d23bc 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -295,22 +295,17 @@ std::pair 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; @@ -318,13 +313,22 @@ std::pair get_xy() { } } - 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); @@ -332,6 +336,9 @@ std::pair get_xy() { 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; }