@@ -168,15 +168,20 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, X11Wind
168
168
( int ) CreateWindowArgs . InputOutput ,
169
169
visual ,
170
170
new UIntPtr ( ( uint ) valueMask ) , ref attr ) ;
171
+ AppendPid ( _handle ) ;
171
172
172
173
if ( _useRenderWindow )
174
+ {
173
175
_renderHandle = XCreateWindow ( _x11 . Display , _handle , 0 , 0 , defaultWidth , defaultHeight , 0 , depth ,
174
176
( int ) CreateWindowArgs . InputOutput ,
175
177
visual ,
176
178
new UIntPtr ( ( uint ) ( SetWindowValuemask . BorderPixel | SetWindowValuemask . BitGravity |
177
179
SetWindowValuemask . WinGravity | SetWindowValuemask . BackingStore ) ) , ref attr ) ;
180
+ }
178
181
else
182
+ {
179
183
_renderHandle = _handle ;
184
+ }
180
185
181
186
Handle = new PlatformHandle ( _handle , "XID" ) ;
182
187
@@ -335,6 +340,55 @@ private void UpdateMotifHints()
335
340
PropertyMode . Replace , ref hints , 5 ) ;
336
341
}
337
342
343
+ /// <summary>
344
+ /// Append `_NET_WM_PID` atom to X11 window
345
+ /// </summary>
346
+ /// <param name="windowXId"></param>
347
+ private void AppendPid ( IntPtr windowXId )
348
+ {
349
+ // See https://github.com/AvaloniaUI/Avalonia/issues/17444
350
+ var pid = ( uint ) s_pid ;
351
+ // 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
352
+ XChangeProperty ( _x11 . Display , windowXId ,
353
+ _x11 . Atoms . _NET_WM_PID , _x11 . Atoms . XA_CARDINAL , 32 ,
354
+ PropertyMode . Replace , ref pid , 1 ) ;
355
+
356
+ const int maxLength = 1024 ;
357
+ var name = stackalloc byte [ maxLength ] ;
358
+ var result = gethostname ( name , maxLength ) ;
359
+ if ( result != 0 )
360
+ {
361
+ // Fail
362
+ return ;
363
+ }
364
+
365
+ var length = 0 ;
366
+ while ( length < maxLength && name [ length ] != 0 )
367
+ {
368
+ length ++ ;
369
+ }
370
+
371
+ XChangeProperty ( _x11 . Display , windowXId ,
372
+ _x11 . Atoms . XA_WM_CLIENT_MACHINE , _x11 . Atoms . XA_STRING , 8 ,
373
+ PropertyMode . Replace , name , length ) ;
374
+ }
375
+
376
+ [ DllImport ( "libc" ) ]
377
+ private static extern int gethostname ( byte * name , int len ) ;
378
+
379
+ private static readonly int s_pid = GetProcessId ( ) ;
380
+
381
+ private static int GetProcessId ( )
382
+ {
383
+ #if NET6_0_OR_GREATER
384
+ var pid = Environment . ProcessId ;
385
+ #else
386
+ using var currentProcess = Process . GetCurrentProcess ( ) ;
387
+ var pid = currentProcess . Id ;
388
+ #endif
389
+ return pid ;
390
+ }
391
+
338
392
private void UpdateSizeHints ( PixelSize ? preResize , bool forceDisableResize = false )
339
393
{
340
394
if ( _overrideRedirect )
0 commit comments