1+ #define _GNU_SOURCE //required for struct ucred
2+
13#include "displayServer.h"
24
35#include <stdlib.h>
79#include <pthread.h>
810#include <dlfcn.h>
911#include <wayland-client.h>
12+ #include <sys/socket.h>
1013
1114typedef struct WaylandData
1215{
@@ -19,6 +22,25 @@ typedef struct WaylandData
1922 struct wl_output_listener output_listener ;
2023} WaylandData ;
2124
25+ static void waylandDetectWM (int fd , FFDisplayServerResult * result )
26+ {
27+ if (fd < 1 )
28+ return ;
29+
30+ struct ucred ucred ;
31+ socklen_t len = sizeof (struct ucred );
32+ if (getsockopt (fd , SOL_SOCKET , SO_PEERCRED , & ucred , & len ) == -1 )
33+ return ;
34+
35+ FFstrbuf procPath ;
36+ ffStrbufInit (& procPath );
37+ ffStrbufAppendF (& procPath , "/proc/%d/cmdline" , ucred .pid ); //We check the cmdline for the process name, because it is not trimmed.
38+ ffReadFileBuffer (procPath .chars , & result -> wmProcessName );
39+ ffStrbufSubstrBeforeFirstC (& result -> wmProcessName , '\0' ); //Trim the arguments
40+ ffStrbufSubstrAfterLastC (& result -> wmProcessName , '/' ); //Trim the path
41+ ffStrbufDestroy (& procPath );
42+ }
43+
2244static void waylandGlobalRemoveListener (void * data , struct wl_registry * wl_registry , uint32_t name ){
2345 FF_UNUSED (data , wl_registry , name );
2446}
@@ -81,6 +103,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
81103 FF_LIBRARY_LOAD (wayland , instance -> config .libWayland , false, "libwayland-client.so" , 1 )
82104
83105 FF_LIBRARY_LOAD_SYMBOL (wayland , wl_display_connect , false)
106+ FF_LIBRARY_LOAD_SYMBOL (wayland , wl_display_get_fd , false)
84107 FF_LIBRARY_LOAD_SYMBOL (wayland , wl_display_dispatch , false)
85108 FF_LIBRARY_LOAD_SYMBOL (wayland , wl_display_roundtrip , false)
86109 FF_LIBRARY_LOAD_SYMBOL (wayland , wl_proxy_marshal_constructor , false)
@@ -89,7 +112,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
89112
90113 WaylandData data ;
91114
92- FF_LIBRARY_LOAD_SYMBOL_ADRESS (wayland , data .ffwl_proxy_marshal_constructor_versioned , ffwl_proxy_marshal_constructor , false)
115+ FF_LIBRARY_LOAD_SYMBOL_ADRESS (wayland , data .ffwl_proxy_marshal_constructor_versioned , wl_proxy_marshal_constructor_versioned , false)
93116 FF_LIBRARY_LOAD_SYMBOL_ADRESS (wayland , data .ffwl_proxy_add_listener , wl_proxy_add_listener , false)
94117 FF_LIBRARY_LOAD_SYMBOL_ADRESS (wayland , data .ffwl_output_interface , wl_output_interface , false)
95118 FF_LIBRARY_LOAD_SYMBOL_ADRESS (wayland , data .ffwl_proxy_destroy , wl_proxy_destroy , false)
@@ -101,6 +124,8 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
101124 return false;
102125 }
103126
127+ waylandDetectWM (ffwl_display_get_fd (display ), result );
128+
104129 struct wl_registry * registry = (struct wl_registry * ) ffwl_proxy_marshal_constructor ((struct wl_proxy * ) display , WL_DISPLAY_GET_REGISTRY , ffwl_registry_interface , NULL );
105130 if (registry == NULL )
106131 {
0 commit comments