mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
kwin: add support for determining active window's monitor name
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ static const char* INTROSPECTION_XML =
|
||||
" <method name='updateActiveWindow'>\n"
|
||||
" <arg type='s' name='title' direction='in'/>\n"
|
||||
" <arg type='b' name='fullscreen' direction='in'/>\n"
|
||||
" <arg type='s' name='monitorName' direction='in'/>\n"
|
||||
" </method>\n"
|
||||
" </interface>\n"
|
||||
" <interface name='org.freedesktop.DBus.Introspectable'>\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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user