mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Added KWin workaround to get current window title
This commit is contained in:
76
src/KwinWorkaround.cpp
Normal file
76
src/KwinWorkaround.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "../include/KwinWorkaround.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#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 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 = getenv("FLATPAK_ID") != NULL;
|
||||
if(inside_flatpak) {
|
||||
std::cerr << "Sorry, KWin workaround isn't available for Flatpak yet. Stay tuned!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* pipe = popen("/usr/bin/gsr-kwin-helper", "r");
|
||||
if (!pipe) {
|
||||
std::cerr << "Failed to start gsr-kwin-helper process\n";
|
||||
return;
|
||||
}
|
||||
|
||||
std::cerr << "Started a KWin helper thread\n";
|
||||
|
||||
char buffer[4096];
|
||||
const std::string prefix = "Active window title set to: ";
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
||||
std::string line(buffer);
|
||||
|
||||
if (!line.empty() && line.back() == '\n') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
size_t pos = line.find(prefix);
|
||||
if (pos != std::string::npos) {
|
||||
std::string title = line.substr(pos + prefix.length());
|
||||
active_kwin_window->title = title;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(pipe);
|
||||
}
|
||||
|
||||
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([&] {
|
||||
kwin_script_thread();
|
||||
}).detach();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "../include/gui/ScreenshotSettingsPage.hpp"
|
||||
#include "../include/gui/GlobalSettingsPage.hpp"
|
||||
#include "../include/gui/Utils.hpp"
|
||||
#include "../include/KwinWorkaround.hpp"
|
||||
#include "../include/HyprlandWorkaround.hpp"
|
||||
#include "../include/gui/PageStack.hpp"
|
||||
#include "../include/WindowUtils.hpp"
|
||||
@@ -553,6 +554,10 @@ namespace gsr {
|
||||
if (get_window_manager_name(x11_dpy).find("Hyprland") != std::string::npos) {
|
||||
start_hyprland_listener_thread();
|
||||
}
|
||||
|
||||
if (get_window_manager_name(x11_dpy) == "KWin") {
|
||||
start_kwin_helper_thread();
|
||||
}
|
||||
}
|
||||
|
||||
update_led_indicator_after_settings_change();
|
||||
@@ -1974,10 +1979,16 @@ namespace gsr {
|
||||
|
||||
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";
|
||||
|
||||
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
|
||||
|
||||
if (is_hyprland) {
|
||||
focused_window_name = get_current_hyprland_window_title();
|
||||
}
|
||||
else if (is_kwin && !inside_flatpak) {
|
||||
focused_window_name = get_current_kwin_window_title();
|
||||
}
|
||||
else {
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = get_focused_window_name(display, WindowCaptureType::FOCUSED, false);
|
||||
|
||||
Reference in New Issue
Block a user