diff --git a/include/KwinWorkaround.hpp b/include/KwinWorkaround.hpp
index 200345c..59b5e07 100644
--- a/include/KwinWorkaround.hpp
+++ b/include/KwinWorkaround.hpp
@@ -6,9 +6,11 @@ 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();
}
diff --git a/src/KwinWorkaround.cpp b/src/KwinWorkaround.cpp
index 6f06818..2dcf7ce 100644
--- a/src/KwinWorkaround.cpp
+++ b/src/KwinWorkaround.cpp
@@ -27,6 +27,7 @@ namespace gsr {
char buffer[4096];
const std::string prefix_title = "Active window title set to: ";
const std::string prefix_fullscreen = "Active window fullscreen state set to: ";
+ const std::string prefix_monitor = "Active window monitor name set to: ";
std::string line;
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
@@ -43,6 +44,9 @@ namespace gsr {
} else if ((pos = line.find(prefix_fullscreen)) != std::string::npos) {
std::string fullscreen = line.substr(pos + prefix_fullscreen.length());
active_kwin_window.fullscreen = fullscreen == "1";
+ } else if ((pos = line.find(prefix_monitor)) != std::string::npos) {
+ std::string monitorName = line.substr(pos + prefix_monitor.length());
+ active_kwin_window.monitorName = std::move(monitorName);
}
}
@@ -57,6 +61,10 @@ namespace gsr {
return active_kwin_window.fullscreen;
}
+ std::string get_current_kwin_window_monitor_name() {
+ return active_kwin_window.monitorName;
+ }
+
void start_kwin_helper_thread() {
if (kwin_helper_thread_started) {
return;
diff --git a/tools/gsr-kwin-helper/gsrkwinhelper.js b/tools/gsr-kwin-helper/gsrkwinhelper.js
index 8a5df47..4135e1d 100644
--- a/tools/gsr-kwin-helper/gsrkwinhelper.js
+++ b/tools/gsr-kwin-helper/gsrkwinhelper.js
@@ -1,10 +1,10 @@
const DAEMON_DBUS_NAME = "com.dec05eba.gpu_screen_recorder";
-function dbusSendUpdateActiveWindow(title, isFullscreen) {
+function dbusSendUpdateActiveWindow(title, isFullscreen, monitorName) {
callDBus(
DAEMON_DBUS_NAME, "/", DAEMON_DBUS_NAME,
"updateActiveWindow",
- title, isFullscreen,
+ title, isFullscreen, monitorName,
);
}
@@ -13,15 +13,18 @@ let prevEmitActiveWindowUpdate = null;
let prevCaption = null;
let prevFullScreen = null;
+let prevMonitorName = null;
function emitActiveWindowUpdate(window) {
if (workspace.activeWindow === window) {
let caption = window.caption || "";
let fullScreen = window.fullScreen || false;
- if (caption !== prevCaption || fullScreen !== prevFullScreen) {
- dbusSendUpdateActiveWindow(caption, fullScreen);
+ let monitorName = window.output?.name || "";
+ if (caption !== prevCaption || fullScreen !== prevFullScreen || monitorName !== prevMonitorName) {
+ dbusSendUpdateActiveWindow(caption, fullScreen, monitorName);
prevCaption = caption;
prevFullScreen = fullScreen;
+ prevMonitorName = monitorName;
}
}
}
@@ -32,10 +35,12 @@ function subscribeToWindow(window) {
if (prevWindow !== null) {
prevWindow.captionChanged.disconnect(prevEmitActiveWindowUpdate);
prevWindow.fullScreenChanged.disconnect(prevEmitActiveWindowUpdate);
+ prevWindow.outputChanged.disconnect(prevEmitActiveWindowUpdate);
}
let emitActiveWindowUpdateBound = emitActiveWindowUpdate.bind(null, window);
window.captionChanged.connect(emitActiveWindowUpdateBound);
window.fullScreenChanged.connect(emitActiveWindowUpdateBound);
+ window.outputChanged.connect(emitActiveWindowUpdateBound);
prevWindow = window;
prevEmitActiveWindowUpdate = emitActiveWindowUpdateBound;
}
diff --git a/tools/gsr-kwin-helper/main.cpp b/tools/gsr-kwin-helper/main.cpp
index 9f564eb..b95557d 100644
--- a/tools/gsr-kwin-helper/main.cpp
+++ b/tools/gsr-kwin-helper/main.cpp
@@ -11,6 +11,7 @@ static const char* INTROSPECTION_XML =
" \n"
" \n"
" \n"
+ " \n"
" \n"
" \n"
" \n"
@@ -25,6 +26,7 @@ class GsrKwinHelper {
public:
std::string active_window_title;
bool active_window_fullscreen;
+ std::string active_window_monitor_name;
DBusConnection* connection = nullptr;
DBusError err;
@@ -114,6 +116,7 @@ public:
DBusMessageIter args;
DBusBasicValue title;
DBusBasicValue fullscreen;
+ DBusBasicValue monitorName;
if (!dbus_message_iter_init(msg, &args)) {
send_error_reply(msg, "No arguments provided");
@@ -138,6 +141,18 @@ public:
}
dbus_message_iter_get_basic(&args, &fullscreen);
+
+ if (!dbus_message_iter_next(&args)) {
+ send_error_reply(msg, "Not enough arguments provided");
+ return;
+ }
+
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) {
+ send_error_reply(msg, "Expected string argument");
+ return;
+ }
+
+ dbus_message_iter_get_basic(&args, &monitorName);
if (title.str) {
if (active_window_title != title.str) {
@@ -156,6 +171,17 @@ public:
std::cout.flush();
}
+ if (monitorName.str) {
+ if (active_window_monitor_name != monitorName.str) {
+ active_window_monitor_name = monitorName.str;
+ std::cout << "Active window monitor name set to: " << active_window_monitor_name << "\n";
+ std::cout.flush();
+ }
+ } else {
+ send_error_reply(msg, "Failed to read string");
+ return;
+ }
+
send_success_reply(msg);
}