From d08ea692771caa8e385412c2f992089672773e30 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 3 May 2025 12:03:43 +0200 Subject: Keep keyboard led when turning on global hotkeys, move files --- src/CursorTracker/CursorTrackerX11.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/CursorTracker/CursorTrackerX11.cpp (limited to 'src/CursorTracker/CursorTrackerX11.cpp') diff --git a/src/CursorTracker/CursorTrackerX11.cpp b/src/CursorTracker/CursorTrackerX11.cpp new file mode 100644 index 0000000..7c98f4d --- /dev/null +++ b/src/CursorTracker/CursorTrackerX11.cpp @@ -0,0 +1,29 @@ +#include "../../include/CursorTracker/CursorTrackerX11.hpp" +#include "../../include/WindowUtils.hpp" + +namespace gsr { + CursorTrackerX11::CursorTrackerX11(Display *dpy) : dpy(dpy) { + + } + + std::optional CursorTrackerX11::get_latest_cursor_info() { + Window window = None; + const auto cursor_pos = get_cursor_position(dpy, &window); + const auto monitors = get_monitors(dpy); + std::string monitor_name; + + for(const auto &monitor : monitors) { + if(cursor_pos.x >= monitor.position.x && cursor_pos.x <= monitor.position.x + monitor.size.x + && cursor_pos.y >= monitor.position.y && cursor_pos.y <= monitor.position.y + monitor.size.y) + { + monitor_name = monitor.name; + break; + } + } + + if(monitor_name.empty()) + return std::nullopt; + + return CursorInfo{ cursor_pos, std::move(monitor_name) }; + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2