diff --git a/build.sh b/build.sh index 1922df2c..e22fe10a 100755 --- a/build.sh +++ b/build.sh @@ -158,6 +158,7 @@ build() { configure $@ fi DESTDIR="$PWD/build/release" ninja -C build/meson64 install + set +e DESTDIR="$PWD/build/release" ninja -C build/meson32 install } diff --git a/meson.build b/meson.build index 0b440538..8f0c6195 100644 --- a/meson.build +++ b/meson.build @@ -89,9 +89,9 @@ vulkan_wsi_deps = [] if is_unixy dep_x11 = dependency('x11', required: get_option('with_x11')) # Not needed right now - #dep_wayland_client = dependency('wayland-client', - # required: get_option('with_wayland'), version : '>=1.11') - dep_wayland_client = null_dep + dep_wayland_client = dependency('wayland-client', + required: get_option('with_wayland'), version : '>=1.11') + #dep_wayland_client = null_dep dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true) # Support 32bit only if library is found cc_input_dep = cc.find_library('libinput', required: false) diff --git a/src/gl/inject_egl.cpp b/src/gl/inject_egl.cpp index 6080b368..5e979c1a 100644 --- a/src/gl/inject_egl.cpp +++ b/src/gl/inject_egl.cpp @@ -12,6 +12,8 @@ #include "imgui_hud.h" +extern void* g_wl_display; + using namespace MangoHud::GL; EXPORT_C_(void *) eglGetProcAddress(const char* procName); @@ -85,15 +87,27 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf) return pfn_eglSwapBuffers(dpy, surf); } +EXPORT_C_(void*) wl_display_connect(const char* dsp) +{ + static decltype(&wl_display_connect) pfn_wl_display_connect = nullptr; + if (!pfn_wl_display_connect) + pfn_wl_display_connect = reinterpret_cast (real_dlsym(real_dlopen("libwayland-client.so.0", RTLD_LAZY | RTLD_NOW), "wl_display_connect")); + + g_wl_display = pfn_wl_display_connect(dsp); + std::cerr << __func__ << ": " << g_wl_display << std::endl; + return g_wl_display; +} + struct func_ptr { const char *name; void *ptr; }; -static std::array name_to_funcptr_map = {{ +static std::array name_to_funcptr_map = {{ #define ADD_HOOK(fn) { #fn, (void *) fn } ADD_HOOK(eglGetProcAddress), ADD_HOOK(eglSwapBuffers), + ADD_HOOK(wl_display_connect), #undef ADD_HOOK }}; diff --git a/src/keybinds_libinput.cpp b/src/keybinds_libinput.cpp index 41a5c25d..cb892fde 100644 --- a/src/keybinds_libinput.cpp +++ b/src/keybinds_libinput.cpp @@ -12,9 +12,13 @@ #include #include #include +#include #include +#include #include "keybinds_libinput.h" +#include "real_dlsym.h" +#include struct key_state { uint32_t key; @@ -26,7 +30,6 @@ struct key_state { //F4 = 62 //F12 = 88 static std::mutex input_mutex; -static std::vector> key_states; static int open_restricted(const char *path, int flags, void *user_data) { @@ -42,19 +45,43 @@ static int open_restricted(const char *path, int flags, void *user_data) return fd; } + wl_display *display = nullptr; + wl_compositor *compositor = nullptr; + wl_shell *shell = nullptr; + wl_seat *seat = nullptr; + static void close_restricted(int fd, void *user_data) { close(fd); } +static void registry_add_object (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);static void registry_remove_object (void *data, struct wl_registry *registry, uint32_t name); +static struct wl_registry_listener registry_listener = {®istry_add_object, ®istry_remove_object}; +void *g_wl_display = nullptr; + struct input_reader { bool quit = false; std::thread thread; bool thread_started = false; - input_reader() + std::vector> key_states; + + wl_display *display = nullptr; + wl_compositor *compositor = nullptr; + wl_shell *shell = nullptr; + wl_seat *seat = nullptr; + + input_reader(const std::vector>& key_states_) + : key_states(key_states_) { + std::cerr << __func__ << " " << g_wl_display << "\n"; + if (!g_wl_display) return; + display = (wl_display*) g_wl_display; thread_started = true; - thread = std::thread(&input_reader::event_thread, this); + //display = wl_display_connect (nullptr); + struct wl_registry *registry = wl_display_get_registry (display); + wl_registry_add_listener (registry, ®istry_listener, nullptr); + wl_display_roundtrip (display); + //thread = std::thread(&input_reader::event_thread, this); } ~input_reader() @@ -62,14 +89,14 @@ struct input_reader { quit = true; if (thread.joinable()) thread.join(); - - // Clear keybinds so we don't falsely assume that their states are legit - std::lock_guard lk(input_mutex); - key_states.clear(); } void event_thread() { + //while (!quit) { + // wl_display_dispatch_pending (display); + //} + return; static struct libinput_interface interface; interface.open_restricted = open_restricted; interface.close_restricted = close_restricted; @@ -137,6 +164,65 @@ struct input_reader { static std::unique_ptr libinput_thread; + +static void keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size) { + std::cerr << __func__ << "\n"; +} + +static void keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { + std::cerr << __func__ << "\n"; +} + +static void keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) { + std::cerr << __func__ << "\n"; +} + +static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { + std::cerr << "Key pressed " << key <<"\n"; + std::lock_guard lk(input_mutex); + if (libinput_thread){ + for (auto& ks : libinput_thread->key_states) + { + for (auto& k : ks) { + if (k.key == key) + { + k.pressed = (state == WL_KEYBOARD_KEY_STATE_PRESSED); + } + } + } + } +} + +static void keyboard_modifiers (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) { + std::cerr << __func__ << "\n"; +} + +static struct wl_keyboard_listener keyboard_listener = {&keyboard_keymap, &keyboard_enter, &keyboard_leave, &keyboard_key, &keyboard_modifiers}; + +static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities) { + std::cerr << __func__ << "\n"; + if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) { + std::cerr << "SEAT\n"; + struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat); + wl_keyboard_add_listener (keyboard, &keyboard_listener, NULL); + } +} +static struct wl_seat_listener seat_listener = {&seat_capabilities}; + +static void registry_add_object (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { + std::cerr << __func__ << ": interface: " << interface << "\n"; + if (!strcmp(interface,"wl_seat")) { + //input_reader* ir = wl_registry_get_user_data(registry); + seat = (wl_seat*)wl_registry_bind (registry, name, &wl_seat_interface, 1); + + std::cerr << "\t wl_seat_add_listener " << wl_proxy_get_listener((wl_proxy*)seat) <<"\n"; + wl_seat_add_listener (seat, &seat_listener, NULL); + } +} +static void registry_remove_object (void *data, struct wl_registry *registry, uint32_t name) { + +} + const std::map input_map_x11_to_linux = { {0x20, 0x39}, /* x11:32 (XK_space) -> linux:57 (KEY_SPACE) */ {0x21, 0x2}, /* x11:33 (XK_exclam) -> linux:2 (KEY_1) */ @@ -320,7 +406,7 @@ void start_input(const overlay_params& params) return; std::lock_guard lk(input_mutex); - key_states.clear(); + std::vector> key_states; key_states.push_back(get_linux_key(params.toggle_hud)); key_states.push_back(get_linux_key(params.toggle_logging)); key_states.push_back(get_linux_key(params.reload_cfg)); @@ -328,7 +414,7 @@ void start_input(const overlay_params& params) key_states.push_back(get_linux_key(params.upload_logs)); key_states.push_back(get_linux_key(params.toggle_fps_limit)); - libinput_thread = std::make_unique(); + libinput_thread = std::make_unique(key_states); } bool libinput_key_is_pressed(std::vector x11_keybinds) @@ -341,7 +427,7 @@ bool libinput_key_is_pressed(std::vector x11_keybinds) if (keybinds.empty()) return false; - for (const auto& ks : key_states) + for (const auto& ks : libinput_thread->key_states) { if (ks.size() != keybinds.size()) continue; diff --git a/src/vulkan.cpp b/src/vulkan.cpp index eadbb40f..b5417bc0 100644 --- a/src/vulkan.cpp +++ b/src/vulkan.cpp @@ -2247,6 +2247,13 @@ static void overlay_DestroyInstance( destroy_instance_data(instance_data); } +static VkResult overlay_CreateWaylandSurfaceKHR( VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface ) +{ + struct instance_data *instance_data = FIND(struct instance_data, instance); + std::cerr << __func__ << std::endl; + return instance_data->vtable.CreateWaylandSurfaceKHR( instance, pCreateInfo, pAllocator, pSurface ); +} + extern "C" VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL overlay_GetDeviceProcAddr(VkDevice dev, const char *funcName); static const struct { @@ -2269,6 +2276,8 @@ static const struct { ADD_HOOK(QueueSubmit), + ADD_HOOK(CreateWaylandSurfaceKHR), + ADD_HOOK(CreateDevice), ADD_HOOK(DestroyDevice),