mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
input: mouse events
This commit is contained in:
parent
1a341a56cc
commit
a102ff09f9
4 changed files with 103 additions and 6 deletions
80
input.c
80
input.c
|
|
@ -13,6 +13,7 @@
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
|
#include "render.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
|
|
@ -287,3 +288,82 @@ input_repeat(struct terminal *term, uint32_t key)
|
||||||
{
|
{
|
||||||
keyboard_key(term, NULL, 0, 0, key, XKB_KEY_DOWN);
|
keyboard_key(term, NULL, 0, 0, key, XKB_KEY_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t serial, struct wl_surface *surface,
|
||||||
|
wl_fixed_t surface_x, wl_fixed_t surface_y)
|
||||||
|
{
|
||||||
|
struct terminal *term = data;
|
||||||
|
term->mouse.x = wl_fixed_to_int(surface_x);
|
||||||
|
term->mouse.y = wl_fixed_to_int(surface_y);
|
||||||
|
|
||||||
|
render_update_cursor_surface(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t serial, struct wl_surface *surface)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
|
||||||
|
{
|
||||||
|
struct terminal *term = data;
|
||||||
|
term->mouse.x = wl_fixed_to_int(surface_x) * 1;//backend->monitor->scale;
|
||||||
|
term->mouse.y = wl_fixed_to_int(surface_y) * 1;//backend->monitor->scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
|
||||||
|
{
|
||||||
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//struct terminal *term = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t time, uint32_t axis, wl_fixed_t value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_frame(void *data, struct wl_pointer *wl_pointer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t axis_source)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t time, uint32_t axis)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t axis, int32_t discrete)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct wl_pointer_listener pointer_listener = {
|
||||||
|
.enter = wl_pointer_enter,
|
||||||
|
.leave = wl_pointer_leave,
|
||||||
|
.motion = wl_pointer_motion,
|
||||||
|
.button = wl_pointer_button,
|
||||||
|
.axis = wl_pointer_axis,
|
||||||
|
.frame = wl_pointer_frame,
|
||||||
|
.axis_source = wl_pointer_axis_source,
|
||||||
|
.axis_stop = wl_pointer_axis_stop,
|
||||||
|
.axis_discrete = wl_pointer_axis_discrete,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
||||||
1
input.h
1
input.h
|
|
@ -5,5 +5,6 @@
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
extern const struct wl_keyboard_listener keyboard_listener;
|
extern const struct wl_keyboard_listener keyboard_listener;
|
||||||
|
extern const struct wl_pointer_listener pointer_listener;
|
||||||
|
|
||||||
void input_repeat(struct terminal *term, uint32_t key);
|
void input_repeat(struct terminal *term, uint32_t key);
|
||||||
|
|
|
||||||
23
main.c
23
main.c
|
|
@ -61,14 +61,25 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
||||||
{
|
{
|
||||||
struct terminal *term = data;
|
struct terminal *term = data;
|
||||||
|
|
||||||
if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD))
|
if (term->wl.keyboard != NULL) {
|
||||||
return;
|
|
||||||
|
|
||||||
if (term->wl.keyboard != NULL)
|
|
||||||
wl_keyboard_release(term->wl.keyboard);
|
wl_keyboard_release(term->wl.keyboard);
|
||||||
|
term->wl.keyboard = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
term->wl.keyboard = wl_seat_get_keyboard(wl_seat);
|
if (term->wl.pointer.pointer != NULL) {
|
||||||
wl_keyboard_add_listener(term->wl.keyboard, &keyboard_listener, term);
|
wl_pointer_release(term->wl.pointer.pointer);
|
||||||
|
term->wl.pointer.pointer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
|
||||||
|
term->wl.keyboard = wl_seat_get_keyboard(wl_seat);
|
||||||
|
wl_keyboard_add_listener(term->wl.keyboard, &keyboard_listener, term);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caps & WL_SEAT_CAPABILITY_POINTER) {
|
||||||
|
term->wl.pointer.pointer = wl_seat_get_pointer(wl_seat);
|
||||||
|
wl_pointer_add_listener(term->wl.pointer.pointer, &pointer_listener, term);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,11 @@ struct terminal {
|
||||||
struct rgba foreground;
|
struct rgba foreground;
|
||||||
struct rgba background;
|
struct rgba background;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} mouse;
|
||||||
|
|
||||||
struct cursor cursor;
|
struct cursor cursor;
|
||||||
struct cursor saved_cursor;
|
struct cursor saved_cursor;
|
||||||
struct cursor alt_saved_cursor;
|
struct cursor alt_saved_cursor;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue