Commit bdfe0151b4dce7d3e12c67c80f51cc3128fb212d Parent: 77579c88434333d01e7e0b2b69fa96cc0ec3715c Author: mcol <mcol@posteo.net> Date: 2020-11-05 10:32:58 +0000 Committer: mcol <mcol@posteo.net> Committed: 2020-11-05 10:32:58 +0000 move types to dedicated header to avoid recursions. Add initial start code
src/types.h Added
@@ -0,0 +1,69 @@ +#pragma once + +#include <stdlib.h> +#include <unistd.h> +#include <wlr/backend.h> +#include <wlr/render/wlr_renderer.h> +#include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_xdg_shell.h> +#include <wlr/util/log.h> + + +enum cursor_mode { + CURSOR_PASSTHROUGH, + CURSOR_MOVE, + CURSOR_RESIZE, +}; + + +struct server { + struct wl_display *display; + struct wlr_backend *backend; + struct wlr_renderer *renderer; + + struct wlr_output_layout *output_layout; + struct wl_list outputs; + struct wl_listener new_output_listener; + + struct wlr_xdg_shell *shell; + struct wl_listener new_xdg_surface_listener; + struct wl_list views; + + struct wlr_cursor *cursor; + struct wlr_xcursor_manager *cursor_manager; + struct wl_listener cursor_motion_listener; + struct wl_listener cursor_motion_absolute_listener; + struct wl_listener cursor_button_listener; + struct wl_listener cursor_axis_listener; + struct wl_listener cursor_frame_listener; + + struct wlr_seat *seat; + struct wl_listener new_input_listener; + struct wl_listener request_cursor_listener; + struct wl_listener request_set_selection_listener; + struct wl_list keyboards; + enum cursor_mode cursor_mode; + struct deskwm_view *grabbed_view; + double grab_x, grab_y; + struct wlr_box grab_geobox; + uint32_t resize_edges; +}; + + +struct view { + struct wl_list link; + struct server *server; + struct wlr_xdg_surface *surface; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener destroy; + struct wl_listener request_move; + struct wl_listener request_resize; + bool is_mapped; + int x, y; +}; + + +struct server create_server();
src/shell.h Modified
@@ -1,6 +1,6 @@ #pragma once -#include "deskwm.h" +#include "types.h" void on_map(struct wl_listener *listener, void *data);
src/shell.c Modified
@@ -1,5 +1,5 @@ -#include "deskwm.h" #include "output.h" +#include "types.h" void on_map(struct wl_listener *listener, void *data) {
src/output.h Modified
@@ -1,7 +1,7 @@ #pragma once #include <wlr/types/wlr_output_layout.h> -#include "deskwm.h" +#include "types.h" struct output {
src/output.c Modified
@@ -1,7 +1,7 @@ #include <wlr/types/wlr_output_layout.h> -#include "deskwm.h" #include "output.h" +#include "types.h" void on_frame(struct wl_listener *listener, void *data) {
src/input.h Added
@@ -0,0 +1,15 @@ +#pragma once + +#include "types.h" + + +void on_cursor_motion(struct wl_listener *listener, void *data); +void on_cursor_motion_absolute(struct wl_listener *listener, void *data); +void on_cursor_button(struct wl_listener *listener, void *data); +void on_cursor_axis(struct wl_listener *listener, void *data); +void on_cursor_frame(struct wl_listener *listener, void *data); +void on_new_input(struct wl_listener *listener, void *data); +void on_request_cursor(struct wl_listener *listener, void *data); +void on_request_set_selection(struct wl_listener *listener, void *data); +void set_up_cursor(struct server *server); +void set_up_keyboard(struct server *server);
src/input.c Added
@@ -0,0 +1,86 @@ +#include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_xcursor_manager.h> + +#include "input.h" +#include "types.h" + + +void on_cursor_motion(struct wl_listener *listener, void *data){ + return; +} + + +void on_cursor_motion_absolute(struct wl_listener *listener, void *data) { + return; +} + + +void on_cursor_button(struct wl_listener *listener, void *data) { + return; +} + +void on_cursor_axis(struct wl_listener *listener, void *data) { + return; +} + + +void on_cursor_frame(struct wl_listener *listener, void *data) { + return; +} + + +void on_new_input(struct wl_listener *listener, void *data) { + return; +} + + +void on_request_cursor(struct wl_listener *listener, void *data) { + return; +} + + +void on_request_set_selection(struct wl_listener *listener, void *data) { + return; +} + + + +void set_up_cursor(struct server *server) { + server->cursor = wlr_cursor_create(); + wlr_cursor_attach_output_layout(server->cursor, server->output_layout); + server->cursor_manager = wlr_xcursor_manager_create(NULL, 24); + wlr_xcursor_manager_load(server->cursor_manager, 1); + + server->cursor_motion_listener.notify = on_cursor_motion; + wl_signal_add(&server->cursor->events.motion, &server->cursor_motion_listener); + + server->cursor_motion_absolute_listener.notify = on_cursor_motion_absolute; + wl_signal_add(&server->cursor->events.motion_absolute, + &server->cursor_motion_absolute_listener); + + server->cursor_button_listener.notify = on_cursor_button; + wl_signal_add(&server->cursor->events.button, &server->cursor_button_listener); + + server->cursor_axis_listener.notify = on_cursor_axis; + wl_signal_add(&server->cursor->events.axis, &server->cursor_axis_listener); + + server->cursor_frame_listener.notify = on_cursor_frame; + wl_signal_add(&server->cursor->events.frame, &server->cursor_frame_listener); +} + + +void set_up_keyboard(struct server *server) { + wl_list_init(&server->keyboards); + + server->new_input_listener.notify = on_new_input; + wl_signal_add(&server->backend->events.new_input, &server->new_input_listener); + + server->seat = wlr_seat_create(server->display, "seat0"); + server->request_cursor_listener.notify = on_request_cursor; + wl_signal_add(&server->seat->events.request_set_cursor, + &server->request_cursor_listener); + + server->request_set_selection_listener.notify = on_request_set_selection; + wl_signal_add(&server->seat->events.request_set_selection, + &server->request_set_selection_listener); +}
src/deskwm.h Modified
@@ -1,42 +1,6 @@ #pragma once -#include <stdlib.h> -#include <unistd.h> -#include <wlr/backend.h> -#include <wlr/render/wlr_renderer.h> -#include <wlr/types/wlr_compositor.h> -#include <wlr/types/wlr_output_layout.h> -#include <wlr/types/wlr_xdg_shell.h> -#include <wlr/util/log.h> +#include "types.h" -struct server { - struct wl_display *display; - struct wlr_backend *backend; - struct wlr_renderer *renderer; - - struct wlr_output_layout *output_layout; - struct wl_list outputs; - struct wl_listener new_output_listener; - - struct wlr_xdg_shell *shell; - struct wl_listener new_xdg_surface_listener; - struct wl_list views; -}; - - -struct view { - struct wl_list link; - struct server *server; - struct wlr_xdg_surface *surface; - struct wl_listener map; - struct wl_listener unmap; - struct wl_listener destroy; - struct wl_listener request_move; - struct wl_listener request_resize; - bool is_mapped; - int x, y; -}; - - -void create_serve(); +struct server create_server();
src/deskwm.c Modified
@@ -7,8 +7,10 @@ #include <wlr/util/log.h> #include "deskwm.h" +#include "input.h" #include "output.h" #include "shell.h" +#include "types.h" struct server create_server() { @@ -39,12 +41,28 @@ // configure set_up_outputs(&server); set_up_shell(&server); + set_up_cursor(&server); + set_up_keyboard(&server); // start + const char *socket = wl_display_add_socket_auto(server.display); + if (!socket) { + wlr_backend_destroy(server.backend); + wl_display_destroy(server.display); + return EXIT_FAILURE; + } + if (!wlr_backend_start(server.backend)) { + wlr_backend_destroy(server.backend); + wl_display_destroy(server.display); + return 1; + } + setenv("WAYLAND_DISPLAY", socket, true); + wlr_log(WLR_INFO, "Starting with WAYLAND_DISPLAY=%s", socket); wl_display_run(server.display); // stop + wl_display_destroy_clients(server.display); wlr_backend_destroy(server.backend); wl_display_destroy(server.display); - return 0; + return EXIT_SUCCESS; }