Move view creation code into view_create

This commit is contained in:
buffet 2019-12-24 16:50:33 +00:00
parent 68eec4ae23
commit 2f4c865afc
3 changed files with 30 additions and 6 deletions

View file

@ -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 */

View file

@ -6,6 +6,10 @@
*/
#include "desktop/view.h"
#include <wlr/util/log.h>
#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;
}

View file

@ -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);