From 45e5f6235ef0343f276acf32512970669b49e255 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Thu, 7 Mar 2019 23:36:45 +0100 Subject: [PATCH] Render cursors --- include/kiwmi/input.h | 15 +++++++++++++++ include/kiwmi/server.h | 1 + kiwmi/input.c | 38 ++++++++++++++++++++++++++++++++++++++ kiwmi/meson.build | 1 + kiwmi/output.c | 17 +++++++++++++---- kiwmi/server.c | 8 ++++++-- 6 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 include/kiwmi/input.h create mode 100644 kiwmi/input.c diff --git a/include/kiwmi/input.h b/include/kiwmi/input.h new file mode 100644 index 0000000..5f4e901 --- /dev/null +++ b/include/kiwmi/input.h @@ -0,0 +1,15 @@ +/* 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_INPUT_H +#define KIWMI_INPUT_H + +#include + +void new_input_notify(struct wl_listener *listener, void *data); + +#endif /* KIWMI_INPUT_H */ diff --git a/include/kiwmi/server.h b/include/kiwmi/server.h index 5cb8b6c..04155cb 100644 --- a/include/kiwmi/server.h +++ b/include/kiwmi/server.h @@ -26,6 +26,7 @@ struct kiwmi_server { struct wl_list outputs; // struct kiwmi_output::link struct wl_listener new_output; struct kiwmi_cursor *cursor; + struct wl_listener new_input; }; bool server_init(struct kiwmi_server *server); diff --git a/kiwmi/input.c b/kiwmi/input.c new file mode 100644 index 0000000..74974bc --- /dev/null +++ b/kiwmi/input.c @@ -0,0 +1,38 @@ +/* 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/input.h" + +#include +#include +#include + +#include "kiwmi/server.h" + +static void +new_pointer(struct kiwmi_server *server, struct wlr_input_device *device) +{ + wlr_cursor_attach_input_device(server->cursor->cursor, device); +} + +void +new_input_notify(struct wl_listener *listener, void *data) +{ + struct kiwmi_server *server = wl_container_of(listener, server, new_input); + struct wlr_input_device *device = data; + + wlr_log(WLR_DEBUG, "Adding input device: '%s'", device->name); + + switch (device->type) { + case WLR_INPUT_DEVICE_POINTER: + new_pointer(server, device); + break; + default: + // NOT HANDLED + break; + } +} diff --git a/kiwmi/meson.build b/kiwmi/meson.build index 320792c..2af4254 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -1,6 +1,7 @@ kiwmi_sources = files( 'main.c', 'server.c', + 'input.c', 'output.c', 'desktop/output.c', 'input/cursor.c', diff --git a/kiwmi/output.c b/kiwmi/output.c index d10e44c..a616b55 100644 --- a/kiwmi/output.c +++ b/kiwmi/output.c @@ -23,15 +23,24 @@ output_frame_notify(struct wl_listener *listener, void *data) struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); - wlr_output_make_current(wlr_output, NULL); - wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height); + if (!wlr_output_make_current(wlr_output, NULL)) { + return; + } + + int width; + int height; + + wlr_output_effective_resolution(wlr_output, &width, &height); + { + wlr_renderer_begin(renderer, width, height); float color[] = {0.18f, 0.20f, 0.25f, 1.0f}; wlr_renderer_clear(renderer, color); wlr_output_render_software_cursors(wlr_output, NULL); - wlr_output_swap_buffers(wlr_output, NULL, NULL); + wlr_renderer_end(renderer); } - wlr_renderer_end(renderer); + + wlr_output_swap_buffers(wlr_output, NULL, NULL); } static void diff --git a/kiwmi/server.c b/kiwmi/server.c index 614bc8c..d531739 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -20,6 +20,7 @@ #include #include "kiwmi/desktop/output.h" +#include "kiwmi/input.h" #include "kiwmi/input/cursor.h" bool @@ -42,6 +43,8 @@ server_init(struct kiwmi_server *server) 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"); @@ -50,13 +53,14 @@ server_init(struct kiwmi_server *server) return false; } - server->output_layout = wlr_output_layout_create(); - 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); + return true; }