Skip to content

Commit

Permalink
switch back to wl_display_connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Etaash-mathamsetty committed Nov 12, 2023
1 parent 60e41b9 commit a300907
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/mangohud.version
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
dlsym;
mangohud_find_glx_ptr;
mangohud_find_egl_ptr;
wl_display_flush;
wl_display_connect;
wl_display_connect_to_fd;
local: *;
};
40 changes: 32 additions & 8 deletions src/wayland_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,50 @@
void* wl_handle = nullptr;
void* wl_display_ptr = nullptr;

EXPORT_C_(int) wl_display_flush(void *display);
EXPORT_C_(void*) wl_display_connect(const char *name);
EXPORT_C_(void*) wl_display_connect_to_fd(int fd);

typedef void* (*pwl_display_connect)(const char *name);
typedef void* (*pwl_display_connect_to_fd)(int fd);
pwl_display_connect wl_display_connect_ptr = nullptr;
pwl_display_connect_to_fd wl_display_connect_to_fd_ptr = nullptr;

typedef int (*pwl_display_flush)(void *display);
pwl_display_flush wl_display_flush_ptr = nullptr;

//TODO: grab every unique wayland display and store all of them to read inputs from
EXPORT_C_(int) wl_display_flush(void* display)
EXPORT_C_(void*) wl_display_connect(const char *name)
{
void *ret = NULL;

if(!wl_handle)
{
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY | RTLD_NOLOAD);
wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect");
wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd");
}

ret = wl_display_connect_ptr(name);

if(!wl_display_ptr)
wl_display_ptr = ret;

return ret;
}

EXPORT_C_(void*) wl_display_connect_to_fd(int fd)
{
int ret = 0;
void *ret = NULL;

if(!wl_handle)
{
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY | RTLD_NOLOAD);
wl_display_flush_ptr = (pwl_display_flush)real_dlsym(wl_handle, "wl_display_flush");
wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd");
wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect");
}

ret = wl_display_flush_ptr(display);
ret = wl_display_connect_to_fd_ptr(fd);

if(!wl_display_ptr)
wl_display_ptr = display;
wl_display_ptr = ret;

return ret;
}

0 comments on commit a300907

Please sign in to comment.