1818#include "kde-output-order-v1-client-protocol.h"
1919#include "xdg-output-unstable-v1-client-protocol.h"
2020
21- #ifdef __linux__
21+ #if __FreeBSD__
22+ #include <sys/un.h>
23+ #include <sys/ucred.h>
24+ #include <sys/sysctl.h>
25+ #endif
26+
2227static bool waylandDetectWM (int fd , FFDisplayServerResult * result )
2328{
24- struct ucred ucred ;
29+ #if __linux__ || (__FreeBSD__ && !__DragonFly__ )
30+
31+ #if __linux
32+ struct ucred ucred = {};
2533 socklen_t len = sizeof (ucred );
2634 if (getsockopt (fd , SOL_SOCKET , SO_PEERCRED , & ucred , & len ) == -1 || ucred .pid <= 0 )
2735 return false;
@@ -30,6 +38,19 @@ static bool waylandDetectWM(int fd, FFDisplayServerResult* result)
3038 ffStrbufAppendF (& procPath , "/proc/%d/cmdline" , ucred .pid ); //We check the cmdline for the process name, because it is not trimmed.
3139 if (!ffReadFileBuffer (procPath .chars , & result -> wmProcessName ))
3240 return false;
41+ #else
42+ struct xucred ucred = {};
43+ socklen_t len = sizeof (ucred );
44+ if (getsockopt (fd , AF_UNSPEC , LOCAL_PEERCRED , & ucred , & len ) == -1 || ucred .cr_pid <= 0 )
45+ return false;
46+
47+ size_t size = 4096 ;
48+ ffStrbufEnsureFixedLengthFree (& result -> wmProcessName , (uint32_t ) size );
49+
50+ if (sysctl ((int []){CTL_KERN , KERN_PROC , KERN_PROC_ARGS , ucred .cr_pid }, 4 , result -> wmProcessName .chars , & size , NULL , 0 ) != 0 )
51+ return false;
52+ result -> wmProcessName .length = (uint32_t ) size - 1 ;
53+ #endif
3354
3455 // #1135: wl-restart is a special case
3556 const char * filename = strrchr (result -> wmProcessName .chars , '/' );
@@ -45,14 +66,12 @@ static bool waylandDetectWM(int fd, FFDisplayServerResult* result)
4566 ffStrbufSubstrAfterLastC (& result -> wmProcessName , '/' ); //Trim the path
4667
4768 return true;
48- }
69+
4970#else
50- static bool waylandDetectWM (int fd , FFDisplayServerResult * result )
51- {
5271 FF_UNUSED (fd , result );
5372 return false;
54- }
5573#endif
74+ }
5675
5776static void waylandGlobalAddListener (void * data , struct wl_registry * registry , uint32_t name , const char * interface , uint32_t version )
5877{
0 commit comments