mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Simplify gsr-hyprland-helper, some cleanups
This commit is contained in:
@@ -1,30 +1,22 @@
|
||||
#include "../include/HyprlandWorkaround.hpp"
|
||||
#include "../include/Process.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <thread>
|
||||
|
||||
namespace gsr {
|
||||
static ActiveHyprlandWindow *active_hyprland_window = nullptr;
|
||||
static ActiveHyprlandWindow active_hyprland_window;
|
||||
static bool hyprland_listener_thread_started = false;
|
||||
|
||||
static void hyprland_listener_thread() {
|
||||
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
||||
|
||||
const std::string hyprland_helper_bin = (
|
||||
const char *hyprland_helper_bin =
|
||||
inside_flatpak ?
|
||||
"flatpak-spawn --host -- /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/gsr-hyprland-helper"
|
||||
: "/usr/bin/gsr-hyprland-helper"
|
||||
);
|
||||
: "gsr-hyprland-helper";
|
||||
|
||||
FILE* pipe = popen(hyprland_helper_bin.c_str(), "r");
|
||||
FILE* pipe = popen(hyprland_helper_bin, "r");
|
||||
if (!pipe) {
|
||||
std::cerr << "Failed to start gsr-hyprland-helper process\n";
|
||||
return;
|
||||
@@ -35,8 +27,9 @@ namespace gsr {
|
||||
char buffer[4096];
|
||||
const std::string prefix = "Window title changed: ";
|
||||
|
||||
std::string line;
|
||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
||||
std::string line(buffer);
|
||||
line = buffer;
|
||||
|
||||
if (!line.empty() && line.back() == '\n') {
|
||||
line.pop_back();
|
||||
@@ -44,9 +37,7 @@ namespace gsr {
|
||||
|
||||
size_t pos = line.find(prefix);
|
||||
if (pos != std::string::npos) {
|
||||
std::string title = line.substr(pos + prefix.length());
|
||||
|
||||
active_hyprland_window->title = title;
|
||||
active_hyprland_window.title = line.substr(pos + prefix.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,11 +45,7 @@ namespace gsr {
|
||||
}
|
||||
|
||||
std::string get_current_hyprland_window_title() {
|
||||
if (active_hyprland_window == nullptr) {
|
||||
return "Game";
|
||||
}
|
||||
|
||||
return active_hyprland_window->title;
|
||||
return active_hyprland_window.title;
|
||||
}
|
||||
|
||||
void start_hyprland_listener_thread() {
|
||||
@@ -66,10 +53,6 @@ namespace gsr {
|
||||
return;
|
||||
}
|
||||
|
||||
if (active_hyprland_window == nullptr) {
|
||||
active_hyprland_window = new ActiveHyprlandWindow();
|
||||
}
|
||||
|
||||
hyprland_listener_thread_started = true;
|
||||
|
||||
std::thread([&] {
|
||||
|
||||
@@ -6,29 +6,16 @@
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
namespace gsr {
|
||||
static ActiveKwinWindow *active_kwin_window = nullptr;
|
||||
static ActiveKwinWindow active_kwin_window;
|
||||
static bool kwin_helper_thread_started = false;
|
||||
|
||||
std::string get_current_kwin_window_title() {
|
||||
if (active_kwin_window == nullptr) {
|
||||
return "Game";
|
||||
}
|
||||
|
||||
return active_kwin_window->title;
|
||||
}
|
||||
|
||||
void kwin_script_thread() {
|
||||
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
||||
|
||||
const std::string kwin_helper_bin = inside_flatpak ? "/app/bin/gsr-kwin-helper" : "/usr/bin/gsr-kwin-helper";
|
||||
|
||||
FILE* pipe = popen(kwin_helper_bin.c_str(), "r");
|
||||
FILE* pipe = popen("gsr-kwin-helper", "r");
|
||||
if (!pipe) {
|
||||
std::cerr << "Failed to start gsr-kwin-helper process\n";
|
||||
return;
|
||||
@@ -39,8 +26,9 @@ namespace gsr {
|
||||
char buffer[4096];
|
||||
const std::string prefix = "Active window title set to: ";
|
||||
|
||||
std::string line;
|
||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
||||
std::string line(buffer);
|
||||
line = buffer;
|
||||
|
||||
if (!line.empty() && line.back() == '\n') {
|
||||
line.pop_back();
|
||||
@@ -50,26 +38,26 @@ namespace gsr {
|
||||
if (pos != std::string::npos) {
|
||||
std::string title = line.substr(pos + prefix.length());
|
||||
|
||||
if (title == "gsr ui") {
|
||||
continue; // ignore the overlay
|
||||
if (title == "gsr ui" || title == "gsr notify") {
|
||||
continue; // ignore the overlay and notification
|
||||
}
|
||||
|
||||
active_kwin_window->title = title;
|
||||
active_kwin_window.title = std::move(title);
|
||||
}
|
||||
}
|
||||
|
||||
pclose(pipe);
|
||||
}
|
||||
|
||||
std::string get_current_kwin_window_title() {
|
||||
return active_kwin_window.title;
|
||||
}
|
||||
|
||||
void start_kwin_helper_thread() {
|
||||
if (kwin_helper_thread_started) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (active_kwin_window == nullptr) {
|
||||
active_kwin_window = new ActiveKwinWindow();
|
||||
}
|
||||
|
||||
kwin_helper_thread_started = true;
|
||||
|
||||
std::thread([&] {
|
||||
|
||||
@@ -555,9 +555,7 @@ namespace gsr {
|
||||
|
||||
if (wm_name.find("Hyprland") != std::string::npos) {
|
||||
start_hyprland_listener_thread();
|
||||
}
|
||||
|
||||
if (wm_name == "KWin") {
|
||||
} else if (wm_name == "KWin") {
|
||||
start_kwin_helper_thread();
|
||||
}
|
||||
}
|
||||
@@ -1975,25 +1973,27 @@ namespace gsr {
|
||||
mgl_context *context = mgl_get_context();
|
||||
Display *display = (Display*)context->connection;
|
||||
const std::string video_filename = filepath_get_filename(video_filepath.c_str());
|
||||
|
||||
const Window gsr_ui_window = window ? (Window)window->get_system_handle() : None;
|
||||
std::string focused_window_name = get_window_name_at_cursor_position(display, gsr_ui_window);
|
||||
|
||||
const std::string wm_name = get_window_manager_name(display);
|
||||
const bool is_hyprland = wm_name.find("Hyprland") != std::string::npos;
|
||||
const bool is_kwin = wm_name == "KWin";
|
||||
|
||||
std::string focused_window_name;
|
||||
if (is_hyprland) {
|
||||
focused_window_name = get_current_hyprland_window_title();
|
||||
} else if (is_kwin) {
|
||||
focused_window_name = get_current_kwin_window_title();
|
||||
} else {
|
||||
const Window gsr_ui_window = window ? (Window)window->get_system_handle() : None;
|
||||
std::string focused_window_name = get_window_name_at_cursor_position(display, gsr_ui_window);
|
||||
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = get_focused_window_name(display, WindowCaptureType::FOCUSED, false);
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = "Game";
|
||||
}
|
||||
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = "Game";
|
||||
|
||||
string_replace_characters(focused_window_name.data(), "/\\", ' ');
|
||||
|
||||
std::string video_directory = filepath_get_directory(video_filepath.c_str()) + "/" + focused_window_name;
|
||||
|
||||
Reference in New Issue
Block a user