diff --git a/include/waybox/cursor.h b/include/waybox/cursor.h index ac99f68..38af5ad 100644 --- a/include/waybox/cursor.h +++ b/include/waybox/cursor.h @@ -1,10 +1,9 @@ -#ifndef CURSOR_H -#define CURSOR_H -#include +#ifndef _WB_CURSOR_H +#define _WB_CURSOR_H #include #include -#include "waybox/server.h" +struct wb_server; enum wb_cursor_mode { WB_CURSOR_PASSTHROUGH, @@ -32,4 +31,4 @@ struct wb_cursor { struct wb_cursor *wb_cursor_create(struct wb_server *server); void wb_cursor_destroy(struct wb_cursor *cursor); -#endif // cursor.h +#endif /* cursor.h */ diff --git a/include/waybox/output.h b/include/waybox/output.h index 69e5135..4cde0fd 100644 --- a/include/waybox/output.h +++ b/include/waybox/output.h @@ -1,5 +1,5 @@ -#ifndef OUTPUT_H -#define OUTPUT_H +#ifndef _WB_OUTPUT_H +#define _WB_OUTPUT_H #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L @@ -45,4 +45,4 @@ void output_frame_notify(struct wl_listener* listener, void *data); void output_destroy_notify(struct wl_listener* listener, void *data); void new_output_notify(struct wl_listener* listener, void *data); -#endif // output.h +#endif /* output.h */ diff --git a/include/waybox/seat.h b/include/waybox/seat.h index 19500c5..8501400 100644 --- a/include/waybox/seat.h +++ b/include/waybox/seat.h @@ -6,7 +6,7 @@ #include #include -#include "waybox/server.h" +struct wb_server; struct wb_seat { struct wlr_seat *seat; diff --git a/include/waybox/server.h b/include/waybox/server.h index 61394df..e6238bd 100644 --- a/include/waybox/server.h +++ b/include/waybox/server.h @@ -1,5 +1,5 @@ -#ifndef SERVER_H -#define SERVER_H +#ifndef _WB_SERVER_H +#define _WB_SERVER_H #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L @@ -25,38 +25,40 @@ #include #define _ gettext -#include "waybox/output.h" #include "waybox/cursor.h" +#include "decoration.h" +#include "waybox/output.h" #include "waybox/seat.h" struct wb_server { struct wl_display *wl_display; + struct wlr_allocator *allocator; struct wlr_backend *backend; struct wlr_compositor *compositor; - struct wlr_renderer *renderer; - struct wlr_allocator *allocator; - struct wlr_output_layout *layout; + struct wlr_renderer *renderer; + struct wb_cursor *cursor; struct wb_seat *seat; struct wb_view *grabbed_view; - double grab_x, grab_y; struct wlr_box grab_geo_box; + double grab_x, grab_y; uint32_t resize_edges; + struct wl_list views; struct wlr_xdg_shell *xdg_shell; struct wl_listener new_xdg_surface; - struct wl_list views; + struct wl_listener new_xdg_decoration; - struct wl_listener new_output; struct wl_listener new_input; - struct wl_list outputs; // wb_output::link + struct wl_listener new_output; + struct wl_list outputs; /* wb_output::link */ }; bool wb_create_backend(struct wb_server* server); bool wb_start_server(struct wb_server* server); bool wb_terminate(struct wb_server* server); -#endif // server.h +#endif /* server.h */ diff --git a/include/waybox/xdg_shell.h b/include/waybox/xdg_shell.h index 08833bb..88bc580 100644 --- a/include/waybox/xdg_shell.h +++ b/include/waybox/xdg_shell.h @@ -1,3 +1,6 @@ +#ifndef _WB_XDG_SHELL_H +#define _WB_XDG_SHELL_H + #include "waybox/server.h" void init_xdg_shell(struct wb_server *server); @@ -5,3 +8,4 @@ void focus_view(struct wb_view *view, struct wlr_surface *surface); struct wb_view *desktop_view_at( struct wb_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); +#endif diff --git a/waybox/decoration.c b/waybox/decoration.c new file mode 100644 index 0000000..66b7ec5 --- /dev/null +++ b/waybox/decoration.c @@ -0,0 +1,43 @@ +#include "decoration.h" + +static void destroy_xdg_toplevel_decoration(struct wl_listener *listener, void *data) +{ + struct wb_decoration *decoration = wl_container_of(listener, decoration, toplevel_decoration_destroy); + wl_list_remove(&decoration->toplevel_decoration_destroy.link); + free(decoration); +} + +static void free_xdg_decoration_mode(struct wl_listener *listener, void *data) +{ + struct wb_decoration *decoration = wl_container_of(listener, decoration, mode_destroy); + wl_list_remove(&decoration->mode_destroy.link); + wl_list_remove(&decoration->request_mode.link); +} + +static void handle_xdg_decoration_mode(struct wl_listener *listener, void *data) +{ + struct wlr_xdg_toplevel_decoration_v1 *toplevel_decoration = data; + wlr_xdg_toplevel_decoration_v1_set_mode(toplevel_decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); +} + +static void handle_new_xdg_toplevel_decoration(struct wl_listener *listener, void *data) +{ + struct wb_decoration *decoration = (struct wb_decoration *) calloc(1, sizeof(struct wb_decoration)); + handle_xdg_decoration_mode(&decoration->request_mode, data); + struct wb_server *server = wl_container_of(listener, server, new_xdg_decoration); + decoration->server = server; + struct wlr_xdg_toplevel_decoration_v1 *toplevel_decoration = data; + decoration->toplevel_decoration_destroy.notify = destroy_xdg_toplevel_decoration; + wl_signal_add(&toplevel_decoration->manager->events.destroy, &decoration->toplevel_decoration_destroy); + decoration->request_mode.notify = handle_xdg_decoration_mode; + wl_signal_add(&toplevel_decoration->events.request_mode, &decoration->request_mode); + decoration->mode_destroy.notify = free_xdg_decoration_mode; + wl_signal_add(&toplevel_decoration->events.destroy, &decoration->mode_destroy); +} + +void init_xdg_decoration(struct wb_server *server) +{ + struct wlr_xdg_decoration_manager_v1 *decoration = wlr_xdg_decoration_manager_v1_create(server->wl_display); + server->new_xdg_decoration.notify = handle_new_xdg_toplevel_decoration; + wl_signal_add(&decoration->events.new_toplevel_decoration, &server->new_xdg_decoration); +} diff --git a/waybox/decoration.h b/waybox/decoration.h new file mode 100644 index 0000000..a079511 --- /dev/null +++ b/waybox/decoration.h @@ -0,0 +1,20 @@ +#ifndef _WB_DECORATION_H +#define _WB_DECORATION_H + +#include + +#include "waybox/server.h" + +struct wb_decoration { + struct wb_server *server; + struct wlr_xdg_decoration_manager_v1 *decoration_manager; + struct wlr_xdg_toplevel_decoration_v1 *toplevel_decoration; + + struct wl_listener toplevel_decoration_destroy; + struct wl_listener request_mode; + struct wl_listener mode_destroy; + int yes; +}; + +void init_xdg_decoration(struct wb_server *server); +#endif diff --git a/waybox/main.c b/waybox/main.c index 662ad0d..d8590de 100644 --- a/waybox/main.c +++ b/waybox/main.c @@ -1,6 +1,5 @@ #include #include -#include #include "waybox/server.h" diff --git a/waybox/meson.build b/waybox/meson.build index c793af0..9cddd5f 100644 --- a/waybox/meson.build +++ b/waybox/meson.build @@ -1,5 +1,6 @@ wb_src = files( 'cursor.c', + 'decoration.c', 'main.c', 'output.c', 'seat.c', diff --git a/waybox/server.c b/waybox/server.c index e0b4552..921c2d8 100644 --- a/waybox/server.c +++ b/waybox/server.c @@ -69,6 +69,7 @@ bool wb_start_server(struct wb_server* server) { wlr_data_device_manager_create(server->wl_display); wl_list_init(&server->views); + init_xdg_decoration(server); init_xdg_shell(server); return true; @@ -76,6 +77,7 @@ bool wb_start_server(struct wb_server* server) { bool wb_terminate(struct wb_server* server) { wb_cursor_destroy(server->cursor); + wl_list_remove(&server->new_xdg_decoration.link); /* wb_decoration_destroy */ wb_seat_destroy(server->seat); wl_display_destroy_clients(server->wl_display); wl_display_destroy(server->wl_display); diff --git a/waybox/xdg_shell.c b/waybox/xdg_shell.c index 625355b..db2cb35 100644 --- a/waybox/xdg_shell.c +++ b/waybox/xdg_shell.c @@ -86,7 +86,7 @@ static void begin_interactive(struct wb_view *view, struct wb_server *server = view->server; struct wlr_surface *focused_surface = server->seat->seat->pointer_state.focused_surface; - if (view->xdg_surface->surface != focused_surface) { + if (view->xdg_surface->surface != wlr_surface_get_root_surface(focused_surface)) { /* Deny move/resize requests from unfocused clients. */ return; }