mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Add locks around kwin/hyprland active window access
This commit is contained in:
@@ -4,10 +4,12 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
static ActiveHyprlandWindow active_hyprland_window;
|
static ActiveHyprlandWindow active_hyprland_window;
|
||||||
static bool hyprland_listener_thread_started = false;
|
static bool hyprland_listener_thread_started = false;
|
||||||
|
static std::mutex active_window_mutex;
|
||||||
|
|
||||||
static bool get_hyprland_socket_path(char *path, int path_len) {
|
static bool get_hyprland_socket_path(char *path, int path_len) {
|
||||||
const char* xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
|
const char* xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
|
||||||
@@ -83,6 +85,7 @@ namespace gsr {
|
|||||||
|
|
||||||
size_t pos = line.find(prefix);
|
size_t pos = line.find(prefix);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
|
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||||
active_hyprland_window.title = line.substr(pos + prefix.length());
|
active_hyprland_window.title = line.substr(pos + prefix.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +108,7 @@ namespace gsr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string get_current_hyprland_window_title() {
|
std::string get_current_hyprland_window_title() {
|
||||||
|
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||||
return active_hyprland_window.title;
|
return active_hyprland_window.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <cstdlib>
|
#include <mutex>
|
||||||
#include <cstring>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
static ActiveKwinWindow active_kwin_window;
|
static ActiveKwinWindow active_kwin_window;
|
||||||
static bool kwin_helper_thread_started = false;
|
static bool kwin_helper_thread_started = false;
|
||||||
|
static std::mutex active_window_mutex;
|
||||||
|
|
||||||
void kwin_script_thread() {
|
void kwin_script_thread() {
|
||||||
FILE* pipe = popen("gsr-kwin-helper", "r");
|
FILE* pipe = popen("gsr-kwin-helper", "r");
|
||||||
@@ -37,6 +34,7 @@ namespace gsr {
|
|||||||
line.pop_back();
|
line.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||||
size_t pos = std::string::npos;
|
size_t pos = std::string::npos;
|
||||||
if ((pos = line.find(prefix_title)) != std::string::npos) {
|
if ((pos = line.find(prefix_title)) != std::string::npos) {
|
||||||
std::string title = line.substr(pos + prefix_title.length());
|
std::string title = line.substr(pos + prefix_title.length());
|
||||||
@@ -54,14 +52,17 @@ namespace gsr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string get_current_kwin_window_title() {
|
std::string get_current_kwin_window_title() {
|
||||||
|
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||||
return active_kwin_window.title;
|
return active_kwin_window.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_current_kwin_window_fullscreen() {
|
bool get_current_kwin_window_fullscreen() {
|
||||||
|
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||||
return active_kwin_window.fullscreen;
|
return active_kwin_window.fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_current_kwin_window_monitor_name() {
|
std::string get_current_kwin_window_monitor_name() {
|
||||||
|
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||||
return active_kwin_window.monitorName;
|
return active_kwin_window.monitorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user