From 9bcd635aca75bf1bcc7d3637ba6495a9c590245b Mon Sep 17 00:00:00 2001 From: buffet Date: Thu, 21 Mar 2019 17:29:26 +0100 Subject: [PATCH] Merged output.cs and input.cs --- include/kiwmi/desktop/output.h | 11 +++++ include/kiwmi/input.h | 15 ------- include/kiwmi/output.h | 27 ------------ kiwmi/desktop/output.c | 65 +++++++++++++++++++++++++++- kiwmi/input.c | 56 ------------------------ kiwmi/input/input.c | 43 ++++++++++++++++++- kiwmi/meson.build | 2 - kiwmi/output.c | 78 ---------------------------------- kiwmi/server.c | 1 - 9 files changed, 117 insertions(+), 181 deletions(-) delete mode 100644 include/kiwmi/input.h delete mode 100644 include/kiwmi/output.h delete mode 100644 kiwmi/input.c delete mode 100644 kiwmi/output.c diff --git a/include/kiwmi/desktop/output.h b/include/kiwmi/desktop/output.h index 276f23f..0bad551 100644 --- a/include/kiwmi/desktop/output.h +++ b/include/kiwmi/desktop/output.h @@ -9,6 +9,17 @@ #define KIWMI_DESKTOP_OUTPUT_H #include +#include + +#include "kiwmi/desktop/desktop.h" + +struct kiwmi_output { + struct wl_list link; + struct kiwmi_desktop *desktop; + struct wlr_output *wlr_output; + struct wl_listener frame; + struct wl_listener destroy; +}; void new_output_notify(struct wl_listener *listener, void *data); diff --git a/include/kiwmi/input.h b/include/kiwmi/input.h deleted file mode 100644 index 524f127..0000000 --- a/include/kiwmi/input.h +++ /dev/null @@ -1,15 +0,0 @@ -/* Copyright (c), Niclas 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/output.h b/include/kiwmi/output.h deleted file mode 100644 index 4373d35..0000000 --- a/include/kiwmi/output.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (c), Niclas 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_OUTPUT_H -#define KIWMI_OUTPUT_H - -#include -#include - -#include "kiwmi/desktop/desktop.h" - -struct kiwmi_output { - struct wl_list link; - 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_desktop *desktop); - -#endif /* KIWMI_OUTPUT_H */ diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index 93fb17b..832a16b 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -7,15 +7,78 @@ #include "kiwmi/desktop/output.h" +#include + #include +#include #include #include #include -#include "kiwmi/output.h" #include "kiwmi/server.h" #include "kiwmi/desktop/desktop.h" +static void +output_frame_notify(struct wl_listener *listener, void *data) +{ + struct kiwmi_output *output = wl_container_of(listener, output, frame); + struct wlr_output *wlr_output = data; + struct wlr_renderer *renderer = + wlr_backend_get_renderer(wlr_output->backend); + + 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); + wlr_renderer_clear(renderer, (float[]){0.18f, 0.20f, 0.25f, 1.0f}); + wlr_output_render_software_cursors(wlr_output, NULL); + wlr_renderer_end(renderer); + } + + wlr_output_swap_buffers(wlr_output, NULL, NULL); +} + +static void +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->desktop->output_layout, output->wlr_output); + + wl_list_remove(&output->link); + wl_list_remove(&output->frame.link); + wl_list_remove(&output->destroy.link); + + free(output); +} + +static struct kiwmi_output * +output_create(struct wlr_output *wlr_output, struct kiwmi_desktop *desktop) +{ + struct kiwmi_output *output = calloc(1, sizeof(*output)); + if (!output) { + return NULL; + } + + output->wlr_output = wlr_output; + output->desktop = desktop; + + output->frame.notify = output_frame_notify; + wl_signal_add(&wlr_output->events.frame, &output->frame); + + output->destroy.notify = output_destroy_notify; + wl_signal_add(&wlr_output->events.destroy, &output->destroy); + + return output; +} + void new_output_notify(struct wl_listener *listener, void *data) { diff --git a/kiwmi/input.c b/kiwmi/input.c deleted file mode 100644 index d04d225..0000000 --- a/kiwmi/input.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (c), Niclas 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" -#include "kiwmi/input/input.h" -#include "kiwmi/input/keyboard.h" - -static void -new_pointer(struct kiwmi_input *input, struct wlr_input_device *device) -{ - wlr_cursor_attach_input_device(input->cursor->cursor, device); -} - -static void -new_keyboard(struct kiwmi_input *input, struct wlr_input_device *device) -{ - struct kiwmi_server *server = wl_container_of(input, server, input); - - struct kiwmi_keyboard *keyboard = keyboard_create(server, device); - if (!keyboard) { - return; - } - - wl_list_insert(&input->keyboards, &keyboard->link); -} - -void -new_input_notify(struct wl_listener *listener, void *data) -{ - struct kiwmi_input *input = wl_container_of(listener, input, new_input); - struct wlr_input_device *device = data; - - wlr_log(WLR_DEBUG, "New input %p: %s", device, device->name); - - switch (device->type) { - case WLR_INPUT_DEVICE_POINTER: - new_pointer(input, device); - break; - case WLR_INPUT_DEVICE_KEYBOARD: - new_keyboard(input, device); - break; - default: - // NOT HANDLED - break; - } -} diff --git a/kiwmi/input/input.c b/kiwmi/input/input.c index e255c4a..615f7e1 100644 --- a/kiwmi/input/input.c +++ b/kiwmi/input/input.c @@ -8,10 +8,51 @@ #include "kiwmi/input/input.h" #include +#include #include -#include "kiwmi/input.h" #include "kiwmi/server.h" +#include "kiwmi/input/keyboard.h" + +static void +new_pointer(struct kiwmi_input *input, struct wlr_input_device *device) +{ + wlr_cursor_attach_input_device(input->cursor->cursor, device); +} + +static void +new_keyboard(struct kiwmi_input *input, struct wlr_input_device *device) +{ + struct kiwmi_server *server = wl_container_of(input, server, input); + + struct kiwmi_keyboard *keyboard = keyboard_create(server, device); + if (!keyboard) { + return; + } + + wl_list_insert(&input->keyboards, &keyboard->link); +} + +static void +new_input_notify(struct wl_listener *listener, void *data) +{ + struct kiwmi_input *input = wl_container_of(listener, input, new_input); + struct wlr_input_device *device = data; + + wlr_log(WLR_DEBUG, "New input %p: %s", device, device->name); + + switch (device->type) { + case WLR_INPUT_DEVICE_POINTER: + new_pointer(input, device); + break; + case WLR_INPUT_DEVICE_KEYBOARD: + new_keyboard(input, device); + break; + default: + // NOT HANDLED + break; + } +} bool input_init(struct kiwmi_input *input) diff --git a/kiwmi/meson.build b/kiwmi/meson.build index e6d0902..489b970 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -1,7 +1,5 @@ kiwmi_sources = files( 'main.c', - 'input.c', - 'output.c', 'server.c', 'desktop/desktop.c', 'desktop/output.c', diff --git a/kiwmi/output.c b/kiwmi/output.c deleted file mode 100644 index 2b90321..0000000 --- a/kiwmi/output.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (c), Niclas 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/output.h" - -#include - -#include -#include -#include -#include - -#include "kiwmi/desktop/desktop.h" - -static void -output_frame_notify(struct wl_listener *listener, void *data) -{ - struct kiwmi_output *output = wl_container_of(listener, output, frame); - struct wlr_output *wlr_output = data; - struct wlr_renderer *renderer = - wlr_backend_get_renderer(wlr_output->backend); - - 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); - wlr_renderer_clear(renderer, (float[]){0.18f, 0.20f, 0.25f, 1.0f}); - wlr_output_render_software_cursors(wlr_output, NULL); - wlr_renderer_end(renderer); - } - - wlr_output_swap_buffers(wlr_output, NULL, NULL); -} - -static void -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->desktop->output_layout, output->wlr_output); - - wl_list_remove(&output->link); - wl_list_remove(&output->frame.link); - wl_list_remove(&output->destroy.link); - - free(output); -} - -struct kiwmi_output * -output_create(struct wlr_output *wlr_output, struct kiwmi_desktop *desktop) -{ - struct kiwmi_output *output = calloc(1, sizeof(*output)); - if (!output) { - return NULL; - } - - output->wlr_output = wlr_output; - output->desktop = desktop; - - output->frame.notify = output_frame_notify; - wl_signal_add(&wlr_output->events.frame, &output->frame); - - output->destroy.notify = output_destroy_notify; - wl_signal_add(&wlr_output->events.destroy, &output->destroy); - - return output; -} diff --git a/kiwmi/server.c b/kiwmi/server.c index 707d5d3..eabd052 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -15,7 +15,6 @@ #include #include "kiwmi/desktop/desktop.h" -#include "kiwmi/input.h" #include "kiwmi/input/cursor.h" #include "kiwmi/input/input.h"