Skip to content

Commit

Permalink
wayland: Improve seat / input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
markbolhuis committed Dec 7, 2024
1 parent 975815c commit 01d70fb
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 122 deletions.
32 changes: 22 additions & 10 deletions src/gl/inject_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ EXPORT_C_(void*) eglGetPlatformDisplay( unsigned int platform, void* native_disp
#ifdef HAVE_WAYLAND
if(platform == EGL_PLATFORM_WAYLAND_KHR)
{
wl_display_ptr = (struct wl_display*)native_display;
wl_display* display = static_cast<wl_display*>(native_display);
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
init_wayland_data();
init_wayland_data(display);
}
#endif

Expand All @@ -117,14 +116,12 @@ EXPORT_C_(void*) eglGetDisplay( void* native_display )
#ifdef HAVE_WAYLAND
try
{
void** display_ptr = (void**)native_display;
wl_interface* iface = (wl_interface*)*display_ptr;
wl_interface* iface = *static_cast<wl_interface**>(native_display);
if(iface && strcmp(iface->name, wl_display_interface.name) == 0)
{
wl_display_ptr = (struct wl_display*)native_display;
wl_display* display = static_cast<wl_display*>(native_display);
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
init_wayland_data();
init_wayland_data(display);
}
}
catch(...)
Expand All @@ -135,17 +132,32 @@ EXPORT_C_(void*) eglGetDisplay( void* native_display )
return pfn_eglGetDisplay(native_display);
}

EXPORT_C_(unsigned) eglTerminate( void* native_display );
EXPORT_C_(unsigned) eglTerminate( void* native_display )
{
static unsigned (*pfn_eglTerminate)(void*) = nullptr;
if (!pfn_eglTerminate)
pfn_eglTerminate= reinterpret_cast<decltype(pfn_eglTerminate)>(get_egl_proc_address("eglTerminate"));

#ifdef HAVE_WAYLAND
fini_wayland_data();
#endif

return pfn_eglTerminate(native_display);
}

struct func_ptr {
const char *name;
void *ptr;
};

static std::array<const func_ptr, 4> name_to_funcptr_map = {{
static std::array<const func_ptr, 5> name_to_funcptr_map = {{
#define ADD_HOOK(fn) { #fn, (void *) fn }
ADD_HOOK(eglGetProcAddress),
ADD_HOOK(eglSwapBuffers),
ADD_HOOK(eglGetPlatformDisplay),
ADD_HOOK(eglGetDisplay)
ADD_HOOK(eglGetDisplay),
ADD_HOOK(eglTerminate)
#undef ADD_HOOK
}};

Expand Down
10 changes: 2 additions & 8 deletions src/keybinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ typedef unsigned long KeySym;
static inline bool keys_are_pressed(const std::vector<KeySym>& keys)
{
#if defined(HAVE_WAYLAND)
if(wl_display_ptr && wl_handle)
{
update_wl_queue();

if(wl_pressed_keys == keys)
{
return true;
}
if (any_wayland_seat_syms_are_pressed(keys)) {
return true;
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions src/vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,9 @@ static void overlay_DestroyInstance(
stop_notifier(instance_data->notifier);
#endif
destroy_instance_data(instance_data);
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
fini_wayland_data();
#endif
}

#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Expand All @@ -2042,11 +2045,8 @@ static VkResult overlay_CreateWaylandSurfaceKHR(
)
{
struct instance_data *instance_data = FIND(struct instance_data, instance);
if (!wl_handle)
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
wl_display_ptr = pCreateInfo->display;
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
init_wayland_data();
init_wayland_data(pCreateInfo->display);
return instance_data->vtable.CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
}
#endif
Expand Down
17 changes: 11 additions & 6 deletions src/wayland_hook.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include <wayland-client.h>
#pragma once
#ifndef MANGOHUD_WAYLAND_HOOK_H
#define MANGOHUD_WAYLAND_HOOK_H

#include <vector>

struct wl_display;

#ifndef KeySym
typedef unsigned long KeySym;
#endif

extern void* wl_handle;
extern struct wl_display* wl_display_ptr;
extern std::vector<KeySym> wl_pressed_keys;
void init_wayland_data(wl_display *display);
void fini_wayland_data();

void init_wayland_data();
void update_wl_queue();
bool any_wayland_seat_syms_are_pressed(const std::vector<KeySym> &syms);

#endif
Loading

0 comments on commit 01d70fb

Please sign in to comment.