Файл для обработки ввода
This commit is contained in:
10
wayland/include/input-handle.h
Normal file
10
wayland/include/input-handle.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef INPUT_HANDLE_H
|
||||||
|
#define INPUT_HANDLE_H
|
||||||
|
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
#include "window.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
void keyboard_key_handle(xkb_keycode_t kc, xkb_keysym_t ks, enum keyboard_key_state state, struct wayland_window* window);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,7 +8,19 @@ void input_register_seat(struct wl_seat *seat);
|
|||||||
/* Очистка input (разрушить keyboard и xkb state) */
|
/* Очистка input (разрушить keyboard и xkb state) */
|
||||||
void input_cleanup(void);
|
void input_cleanup(void);
|
||||||
|
|
||||||
/* Возвращает wl_surface, имеющую фокус клавиатуры или NULL */
|
enum keyboard_key_state {
|
||||||
struct wl_surface *input_get_keyboard_focus(void);
|
/**
|
||||||
|
* key is not pressed
|
||||||
|
*/
|
||||||
|
KEYBOARD_KEY_STATE_RELEASED = 0,
|
||||||
|
/**
|
||||||
|
* key is pressed
|
||||||
|
*/
|
||||||
|
KEYBOARD_KEY_STATE_PRESSED = 1,
|
||||||
|
/**
|
||||||
|
* key was repeated
|
||||||
|
*/
|
||||||
|
KEYBOARD_KEY_STATE_REPEATED = 2,
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,4 +15,7 @@ void wait_for_windows(void);
|
|||||||
/* Остановить оконные потоки, очистить input и закрыть соединение Wayland */
|
/* Остановить оконные потоки, очистить input и закрыть соединение Wayland */
|
||||||
void destroy_wayland(void);
|
void destroy_wayland(void);
|
||||||
|
|
||||||
|
/* Поиск окна по wl_surface */
|
||||||
|
struct wayland_window* get_window_by_surface(struct wl_surface* surf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -14,8 +14,6 @@ main:
|
|||||||
|
|
||||||
; Launch the first window thread (duplicate calls for more windows)
|
; Launch the first window thread (duplicate calls for more windows)
|
||||||
call run_window
|
call run_window
|
||||||
call run_window
|
|
||||||
call run_window
|
|
||||||
|
|
||||||
call wait_for_windows
|
call wait_for_windows
|
||||||
|
|
||||||
|
|||||||
16
wayland/src/input-handle.c
Normal file
16
wayland/src/input-handle.c
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "input-handle.h"
|
||||||
|
|
||||||
|
void keyboard_key_handle(xkb_keycode_t kc, xkb_keysym_t ks, enum keyboard_key_state state, struct wayland_window *window)
|
||||||
|
{
|
||||||
|
if (ks != XKB_KEY_NoSymbol)
|
||||||
|
{
|
||||||
|
char buf[64];
|
||||||
|
int n = xkb_keysym_to_utf8(ks, buf, sizeof(buf));
|
||||||
|
if (ks == XKB_KEY_Return)
|
||||||
|
sprintf(buf, "Return");
|
||||||
|
if (n > 0)
|
||||||
|
printf("keyboard: symbol '%s' (keysym 0x%x) on surface:%p\n", buf, ks, window);
|
||||||
|
else
|
||||||
|
printf("keyboard: keysym 0x%x (no UTF-8 representation)\n", ks);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "input.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
@@ -7,12 +6,17 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "input.h"
|
||||||
|
#include "input-handle.h"
|
||||||
|
#include "wayland-runtime.h"
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
static struct wl_seat *seat = NULL;
|
static struct wl_seat *seat = NULL;
|
||||||
static struct wl_keyboard *keyboard = NULL;
|
static struct wl_keyboard *keyboard = NULL;
|
||||||
static struct xkb_context *xkb_ctx = NULL;
|
static struct xkb_context *xkb_ctx = NULL;
|
||||||
static struct xkb_keymap *xkb_keymap = NULL;
|
static struct xkb_keymap *xkb_keymap = NULL;
|
||||||
static struct xkb_state *xkb_state = NULL;
|
static struct xkb_state *xkb_state = NULL;
|
||||||
static struct wl_surface *keyboard_focus = NULL;
|
static struct wayland_window* focused_window = NULL;
|
||||||
|
|
||||||
/* Обработчики клавиатуры */
|
/* Обработчики клавиатуры */
|
||||||
static void keyboard_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size)
|
static void keyboard_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size)
|
||||||
@@ -68,40 +72,29 @@ static void keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t se
|
|||||||
{
|
{
|
||||||
printf("keyboard: enter serial=%u surface=%p\n", serial, surface);
|
printf("keyboard: enter serial=%u surface=%p\n", serial, surface);
|
||||||
/* Сохраняем поверхность, которая получила фокус клавиатуры */
|
/* Сохраняем поверхность, которая получила фокус клавиатуры */
|
||||||
keyboard_focus = surface;
|
focused_window = get_window_by_surface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
printf("keyboard: leave serial=%u surface=%p\n", serial, surface);
|
printf("keyboard: leave serial=%u surface=%p\n", serial, surface);
|
||||||
/* Если уходим с фокусной поверхности — сбросить фокус */
|
/* Если уходим с фокусной поверхности — сбросить фокус */
|
||||||
if (keyboard_focus == surface)
|
if (focused_window && focused_window->wl_surface == surface)
|
||||||
keyboard_focus = NULL;
|
focused_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
const char *s = (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "PRESSED"
|
enum keyboard_key_state key_state = (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? KEYBOARD_KEY_STATE_PRESSED
|
||||||
: (state == WL_KEYBOARD_KEY_STATE_RELEASED) ? "RELEASED"
|
: (state == WL_KEYBOARD_KEY_STATE_REPEATED) ? KEYBOARD_KEY_STATE_REPEATED
|
||||||
: (state == WL_KEYBOARD_KEY_STATE_REPEATED) ? "REPEATED"
|
: KEYBOARD_KEY_STATE_RELEASED;
|
||||||
: "Unknown";
|
|
||||||
/* Отладочный вывод удалён */
|
|
||||||
|
|
||||||
if (xkb_state && keyboard_focus)
|
if (xkb_state && focused_window)
|
||||||
{
|
{
|
||||||
xkb_keycode_t kc = (xkb_keycode_t)key + 8;
|
xkb_keycode_t kc = (xkb_keycode_t)key + 8;
|
||||||
xkb_keysym_t ks = xkb_state_key_get_one_sym(xkb_state, kc);
|
xkb_keysym_t ks = xkb_state_key_get_one_sym(xkb_state, kc);
|
||||||
if (ks != XKB_KEY_NoSymbol)
|
|
||||||
{
|
keyboard_key_handle(kc, ks, key_state, focused_window);
|
||||||
char buf[64];
|
|
||||||
int n = xkb_keysym_to_utf8(ks, buf, sizeof(buf));
|
|
||||||
if (ks == XKB_KEY_Return)
|
|
||||||
sprintf(buf, "Return");
|
|
||||||
if (n > 0)
|
|
||||||
printf("keyboard: symbol '%s' (keysym 0x%x) on surface:%p\n", buf, ks, keyboard_focus);
|
|
||||||
else
|
|
||||||
printf("keyboard: keysym 0x%x (no UTF-8 representation)\n", ks);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,10 +200,5 @@ void input_cleanup(void)
|
|||||||
xkb_context_unref(xkb_ctx);
|
xkb_context_unref(xkb_ctx);
|
||||||
xkb_ctx = NULL;
|
xkb_ctx = NULL;
|
||||||
}
|
}
|
||||||
keyboard_focus = NULL;
|
focused_window = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
struct wl_surface *input_get_keyboard_focus(void)
|
|
||||||
{
|
|
||||||
return keyboard_focus;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,3 +218,4 @@ struct xdg_wm_base *registry_get_xdg_wm_base(void)
|
|||||||
{
|
{
|
||||||
return global_wm_base;
|
return global_wm_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
#include "wayland_runtime.h"
|
#include "wayland-runtime.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#define MAX_WINDOW_THREADS 128
|
#define MAX_WINDOW_THREADS 128
|
||||||
@@ -177,3 +177,11 @@ void destroy_wayland(void)
|
|||||||
g_initialized = 0;
|
g_initialized = 0;
|
||||||
atomic_store(&g_shutdown, 0);
|
atomic_store(&g_shutdown, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wayland_window* get_window_by_surface(struct wl_surface* surf)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < MAX_WINDOW_THREADS; i++)
|
||||||
|
if(g_slots[i].window.wl_surface == surf)
|
||||||
|
return &g_slots[i].window;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user