Added desktop_init

This commit is contained in:
buffet 2019-03-17 20:04:52 +01:00
parent 1e2bef4cae
commit 5b91ce1835
9 changed files with 96 additions and 42 deletions

View file

@ -0,0 +1,30 @@
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
*
* 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 <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_output_layout.h>
#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 */

View file

@ -11,17 +11,17 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include "kiwmi/server.h" #include "kiwmi/desktop/desktop.h"
struct kiwmi_output { struct kiwmi_output {
struct wl_list link; struct wl_list link;
struct kiwmi_server *server; struct kiwmi_desktop *desktop;
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
}; };
struct kiwmi_output * 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 */ #endif /* KIWMI_OUTPUT_H */

View file

@ -10,23 +10,15 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_output_layout.h>
#include "kiwmi/input/cursor.h" #include "kiwmi/desktop/desktop.h"
struct kiwmi_server { struct kiwmi_server {
struct wl_display *wl_display; struct wl_display *wl_display;
struct wlr_backend *backend; 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; const char *socket;
struct kiwmi_desktop desktop;
struct wl_list keyboards; // struct kiwmi_keyboard::link 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; struct wl_listener new_input;
}; };

44
kiwmi/desktop/desktop.c Normal file
View file

@ -0,0 +1,44 @@
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
*
* 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 <stdbool.h>
#include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h>
#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;
}

View file

@ -13,11 +13,14 @@
#include "kiwmi/output.h" #include "kiwmi/output.h"
#include "kiwmi/server.h" #include "kiwmi/server.h"
#include "kiwmi/desktop/desktop.h"
void void
new_output_notify(struct wl_listener *listener, void *data) 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; struct wlr_output *wlr_output = data;
wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); 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); 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) { if (!output) {
wlr_log(WLR_ERROR, "Failed to create output"); wlr_log(WLR_ERROR, "Failed to create output");
return; return;
} }
struct kiwmi_cursor *cursor = server->cursor; struct kiwmi_cursor *cursor = desktop->cursor;
wlr_xcursor_manager_load(cursor->xcursor_manager, wlr_output->scale); 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); wlr_output_create_global(wlr_output);
} }

View file

@ -17,7 +17,7 @@
static void static void
new_pointer(struct kiwmi_server *server, struct wlr_input_device *device) 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 static void

View file

@ -3,6 +3,7 @@ kiwmi_sources = files(
'input.c', 'input.c',
'output.c', 'output.c',
'server.c', 'server.c',
'desktop/desktop.c',
'desktop/output.c', 'desktop/output.c',
'input/cursor.c', 'input/cursor.c',
'input/keyboard.c', 'input/keyboard.c',

View file

@ -13,7 +13,7 @@
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include "kiwmi/server.h" #include "kiwmi/desktop/desktop.h"
static void static void
output_frame_notify(struct wl_listener *listener, void *data) 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); 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->link);
wl_list_remove(&output->frame.link); wl_list_remove(&output->frame.link);
@ -57,7 +57,7 @@ output_destroy_notify(struct wl_listener *listener, void *UNUSED(data))
} }
struct kiwmi_output * 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)); struct kiwmi_output *output = calloc(1, sizeof(*output));
if (!output) { if (!output) {
@ -65,7 +65,7 @@ output_create(struct wlr_output *wlr_output, struct kiwmi_server *server)
} }
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
output->server = server; output->desktop = desktop;
output->frame.notify = output_frame_notify; output->frame.notify = output_frame_notify;
wl_signal_add(&wlr_output->events.frame, &output->frame); wl_signal_add(&wlr_output->events.frame, &output->frame);

View file

@ -11,15 +11,10 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/backend.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_data_device.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "kiwmi/desktop/output.h" #include "kiwmi/desktop/desktop.h"
#include "kiwmi/input.h" #include "kiwmi/input.h"
#include "kiwmi/input/cursor.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); struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
wlr_renderer_init_wl_display(renderer, server->wl_display); wlr_renderer_init_wl_display(renderer, server->wl_display);
server->compositor = wlr_compositor_create(server->wl_display, renderer); if (!desktop_init(&server->desktop, renderer)) {
server->data_device_manager = wlr_log(WLR_ERROR, "Failed to initialize desktop");
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");
wl_display_destroy(server->wl_display); wl_display_destroy(server->wl_display);
return false; return false;
} }
wl_list_init(&server->keyboards); 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; server->new_input.notify = new_input_notify;
wl_signal_add(&server->backend->events.new_input, &server->new_input); wl_signal_add(&server->backend->events.new_input, &server->new_input);