Skip to content

Commit

Permalink
Add _NET_WM_PID atom to Linux X11 window
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi authored and walterlv committed Nov 11, 2024
1 parent a9d032b commit 669e228
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,21 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, bool ov
(int)CreateWindowArgs.InputOutput,
visual,
new UIntPtr((uint)valueMask), ref attr);
AppendPid(_handle);

if (_useRenderWindow)
{
_renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, defaultWidth, defaultHeight, 0, depth,
(int)CreateWindowArgs.InputOutput,
visual,
new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
AppendPid(_renderHandle);
}
else
{
_renderHandle = _handle;
}

Handle = new PlatformHandle(_handle, "XID");

Expand Down Expand Up @@ -323,6 +329,25 @@ private void UpdateMotifHints()
PropertyMode.Replace, ref hints, 5);
}

/// <summary>
/// Append `_NET_WM_PID` atom to X11 window
/// </summary>
/// <param name="windowXId"></param>
private void AppendPid(IntPtr windowXId)
{
// See https://github.com/AvaloniaUI/Avalonia/issues/17444
#if NET6_0_OR_GREATER
var pid = (uint) Environment.ProcessId;
#else
using var currentProcess = Process.GetCurrentProcess();
var pid = (uint) currentProcess.Id;
#endif
// The type of `_NET_WM_PID` is `CARDINAL` which is 32-bit unsigned integer, see https://specifications.freedesktop.org/wm-spec/1.3/ar01s05.html
XChangeProperty(_x11.Display, windowXId,
_x11.Atoms._NET_WM_PID, _x11.Atoms.XA_CARDINAL, 32,
PropertyMode.Replace, ref pid, 1);
}

private void UpdateSizeHints(PixelSize? preResize, bool forceDisableResize = false)
{
if (_overrideRedirect)
Expand Down

0 comments on commit 669e228

Please sign in to comment.