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,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
#include "../include/HyprlandWorkaround.hpp"
|
#include "../include/HyprlandWorkaround.hpp"
|
||||||
#include "../include/Process.hpp"
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <thread>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <thread>
|
||||||
#include <sys/un.h>
|
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
static ActiveHyprlandWindow *active_hyprland_window = nullptr;
|
static ActiveHyprlandWindow active_hyprland_window;
|
||||||
static bool hyprland_listener_thread_started = false;
|
static bool hyprland_listener_thread_started = false;
|
||||||
|
|
||||||
static void hyprland_listener_thread() {
|
static void hyprland_listener_thread() {
|
||||||
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
||||||
|
|
||||||
const std::string hyprland_helper_bin = (
|
const char *hyprland_helper_bin =
|
||||||
inside_flatpak ?
|
inside_flatpak ?
|
||||||
"flatpak-spawn --host -- /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/gsr-hyprland-helper"
|
"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) {
|
if (!pipe) {
|
||||||
std::cerr << "Failed to start gsr-hyprland-helper process\n";
|
std::cerr << "Failed to start gsr-hyprland-helper process\n";
|
||||||
return;
|
return;
|
||||||
@@ -35,8 +27,9 @@ namespace gsr {
|
|||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
const std::string prefix = "Window title changed: ";
|
const std::string prefix = "Window title changed: ";
|
||||||
|
|
||||||
|
std::string line;
|
||||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
||||||
std::string line(buffer);
|
line = buffer;
|
||||||
|
|
||||||
if (!line.empty() && line.back() == '\n') {
|
if (!line.empty() && line.back() == '\n') {
|
||||||
line.pop_back();
|
line.pop_back();
|
||||||
@@ -44,9 +37,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::string title = line.substr(pos + prefix.length());
|
active_hyprland_window.title = line.substr(pos + prefix.length());
|
||||||
|
|
||||||
active_hyprland_window->title = title;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,11 +45,7 @@ namespace gsr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string get_current_hyprland_window_title() {
|
std::string get_current_hyprland_window_title() {
|
||||||
if (active_hyprland_window == nullptr) {
|
return active_hyprland_window.title;
|
||||||
return "Game";
|
|
||||||
}
|
|
||||||
|
|
||||||
return active_hyprland_window->title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_hyprland_listener_thread() {
|
void start_hyprland_listener_thread() {
|
||||||
@@ -66,10 +53,6 @@ namespace gsr {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active_hyprland_window == nullptr) {
|
|
||||||
active_hyprland_window = new ActiveHyprlandWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
hyprland_listener_thread_started = true;
|
hyprland_listener_thread_started = true;
|
||||||
|
|
||||||
std::thread([&] {
|
std::thread([&] {
|
||||||
|
|||||||
@@ -6,29 +6,16 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <array>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
static ActiveKwinWindow *active_kwin_window = nullptr;
|
static ActiveKwinWindow active_kwin_window;
|
||||||
static bool kwin_helper_thread_started = false;
|
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() {
|
void kwin_script_thread() {
|
||||||
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
FILE* pipe = popen("gsr-kwin-helper", "r");
|
||||||
|
|
||||||
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");
|
|
||||||
if (!pipe) {
|
if (!pipe) {
|
||||||
std::cerr << "Failed to start gsr-kwin-helper process\n";
|
std::cerr << "Failed to start gsr-kwin-helper process\n";
|
||||||
return;
|
return;
|
||||||
@@ -39,8 +26,9 @@ namespace gsr {
|
|||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
const std::string prefix = "Active window title set to: ";
|
const std::string prefix = "Active window title set to: ";
|
||||||
|
|
||||||
|
std::string line;
|
||||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
||||||
std::string line(buffer);
|
line = buffer;
|
||||||
|
|
||||||
if (!line.empty() && line.back() == '\n') {
|
if (!line.empty() && line.back() == '\n') {
|
||||||
line.pop_back();
|
line.pop_back();
|
||||||
@@ -50,26 +38,26 @@ namespace gsr {
|
|||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
std::string title = line.substr(pos + prefix.length());
|
std::string title = line.substr(pos + prefix.length());
|
||||||
|
|
||||||
if (title == "gsr ui") {
|
if (title == "gsr ui" || title == "gsr notify") {
|
||||||
continue; // ignore the overlay
|
continue; // ignore the overlay and notification
|
||||||
}
|
}
|
||||||
|
|
||||||
active_kwin_window->title = title;
|
active_kwin_window.title = std::move(title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pclose(pipe);
|
pclose(pipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get_current_kwin_window_title() {
|
||||||
|
return active_kwin_window.title;
|
||||||
|
}
|
||||||
|
|
||||||
void start_kwin_helper_thread() {
|
void start_kwin_helper_thread() {
|
||||||
if (kwin_helper_thread_started) {
|
if (kwin_helper_thread_started) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active_kwin_window == nullptr) {
|
|
||||||
active_kwin_window = new ActiveKwinWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
kwin_helper_thread_started = true;
|
kwin_helper_thread_started = true;
|
||||||
|
|
||||||
std::thread([&] {
|
std::thread([&] {
|
||||||
|
|||||||
@@ -555,9 +555,7 @@ namespace gsr {
|
|||||||
|
|
||||||
if (wm_name.find("Hyprland") != std::string::npos) {
|
if (wm_name.find("Hyprland") != std::string::npos) {
|
||||||
start_hyprland_listener_thread();
|
start_hyprland_listener_thread();
|
||||||
}
|
} else if (wm_name == "KWin") {
|
||||||
|
|
||||||
if (wm_name == "KWin") {
|
|
||||||
start_kwin_helper_thread();
|
start_kwin_helper_thread();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1976,23 +1974,25 @@ namespace gsr {
|
|||||||
Display *display = (Display*)context->connection;
|
Display *display = (Display*)context->connection;
|
||||||
const std::string video_filename = filepath_get_filename(video_filepath.c_str());
|
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 std::string wm_name = get_window_manager_name(display);
|
||||||
const bool is_hyprland = wm_name.find("Hyprland") != std::string::npos;
|
const bool is_hyprland = wm_name.find("Hyprland") != std::string::npos;
|
||||||
const bool is_kwin = wm_name == "KWin";
|
const bool is_kwin = wm_name == "KWin";
|
||||||
|
|
||||||
|
std::string focused_window_name;
|
||||||
if (is_hyprland) {
|
if (is_hyprland) {
|
||||||
focused_window_name = get_current_hyprland_window_title();
|
focused_window_name = get_current_hyprland_window_title();
|
||||||
} else if (is_kwin) {
|
} else if (is_kwin) {
|
||||||
focused_window_name = get_current_kwin_window_title();
|
focused_window_name = get_current_kwin_window_title();
|
||||||
} else {
|
} 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())
|
if(focused_window_name.empty())
|
||||||
focused_window_name = get_focused_window_name(display, WindowCaptureType::FOCUSED, false);
|
focused_window_name = get_focused_window_name(display, WindowCaptureType::FOCUSED, false);
|
||||||
|
}
|
||||||
|
|
||||||
if(focused_window_name.empty())
|
if(focused_window_name.empty())
|
||||||
focused_window_name = "Game";
|
focused_window_name = "Game";
|
||||||
}
|
|
||||||
|
|
||||||
string_replace_characters(focused_window_name.data(), "/\\", ' ');
|
string_replace_characters(focused_window_name.data(), "/\\", ' ');
|
||||||
|
|
||||||
|
|||||||
@@ -1,243 +1,95 @@
|
|||||||
#include "unistd.h"
|
#include <unistd.h>
|
||||||
#include "string.h"
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
static bool get_hyprland_socket_path(char *path, int path_len) {
|
||||||
struct ActiveHyprlandWindow {
|
|
||||||
char* window_id;
|
|
||||||
char* title;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct ActiveHyprlandWindow* active_window;
|
|
||||||
|
|
||||||
|
|
||||||
const char* get_hyprland_socket_path() {
|
|
||||||
const char* xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
|
const char* xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
|
||||||
const char* instance_sig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
const char* instance_sig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
if (!xdg_runtime_dir || !instance_sig) {
|
if (!xdg_runtime_dir || !instance_sig) {
|
||||||
fprintf(stderr, "Error: Env vars not set.\n");
|
fprintf(stderr, "Error: gsr-hypland-helper: environment variables not set\n");
|
||||||
exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate buffer for the full path
|
if (snprintf(path, path_len, "%s/hypr/%s/.socket2.sock", xdg_runtime_dir, instance_sig) >= path_len) {
|
||||||
size_t path_len = strlen(xdg_runtime_dir) + strlen(instance_sig) + 32;
|
fprintf(stderr, "Error: gsr-hypland-helper: path to hyprland socket (%s/hypr/%s/.socket2.sock) is more than %d characters long\n", xdg_runtime_dir, instance_sig, path_len);
|
||||||
char* socket_path = malloc(path_len);
|
return false;
|
||||||
if (!socket_path) {
|
|
||||||
fprintf(stderr, "Error: Memory allocation failed.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(socket_path, path_len, "%s/hypr/%s/.socket2.sock", xdg_runtime_dir, instance_sig);
|
return true;
|
||||||
return socket_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_window_title(const char *window_title) {
|
||||||
void print_window_title(void) {
|
if (window_title[0] == 0) {
|
||||||
if (strlen(active_window->title) == 0) {
|
|
||||||
printf("Window title changed: %s\n", "Desktop");
|
printf("Window title changed: %s\n", "Desktop");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Window title changed: %s\n", active_window->title);
|
printf("Window title changed: %s\n", window_title);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int handle_ipc(void) {
|
||||||
void handle_ipc(void) {
|
const int sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
int sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sock_fd == -1) {
|
if (sock_fd == -1) {
|
||||||
perror("socket");
|
perror("Error: gsr-hyprland-helper: socket");
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
active_window = malloc(sizeof(struct ActiveHyprlandWindow));
|
|
||||||
active_window->window_id = NULL;
|
|
||||||
active_window->title = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
|
if (!get_hyprland_socket_path(addr.sun_path, sizeof(addr.sun_path))) {
|
||||||
const char* socket_path = get_hyprland_socket_path();
|
return 1;
|
||||||
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
}
|
||||||
|
|
||||||
|
|
||||||
if (connect(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
if (connect(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||||
perror("connect");
|
perror("Error: gsr-hyprland-helper: connect");
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
free((void*)socket_path);
|
return 1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Info: gsr-hyprland-helper: connected to Hyprland socket: %s\n", addr.sun_path);
|
||||||
|
|
||||||
printf("Connected to Hyprland socket: %s\n", socket_path);
|
FILE *sock_file = fdopen(sock_fd, "r");
|
||||||
fflush(stdout);
|
if (!sock_file) {
|
||||||
free((void*)socket_path);
|
perror("Error: gsr-hyprland-helper: fdopen");
|
||||||
|
|
||||||
|
|
||||||
char buffer[4096];
|
|
||||||
char* incomplete_line = NULL;
|
|
||||||
size_t incomplete_len = 0;
|
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
ssize_t bytes_read = read(sock_fd, buffer, sizeof(buffer));
|
|
||||||
|
|
||||||
|
|
||||||
if (bytes_read == 0) {
|
|
||||||
fprintf(stderr, "Connection closed by Hyprland\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (bytes_read < 0) {
|
|
||||||
perror("read");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t total_len = incomplete_len + bytes_read;
|
|
||||||
char *data = malloc(total_len + 1);
|
|
||||||
if (!data) {
|
|
||||||
perror("malloc");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (incomplete_line) {
|
|
||||||
memcpy(data, incomplete_line, incomplete_len);
|
|
||||||
fflush(stdout);
|
|
||||||
free(incomplete_line);
|
|
||||||
incomplete_line = NULL;
|
|
||||||
}
|
|
||||||
memcpy(data + incomplete_len, buffer, bytes_read);
|
|
||||||
data[total_len] = '\0';
|
|
||||||
|
|
||||||
|
|
||||||
char* line_start = data;
|
|
||||||
char* newline_pos;
|
|
||||||
|
|
||||||
|
|
||||||
while ((newline_pos = strchr(line_start, '\n')) != NULL) {
|
|
||||||
*newline_pos = '\0';
|
|
||||||
char *line = line_start;
|
|
||||||
|
|
||||||
|
|
||||||
char *delimiter = strstr(line, ">>");
|
|
||||||
|
|
||||||
|
|
||||||
if (delimiter != NULL) {
|
|
||||||
*delimiter = '\0';
|
|
||||||
char *event_name = line;
|
|
||||||
char *event_data = delimiter + 2;
|
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(event_name, "activewindowv2") == 0) {
|
|
||||||
fflush(stdout);
|
|
||||||
if (active_window->window_id) {
|
|
||||||
free(active_window->window_id);
|
|
||||||
}
|
|
||||||
active_window->window_id = strdup(event_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(event_name, "activewindow") == 0) {
|
|
||||||
char *title_delimiter = strchr(event_data, ',');
|
|
||||||
if (title_delimiter != NULL) {
|
|
||||||
char *window_title = title_delimiter + 1;
|
|
||||||
if (strcmp(window_title, "gsr ui") == 0 ||
|
|
||||||
strcmp(window_title, "gsr notify") == 0) {
|
|
||||||
line_start = newline_pos + 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
if (active_window->title) {
|
|
||||||
free(active_window->title);
|
|
||||||
}
|
|
||||||
active_window->title = strdup(window_title);
|
|
||||||
print_window_title();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(event_name, "windowtitlev2") == 0) {
|
|
||||||
char *data_delimiter = strchr(event_data, ',');
|
|
||||||
if (data_delimiter != NULL) {
|
|
||||||
*data_delimiter = '\0';
|
|
||||||
char *win_id = event_data;
|
|
||||||
char *new_window_title = data_delimiter + 1;
|
|
||||||
|
|
||||||
if (strcmp(new_window_title, "gsr ui") == 0 ||
|
|
||||||
strcmp(new_window_title, "gsr notify") == 0) {
|
|
||||||
line_start = newline_pos + 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(active_window->window_id, win_id) != 0) {
|
|
||||||
line_start = newline_pos + 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
if (active_window->title) {
|
|
||||||
free(active_window->title);
|
|
||||||
}
|
|
||||||
active_window->title = strdup(new_window_title);
|
|
||||||
print_window_title();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
line_start = newline_pos + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t remaining = strlen(line_start);
|
|
||||||
if (remaining > 0) {
|
|
||||||
incomplete_line = malloc(remaining + 1);
|
|
||||||
if (incomplete_line) {
|
|
||||||
memcpy(incomplete_line, line_start, remaining);
|
|
||||||
incomplete_line[remaining] = '\0';
|
|
||||||
incomplete_len = remaining;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
incomplete_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (incomplete_line) {
|
|
||||||
fflush(stdout);
|
|
||||||
free(incomplete_line);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (active_window) {
|
|
||||||
if (active_window->window_id) {
|
|
||||||
free(active_window->window_id);
|
|
||||||
}
|
|
||||||
if (active_window->title) {
|
|
||||||
free(active_window->title);
|
|
||||||
}
|
|
||||||
free(active_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[1024];
|
||||||
|
while (fgets(buffer, sizeof(buffer), sock_file)) {
|
||||||
|
int line_len = strlen(buffer);
|
||||||
|
if(line_len > 0 && buffer[line_len - 1] == '\n') {
|
||||||
|
buffer[line_len - 1] = '\0';
|
||||||
|
line_len -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
if(line_len >= 14 && memcmp(buffer, "activewindow>>", 14) == 0) {
|
||||||
handle_ipc();
|
char *window_id = buffer + 14;
|
||||||
|
char *window_title = strchr(buffer + 14, ',');
|
||||||
|
if(!window_title)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
window_title[0] = '\0';
|
||||||
|
window_title += 1;
|
||||||
|
if(strcmp(window_id, "gsr-ui") == 0 || strcmp(window_id, "gsr-notify") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
print_window_title(window_title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(sock_file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
return handle_ipc();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#include "dbus/dbus.h"
|
#include <dbus/dbus.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
const char* INTROSPECTION_XML =
|
static const char* INTROSPECTION_XML =
|
||||||
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
|
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
|
||||||
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
|
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
|
||||||
"<node>\n"
|
"<node>\n"
|
||||||
@@ -32,43 +31,42 @@ public:
|
|||||||
|
|
||||||
connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
||||||
if (dbus_error_is_set(&err)) {
|
if (dbus_error_is_set(&err)) {
|
||||||
std::cerr << "Failed to connect to session bus: " << err.message << "\n";
|
std::cerr << "Error: gsr-kwin-helper: failed to connect to session bus: " << err.message << "\n";
|
||||||
dbus_error_free(&err);
|
dbus_error_free(&err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
std::cerr << "Connection is null\n";
|
std::cerr << "Error: gsr-kwin-helper: connection is null\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = dbus_bus_request_name(connection, "com.dec05eba.gsr_kwin_helper",
|
int ret = dbus_bus_request_name(connection, "com.dec05eba.gsr_kwin_helper",
|
||||||
DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
|
DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
|
||||||
if (dbus_error_is_set(&err)) {
|
if (dbus_error_is_set(&err)) {
|
||||||
std::cerr << "Failed to request name: " << err.message << "\n";
|
std::cerr << "Error: gsr-kwin-helper: failed to request name: " << err.message << "\n";
|
||||||
dbus_error_free(&err);
|
dbus_error_free(&err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
|
if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
|
||||||
std::cerr << "Not primary owner of the name\n";
|
std::cerr << "Error: gsr-kwin-helper: not primary owner of the name\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "DBus server initialized on com.dec05eba.gsr_kwin_helper\n";
|
std::cerr << "Info: gsr-kwin-helper: DBus server initialized on com.dec05eba.gsr_kwin_helper\n";
|
||||||
|
|
||||||
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
const bool inside_flatpak = access("/app/manifest.json", F_OK) == 0;
|
||||||
|
|
||||||
std::string helper_path = (
|
const char *helper_path =
|
||||||
!inside_flatpak
|
!inside_flatpak
|
||||||
? KWIN_HELPER_SCRIPT_PATH
|
? KWIN_HELPER_SCRIPT_PATH
|
||||||
: "/var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/share/gsr-ui/gsrkwinhelper.js"
|
: "/var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/share/gsr-ui/gsrkwinhelper.js";
|
||||||
);
|
|
||||||
|
|
||||||
std::cout << "KWin script path: " << helper_path << std::endl;
|
std::cerr << "Info: gsr-kwin-helper: KWin script path: " << helper_path << std::endl;
|
||||||
|
|
||||||
if (!load_kwin_script(connection, helper_path.c_str())) {
|
if (!load_kwin_script(connection, helper_path)) {
|
||||||
std::cerr << "Warning: Failed to load KWin script\n";
|
std::cerr << "Warning: gsr-kwin-helper: failed to load KWin script\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -164,7 +162,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
std::cerr << "Failed to create message for " << method << "\n";
|
std::cerr << "Error: gsr-kwin-helper: failed to create message for " << method << "\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +182,7 @@ public:
|
|||||||
dbus_message_unref(msg);
|
dbus_message_unref(msg);
|
||||||
|
|
||||||
if (dbus_error_is_set(&err)) {
|
if (dbus_error_is_set(&err)) {
|
||||||
std::cerr << "Error calling " << method << ": " << err.message << "\n";
|
std::cerr << "Error: gsr-kwin-helper: error calling " << method << ": " << err.message << "\n";
|
||||||
dbus_error_free(&err);
|
dbus_error_free(&err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -201,16 +199,16 @@ public:
|
|||||||
call_kwin_method(conn, "unloadScript", "gsrkwinhelper");
|
call_kwin_method(conn, "unloadScript", "gsrkwinhelper");
|
||||||
|
|
||||||
if (!call_kwin_method(conn, "loadScript", script_path, "gsrkwinhelper")) {
|
if (!call_kwin_method(conn, "loadScript", script_path, "gsrkwinhelper")) {
|
||||||
std::cerr << "Failed to load KWin script\n";
|
std::cerr << "Error: gsr-kwin-helper: failed to load KWin script\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!call_kwin_method(conn, "start")) {
|
if (!call_kwin_method(conn, "start")) {
|
||||||
std::cerr << "Failed to start KWin script\n";
|
std::cerr << "Error: gsr-kwin-helper: failed to start KWin script\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "KWin script loaded and started successfully\n";
|
std::cerr << "Info: gsr-kwin-helper: KWin script loaded and started successfully\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user