diff --git a/include/kiwmi/desktop/desktop.h b/include/kiwmi/desktop/desktop.h new file mode 100644 index 0000000..0b2d424 --- /dev/null +++ b/include/kiwmi/desktop/desktop.h @@ -0,0 +1,30 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef KIWMI_DESKTOP_DESKTOP_H +#define KIWMI_DESKTOP_DESKTOP_H + +#include +#include +#include +#include + +#include "kiwmi/input/cursor.h" + +struct kiwmi_desktop { + struct wlr_compositor *compositor; + struct wlr_data_device_manager *data_device_manager; + struct wlr_output_layout *output_layout; + struct kiwmi_cursor *cursor; + struct wl_list outputs; // struct kiwmi_output::link + + struct wl_listener new_output; +}; + +bool desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer); + +#endif /* KIWMI_DESKTOP_DESKTOP_H */ diff --git a/include/kiwmi/output.h b/include/kiwmi/output.h index d2a49f3..c5d9650 100644 --- a/include/kiwmi/output.h +++ b/include/kiwmi/output.h @@ -11,17 +11,17 @@ #include #include -#include "kiwmi/server.h" +#include "kiwmi/desktop/desktop.h" struct kiwmi_output { struct wl_list link; - struct kiwmi_server *server; + struct kiwmi_desktop *desktop; struct wlr_output *wlr_output; struct wl_listener frame; struct wl_listener destroy; }; struct kiwmi_output * -output_create(struct wlr_output *wlr_output, struct kiwmi_server *server); +output_create(struct wlr_output *wlr_output, struct kiwmi_desktop *desktop); #endif /* KIWMI_OUTPUT_H */ diff --git a/include/kiwmi/server.h b/include/kiwmi/server.h index 15e8318..b4254ca 100644 --- a/include/kiwmi/server.h +++ b/include/kiwmi/server.h @@ -10,23 +10,15 @@ #include #include -#include -#include -#include -#include "kiwmi/input/cursor.h" +#include "kiwmi/desktop/desktop.h" struct kiwmi_server { struct wl_display *wl_display; struct wlr_backend *backend; - struct wlr_compositor *compositor; - struct wlr_data_device_manager *data_device_manager; - struct wlr_output_layout *output_layout; const char *socket; + struct kiwmi_desktop desktop; struct wl_list keyboards; // struct kiwmi_keyboard::link - struct wl_list outputs; // struct kiwmi_output::link - struct wl_listener new_output; - struct kiwmi_cursor *cursor; struct wl_listener new_input; }; diff --git a/kiwmi/desktop/desktop.c b/kiwmi/desktop/desktop.c new file mode 100644 index 0000000..a1f87e6 --- /dev/null +++ b/kiwmi/desktop/desktop.c @@ -0,0 +1,44 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include "kiwmi/desktop/desktop.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include "kiwmi/server.h" +#include "kiwmi/desktop/output.h" +#include "kiwmi/input/cursor.h" + +bool +desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer) +{ + struct kiwmi_server *server = wl_container_of(desktop, server, desktop); + desktop->compositor = wlr_compositor_create(server->wl_display, renderer); + desktop->data_device_manager = + wlr_data_device_manager_create(server->wl_display); + desktop->output_layout = wlr_output_layout_create(); + + desktop->cursor = cursor_create(desktop->output_layout); + if (!desktop->cursor) { + wlr_log(WLR_ERROR, "Failed to create cursor"); + return false; + } + + wl_list_init(&desktop->outputs); + + desktop->new_output.notify = new_output_notify; + wl_signal_add(&server->backend->events.new_output, &desktop->new_output); + + return true; +} diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index 1662826..6262deb 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -13,11 +13,14 @@ #include "kiwmi/output.h" #include "kiwmi/server.h" +#include "kiwmi/desktop/desktop.h" void new_output_notify(struct wl_listener *listener, void *data) { - struct kiwmi_server *server = wl_container_of(listener, server, new_output); + struct kiwmi_desktop *desktop = + wl_container_of(listener, desktop, new_output); + struct kiwmi_server *server = wl_container_of(desktop, server, desktop); struct wlr_output *wlr_output = data; wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); @@ -28,19 +31,19 @@ new_output_notify(struct wl_listener *listener, void *data) wlr_output_set_mode(wlr_output, mode); } - struct kiwmi_output *output = output_create(wlr_output, server); + struct kiwmi_output *output = output_create(wlr_output, desktop); if (!output) { wlr_log(WLR_ERROR, "Failed to create output"); return; } - struct kiwmi_cursor *cursor = server->cursor; + struct kiwmi_cursor *cursor = desktop->cursor; wlr_xcursor_manager_load(cursor->xcursor_manager, wlr_output->scale); - wl_list_insert(&server->outputs, &output->link); + wl_list_insert(&desktop->outputs, &output->link); - wlr_output_layout_add_auto(server->output_layout, wlr_output); + wlr_output_layout_add_auto(desktop->output_layout, wlr_output); wlr_output_create_global(wlr_output); } diff --git a/kiwmi/input.c b/kiwmi/input.c index 9e56d53..3caa597 100644 --- a/kiwmi/input.c +++ b/kiwmi/input.c @@ -17,7 +17,7 @@ static void new_pointer(struct kiwmi_server *server, struct wlr_input_device *device) { - wlr_cursor_attach_input_device(server->cursor->cursor, device); + wlr_cursor_attach_input_device(server->desktop.cursor->cursor, device); } static void diff --git a/kiwmi/meson.build b/kiwmi/meson.build index dbc70aa..7f70811 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -3,6 +3,7 @@ kiwmi_sources = files( 'input.c', 'output.c', 'server.c', + 'desktop/desktop.c', 'desktop/output.c', 'input/cursor.c', 'input/keyboard.c', diff --git a/kiwmi/output.c b/kiwmi/output.c index 2ac7e00..76e2d63 100644 --- a/kiwmi/output.c +++ b/kiwmi/output.c @@ -13,7 +13,7 @@ #include #include -#include "kiwmi/server.h" +#include "kiwmi/desktop/desktop.h" static void output_frame_notify(struct wl_listener *listener, void *data) @@ -47,7 +47,7 @@ output_destroy_notify(struct wl_listener *listener, void *UNUSED(data)) { struct kiwmi_output *output = wl_container_of(listener, output, destroy); - wlr_output_layout_remove(output->server->output_layout, output->wlr_output); + wlr_output_layout_remove(output->desktop->output_layout, output->wlr_output); wl_list_remove(&output->link); wl_list_remove(&output->frame.link); @@ -57,7 +57,7 @@ output_destroy_notify(struct wl_listener *listener, void *UNUSED(data)) } struct kiwmi_output * -output_create(struct wlr_output *wlr_output, struct kiwmi_server *server) +output_create(struct wlr_output *wlr_output, struct kiwmi_desktop *desktop) { struct kiwmi_output *output = calloc(1, sizeof(*output)); if (!output) { @@ -65,7 +65,7 @@ output_create(struct wlr_output *wlr_output, struct kiwmi_server *server) } output->wlr_output = wlr_output; - output->server = server; + output->desktop = desktop; output->frame.notify = output_frame_notify; wl_signal_add(&wlr_output->events.frame, &output->frame); diff --git a/kiwmi/server.c b/kiwmi/server.c index 5e90c68..50c1b0d 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -11,15 +11,10 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include "kiwmi/desktop/output.h" +#include "kiwmi/desktop/desktop.h" #include "kiwmi/input.h" #include "kiwmi/input/cursor.h" @@ -39,24 +34,13 @@ server_init(struct kiwmi_server *server) struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); wlr_renderer_init_wl_display(renderer, server->wl_display); - server->compositor = wlr_compositor_create(server->wl_display, renderer); - server->data_device_manager = - wlr_data_device_manager_create(server->wl_display); - - server->output_layout = wlr_output_layout_create(); - - server->cursor = cursor_create(server->output_layout); - if (!server->cursor) { - wlr_log(WLR_ERROR, "Failed to create cursor"); + if (!desktop_init(&server->desktop, renderer)) { + wlr_log(WLR_ERROR, "Failed to initialize desktop"); wl_display_destroy(server->wl_display); return false; } wl_list_init(&server->keyboards); - wl_list_init(&server->outputs); - - server->new_output.notify = new_output_notify; - wl_signal_add(&server->backend->events.new_output, &server->new_output); server->new_input.notify = new_input_notify; wl_signal_add(&server->backend->events.new_input, &server->new_input);