mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
Output: abstract away a view switch statement
We have our view abstraction, so why not use it?
This commit is contained in:
parent
431320443a
commit
9a99ba604f
5 changed files with 29 additions and 21 deletions
20
output.c
20
output.c
|
|
@ -73,24 +73,6 @@ render_surface(struct wlr_surface *surface, int sx, int sy, void *data)
|
||||||
wlr_surface_send_frame_done(surface, rdata->when);
|
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
|
static void
|
||||||
handle_output_frame(struct wl_listener *listener, void *data)
|
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;
|
struct cg_view *view;
|
||||||
wl_list_for_each_reverse(view, &output->server->views, link) {
|
wl_list_for_each_reverse(view, &output->server->views, link) {
|
||||||
rdata.view = view;
|
rdata.view = view;
|
||||||
view_for_each_surface(view, &rdata, render_surface);
|
view_for_each_surface(view, render_surface, &rdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_renderer_end(renderer);
|
wlr_renderer_end(renderer);
|
||||||
|
|
|
||||||
9
view.c
9
view.c
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Cage: A Wayland kiosk.
|
* Cage: A Wayland kiosk.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018 Jente Hidskes
|
* Copyright (C) 2018-2019 Jente Hidskes
|
||||||
*
|
*
|
||||||
* See the LICENSE file accompanying this file.
|
* See the LICENSE file accompanying this file.
|
||||||
*/
|
*/
|
||||||
|
|
@ -50,6 +50,13 @@ view_center(struct cg_view *view)
|
||||||
view->y = (output_height - height) / 2;
|
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
|
bool
|
||||||
view_is_primary(struct cg_view *view)
|
view_is_primary(struct cg_view *view)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
3
view.h
3
view.h
|
|
@ -41,12 +41,15 @@ struct cg_view {
|
||||||
void (*activate)(struct cg_view *view, bool activate);
|
void (*activate)(struct cg_view *view, bool activate);
|
||||||
void (*maximize)(struct cg_view *view, int output_width, int output_height);
|
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 (*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);
|
bool (*is_primary)(struct cg_view *view);
|
||||||
};
|
};
|
||||||
|
|
||||||
void view_activate(struct cg_view *view, bool activate);
|
void view_activate(struct cg_view *view, bool activate);
|
||||||
void view_maximize(struct cg_view *view);
|
void view_maximize(struct cg_view *view);
|
||||||
void view_center(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);
|
bool view_is_primary(struct cg_view *view);
|
||||||
void view_unmap(struct cg_view *view);
|
void view_unmap(struct cg_view *view);
|
||||||
void view_map(struct cg_view *view, struct wlr_surface *surface);
|
void view_map(struct cg_view *view, struct wlr_surface *surface);
|
||||||
|
|
|
||||||
10
xdg_shell.c
10
xdg_shell.c
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Cage: A Wayland kiosk.
|
* Cage: A Wayland kiosk.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018 Jente Hidskes
|
* Copyright (C) 2018-2019 Jente Hidskes
|
||||||
*
|
*
|
||||||
* See the LICENSE file accompanying this file.
|
* 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;
|
*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
|
static bool
|
||||||
is_primary(struct cg_view *view)
|
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->activate = activate;
|
||||||
view->maximize = maximize;
|
view->maximize = maximize;
|
||||||
view->get_geometry = get_geometry;
|
view->get_geometry = get_geometry;
|
||||||
|
view->for_each_surface = for_each_surface;
|
||||||
view->is_primary = is_primary;
|
view->is_primary = is_primary;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,13 @@ get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
||||||
*height_out = view->xwayland_surface->surface->current.height;
|
*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
|
static bool
|
||||||
is_primary(struct cg_view *view)
|
is_primary(struct cg_view *view)
|
||||||
{
|
{
|
||||||
|
|
@ -82,5 +89,6 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data)
|
||||||
view->activate = activate;
|
view->activate = activate;
|
||||||
view->maximize = maximize;
|
view->maximize = maximize;
|
||||||
view->get_geometry = get_geometry;
|
view->get_geometry = get_geometry;
|
||||||
|
view->for_each_surface = for_each_surface;
|
||||||
view->is_primary = is_primary;
|
view->is_primary = is_primary;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue