diff --git a/Makefile b/Makefile index 50768f0..b442059 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CFLAGS = -Wall -Wextra -I./include/ -g LIBS = $(shell pkg-config --libs wayland-client wayland-egl egl glesv2 wayland-cursor) -build/main: src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/event.o build/xdg-shell-protocol.o - g++ -o build/main $(CFLAGS) src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/event.o build/xdg-shell-protocol.o $(LIBS) +build/main: src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/event.o build/event_input.o build/xdg-shell-protocol.o + g++ -o build/main $(CFLAGS) src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/event.o build/event_input.o build/xdg-shell-protocol.o $(LIBS) build/shader.o: src/shader.cpp include/shader.h g++ -o build/shader.o $(CFLAGS) -c src/shader.cpp @@ -30,6 +30,9 @@ build/input_wayland.o: include/input/wayland.h src/input/wayland.cpp build/event.o: src/event.cpp include/event.h g++ -o build/event.o $(CFLAGS) -c src/event.cpp + +build/event_input.o: src/event/input.cpp include/event/input.h + g++ -o build/event_input.o $(CFLAGS) -c src/event/input.cpp build/xdg-shell-protocol.o: src/xdg-shell-protocol.c gcc -o build/xdg-shell-protocol.o -c $(CFLAGS) $(LIBS) src/xdg-shell-protocol.c diff --git a/include/event.h b/include/event.h index 2c02f0c..3b7a390 100644 --- a/include/event.h +++ b/include/event.h @@ -5,10 +5,34 @@ #include #include -enum class EventType { - INPUT, +enum class EventType : unsigned int { + // ----- INPUT ----- + INPUT = 1 << 0, + // Mouse + MOUSE = 1 << 1, + MOUSE_MOVED = 1 << 2, }; +constexpr EventType operator|(EventType a, EventType b) { + return static_cast( + static_cast(a) | + static_cast(b) + ); +} + +constexpr EventType operator&(EventType a, EventType b) { + return static_cast( + static_cast(a) & + static_cast(b) + ); +} + +constexpr EventType operator~(EventType a) { + return static_cast( + ~static_cast(a) + ); +} + struct Event { public: Event(); diff --git a/include/event/input.h b/include/event/input.h index d57172b..5f36563 100644 --- a/include/event/input.h +++ b/include/event/input.h @@ -13,4 +13,25 @@ public: EventType GetType() const override; }; +struct MouseEvent : public InputEvent { +public: + MouseEvent(EventType type); + ~MouseEvent() = default; + +public: + EventType GetType() const override; + +private: + EventType m_mouse_type; +}; + +struct MouseMoveEvent : public MouseEvent { +public: + MouseMoveEvent(size_t x, size_t y); + ~MouseMoveEvent() = default; +public: + size_t x; + size_t y; +}; + #endif // H_INPUT_EVENT_ diff --git a/include/input/wayland.h b/include/input/wayland.h index c7a3249..c1c0c07 100644 --- a/include/input/wayland.h +++ b/include/input/wayland.h @@ -4,8 +4,11 @@ #include "input.h" +#include #include +#include "event.h" + class WaylandInputHandler : public InputHandlerImpl { private: static void handle_pointer_enter(void *data, @@ -67,6 +70,8 @@ private: struct wl_pointer_listener m_pointer_listener; wl_fixed_t m_surface_x; wl_fixed_t m_surface_y; +private: + std::vector m_event_queue; }; #endif // H_WAYLAND_INPUT_ diff --git a/src/event/input.cpp b/src/event/input.cpp index 71b63c6..79f7d73 100644 --- a/src/event/input.cpp +++ b/src/event/input.cpp @@ -1,6 +1,15 @@ #include "event/input.h" +#include "event.h" EventType InputEvent::GetType() const { return EventType::INPUT; } +MouseEvent::MouseEvent(EventType type) : InputEvent(), m_mouse_type(type) {} + +EventType MouseEvent::GetType() const { + return InputEvent::GetType() | EventType::MOUSE | m_mouse_type; +} + +MouseMoveEvent::MouseMoveEvent() : MouseEvent(EventType::MOUSE_MOVED) {} + diff --git a/src/input/wayland.cpp b/src/input/wayland.cpp index a630cff..ccd97a0 100644 --- a/src/input/wayland.cpp +++ b/src/input/wayland.cpp @@ -2,6 +2,7 @@ #include #include "input/wayland.h" +#include "event/input.h" #include "state/wayland.h" #include #include @@ -69,15 +70,16 @@ void WaylandInputHandler::handle_pointer_leave(void *data, } void WaylandInputHandler::handle_pointer_motion(void *data, - struct wl_pointer *wl_pointer, + struct wl_pointer *pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { - UNUSED(wl_pointer); + UNUSED(pointer); UNUSED(time); auto handler = reinterpret_cast(data); handler->m_surface_x = surface_x; handler->m_surface_y = surface_y; + handler->m_event_queue.push_back(new MouseMoveEvent(surface_x, surface_y)); } void WaylandInputHandler::handle_pointer_button(void *data,