Skip to content

fix(launcher): end the RemoteApp session when the application window closes - #993

Open
X-IOT-study wants to merge 1 commit into
winapps-org:mainfrom
X-IOT-study:fix/exit-session-with-app-window
Open

X-IOT-study wants to merge 1 commit into
winapps-org:mainfrom
X-IOT-study:fix/exit-session-with-app-window

Conversation

@X-IOT-study

Copy link
Copy Markdown

Problem

Closing a RemoteApp window does not end the RemoteApp session. Windows keeps the session alive, so xfreerdp stays connected and the RAIL windows the server created for helper windows stay mapped.

With a Windows input method active this is visible as floating windows left behind after the application is gone — on this setup four Microsoft Text Input Application windows, one of them a 170×59 override-redirect toolbar that stays on the Linux desktop. Since it is override-redirect it has no decorations, so the window manager cannot close it, and it only goes away when the FreeRDP process exits. Restarting the application afterwards then piles up more of them.

Fix

While waiting for FreeRDP to exit, watch the managed windows belonging to the application's WM_CLASS (the same value that is passed to /wm-class). Once the window has been gone for 10 seconds — five 2-second polls, which also covers save dialogs and windows that are re-created — terminate the FreeRDP process. That destroys all of its X windows, helper windows included.

  • New option EXIT_WITH_APP, default on. Set it to off for applications that are expected to keep running without a window; that restores the previous behaviour exactly.
  • Only applies to application launches that pass /wm-class. winapps windows (full desktop) and the manual flavour are untouched.
  • If wmctrl is unavailable, or the window list cannot be read (e.g. a Wayland session), the previous plain wait "$FREERDP_PID" is used and nothing is killed.
  • Documented in the README next to HIDEF.

Tested configuration

  • Ubuntu 22.04, GNOME Shell on X11
  • Windows 11 in libvirt, WAFLAVOR="libvirt"
  • FreeRDP 3.33.0 (/app:.../hidef:on,/wm-class:"Microsoft Word"), WinApps main at 0b950dc

With four Microsoft Text Input Application windows present, clicking Word's own close button left them on screen for the grace period; the session then terminated and no RAIL windows remained. Also verified with Alt+F4, and that winapps windows still waits on FreeRDP as before.

Notes

  • No change to window size, position or maximise handling; this only affects when the session is ended.
  • A 10 second grace period is deliberate: it tolerates dialogs that appear after the main window closes and applications that briefly recreate their window. Open to a different default value if maintainers prefer.
  • DCO sign-off is on the commit.

AI assistance disclosure

Per CONTRIBUTING.md: this change was developed with Claude Code assistance. The author reviewed the resulting code, understands the shell logic, and can answer questions about it; the change is small and was verified end-to-end on the configuration above.

… closes

Environment
-----------
- WinApps (winapps-org/winapps, main at 0b950dc) driving xfreerdp 3.33.0
- Ubuntu 22.04, GNOME Shell on X11, Windows 11 in a libvirt VM
- RemoteApp launch: /app:program:...,hidef:on,/wm-class:"<application name>"

Problem
-------
Closing a RemoteApp window (e.g. Microsoft Word) does not end the RemoteApp
session. Windows keeps the session alive, so the xfreerdp process stays
connected and the RAIL windows the server created for helper windows stay
mapped. With a Windows input method active these include "Microsoft Text
Input Application" windows; one of them is a 170x59 override-redirect
floating toolbar that remains visible on the Linux desktop after the
application is gone. Being override-redirect, it has no decorations, so the
window manager cannot close it, and it only disappears when the FreeRDP
process exits.

Fix
---
While waiting for FreeRDP to exit, watch the managed windows of the
application's WM_CLASS (the value passed to /wm-class). Once the window has
been gone for 10 seconds (five 2-second polls, which also covers save
dialogs and windows that are re-created), terminate the FreeRDP process;
that destroys all of its X windows, helper windows included.

- New configuration option EXIT_WITH_APP (default 'on'). Set it to 'off'
  for applications that are expected to keep running without a window.
- Only applies to application launches that pass /wm-class. Full desktop
  ('windows') and 'manual' launches keep the previous behaviour.
- If wmctrl is unavailable, or the window list cannot be read (e.g. on a
  Wayland session), the previous plain wait is used and nothing is killed.

Verified on the setup above: with four "Microsoft Text Input Application"
windows present, clicking Word's own close button left them on screen for
the grace period, then the session terminated and no RAIL windows remained.

Signed-off-by: X-IOT-study <2453395023@qq.com>
@LDprg

LDprg commented Nov 5, 2026

Copy link
Copy Markdown
Member

Personally I dislike the idea of using wmctrl as it is x11 specific. X11 is end of life and even freerdp starts adding rails to wayland. I therefore don't like to add x11 features only, since it is expected that most users will use wayland in the future (especially with big distros/wms dropping x11).

I would highly prefer a solution that works on Wayland and x11. At first glance this seems pretty much possible since it shouldn't have to need WM specific code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants