Files
gpu-screen-recorder-ui/tools/gsr-kwin-helper/gsrkwinhelper.js
p0358 52afad5824 kwin: emit window fullscreen info + refactor helper script
The helper script was also refactored to minimize the amount of callbacks added and the memory used. There's no need to keep callbacks attached for non-active windows, which happened before.

Also it should be more efficient and simpler to send info over with just a single DBus call (also if more fields were to be added).

Both the script and the helper app will send/print info only if it changed since the previous one. Otherwise we'd keep spamming fullscreen false update when navigating the desktop and so on.
2026-03-07 17:44:10 +01:00

58 lines
1.8 KiB
JavaScript

const DAEMON_DBUS_NAME = "com.dec05eba.gpu_screen_recorder";
function dbusSendUpdateActiveWindow(title, isFullscreen) {
callDBus(
DAEMON_DBUS_NAME, "/", DAEMON_DBUS_NAME,
"updateActiveWindow",
title, isFullscreen,
);
}
let prevWindow = null;
let prevEmitActiveWindowUpdate = null;
let prevCaption = null;
let prevFullScreen = 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);
prevCaption = caption;
prevFullScreen = fullScreen;
}
}
}
function subscribeToWindow(window) {
if (!window) return;
if (prevWindow !== window) {
if (prevWindow !== null) {
prevWindow.captionChanged.disconnect(prevEmitActiveWindowUpdate);
prevWindow.fullScreenChanged.disconnect(prevEmitActiveWindowUpdate);
}
let emitActiveWindowUpdateBound = emitActiveWindowUpdate.bind(null, window);
window.captionChanged.connect(emitActiveWindowUpdateBound);
window.fullScreenChanged.connect(emitActiveWindowUpdateBound);
prevWindow = window;
prevEmitActiveWindowUpdate = emitActiveWindowUpdateBound;
}
}
function updateActiveWindow(window) {
if (!window) return;
if (window.resourceName === "gsr-ui" || window.resourceName === "gsr-notify") return; // ignore the overlay and notification
emitActiveWindowUpdate(window);
subscribeToWindow(window);
}
// handle window focus changes
workspace.windowActivated.connect(updateActiveWindow);
// handle initial state
if (workspace.activeWindow) {
updateActiveWindow(workspace.activeWindow);
}