Output: abstract away a view switch statement

We have our view abstraction, so why not use it?
This commit is contained in:
Jente Hidskes 2019-01-02 21:23:16 +01:00
parent 431320443a
commit 9a99ba604f
No known key found for this signature in database
GPG key ID: 04BE5A29F32D91EA
5 changed files with 29 additions and 21 deletions

View file

@ -73,24 +73,6 @@ render_surface(struct wlr_surface *surface, int sx, int sy, void *data)
wlr_surface_send_frame_done(surface, rdata->when);
}
static void
view_for_each_surface(struct cg_view *view, struct render_data *rdata,
wlr_surface_iterator_func_t iterator)
{
switch(view->type) {
case CAGE_XDG_SHELL_VIEW:
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, rdata);
break;
#ifdef CAGE_HAS_XWAYLAND
case CAGE_XWAYLAND_VIEW:
wlr_surface_for_each_surface(view->wlr_surface, iterator, rdata);
break;
#endif
default:
wlr_log(WLR_ERROR, "Unrecognized view type: %d", view->type);
}
}
static void
handle_output_frame(struct wl_listener *listener, void *data)
{
@ -122,7 +104,7 @@ handle_output_frame(struct wl_listener *listener, void *data)
struct cg_view *view;
wl_list_for_each_reverse(view, &output->server->views, link) {
rdata.view = view;
view_for_each_surface(view, &rdata, render_surface);
view_for_each_surface(view, render_surface, &rdata);
}
wlr_renderer_end(renderer);

9
view.c
View file

@ -1,7 +1,7 @@
/*
* Cage: A Wayland kiosk.
*
* Copyright (C) 2018 Jente Hidskes
* Copyright (C) 2018-2019 Jente Hidskes
*
* See the LICENSE file accompanying this file.
*/
@ -50,6 +50,13 @@ view_center(struct cg_view *view)
view->y = (output_height - height) / 2;
}
void
view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator,
void *data)
{
view->for_each_surface(view, iterator, data);
}
bool
view_is_primary(struct cg_view *view)
{

3
view.h
View file

@ -41,12 +41,15 @@ struct cg_view {
void (*activate)(struct cg_view *view, bool activate);
void (*maximize)(struct cg_view *view, int output_width, int output_height);
void (*get_geometry)(struct cg_view *view, int *width_out, int *height_out);
void (*for_each_surface)(struct cg_view *view, wlr_surface_iterator_func_t iterator,
void *data);
bool (*is_primary)(struct cg_view *view);
};
void view_activate(struct cg_view *view, bool activate);
void view_maximize(struct cg_view *view);
void view_center(struct cg_view *view);
void view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data);
bool view_is_primary(struct cg_view *view);
void view_unmap(struct cg_view *view);
void view_map(struct cg_view *view, struct wlr_surface *surface);

View file

@ -1,7 +1,7 @@
/*
* Cage: A Wayland kiosk.
*
* Copyright (C) 2018 Jente Hidskes
* Copyright (C) 2018-2019 Jente Hidskes
*
* See the LICENSE file accompanying this file.
*/
@ -37,6 +37,13 @@ get_geometry(struct cg_view *view, int *width_out, int *height_out)
*height_out = geom.height;
}
static void
for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator,
void *data)
{
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, data);
}
static bool
is_primary(struct cg_view *view)
{
@ -86,5 +93,6 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data)
view->activate = activate;
view->maximize = maximize;
view->get_geometry = get_geometry;
view->for_each_surface = for_each_surface;
view->is_primary = is_primary;
}

View file

@ -34,6 +34,13 @@ get_geometry(struct cg_view *view, int *width_out, int *height_out)
*height_out = view->xwayland_surface->surface->current.height;
}
static void
for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator,
void *data)
{
wlr_surface_for_each_surface(view->wlr_surface, iterator, data);
}
static bool
is_primary(struct cg_view *view)
{
@ -82,5 +89,6 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data)
view->activate = activate;
view->maximize = maximize;
view->get_geometry = get_geometry;
view->for_each_surface = for_each_surface;
view->is_primary = is_primary;
}