feat: input handler class init
This commit is contained in:
67
include/input/wayland.h
Normal file
67
include/input/wayland.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
#ifndef H_WAYLAND_INPUT_
|
||||
#define H_WAYLAND_INPUT_
|
||||
|
||||
#include <wayland-client-protocol.h>
|
||||
|
||||
class WaylandInputHandler {
|
||||
public:
|
||||
static WaylandInputHandler* GetInstance();
|
||||
private:
|
||||
static void handle_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);
|
||||
static void handle_pointer_leave(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t serial,
|
||||
struct wl_surface *surface);
|
||||
static void handle_pointer_motion(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t time,
|
||||
wl_fixed_t surface_x,
|
||||
wl_fixed_t surface_y);
|
||||
static void handle_pointer_button(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t serial,
|
||||
uint32_t time,
|
||||
uint32_t button,
|
||||
uint32_t state);
|
||||
static void handle_pointer_axis(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t time,
|
||||
uint32_t axis,
|
||||
wl_fixed_t value);
|
||||
static void handle_pointer_frame(void *data,
|
||||
struct wl_pointer *wl_pointer);
|
||||
static void handle_pointer_axis_source(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t axis_source);
|
||||
static void handle_pointer_axis_stop(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t time,
|
||||
uint32_t axis);
|
||||
static void handle_pointer_axis_discrete(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t axis,
|
||||
int32_t discrete);
|
||||
static void handle_pointer_axis_value120(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t axis,
|
||||
int32_t value120);
|
||||
static void handle_pointer_axis_relative_direction(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t axis,
|
||||
uint32_t direction);
|
||||
private:
|
||||
WaylandInputHandler();
|
||||
~WaylandInputHandler() = default;
|
||||
private:
|
||||
static WaylandInputHandler* s_instance;
|
||||
private:
|
||||
struct wl_pointer_listener m_pointer_listener;
|
||||
};
|
||||
|
||||
#endif // H_WAYLAND_INPUT_
|
||||
103
src/input/wayland.cpp
Normal file
103
src/input/wayland.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <cassert>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "input/wayland.h"
|
||||
#include "state/wayland.h"
|
||||
#include <wayland-client-core.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#include <wayland-util.h>
|
||||
#include <wayland-cursor.h>
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
WaylandInputHandler *WaylandInputHandler::s_instance = nullptr;
|
||||
|
||||
WaylandInputHandler::WaylandInputHandler() {
|
||||
auto pointer = WaylandState::GetInstance()->m_pointer;
|
||||
m_pointer_listener.enter = handle_pointer_enter;
|
||||
m_pointer_listener.leave = handle_pointer_leave;
|
||||
m_pointer_listener.motion = handle_pointer_motion;
|
||||
m_pointer_listener.button = handle_pointer_button;
|
||||
m_pointer_listener.axis = handle_pointer_axis;
|
||||
m_pointer_listener.frame = handle_pointer_frame;
|
||||
m_pointer_listener.axis_source = handle_pointer_axis_source;
|
||||
m_pointer_listener.axis_stop = handle_pointer_axis_stop;
|
||||
m_pointer_listener.axis_discrete = handle_pointer_axis_discrete;
|
||||
m_pointer_listener.axis_value120 = handle_pointer_axis_value120;
|
||||
m_pointer_listener.axis_relative_direction = handle_pointer_axis_relative_direction;
|
||||
wl_pointer_add_listener(pointer, &m_pointer_listener, this);
|
||||
}
|
||||
|
||||
WaylandInputHandler *WaylandInputHandler::GetInstance() {
|
||||
if (!WaylandInputHandler::s_instance)
|
||||
WaylandInputHandler::s_instance = new WaylandInputHandler();
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void WaylandInputHandler::handle_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) {
|
||||
UNUSED(wl_pointer);
|
||||
UNUSED(surface);
|
||||
auto handler = reinterpret_cast<WaylandInputHandler*>(data);
|
||||
// auto state = WaylandState::GetInstance();
|
||||
UNUSED(handler);
|
||||
printf("[DEBUG] INPUT.POINTER: pointer enter event:\n\tserial = %d, surface_x = %f, surface_y = %f\n", serial, wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y));
|
||||
// const char* cursor_theme = "XCursor-Pro-Dark";
|
||||
// auto theme = wl_cursor_theme_load(cursor_theme, 22, state->m_shm);
|
||||
// printf("[DEBUG] CURSOR: theme '%s' loaded: %p\n", cursor_theme, theme);
|
||||
// auto cursor = wl_cursor_theme_get_cursor(theme, "hand2");
|
||||
// printf("[DEBUG] CURSOR: cursor found (%p) with %u images\n", cursor, cursor->image_count);
|
||||
// auto buffer = wl_cursor_image_get_buffer(*cursor->images);
|
||||
// printf("[DEBUG] CURSOR: buffer for cursor '%s' loaded (%p)\n", cursor->name, buffer);
|
||||
// auto pointer_surface = wl_compositor_create_surface(state->m_compositor);
|
||||
// wl_pointer_set_cursor(state->m_pointer, serial, pointer_surface, cursor->images[0]->hotspot_x, cursor->images[0]->hotspot_y);
|
||||
// wl_surface_attach(pointer_surface, buffer, 0, 0);
|
||||
// wl_surface_commit(pointer_surface);
|
||||
}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_leave(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t serial,
|
||||
struct wl_surface *surface) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_motion(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t time,
|
||||
wl_fixed_t surface_x,
|
||||
wl_fixed_t surface_y) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_button(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t serial, uint32_t time,
|
||||
uint32_t button,
|
||||
uint32_t state) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_axis(void *data,
|
||||
struct wl_pointer *wl_pointer,
|
||||
uint32_t time, uint32_t axis,
|
||||
wl_fixed_t value) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_frame(void *data,
|
||||
struct wl_pointer *wl_pointer) {
|
||||
printf("[DEBUG] INPUT.POINTER: received pointer frame event\n");
|
||||
}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_axis_source(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t axis_source) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_axis_stop(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_axis_discrete(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t axis,
|
||||
int32_t discrete) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_axis_value120(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t axis,
|
||||
int32_t value120) {}
|
||||
|
||||
void WaylandInputHandler::handle_pointer_axis_relative_direction(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t axis,
|
||||
uint32_t direction) {}
|
||||
|
||||
Reference in New Issue
Block a user