Re-add kwin and hyprland helper to get window title, this time without a thread

This commit is contained in:
dec05eba
2026-04-27 00:04:29 +02:00
parent 57c60b6aee
commit 71d7477aea
15 changed files with 318 additions and 187 deletions

View File

@@ -0,0 +1,20 @@
#pragma once
#include <string>
namespace gsr {
class DesktopEnvironment {
public:
DesktopEnvironment() = default;
DesktopEnvironment(const DesktopEnvironment&) = delete;
DesktopEnvironment& operator=(const DesktopEnvironment&) = delete;
virtual ~DesktopEnvironment() = default;
virtual bool start() = 0;
virtual void update() = 0;
// Return an empty string if none
virtual std::string get_focused_window_title() = 0;
// Return an empty string if unknown
//virtual std::string get_focused_monitor_name() = 0;
};
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "DesktopEnvironment.hpp"
#include <sys/types.h>
#include <stdio.h>
namespace gsr {
class DesktopEnvironmentHyprland : public DesktopEnvironment {
public:
DesktopEnvironmentHyprland() = default;
DesktopEnvironmentHyprland(const DesktopEnvironmentHyprland&) = delete;
DesktopEnvironmentHyprland& operator=(const DesktopEnvironmentHyprland&) = delete;
~DesktopEnvironmentHyprland();
bool start() override;
void update() override;
std::string get_focused_window_title() override;
//std::string get_focused_monitor_name() override;
private:
void shutdown();
private:
pid_t process_id = -1;
FILE *stdout_file = nullptr;
int read_fd = -1;
char line_buffer[1024];
std::string line;
std::string window_title;
};
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include "DesktopEnvironment.hpp"
namespace gsr {
class DesktopEnvironmentKde : public DesktopEnvironment {
public:
DesktopEnvironmentKde() = default;
DesktopEnvironmentKde(const DesktopEnvironmentKde&) = delete;
DesktopEnvironmentKde& operator=(const DesktopEnvironmentKde&) = delete;
~DesktopEnvironmentKde();
bool start() override;
void update() override;
std::string get_focused_window_title() override;
//std::string get_focused_monitor_name() override;
private:
void shutdown();
private:
pid_t process_id = -1;
FILE *stdout_file = nullptr;
int read_fd = -1;
char line_buffer[1024];
std::string line;
std::string window_title;
std::string monitor_name;
};
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "DesktopEnvironment.hpp"
#include <X11/Xlib.h>
namespace gsr {
class DesktopEnvironmentX11 : public DesktopEnvironment {
public:
DesktopEnvironmentX11(Display *dpy) : dpy(dpy) {}
DesktopEnvironmentX11(const DesktopEnvironmentX11&) = delete;
DesktopEnvironmentX11& operator=(const DesktopEnvironmentX11&) = delete;
~DesktopEnvironmentX11();
bool start() override;
void update() override;
std::string get_focused_window_title() override;
//std::string get_focused_monitor_name() override;
private:
Display *dpy = NULL;
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <string>
namespace gsr {
struct ActiveHyprlandWindow {
std::string window_id = "";
std::string title = "Game";
};
void start_hyprland_listener_thread();
std::string get_current_hyprland_window_title();
}

View File

@@ -1,16 +0,0 @@
#pragma once
#include <string>
namespace gsr {
struct ActiveKwinWindow {
std::string title = "Game";
bool fullscreen = false;
std::string monitorName = "";
};
void start_kwin_helper_thread();
std::string get_current_kwin_window_title();
bool get_current_kwin_window_fullscreen();
std::string get_current_kwin_window_monitor_name();
}

View File

@@ -12,6 +12,7 @@
#include "ClipboardFile.hpp"
#include "LedIndicator.hpp"
#include "CursorTracker/CursorTracker.hpp"
#include "DesktopEnvironment/DesktopEnvironment.hpp"
#include <mglpp/window/Window.hpp>
#include <mglpp/window/Event.hpp>
@@ -304,5 +305,6 @@ namespace gsr {
std::unique_ptr<LedIndicator> led_indicator = nullptr;
bool supports_window_title = false;
std::unique_ptr<DesktopEnvironment> desktop_environment;
};
}

View File

@@ -30,8 +30,8 @@ namespace gsr {
std::optional<std::string> get_window_title(Display *dpy, Window window);
Window get_focused_window(Display *dpy, WindowCaptureType cap_type, bool fallback_cursor_focused = true);
std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type, bool fallback_cursor_focused = true);
std::string get_window_name_at_position(Display *dpy, mgl::vec2i position, Window ignore_window);
std::string get_window_name_at_cursor_position(Display *dpy, Window ignore_window);
std::string get_window_name_at_position(Display *dpy, mgl::vec2i position, std::string_view ignore_window_title);
std::string get_window_name_at_cursor_position(Display *dpy, std::string_view ignore_window_title);
void set_window_size_not_resizable(Display *dpy, Window window, int width, int height);
Window window_get_target_window_child(Display *display, Window window);
unsigned char* window_get_property(Display *dpy, Window window, Atom property_type, const char *property_name, unsigned int *property_size);