|
|
@ -1,5 +1,11 @@
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
|
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#include "wsi_helpers.h"
|
|
|
|
#include "wsi_helpers.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
|
@ -9,10 +15,10 @@ static bool check_window_focus(xcb_connection_t * connection, xcb_window_t windo
|
|
|
|
auto reply = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr);
|
|
|
|
auto reply = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr);
|
|
|
|
if (reply)
|
|
|
|
if (reply)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SPDLOG_DEBUG("Window: {:08x} Focus WId: {:08x}", window, reply->focus);
|
|
|
|
SPDLOG_DEBUG("Window: {:08x} Focus WId: {:08x}", window, reply->focus);
|
|
|
|
bool has_focus = (window == reply->focus);
|
|
|
|
bool has_focus = (window == reply->focus);
|
|
|
|
free(reply);
|
|
|
|
free(reply);
|
|
|
|
return has_focus;
|
|
|
|
return has_focus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// xcb_query_tree_cookie_t cookie = xcb_query_tree(connection, reply->focus);
|
|
|
|
// xcb_query_tree_cookie_t cookie = xcb_query_tree(connection, reply->focus);
|
|
|
@ -92,33 +98,56 @@ void window_has_focus(wsi_connection* conn)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct interfaces_
|
|
|
|
struct wl_state
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wl_shell *shell;
|
|
|
|
// wl_shell *shell;
|
|
|
|
wl_seat *seat;
|
|
|
|
// wl_seat *seat;
|
|
|
|
wsi_connection *wsi;
|
|
|
|
wsi_connection *wsi;
|
|
|
|
};
|
|
|
|
xkb_context *ctx;
|
|
|
|
|
|
|
|
xkb_keymap *keymap;
|
|
|
|
|
|
|
|
struct xkb_state *state;
|
|
|
|
|
|
|
|
} g_wl_state {}; //TODO per surface etc instance?
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size) {
|
|
|
|
static void keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size) {
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1);
|
|
|
|
|
|
|
|
char *map_shm = reinterpret_cast<char *>(mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0));
|
|
|
|
|
|
|
|
assert(map_shm != MAP_FAILED);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xkb_keymap_unref(g_wl_state.keymap);
|
|
|
|
|
|
|
|
g_wl_state.keymap = xkb_keymap_new_from_string(g_wl_state.ctx, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
|
|
|
|
|
|
XKB_KEYMAP_COMPILE_NO_FLAGS); // FIXME probably leaking stuff
|
|
|
|
|
|
|
|
munmap(map_shm, size);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xkb_state_unref(g_wl_state.state);
|
|
|
|
|
|
|
|
g_wl_state.state = xkb_state_new(g_wl_state.keymap); // FIXME probably leaking stuff
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
|
|
|
|
static void keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
|
|
|
|
auto wsi = reinterpret_cast<wsi_connection*>(data);
|
|
|
|
auto wsi = reinterpret_cast<wsi_connection*>(data);
|
|
|
|
|
|
|
|
SPDLOG_DEBUG("{}: {} == {}", __func__, (void*)wsi->wl.surface, (void*)surface);
|
|
|
|
if (wsi->focus_changed && surface == wsi->wl.surface)
|
|
|
|
if (wsi->focus_changed && surface == wsi->wl.surface)
|
|
|
|
wsi->focus_changed(true);
|
|
|
|
wsi->focus_changed(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) {
|
|
|
|
static void keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) {
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
SPDLOG_DEBUG("{}: {}", __func__, (void*)surface);
|
|
|
|
auto wsi = reinterpret_cast<wsi_connection*>(data);
|
|
|
|
auto wsi = reinterpret_cast<wsi_connection*>(data);
|
|
|
|
if (wsi->focus_changed && surface == wsi->wl.surface)
|
|
|
|
if (wsi->focus_changed && surface == wsi->wl.surface)
|
|
|
|
wsi->focus_changed(false);
|
|
|
|
wsi->focus_changed(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
|
|
|
|
static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
|
|
|
|
SPDLOG_DEBUG("{}: key pressed: {}", __func__, key);
|
|
|
|
auto wsi = reinterpret_cast<wsi_connection*>(data);
|
|
|
|
|
|
|
|
uint32_t keycode = key + 8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xkb_keysym_t sym = xkb_state_key_get_one_sym(g_wl_state.state, keycode);
|
|
|
|
|
|
|
|
if (wsi->key_pressed)
|
|
|
|
|
|
|
|
wsi->key_pressed(sym, state);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_DEBUG("{}: key pressed: {}, {}, {:08x}", __func__, key, state, sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
@ -130,7 +159,7 @@ static struct wl_keyboard_listener keyboard_listener = {&keyboard_keymap, &keybo
|
|
|
|
static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities) {
|
|
|
|
static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities) {
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
|
|
|
|
if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
|
|
|
|
SPDLOG_DEBUG("SEAT");
|
|
|
|
SPDLOG_DEBUG("Got usable seat");
|
|
|
|
struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
|
|
|
|
struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
|
|
|
|
wl_keyboard_add_listener (keyboard, &keyboard_listener, data);
|
|
|
|
wl_keyboard_add_listener (keyboard, &keyboard_listener, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -139,7 +168,7 @@ 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) {
|
|
|
|
static void registry_add_object (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
SPDLOG_DEBUG("{}", __func__);
|
|
|
|
if (!strcmp(interface,"wl_seat")) {
|
|
|
|
if (!strcmp(interface, "wl_seat")) {
|
|
|
|
//input_reader* ir = wl_registry_get_user_data(registry);
|
|
|
|
//input_reader* ir = wl_registry_get_user_data(registry);
|
|
|
|
auto seat = (wl_seat*)wl_registry_bind (registry, name, &wl_seat_interface, 1);
|
|
|
|
auto seat = (wl_seat*)wl_registry_bind (registry, name, &wl_seat_interface, 1);
|
|
|
|
// SPDLOG_DEBUG("wl_seat_add_listener {}", wl_proxy_get_listener((wl_proxy*)seat));
|
|
|
|
// SPDLOG_DEBUG("wl_seat_add_listener {}", wl_proxy_get_listener((wl_proxy*)seat));
|
|
|
@ -152,11 +181,11 @@ static void registry_remove_object (void *data, struct wl_registry *registry, ui
|
|
|
|
|
|
|
|
|
|
|
|
static struct wl_registry_listener registry_listener = {®istry_add_object, ®istry_remove_object};
|
|
|
|
static struct wl_registry_listener registry_listener = {®istry_add_object, ®istry_remove_object};
|
|
|
|
|
|
|
|
|
|
|
|
// interfaces_ g_interfaces {};
|
|
|
|
void wsi_wayland_init(wsi_connection& conn)
|
|
|
|
|
|
|
|
|
|
|
|
void wayland_init(wsi_connection& conn)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto registry = wl_display_get_registry(conn.wl.display);
|
|
|
|
auto registry = wl_display_get_registry(conn.wl.display);
|
|
|
|
wl_registry_add_listener(registry, ®istry_listener, &conn);
|
|
|
|
g_wl_state.ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); //FIXME probably leaking stuff
|
|
|
|
wl_display_roundtrip(conn.wl.display);
|
|
|
|
g_wl_state.wsi = &conn; //TODO per surfacei nstance?
|
|
|
|
|
|
|
|
wl_registry_add_listener(registry, ®istry_listener, &conn);
|
|
|
|
|
|
|
|
wl_display_roundtrip(conn.wl.display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|