From 2f4c865afc033ee90f029cb409e125bd0be61946 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Tue, 24 Dec 2019 16:50:33 +0000 Subject: [PATCH] Move view creation code into view_create --- include/desktop/view.h | 1 + kiwmi/desktop/view.c | 27 +++++++++++++++++++++++++++ kiwmi/desktop/xdg_shell.c | 8 ++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/desktop/view.h b/include/desktop/view.h index a7475c8..51de2ac 100644 --- a/include/desktop/view.h +++ b/include/desktop/view.h @@ -53,5 +53,6 @@ void kiwmi_view_for_each_surface( void *user_data); void focus_view(struct kiwmi_view *view, struct wlr_surface *surface); +struct kiwmi_view *view_create(struct kiwmi_desktop *desktop, enum kiwmi_view_type type, const struct kiwmi_view_impl *impl); #endif /* KIWMI_DESKTOP_VIEW_H */ diff --git a/kiwmi/desktop/view.c b/kiwmi/desktop/view.c index a0d091f..648d994 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -6,6 +6,10 @@ */ #include "desktop/view.h" + +#include + +#include "desktop/output.h" #include "server.h" void @@ -55,3 +59,26 @@ focus_view(struct kiwmi_view *view, struct wlr_surface *surface) keyboard->num_keycodes, &keyboard->modifiers); } + +struct kiwmi_view * +view_create( + struct kiwmi_desktop *desktop, + enum kiwmi_view_type type, + const struct kiwmi_view_impl *impl) +{ + struct kiwmi_view *view = malloc(sizeof(*view)); + if (!view) { + wlr_log(WLR_ERROR, "Failed to allocate view"); + return NULL; + } + + view->desktop = desktop; + view->type = type; + view->impl = impl; + view->mapped = false; + + view->x = 0; + view->y = 0; + + return view; +} diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index 7c6b28d..474eaca 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -75,17 +75,13 @@ xdg_shell_new_surface_notify(struct wl_listener *listener, void *data) wlr_xdg_surface_ping(xdg_surface); - struct kiwmi_view *view = malloc(sizeof(*view)); + struct kiwmi_view *view = + view_create(desktop, KIWMI_VIEW_XDG_SHELL, &xdg_shell_view_impl); if (!view) { - wlr_log(WLR_ERROR, "Failed to allocate view"); return; } - view->desktop = desktop; - view->type = KIWMI_VIEW_XDG_SHELL; - view->impl = &xdg_shell_view_impl; view->xdg_surface = xdg_surface; - view->mapped = false; view->map.notify = xdg_surface_map_notify; wl_signal_add(&xdg_surface->events.map, &view->map);