kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

commit ace8d7044def758884407d576fa731b8f7d0c8c2
parent 2fd6f353433d9c6bbee37159bc94e837ead9dae8
Author: deurzen <m.deurzen@tum.de>
Date:   Sun, 22 May 2022 01:58:11 +0200

adds output handling

Diffstat:
Minclude/kranewl/input/keyboard.hh | 12+++++++++++-
Ainclude/kranewl/input/seat.hh | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Minclude/kranewl/model.hh | 2+-
Minclude/kranewl/server.hh | 101++++++++++++++++++++++++-------------------------------------------------------
Minclude/kranewl/tree/output.hh | 12+++++++++---
Minclude/version.hh | 4++--
Asrc/kranewl/input/keyboard.cc | 37+++++++++++++++++++++++++++++++++++++
Asrc/kranewl/input/seat.cc | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/kranewl/main.cc | 2+-
Msrc/kranewl/model.cc | 11++++++++---
Msrc/kranewl/server.cc | 736++++++++-----------------------------------------------------------------------
Msrc/kranewl/tree/output.cc | 86++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/kranewl/tree/root.cc | 2+-
13 files changed, 448 insertions(+), 785 deletions(-)

diff --git a/include/kranewl/input/keyboard.hh b/include/kranewl/input/keyboard.hh @@ -9,15 +9,25 @@ extern "C" { #include <unordered_set> typedef class Server* Server_ptr; +typedef class Seat* Seat_ptr; typedef struct Keyboard { + Keyboard(Server_ptr, Seat_ptr, struct wlr_input_device*); + ~Keyboard(); + + static void handle_destroy(struct wl_listener*, void*); + static void handle_modifiers(struct wl_listener*, void*); + static void handle_key(struct wl_listener*, void*); + Server_ptr mp_server; + Seat_ptr mp_seat; - struct wl_list m_link; struct wlr_input_device* mp_device; + struct wl_listener ml_destroy; struct wl_listener ml_modifiers; struct wl_listener ml_key; + }* Keyboard_ptr; struct KeyboardInput { diff --git a/include/kranewl/input/seat.hh b/include/kranewl/input/seat.hh @@ -0,0 +1,82 @@ +#pragma once + +#include <kranewl/common.hh> +#include <kranewl/geometry.hh> + +extern "C" { +#include <wayland-server-core.h> +#include <wlr/types/wlr_output.h> +} + +#include <vector> + +typedef class Server* Server_ptr; +typedef class Model* Model_ptr; +typedef class Keyboard* Keyboard_ptr; +typedef class Client* Client_ptr; + +typedef class Seat final { +public: + enum class CursorMode { + Passthrough, + Move, + Resize, + }; + + enum class CursorButton { + Left = 272, + Right = 273, + Middle = 274, + }; + + Seat(Server_ptr, Model_ptr, struct wlr_seat*, struct wlr_cursor*); + ~Seat(); + + static void handle_new_node(struct wl_listener*, void*); + static void handle_new_input(struct wl_listener*, void*); + static void handle_destroy(struct wl_listener*, void*); + static void handle_cursor_motion(struct wl_listener*, void*); + static void handle_cursor_motion_absolute(struct wl_listener*, void*); + static void handle_cursor_button(struct wl_listener*, void*); + static void handle_cursor_axis(struct wl_listener*, void*); + static void handle_cursor_frame(struct wl_listener*, void*); + static void handle_request_start_drag(struct wl_listener*, void*); + static void handle_start_drag(struct wl_listener*, void*); + static void handle_request_set_cursor(struct wl_listener*, void*); + static void handle_request_set_selection(struct wl_listener*, void*); + static void handle_request_set_primary_selection(struct wl_listener*, void*); + +public: + Server_ptr mp_server; + Model_ptr mp_model; + + struct wlr_seat* mp_seat; + struct wlr_cursor* mp_cursor; + CursorMode m_cursor_mode; + + std::vector<Keyboard_ptr> m_keyboards; + + struct { + Client_ptr client; + double x, y; + Region region; + uint32_t resize_edges; + } m_grab_state; + + struct wl_client* mp_exclusive_client; + + struct wl_listener ml_new_node; + struct wl_listener ml_new_input; + struct wl_listener ml_destroy; + struct wl_listener ml_cursor_motion; + struct wl_listener ml_cursor_motion_absolute; + struct wl_listener ml_cursor_button; + struct wl_listener ml_cursor_axis; + struct wl_listener ml_cursor_frame; + struct wl_listener ml_request_start_drag; + struct wl_listener ml_start_drag; + struct wl_listener ml_request_set_cursor; + struct wl_listener ml_request_set_selection; + struct wl_listener ml_request_set_primary_selection; + +}* Seat_ptr; diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -29,7 +29,7 @@ public: void register_keyboard(Keyboard_ptr); void unregister_keyboard(Keyboard_ptr); - Output_ptr create_output(struct wlr_output*, struct wlr_scene_output*); + Output_ptr create_output(struct wlr_output*, struct wlr_scene_output*, bool = false); void register_output(Output_ptr); void unregister_output(Output_ptr); diff --git a/include/kranewl/server.hh b/include/kranewl/server.hh @@ -2,6 +2,7 @@ #include <kranewl/geometry.hh> #include <kranewl/tree/root.hh> +#include <kranewl/input/seat.hh> extern "C" { #include <wlr/backend.h> @@ -13,7 +14,7 @@ extern "C" { #include <string> typedef class Model* Model_ptr; -typedef struct Client* Client_ptr; +typedef class Client* Client_ptr; typedef class Server* Server_ptr; typedef class Server final { enum class CursorMode { @@ -26,64 +27,38 @@ public: Server(Model_ptr); ~Server(); - void start() noexcept; + void run() noexcept; private: - static void new_output(struct wl_listener*, void*); - static void output_layout_change(struct wl_listener*, void*); - static void output_manager_apply(struct wl_listener*, void*); - static void output_manager_test(struct wl_listener*, void*); - - static void new_xdg_surface(struct wl_listener*, void*); - static void new_layer_shell_surface(struct wl_listener*, void*); - static void xdg_activation(struct wl_listener*, void*); - - static void new_input(struct wl_listener*, void*); - static void new_pointer(Server*, struct wlr_input_device*); - static void new_keyboard(Server*, struct wlr_input_device*); - static void inhibit_activate(struct wl_listener*, void*); - static void inhibit_deactivate(struct wl_listener*, void*); - static void idle_inhibitor_create(struct wl_listener*, void*); - static void idle_inhibitor_destroy(struct wl_listener*, void*); - - static void cursor_motion(struct wl_listener*, void*); - static void cursor_motion_absolute(struct wl_listener*, void*); - static void cursor_axis(struct wl_listener*, void*); - static void cursor_button(struct wl_listener*, void*); - static void cursor_frame(struct wl_listener*, void*); - static void request_set_cursor(struct wl_listener*, void*); - static void cursor_process_motion(Server*, uint32_t); - static void cursor_process_move(Server*, uint32_t); - static void cursor_process_resize(Server*, uint32_t); - static void request_start_drag(struct wl_listener*, void*); - static void start_drag(struct wl_listener*, void*); - - static void keyboard_handle_modifiers(struct wl_listener*, void*); - static void keyboard_handle_key(struct wl_listener*, void*); - static bool keyboard_handle_keybinding(Server*, xkb_keysym_t); - static void request_set_selection(struct wl_listener*, void*); - static void request_set_primary_selection(struct wl_listener*, void*); - - static Client_ptr desktop_client_at(Server_ptr, double, double, struct wlr_surface**, double*, double*); - static void focus_client(Client_ptr, struct wlr_surface*); - - static void xdg_toplevel_map(struct wl_listener*, void*); - static void xdg_toplevel_unmap(struct wl_listener*, void*); - static void xdg_toplevel_destroy(struct wl_listener*, void*); - static void xdg_toplevel_request_move(struct wl_listener*, void*); - static void xdg_toplevel_request_resize(struct wl_listener*, void*); - static void xdg_toplevel_handle_moveresize(Client_ptr, CursorMode, uint32_t); - + static void handle_new_output(struct wl_listener*, void*); + static void handle_output_layout_change(struct wl_listener*, void*); + static void handle_output_manager_apply(struct wl_listener*, void*); + static void handle_output_manager_test(struct wl_listener*, void*); + static void handle_new_xdg_surface(struct wl_listener*, void*); + static void handle_new_layer_shell_surface(struct wl_listener*, void*); + static void handle_xdg_activation(struct wl_listener*, void*); + static void handle_new_input(struct wl_listener*, void*); + static void handle_inhibit_activate(struct wl_listener*, void*); + static void handle_inhibit_deactivate(struct wl_listener*, void*); + static void handle_idle_inhibitor_create(struct wl_listener*, void*); + static void handle_idle_inhibitor_destroy(struct wl_listener*, void*); + static void handle_xdg_toplevel_map(struct wl_listener*, void*); + static void handle_xdg_toplevel_unmap(struct wl_listener*, void*); + static void handle_xdg_toplevel_destroy(struct wl_listener*, void*); + static void handle_xdg_toplevel_request_move(struct wl_listener*, void*); + static void handle_xdg_toplevel_request_resize(struct wl_listener*, void*); + static void handle_xdg_toplevel_handle_moveresize(Client_ptr, CursorMode, uint32_t); #ifdef XWAYLAND - static void xwayland_ready(struct wl_listener*, void*); - static void new_xwayland_surface(struct wl_listener*, void*); - static void xwayland_request_activate(struct wl_listener*, void*); - static void xwayland_request_configure(struct wl_listener*, void*); - static void xwayland_set_hints(struct wl_listener*, void*); + static void handle_xwayland_ready(struct wl_listener*, void*); + static void handle_new_xwayland_surface(struct wl_listener*, void*); + static void handle_xwayland_request_activate(struct wl_listener*, void*); + static void handle_xwayland_request_configure(struct wl_listener*, void*); + static void handle_xwayland_set_hints(struct wl_listener*, void*); #endif Model_ptr mp_model; +public: struct wl_display* mp_display; struct wl_event_loop* mp_event_loop; @@ -94,26 +69,22 @@ private: struct wlr_compositor* mp_compositor; struct wlr_data_device_manager* mp_data_device_manager; struct wlr_scene* mp_scene; - - Root m_root; - #ifdef XWAYLAND struct wlr_xwayland* mp_xwayland; #endif + Root m_root; + Seat m_seat; + +private: struct wlr_xdg_shell* mp_xdg_shell; struct wlr_layer_shell_v1* mp_layer_shell; struct wlr_xdg_activation_v1* mp_xdg_activation; - struct wlr_output_manager_v1* mp_output_manager; struct wlr_presentation* mp_presentation; struct wlr_idle* mp_idle; - struct wlr_server_decoration_manager* mp_server_decoration_manager; struct wlr_xdg_decoration_manager_v1* mp_xdg_decoration_manager; - - struct wlr_seat* mp_seat; - struct wlr_cursor* mp_cursor; struct wlr_xcursor_manager* mp_cursor_manager; struct wlr_pointer_constraints_v1* mp_pointer_constraints; struct wlr_relative_pointer_manager_v1* mp_relative_pointer_manager; @@ -130,17 +101,7 @@ private: struct wl_listener ml_new_xdg_surface; struct wl_listener ml_new_layer_shell_surface; struct wl_listener ml_xdg_activation; - struct wl_listener ml_cursor_motion; - struct wl_listener ml_cursor_motion_absolute; - struct wl_listener ml_cursor_button; - struct wl_listener ml_cursor_axis; - struct wl_listener ml_cursor_frame; - struct wl_listener ml_request_set_cursor; - struct wl_listener ml_request_start_drag; - struct wl_listener ml_start_drag; struct wl_listener ml_new_input; - struct wl_listener ml_request_set_selection; - struct wl_listener ml_request_set_primary_selection; struct wl_listener ml_inhibit_activate; struct wl_listener ml_inhibit_deactivate; struct wl_listener ml_idle_inhibitor_create; diff --git a/include/kranewl/tree/output.hh b/include/kranewl/tree/output.hh @@ -16,14 +16,20 @@ typedef class Context* Context_ptr; typedef class Output final : public Node { public: - Output(Server_ptr, Model_ptr, struct wlr_output*, struct wlr_scene_output*); + Output( + Server_ptr, + Model_ptr, + struct wlr_output*, + struct wlr_scene_output*, + bool fallback = false + ); ~Output(); static void handle_frame(struct wl_listener*, void*); + static void handle_commit(struct wl_listener*, void*); static void handle_destroy(struct wl_listener*, void*); static void handle_present(struct wl_listener*, void*); static void handle_mode(struct wl_listener*, void*); - static void handle_commit(struct wl_listener*, void*); void set_context(Context_ptr context); Context_ptr context() const; @@ -49,10 +55,10 @@ public: enum wl_output_subpixel m_subpixel; struct wl_listener ml_frame; + struct wl_listener ml_commit; struct wl_listener ml_destroy; struct wl_listener ml_present; struct wl_listener ml_mode; - struct wl_listener ml_commit; struct { struct wl_signal disable; diff --git a/include/version.hh b/include/version.hh @@ -1 +1 @@ -#define VERSION "master/7e52bfd+" -\ No newline at end of file +#define VERSION "master/2fd6f35+" +\ No newline at end of file diff --git a/src/kranewl/input/keyboard.cc b/src/kranewl/input/keyboard.cc @@ -0,0 +1,37 @@ +#include <trace.hh> + +#include <kranewl/input/keyboard.hh> + +Keyboard::Keyboard(Server_ptr server, Seat_ptr seat, struct wlr_input_device* device) + : mp_server(server), + mp_seat(seat), + mp_device(device), + ml_destroy({ .notify = handle_destroy }), + ml_modifiers({ .notify = handle_modifiers }), + ml_key({ .notify = handle_key }) +{ +} + +Keyboard::~Keyboard() +{} + +void +Keyboard::handle_destroy(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Keyboard::handle_modifiers(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Keyboard::handle_key(struct wl_listener*, void*) +{ + TRACE(); + +} diff --git a/src/kranewl/input/seat.cc b/src/kranewl/input/seat.cc @@ -0,0 +1,146 @@ +#include <trace.hh> + +#include <kranewl/input/seat.hh> + +extern "C" { +#include <wlr/types/wlr_seat.h> +#include <wlr/types/wlr_cursor.h> +} + +Seat::Seat( + Server_ptr server, + Model_ptr model, + struct wlr_seat* seat, + struct wlr_cursor* cursor +) + : mp_server(server), + mp_model(model), + mp_seat(seat), + mp_cursor(cursor), + ml_new_node({ .notify = Seat::handle_new_node }), + ml_new_input({ .notify = Seat::handle_new_input }), + ml_destroy({ .notify = Seat::handle_destroy }), + ml_cursor_motion({ .notify = Seat::handle_cursor_motion }), + ml_cursor_motion_absolute({ .notify = Seat::handle_cursor_motion_absolute }), + ml_cursor_button({ .notify = Seat::handle_cursor_button }), + ml_cursor_axis({ .notify = Seat::handle_cursor_axis }), + ml_cursor_frame({ .notify = Seat::handle_cursor_frame }), + ml_request_start_drag({ .notify = Seat::handle_request_start_drag }), + ml_start_drag({ .notify = Seat::handle_start_drag }), + ml_request_set_cursor({ .notify = Seat::handle_request_set_cursor }), + ml_request_set_selection({ .notify = Seat::handle_request_set_selection }), + ml_request_set_primary_selection({ .notify = Seat::handle_request_set_primary_selection }) +{ + TRACE(); + + /* wl_signal_add(&seat->events.__, &ml_new_node); */ + /* wl_signal_add(&seat->events.new_input, &ml_new_input); */ + wl_signal_add(&seat->events.destroy, &ml_destroy); + wl_signal_add(&cursor->events.motion, &ml_cursor_motion); + wl_signal_add(&cursor->events.motion_absolute, &ml_cursor_motion_absolute); + wl_signal_add(&cursor->events.button, &ml_cursor_button); + wl_signal_add(&cursor->events.axis, &ml_cursor_axis); + wl_signal_add(&cursor->events.frame, &ml_cursor_frame); + wl_signal_add(&seat->events.request_start_drag, &ml_request_start_drag); + wl_signal_add(&seat->events.start_drag, &ml_start_drag); + wl_signal_add(&seat->events.request_set_cursor, &ml_request_set_cursor); + wl_signal_add(&seat->events.request_set_selection, &ml_request_set_selection); + wl_signal_add(&seat->events.request_set_primary_selection, &ml_request_set_primary_selection); +} + +Seat::~Seat() +{ + TRACE(); + +} + +void +Seat::handle_new_node(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_new_input(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_destroy(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_cursor_motion(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_cursor_motion_absolute(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_cursor_button(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_cursor_axis(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_cursor_frame(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_request_start_drag(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_start_drag(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_request_set_cursor(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_request_set_selection(struct wl_listener*, void*) +{ + TRACE(); + +} + +void +Seat::handle_request_set_primary_selection(struct wl_listener*, void*) +{ + TRACE(); + +} diff --git a/src/kranewl/main.cc b/src/kranewl/main.cc @@ -36,7 +36,7 @@ main(int argc, char** argv) const Config config = config_parser.generate_config(); Model model{config, options.autostart_path}; - Server{&model}.start(); + Server{&model}.run(); return EXIT_SUCCESS; } diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -98,7 +98,8 @@ Model::register_server(Server_ptr server) Output_ptr Model::create_output( struct wlr_output* wlr_output, - struct wlr_scene_output* wlr_scene_output + struct wlr_scene_output* wlr_scene_output, + bool fallback ) { TRACE(); @@ -107,7 +108,8 @@ Model::create_output( mp_server, this, wlr_output, - wlr_scene_output + wlr_scene_output, + fallback ); register_output(output); @@ -129,6 +131,7 @@ Model::unregister_output(Output_ptr output) TRACE(); m_outputs.remove_element(output); + delete output; } Client_ptr @@ -154,4 +157,6 @@ Model::register_client(Client_ptr client) void Model::unregister_client(Client_ptr client) -{} +{ + delete client; +} diff --git a/src/kranewl/server.cc b/src/kranewl/server.cc @@ -98,7 +98,6 @@ Server::Server(Model_ptr model) struct wlr_output* wlr_output = wlr_headless_add_output(mp_headless_backend, 800, 600); - wlr_output_set_name(wlr_output, "FALLBACK"); return Root( @@ -107,15 +106,18 @@ Server::Server(Model_ptr model) wlr_output_layout, mp_model->create_output( wlr_output, - wlr_scene_output_create(mp_scene, wlr_output) + wlr_scene_output_create(mp_scene, wlr_output), + true ) ); }(mp_display)), + m_seat(this, mp_model, wlr_seat_create(mp_display, "seat0"), wlr_cursor_create()), +#ifdef XWAYLAND + mp_xwayland(wlr_xwayland_create(mp_display, mp_compositor, 1)), +#endif mp_layer_shell(wlr_layer_shell_v1_create(mp_display)), mp_xdg_shell(wlr_xdg_shell_create(mp_display)), - mp_cursor(wlr_cursor_create()), mp_cursor_manager(wlr_xcursor_manager_create(NULL, 24)), - mp_seat(wlr_seat_create(mp_display, "seat0")), mp_presentation(wlr_presentation_create(mp_display, mp_backend)), mp_idle(wlr_idle_create(mp_display)), mp_idle_inhibit_manager(wlr_idle_inhibit_v1_create(mp_display)), @@ -128,33 +130,20 @@ Server::Server(Model_ptr model) mp_relative_pointer_manager(wlr_relative_pointer_manager_v1_create(mp_display)), mp_virtual_pointer_manager(wlr_virtual_pointer_manager_v1_create(mp_display)), mp_virtual_keyboard_manager(wlr_virtual_keyboard_manager_v1_create(mp_display)), + ml_new_output({ .notify = Server::handle_new_output }), + ml_output_manager_apply({ .notify = Server::handle_output_manager_apply }), + ml_output_manager_test({ .notify = Server::handle_output_manager_test }), + ml_new_xdg_surface({ .notify = Server::handle_new_xdg_surface }), + ml_new_layer_shell_surface({ .notify = Server::handle_new_layer_shell_surface }), + ml_xdg_activation({ .notify = Server::handle_xdg_activation }), + ml_new_input({ .notify = Server::handle_new_input }), + ml_inhibit_activate({ .notify = Server::handle_inhibit_activate }), + ml_inhibit_deactivate({ .notify = Server::handle_inhibit_deactivate }), + ml_idle_inhibitor_create({ .notify = Server::handle_idle_inhibitor_create }), + ml_idle_inhibitor_destroy({ .notify = Server::handle_idle_inhibitor_destroy }), #ifdef XWAYLAND - mp_xwayland(wlr_xwayland_create(mp_display, mp_compositor, 1)), -#endif - ml_new_output({ .notify = Server::new_output }), - ml_output_manager_apply({ .notify = Server::output_manager_apply }), - ml_output_manager_test({ .notify = Server::output_manager_test }), - ml_new_xdg_surface({ .notify = Server::new_xdg_surface }), - ml_new_layer_shell_surface({ .notify = Server::new_layer_shell_surface }), - ml_xdg_activation({ .notify = Server::xdg_activation }), - ml_cursor_motion({ .notify = Server::cursor_motion }), - ml_cursor_motion_absolute({ .notify = Server::cursor_motion_absolute }), - ml_cursor_button({ .notify = Server::cursor_button }), - ml_cursor_axis({ .notify = Server::cursor_axis }), - ml_cursor_frame({ .notify = Server::cursor_frame }), - ml_request_set_cursor({ .notify = Server::request_set_cursor }), - ml_request_start_drag({ .notify = Server::request_start_drag }), - ml_start_drag({ .notify = Server::start_drag }), - ml_new_input({ .notify = Server::new_input }), - ml_request_set_selection({ .notify = Server::request_set_selection }), - ml_request_set_primary_selection({ .notify = Server::request_set_primary_selection }), - ml_inhibit_activate({ .notify = Server::inhibit_activate }), - ml_inhibit_deactivate({ .notify = Server::inhibit_deactivate }), - ml_idle_inhibitor_create({ .notify = Server::idle_inhibitor_create }), - ml_idle_inhibitor_destroy({ .notify = Server::idle_inhibitor_destroy }), -#ifdef XWAYLAND - ml_xwayland_ready({ .notify = Server::xwayland_ready }), - ml_new_xwayland_surface({ .notify = Server::new_xwayland_surface }), + ml_xwayland_ready({ .notify = Server::handle_xwayland_ready }), + ml_new_xwayland_surface({ .notify = Server::handle_new_xwayland_surface }), #endif m_socket(wl_display_add_socket_auto(mp_display)) { @@ -170,7 +159,6 @@ Server::Server(Model_ptr model) } wlr_multi_backend_add(mp_backend, mp_headless_backend); - wlr_export_dmabuf_manager_v1_create(mp_display); wlr_screencopy_manager_v1_create(mp_display); wlr_data_control_manager_v1_create(mp_display); @@ -178,7 +166,7 @@ Server::Server(Model_ptr model) wlr_primary_selection_v1_device_manager_create(mp_display); wlr_scene_attach_output_layout(mp_scene, m_root.mp_output_layout); - wlr_cursor_attach_output_layout(mp_cursor, m_root.mp_output_layout); + wlr_cursor_attach_output_layout(m_seat.mp_cursor, m_root.mp_output_layout); wlr_xcursor_manager_load(mp_cursor_manager, 1); wlr_scene_set_presentation(mp_scene, wlr_presentation_create(mp_display, mp_backend)); wlr_server_decoration_manager_set_default_mode( @@ -190,15 +178,7 @@ Server::Server(Model_ptr model) wl_signal_add(&mp_layer_shell->events.new_surface, &ml_new_layer_shell_surface); wl_signal_add(&mp_xdg_shell->events.new_surface, &ml_new_xdg_surface); wl_signal_add(&mp_idle_inhibit_manager->events.new_inhibitor, &ml_idle_inhibitor_create); - wl_signal_add(&mp_cursor->events.motion, &ml_cursor_motion); - wl_signal_add(&mp_cursor->events.motion_absolute, &ml_cursor_motion_absolute); - wl_signal_add(&mp_cursor->events.button, &ml_cursor_button); - wl_signal_add(&mp_cursor->events.axis, &ml_cursor_axis); - wl_signal_add(&mp_cursor->events.frame, &ml_cursor_frame); wl_signal_add(&mp_backend->events.new_input, &ml_new_input); - wl_signal_add(&mp_seat->events.request_set_cursor, &ml_request_set_cursor); - wl_signal_add(&mp_seat->events.request_set_selection, &ml_request_set_selection); - wl_signal_add(&mp_seat->events.request_set_primary_selection, &ml_request_set_primary_selection); wl_signal_add(&mp_output_manager->events.apply, &ml_output_manager_apply); wl_signal_add(&mp_output_manager->events.test, &ml_output_manager_test); wl_signal_add(&mp_input_inhibit_manager->events.activate, &ml_inhibit_activate); @@ -245,7 +225,7 @@ Server::~Server() } void -Server::start() noexcept +Server::run() noexcept { TRACE(); @@ -253,7 +233,7 @@ Server::start() noexcept } void -Server::new_output(struct wl_listener* listener, void* data) +Server::handle_new_output(struct wl_listener* listener, void* data) { TRACE(); @@ -288,739 +268,157 @@ Server::new_output(struct wl_listener* listener, void* data) } void -Server::output_manager_apply(struct wl_listener* listener, void* data) -{ - // TODO -} - -void -Server::output_manager_test(struct wl_listener* listener, void* data) -{ - // TODO -} - -void -Server::new_xdg_surface(struct wl_listener* listener, void* data) -{ - /* Server_ptr server = wl_container_of(listener, server, ml_new_xdg_surface); */ - - /* struct wlr_xdg_surface* xdg_surface = reinterpret_cast<struct wlr_xdg_surface*>(data); */ - - /* if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { */ - /* struct wlr_xdg_surface* parent */ - /* = wlr_xdg_surface_from_wlr_surface(xdg_surface->popup->parent); */ - - /* struct wlr_scene_node* parent_node */ - /* = reinterpret_cast<struct wlr_scene_node*>(parent->data); */ - - /* xdg_surface->data = wlr_scene_xdg_surface_create(parent_node, xdg_surface); */ - /* return; */ - /* } */ - /* assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); */ - - /* Client_ptr client = new Client( */ - /* server, */ - /* Surface{xdg_surface, true}, */ - /* nullptr, */ - /* nullptr, */ - /* nullptr */ - /* ); */ - - /* xdg_surface->data = client->mp_scene; */ - /* client->mp_scene = wlr_scene_xdg_surface_create( */ - /* &client->mp_server->mp_scene->node, */ - /* client->m_surface.xdg */ - /* ); */ - - /* client->mp_scene->data = client; */ - - /* client->ml_map.notify = xdg_toplevel_map; */ - /* wl_signal_add(&xdg_surface->events.map, &client->ml_map); */ - /* client->ml_unmap.notify = xdg_toplevel_unmap; */ - /* wl_signal_add(&xdg_surface->events.unmap, &client->ml_unmap); */ - /* client->ml_destroy.notify = xdg_toplevel_destroy; */ - /* wl_signal_add(&xdg_surface->events.destroy, &client->ml_destroy); */ - - /* struct wlr_xdg_toplevel* toplevel = xdg_surface->toplevel; */ - /* client->ml_request_move.notify = xdg_toplevel_request_move; */ - /* wl_signal_add(&toplevel->events.request_move, &client->ml_request_move); */ - /* client->ml_request_resize.notify = xdg_toplevel_request_resize; */ - /* wl_signal_add(&toplevel->events.request_resize, &client->ml_request_resize); */ -} - -void -Server::new_layer_shell_surface(struct wl_listener* listener, void* data) -{ - // TODO -} - -void -Server::xdg_activation(struct wl_listener* listener, void* data) -{ - // TODO -} - -void -Server::new_input(struct wl_listener* listener, void* data) -{ - /* Server_ptr server = wl_container_of(listener, server, ml_new_input); */ - /* struct wlr_input_device* device = reinterpret_cast<struct wlr_input_device*>(data); */ - - /* switch (device->type) { */ - /* case WLR_INPUT_DEVICE_KEYBOARD: */ - /* new_keyboard(server, device); */ - /* break; */ - /* case WLR_INPUT_DEVICE_POINTER: */ - /* new_pointer(server, device); */ - /* break; */ - /* default: */ - /* break; */ - /* } */ - - /* uint32_t caps = WL_SEAT_CAPABILITY_POINTER; */ - /* if (!wl_list_empty(&server->m_keyboards)) */ - /* caps |= WL_SEAT_CAPABILITY_KEYBOARD; */ - - /* wlr_seat_set_capabilities(server->mp_seat, caps); */ -} - -void -Server::new_pointer(Server_ptr server, struct wlr_input_device* device) -{ - /* wlr_cursor_attach_input_device(server->mp_cursor, device); */ -} - -void -Server::new_keyboard(Server_ptr server, struct wlr_input_device* device) +Server::handle_output_layout_change(struct wl_listener*, void*) { - /* Keyboard* keyboard = reinterpret_cast<Keyboard*>(calloc(1, sizeof(Keyboard))); */ - /* keyboard->mp_server = server; */ - /* keyboard->mp_device = device; */ - - /* struct xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); */ - /* struct xkb_keymap* keymap = xkb_keymap_new_from_names( */ - /* context, */ - /* NULL, */ - /* XKB_KEYMAP_COMPILE_NO_FLAGS */ - /* ); */ - - /* wlr_keyboard_set_keymap(device->keyboard, keymap); */ - /* xkb_keymap_unref(keymap); */ - /* xkb_context_unref(context); */ - /* wlr_keyboard_set_repeat_info(device->keyboard, 25, 600); */ - - /* keyboard->ml_modifiers.notify = keyboard_handle_modifiers; */ - /* wl_signal_add(&device->keyboard->events.modifiers, &keyboard->ml_modifiers); */ - /* keyboard->ml_key.notify = keyboard_handle_key; */ - /* wl_signal_add(&device->keyboard->events.key, &keyboard->ml_key); */ - - /* wlr_seat_set_keyboard(server->mp_seat, device); */ - /* wl_list_insert(&server->m_keyboards, &keyboard->m_link); */ -} - -void -Server::inhibit_activate(struct wl_listener* listener, void* data) -{ - // TODO -} + TRACE(); -void -Server::inhibit_deactivate(struct wl_listener* listener, void* data) -{ - // TODO } void -Server::idle_inhibitor_create(struct wl_listener* listener, void* data) +Server::handle_output_manager_apply(struct wl_listener*, void*) { - // TODO -} + TRACE(); -void -Server::idle_inhibitor_destroy(struct wl_listener* listener, void* data) -{ - // TODO } void -Server::cursor_motion(struct wl_listener* listener, void* data) +Server::handle_output_manager_test(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_cursor_motion); */ - /* struct wlr_event_pointer_motion* event */ - /* = reinterpret_cast<wlr_event_pointer_motion*>(data); */ + TRACE(); - /* wlr_cursor_move(server->mp_cursor, event->device, event->delta_x, event->delta_y); */ - /* cursor_process_motion(server, event->time_msec); */ } void -Server::cursor_motion_absolute(struct wl_listener* listener, void* data) +Server::handle_new_xdg_surface(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_cursor_motion_absolute); */ - /* struct wlr_event_pointer_motion_absolute* event */ - /* = reinterpret_cast<wlr_event_pointer_motion_absolute*>(data); */ + TRACE(); - /* wlr_cursor_warp_absolute(server->mp_cursor, event->device, event->x, event->y); */ - /* cursor_process_motion(server, event->time_msec); */ } void -Server::cursor_button(struct wl_listener* listener, void* data) +Server::handle_new_layer_shell_surface(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_cursor_button); */ - - /* struct wlr_event_pointer_button* event */ - /* = reinterpret_cast<wlr_event_pointer_button*>(data); */ - - /* wlr_seat_pointer_notify_button( */ - /* server->mp_seat, */ - /* event->time_msec, */ - /* event->button, */ - /* event->state */ - /* ); */ - - /* struct wlr_surface* surface = NULL; */ - - /* double sx, sy; */ - /* Client_ptr client = desktop_client_at( */ - /* server, */ - /* server->mp_cursor->x, */ - /* server->mp_cursor->y, */ - /* &surface, */ - /* &sx, */ - /* &sy */ - /* ); */ - - /* if (event->state == WLR_BUTTON_RELEASED) */ - /* server->m_cursor_mode = Server::CursorMode::Passthrough; */ - /* else */ - /* focus_client(client, surface); */ -} + TRACE(); -void -Server::cursor_axis(struct wl_listener* listener, void* data) -{ - /* Server_ptr server = wl_container_of(listener, server, ml_cursor_axis); */ - - /* struct wlr_event_pointer_axis* event */ - /* = reinterpret_cast<wlr_event_pointer_axis*>(data); */ - - /* wlr_seat_pointer_notify_axis( */ - /* server->mp_seat, */ - /* event->time_msec, */ - /* event->orientation, */ - /* event->delta, */ - /* event->delta_discrete, */ - /* event->source */ - /* ); */ } void -Server::cursor_frame(struct wl_listener* listener, void* data) +Server::handle_xdg_activation(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_cursor_frame); */ + TRACE(); - /* wlr_seat_pointer_notify_frame(server->mp_seat); */ } void -Server::request_set_cursor(struct wl_listener* listener, void* data) +Server::handle_new_input(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_request_set_cursor); */ - - /* struct wlr_seat_pointer_request_set_cursor_event* event */ - /* = reinterpret_cast<struct wlr_seat_pointer_request_set_cursor_event*>(data); */ - /* struct wlr_seat_client* focused_client = server->mp_seat->pointer_state.focused_client; */ - - /* if (focused_client == event->seat_client) */ - /* wlr_cursor_set_surface( */ - /* server->mp_cursor, */ - /* event->surface, */ - /* event->hotspot_x, */ - /* event->hotspot_y */ - /* ); */ -} + TRACE(); -void -Server::cursor_process_motion(Server_ptr server, uint32_t time) -{ - /* switch (server->m_cursor_mode) { */ - /* case Server::CursorMode::Move: cursor_process_move(server, time); return; */ - /* case Server::CursorMode::Resize: cursor_process_resize(server, time); return; */ - /* default: break; */ - /* } */ - - /* struct wlr_seat* seat = server->mp_seat; */ - /* struct wlr_surface* surface = NULL; */ - - /* double sx, sy; */ - /* Client_ptr client = desktop_client_at( */ - /* server, */ - /* server->mp_cursor->x, */ - /* server->mp_cursor->y, */ - /* &surface, */ - /* &sx, */ - /* &sy */ - /* ); */ - - /* if (!client) */ - /* wlr_xcursor_manager_set_cursor_image( */ - /* server->mp_cursor_manager, */ - /* "left_ptr", */ - /* server->mp_cursor */ - /* ); */ - - /* if (surface) { */ - /* wlr_seat_pointer_notify_enter(seat, surface, sx, sy); */ - /* wlr_seat_pointer_notify_motion(seat, time, sx, sy); */ - /* } else */ - /* wlr_seat_pointer_clear_focus(seat); */ } void -Server::cursor_process_move(Server_ptr server, uint32_t time) +Server::handle_inhibit_activate(struct wl_listener*, void*) { - /* Client_ptr client = server->mp_grabbed_client; */ - - /* client->m_active_region.pos.x = server->mp_cursor->x - server->m_grab_x; */ - /* client->m_active_region.pos.y = server->mp_cursor->y - server->m_grab_y; */ + TRACE(); - /* wlr_scene_node_set_position( */ - /* client->mp_scene, */ - /* client->m_active_region.pos.x, */ - /* client->m_active_region.pos.y */ - /* ); */ } void -Server::cursor_process_resize(Server_ptr server, uint32_t time) +Server::handle_inhibit_deactivate(struct wl_listener*, void*) { - /* Client_ptr client = server->mp_grabbed_client; */ - - /* double border_x = server->mp_cursor->x - server->m_grab_x; */ - /* double border_y = server->mp_cursor->y - server->m_grab_y; */ - - /* int new_left = server->m_grab_geobox.x; */ - /* int new_right = server->m_grab_geobox.x + server->m_grab_geobox.width; */ - /* int new_top = server->m_grab_geobox.y; */ - /* int new_bottom = server->m_grab_geobox.y + server->m_grab_geobox.height; */ - - /* if (server->m_resize_edges & WLR_EDGE_TOP) { */ - /* new_top = border_y; */ - - /* if (new_top >= new_bottom) */ - /* new_top = new_bottom - 1; */ - /* } else if (server->m_resize_edges & WLR_EDGE_BOTTOM) { */ - /* new_bottom = border_y; */ - - /* if (new_bottom <= new_top) */ - /* new_bottom = new_top + 1; */ - /* } */ - - /* if (server->m_resize_edges & WLR_EDGE_LEFT) { */ - /* new_left = border_x; */ - - /* if (new_left >= new_right) */ - /* new_left = new_right - 1; */ - /* } else if (server->m_resize_edges & WLR_EDGE_RIGHT) { */ - /* new_right = border_x; */ - - /* if (new_right <= new_left) */ - /* new_right = new_left + 1; */ - /* } */ - - /* struct wlr_box geo_box; */ - /* wlr_xdg_surface_get_geometry(client->m_surface.xdg, &geo_box); */ - - /* client->m_active_region.pos.x = new_left - geo_box.x; */ - /* client->m_active_region.pos.y = new_top - geo_box.y; */ - - /* wlr_scene_node_set_position( */ - /* client->mp_scene, */ - /* client->m_active_region.pos.x, */ - /* client->m_active_region.pos.y */ - /* ); */ - - /* int new_width = new_right - new_left; */ - /* int new_height = new_bottom - new_top; */ + TRACE(); - /* wlr_xdg_toplevel_set_size( */ - /* client->m_surface.xdg, */ - /* new_width, */ - /* new_height */ - /* ); */ } void -Server::request_start_drag(struct wl_listener*, void*) +Server::handle_idle_inhibitor_create(struct wl_listener*, void*) { + TRACE(); } void -Server::start_drag(struct wl_listener*, void*) +Server::handle_idle_inhibitor_destroy(struct wl_listener*, void*) { + TRACE(); } void -Server::keyboard_handle_modifiers(struct wl_listener* listener, void* data) +Server::handle_xdg_toplevel_map(struct wl_listener*, void*) { - /* Keyboard* keyboard = wl_container_of(listener, keyboard, ml_modifiers); */ + TRACE(); - /* wlr_seat_set_keyboard(keyboard->mp_server->mp_seat, keyboard->mp_device); */ - /* wlr_seat_keyboard_notify_modifiers( */ - /* keyboard->mp_server->mp_seat, */ - /* &keyboard->mp_device->keyboard->modifiers */ - /* ); */ } void -Server::keyboard_handle_key(struct wl_listener* listener, void* data) +Server::handle_xdg_toplevel_unmap(struct wl_listener*, void*) { - /* Keyboard* keyboard = wl_container_of(listener, keyboard, ml_key); */ - /* Server_ptr server = keyboard->mp_server; */ - - /* struct wlr_event_keyboard_key* event */ - /* = reinterpret_cast<struct wlr_event_keyboard_key*>(data); */ - /* struct wlr_seat* seat = server->mp_seat; */ - - /* uint32_t keycode = event->keycode + 8; */ - /* const xkb_keysym_t* syms; */ - - /* int nsyms = xkb_state_key_get_syms( */ - /* keyboard->mp_device->keyboard->xkb_state, */ - /* keycode, */ - /* &syms */ - /* ); */ - - /* bool handled = false; */ - /* uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->mp_device->keyboard); */ - - /* if ((modifiers & WLR_MODIFIER_ALT) && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { */ - /* for (int i = 0; i < nsyms; i++) */ - /* handled = keyboard_handle_keybinding(server, syms[i]); */ - /* } */ - - /* if (!handled) { */ - /* wlr_seat_set_keyboard(seat, keyboard->mp_device); */ - /* wlr_seat_keyboard_notify_key( */ - /* seat, */ - /* event->time_msec, */ - /* event->keycode, */ - /* event->state */ - /* ); */ - /* } */ -} + TRACE(); -bool -Server::keyboard_handle_keybinding(Server_ptr server, xkb_keysym_t sym) -{ - /* switch (sym) { */ - /* case XKB_KEY_Escape: */ - /* wl_display_terminate(server->mp_display); */ - /* break; */ - /* case XKB_KEY_j: */ - /* { */ - /* if (wl_list_length(&server->m_clients) < 2) */ - /* break; */ - - /* /1* Client_ptr prev_client = wl_container_of( *1/ */ - /* /1* server->m_clients.prev, *1/ */ - /* /1* prev_client, *1/ */ - /* /1* link *1/ */ - /* /1* ); *1/ */ - - /* /1* focus_client( *1/ */ - /* /1* prev_client, *1/ */ - /* /1* prev_client->get_surface() *1/ */ - /* /1* ); *1/ */ - /* } */ - /* break; */ - /* case XKB_KEY_Return: */ - /* { */ - /* std::string foot = "foot"; */ - /* exec_external(foot); */ - /* } */ - /* break; */ - /* case XKB_KEY_semicolon: */ - /* { */ - /* std::string st = "st"; */ - /* exec_external(st); */ - /* } */ - /* break; */ - /* default: return false; */ - /* } */ - - /* return true; */ } void -Server::request_set_selection(struct wl_listener* listener, void* data) +Server::handle_xdg_toplevel_destroy(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_request_set_selection); */ - - /* struct wlr_seat_request_set_selection_event* event */ - /* = reinterpret_cast<struct wlr_seat_request_set_selection_event*>(data); */ + TRACE(); - /* wlr_seat_set_selection(server->mp_seat, event->source, event->serial); */ } void -Server::request_set_primary_selection(struct wl_listener* listener, void* data) +Server::handle_xdg_toplevel_request_move(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_request_set_primary_selection); */ - - /* struct wlr_seat_request_set_primary_selection_event* event */ - /* = reinterpret_cast<struct wlr_seat_request_set_primary_selection_event*>(data); */ - - /* wlr_seat_set_primary_selection(server->mp_seat, event->source, event->serial); */ -} - -Client_ptr -Server::desktop_client_at( - Server_ptr server, - double lx, - double ly, - struct wlr_surface** surface, - double* sx, - double* sy -) -{ - /* struct wlr_scene_node* node = wlr_scene_node_at( */ - /* &server->mp_scene->node, */ - /* lx, ly, */ - /* sx, sy */ - /* ); */ - - /* if (!node || node->type != WLR_SCENE_NODE_SURFACE) */ - /* return nullptr; */ - - /* *surface = wlr_scene_surface_from_node(node)->surface; */ - - /* while (node && !node->data) */ - /* node = node->parent; */ - - /* return reinterpret_cast<Client_ptr>(node->data); */ -} + TRACE(); -void -Server::focus_client(Client_ptr client, struct wlr_surface* surface) -{ - /* if (!client) */ - /* return; */ - - /* Server_ptr server = client->mp_server; */ - /* struct wlr_seat* seat = server->mp_seat; */ - /* struct wlr_surface* prev_surface = seat->keyboard_state.focused_surface; */ - - /* if (prev_surface == surface) */ - /* return; */ - - /* /1* if (prev_surface) *1/ */ - /* /1* wlr_xdg_toplevel_set_activated( *1/ */ - /* /1* wlr_xdg_surface_from_wlr_surface( *1/ */ - /* /1* seat->keyboard_state.focused_surface *1/ */ - /* /1* ), *1/ */ - /* /1* false *1/ */ - /* /1* ); *1/ */ - - /* struct wlr_keyboard* keyboard = wlr_seat_get_keyboard(seat); */ - - /* if (client->mp_scene) */ - /* wlr_scene_node_raise_to_top(client->mp_scene); */ - - /* /1* wl_list_remove(&client->link); *1/ */ - /* /1* wl_list_insert(&server->m_clients, &client->link); *1/ */ - - /* if (client->m_surface.type == SurfaceType::XDGShell || client->m_surface.type == SurfaceType::LayerShell) */ - /* wlr_xdg_toplevel_set_activated(client->m_surface.xdg, true); */ - - /* wlr_seat_keyboard_notify_enter( */ - /* seat, */ - /* client->get_surface(), */ - /* keyboard->keycodes, */ - /* keyboard->num_keycodes, */ - /* &keyboard->modifiers */ - /* ); */ } void -Server::xdg_toplevel_map(struct wl_listener* listener, void* data) +Server::handle_xdg_toplevel_request_resize(struct wl_listener*, void*) { - /* Client_ptr client = wl_container_of(listener, client, ml_map); */ + TRACE(); - /* /1* wl_list_insert(&client->server->m_clients, &client->link); *1/ */ - /* focus_client(client, client->get_surface()); */ } void -Server::xdg_toplevel_unmap(struct wl_listener* listener, void* data) +Server::handle_xdg_toplevel_handle_moveresize(Client_ptr, CursorMode, uint32_t) { - /* Client_ptr client = wl_container_of(listener, client, ml_unmap); */ - /* /1* wl_list_remove(&client->link); *1/ */ -} - -void -Server::xdg_toplevel_destroy(struct wl_listener* listener, void* data) -{ - /* Client_ptr client = wl_container_of(listener, client, ml_destroy); */ - - /* wl_list_remove(&client->ml_map.link); */ - /* wl_list_remove(&client->ml_unmap.link); */ - /* wl_list_remove(&client->ml_destroy.link); */ - /* wl_list_remove(&client->ml_request_move.link); */ - /* wl_list_remove(&client->ml_request_resize.link); */ - - /* delete client; */ -} + TRACE(); -void -Server::xdg_toplevel_request_move(struct wl_listener* listener, void* data) -{ - /* Client_ptr client = wl_container_of(listener, client, ml_request_move); */ - /* xdg_toplevel_handle_moveresize(client, Server::CursorMode::Move, 0); */ } +#ifdef XWAYLAND void -Server::xdg_toplevel_request_resize(struct wl_listener* listener, void* data) +Server::handle_xwayland_ready(struct wl_listener*, void*) { - /* struct wlr_xdg_toplevel_resize_event* event */ - /* = reinterpret_cast<struct wlr_xdg_toplevel_resize_event*>(data); */ - - /* Client_ptr client = wl_container_of(listener, client, ml_request_resize); */ - /* xdg_toplevel_handle_moveresize(client, Server::CursorMode::Resize, event->edges); */ -} + TRACE(); -void -Server::xdg_toplevel_handle_moveresize( - Client_ptr client, - Server::CursorMode mode, - uint32_t edges -) -{ - /* Server_ptr server = client->mp_server; */ - - /* if (client->get_surface() */ - /* != wlr_surface_get_root_surface(server->mp_seat->pointer_state.focused_surface)) */ - /* { */ - /* return; */ - /* } */ - - /* server->mp_grabbed_client = client; */ - /* server->m_cursor_mode = mode; */ - - /* switch (mode) { */ - /* case Server::CursorMode::Move: */ - /* server->m_grab_x = server->mp_cursor->x - client->m_active_region.pos.x; */ - /* server->m_grab_y = server->mp_cursor->y - client->m_active_region.pos.y; */ - /* return; */ - /* case Server::CursorMode::Resize: */ - /* { */ - /* struct wlr_box geo_box; */ - /* wlr_xdg_surface_get_geometry(client->m_surface.xdg, &geo_box); */ - - /* double border_x = (client->m_active_region.pos.x + geo_box.x) + */ - /* ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0); */ - - /* double border_y = (client->m_active_region.pos.y + geo_box.y) + */ - /* ((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0); */ - - /* server->m_grab_x = server->mp_cursor->x - border_x; */ - /* server->m_grab_y = server->mp_cursor->y - border_y; */ - - /* server->m_grab_geobox = geo_box; */ - /* server->m_grab_geobox.x += client->m_active_region.pos.x; */ - /* server->m_grab_geobox.y += client->m_active_region.pos.y; */ - - /* server->m_resize_edges = edges; */ - /* } */ - /* return; */ - /* default: return; */ - /* } */ } -#ifdef XWAYLAND void -Server::xwayland_ready(struct wl_listener* listener, void*) +Server::handle_new_xwayland_surface(struct wl_listener*, void*) { - /* Server_ptr server = wl_container_of(listener, server, ml_xwayland_ready); */ - - /* xcb_connection_t* xconn = xcb_connect(server->mp_xwayland->display_name, NULL); */ - /* if (xcb_connection_has_error(xconn)) { */ - /* spdlog::error("Could not establish a connection with the X server"); */ - /* spdlog::warn("Continuing with limited XWayland functionality"); */ - /* return; */ - /* } */ - - /* /1* netatom[NetWMWindowTypeDialog] = getatom(xconn, "_NET_WM_WINDOW_TYPE_DIALOG"); *1/ */ - /* /1* netatom[NetWMWindowTypeSplash] = getatom(xconn, "_NET_WM_WINDOW_TYPE_SPLASH"); *1/ */ - /* /1* netatom[NetWMWindowTypeToolbar] = getatom(xconn, "_NET_WM_WINDOW_TYPE_TOOLBAR"); *1/ */ - /* /1* netatom[NetWMWindowTypeUtility] = getatom(xconn, "_NET_WM_WINDOW_TYPE_UTILITY"); *1/ */ - - /* wlr_xwayland_set_seat(server->mp_xwayland, server->mp_seat); */ - - /* struct wlr_xcursor* xcursor; */ - /* if ((xcursor = wlr_xcursor_manager_get_xcursor(server->mp_cursor_manager, "left_ptr", 1))) */ - /* wlr_xwayland_set_cursor(server->mp_xwayland, */ - /* xcursor->images[0]->buffer, xcursor->images[0]->width * 4, */ - /* xcursor->images[0]->width, xcursor->images[0]->height, */ - /* xcursor->images[0]->hotspot_x, xcursor->images[0]->hotspot_y); */ - - /* xcb_disconnect(xconn); */ -} + TRACE(); -void -Server::new_xwayland_surface(struct wl_listener* listener, void* data) -{ - /* Server_ptr server = wl_container_of(listener, server, ml_new_xwayland_surface); */ - - /* struct wlr_xwayland_surface* xwayland_surface */ - /* = reinterpret_cast<wlr_xwayland_surface*>(data); */ - - /* Client_ptr client = new Client( */ - /* server, */ - /* Surface{xwayland_surface, xwayland_surface->override_redirect}, */ - /* nullptr, */ - /* nullptr, */ - /* nullptr */ - /* ); */ - - /* xwayland_surface->data = client; */ - - /* client->ml_map = { .notify = Server::xdg_toplevel_map }; */ - /* client->ml_unmap = { .notify = Server::xdg_toplevel_unmap }; */ - /* client->ml_destroy = { .notify = Server::xdg_toplevel_destroy }; */ - /* // TODO: client->ml_set_title = { .notify = Server::... }; */ - /* // TODO: client->ml_fullscreen = { .notify = Server::... }; */ - /* client->ml_request_activate = { .notify = Server::xwayland_request_activate }; */ - /* client->ml_request_configure = { .notify = Server::xwayland_request_configure }; */ - /* client->ml_set_hints = { .notify = Server::xwayland_set_hints }; */ - /* // TODO: client->ml_new_xdg_popup = { .notify = Server::... }; */ - - /* wl_signal_add(&xwayland_surface->events.map, &client->ml_map); */ - /* wl_signal_add(&xwayland_surface->events.unmap, &client->ml_unmap); */ - /* wl_signal_add(&xwayland_surface->events.destroy, &client->ml_destroy); */ - /* wl_signal_add(&xwayland_surface->events.request_activate, &client->ml_request_activate); */ - /* wl_signal_add(&xwayland_surface->events.request_configure, &client->ml_request_configure); */ - /* wl_signal_add(&xwayland_surface->events.set_hints, &client->ml_set_hints); */ } void -Server::xwayland_request_activate(struct wl_listener* listener, void*) +Server::handle_xwayland_request_activate(struct wl_listener*, void*) { + TRACE(); } void -Server::xwayland_request_configure(struct wl_listener* listener, void*) +Server::handle_xwayland_request_configure(struct wl_listener*, void*) { + TRACE(); } void -Server::xwayland_set_hints(struct wl_listener* listener, void*) +Server::handle_xwayland_set_hints(struct wl_listener*, void*) { + TRACE(); } #endif diff --git a/src/kranewl/tree/output.cc b/src/kranewl/tree/output.cc @@ -1,17 +1,29 @@ #include <trace.hh> -#include <kranewl/tree/output.hh> +#include <kranewl/model.hh> #include <kranewl/server.hh> +#include <kranewl/tree/output.hh> +// https://github.com/swaywm/wlroots/issues/682 +#include <pthread.h> +#define class class_ +#define namespace namespace_ +#define static extern "C" { #include <wlr/types/wlr_output_damage.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_scene.h> } +#undef static +#undef class +#undef namespace Output::Output( Server_ptr server, Model_ptr model, struct wlr_output* wlr_output, - struct wlr_scene_output* wlr_scene_output + struct wlr_scene_output* wlr_scene_output, + bool fallback ) : Node(this), mp_context(nullptr), @@ -19,23 +31,25 @@ Output::Output( mp_model(model), mp_wlr_output(wlr_output), mp_wlr_scene_output(wlr_scene_output), - m_subpixel(wlr_output->subpixel) + m_subpixel(wlr_output->subpixel), + ml_frame({ .notify = Output::handle_frame }), + ml_destroy({ .notify = Output::handle_destroy }), + ml_present({ .notify = Output::handle_present }), + ml_mode({ .notify = Output::handle_mode }), + ml_commit({ .notify = Output::handle_commit }) { TRACE(); - ml_frame.notify = Output::handle_frame; - ml_destroy.notify = Output::handle_destroy; - ml_present.notify = Output::handle_present; - ml_mode.notify = Output::handle_mode; - ml_commit.notify = Output::handle_commit; - - wl_signal_add(&mp_wlr_output->events.frame, &ml_frame); wl_signal_add(&mp_wlr_output->events.destroy, &ml_destroy); - wl_signal_add(&mp_wlr_output->events.present, &ml_present); - wl_signal_add(&mp_wlr_output->events.mode, &ml_mode); - wl_signal_add(&mp_wlr_output->events.commit, &ml_commit); - wl_signal_init(&m_events.disable); + if (fallback) { + wl_signal_add(&mp_wlr_output->events.frame, &ml_frame); + wl_signal_add(&mp_wlr_output->events.present, &ml_present); + wl_signal_add(&mp_wlr_output->events.mode, &ml_mode); + wl_signal_add(&mp_wlr_output->events.commit, &ml_commit); + + wl_signal_init(&m_events.disable); + } } Output::~Output() @@ -46,49 +60,53 @@ Output::handle_frame(struct wl_listener* listener, void*) { TRACE(); - /* Output_ptr output = wl_container_of(listener, output, ml_frame); */ + Output_ptr output = wl_container_of(listener, output, ml_frame); + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); - /* struct timespec now; */ - /* clock_gettime(CLOCK_MONOTONIC, &now); */ + if (!wlr_scene_output_commit(output->mp_wlr_scene_output)) + return; - /* wlr_scene_output_commit(output->mp_wlr_scene_output); */ - /* wlr_scene_output_send_frame_done(output->mp_wlr_scene_output, &now); */ + wlr_scene_output_send_frame_done(output->mp_wlr_scene_output, &now); } void -Output::handle_destroy(struct wl_listener*, void*) +Output::handle_commit(struct wl_listener*, void*) { TRACE(); - /* struct wlr_output* wlr_output = reinterpret_cast<struct wlr_output*>(data); */ - /* Output_ptr output = reinterpret_cast<Output_ptr>(wlr_output->data); */ - /* Server_ptr server = output->mp_server; */ - - /* wl_list_remove(&output->ml_destroy.link); */ - /* wl_list_remove(&output->ml_frame.link); */ - - /* wlr_scene_output_destroy(output->mp_wlr_scene_output); */ - /* wlr_output_layout_remove(server->mp_output_layout, output->mp_wlr_output); */ - - /* server->mp_model->unregister_output(output); */ } void -Output::handle_present(struct wl_listener*, void*) +Output::handle_destroy(struct wl_listener*, void* data) { TRACE(); + struct wlr_output* wlr_output = reinterpret_cast<struct wlr_output*>(data); + Output_ptr output = reinterpret_cast<Output_ptr>(wlr_output->data); + + wlr_output_layout_remove(output->mp_server->m_root.mp_output_layout, output->mp_wlr_output); + wlr_scene_output_destroy(output->mp_wlr_scene_output); + + wl_list_remove(&output->ml_frame.link); + wl_list_remove(&output->ml_destroy.link); + wl_list_remove(&output->ml_present.link); + wl_list_remove(&output->ml_mode.link); + wl_list_remove(&output->ml_commit.link); + + output->mp_model->unregister_output(output); } void -Output::handle_mode(struct wl_listener*, void*) +Output::handle_present(struct wl_listener*, void*) { TRACE(); } void -Output::handle_commit(struct wl_listener*, void*) +Output::handle_mode(struct wl_listener*, void*) { TRACE(); diff --git a/src/kranewl/tree/root.cc b/src/kranewl/tree/root.cc @@ -17,13 +17,13 @@ Root::Root( mp_server(server), mp_model(model), mp_output_layout(wlr_output_layout), + ml_output_layout_change({ .notify = Root::handle_output_layout_change }), m_outputs({}, true), m_scratchpad({}, true), mp_fallback_output(fallback_output) { TRACE(); - ml_output_layout_change.notify = Root::handle_output_layout_change; wl_signal_add(&mp_output_layout->events.change, &ml_output_layout_change); wl_signal_init(&m_events.new_node);