mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 01:07:05 +09:00
Add locks around kwin/hyprland active window access
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
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<std::mutex> 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<std::mutex> lock(active_window_mutex);
|
||||
return active_hyprland_window.title;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,12 @@
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <mutex>
|
||||
|
||||
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<std::mutex> 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<std::mutex> lock(active_window_mutex);
|
||||
return active_kwin_window.title;
|
||||
}
|
||||
|
||||
bool get_current_kwin_window_fullscreen() {
|
||||
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||
return active_kwin_window.fullscreen;
|
||||
}
|
||||
|
||||
std::string get_current_kwin_window_monitor_name() {
|
||||
std::lock_guard<std::mutex> lock(active_window_mutex);
|
||||
return active_kwin_window.monitorName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user