diff --git a/src/HyprlandWorkaround.cpp b/src/HyprlandWorkaround.cpp index f9089f2..92022ed 100644 --- a/src/HyprlandWorkaround.cpp +++ b/src/HyprlandWorkaround.cpp @@ -4,10 +4,12 @@ #include #include #include +#include namespace gsr { static ActiveHyprlandWindow active_hyprland_window; static bool hyprland_listener_thread_started = false; + static std::mutex active_window_mutex; static bool get_hyprland_socket_path(char *path, int path_len) { const char* xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"); @@ -83,6 +85,7 @@ namespace gsr { size_t pos = line.find(prefix); if (pos != std::string::npos) { + std::lock_guard lock(active_window_mutex); active_hyprland_window.title = line.substr(pos + prefix.length()); } } @@ -105,6 +108,7 @@ namespace gsr { } std::string get_current_hyprland_window_title() { + std::lock_guard lock(active_window_mutex); return active_hyprland_window.title; } diff --git a/src/KwinWorkaround.cpp b/src/KwinWorkaround.cpp index 2dcf7ce..6761a5b 100644 --- a/src/KwinWorkaround.cpp +++ b/src/KwinWorkaround.cpp @@ -5,15 +5,12 @@ #include #include #include -#include -#include -#include -#include -#include +#include namespace gsr { static ActiveKwinWindow active_kwin_window; static bool kwin_helper_thread_started = false; + static std::mutex active_window_mutex; void kwin_script_thread() { FILE* pipe = popen("gsr-kwin-helper", "r"); @@ -37,6 +34,7 @@ namespace gsr { line.pop_back(); } + std::lock_guard lock(active_window_mutex); size_t pos = std::string::npos; if ((pos = line.find(prefix_title)) != std::string::npos) { std::string title = line.substr(pos + prefix_title.length()); @@ -54,14 +52,17 @@ namespace gsr { } std::string get_current_kwin_window_title() { + std::lock_guard lock(active_window_mutex); return active_kwin_window.title; } bool get_current_kwin_window_fullscreen() { + std::lock_guard lock(active_window_mutex); return active_kwin_window.fullscreen; } std::string get_current_kwin_window_monitor_name() { + std::lock_guard lock(active_window_mutex); return active_kwin_window.monitorName; }