mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
Seat: abstract away a view switch statement
We have our view abstraction, so why not use it?
This commit is contained in:
parent
9a99ba604f
commit
2847e0d54f
5 changed files with 25 additions and 19 deletions
20
seat.c
20
seat.c
|
|
@ -47,25 +47,7 @@ view_at(struct cg_view *view, double lx, double ly,
|
||||||
double view_sy = ly - view->y;
|
double view_sy = ly - view->y;
|
||||||
|
|
||||||
double _sx, _sy;
|
double _sx, _sy;
|
||||||
struct wlr_surface *_surface = NULL;
|
struct wlr_surface *_surface = view_wlr_surface_at(view, view_sx, view_sy, &_sx, &_sy);
|
||||||
switch (view->type) {
|
|
||||||
case CAGE_XDG_SHELL_VIEW:
|
|
||||||
_surface = wlr_xdg_surface_surface_at(view->xdg_surface,
|
|
||||||
view_sx, view_sy,
|
|
||||||
&_sx, &_sy);
|
|
||||||
break;
|
|
||||||
#ifdef CAGE_HAS_XWAYLAND
|
|
||||||
case CAGE_XWAYLAND_VIEW:
|
|
||||||
_surface = wlr_surface_surface_at(view->wlr_surface,
|
|
||||||
view_sx, view_sy,
|
|
||||||
&_sx, &_sy);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
wlr_log(WLR_ERROR, "Unrecognized view type: %d", view->type);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (_surface != NULL) {
|
if (_surface != NULL) {
|
||||||
*sx = _sx;
|
*sx = _sx;
|
||||||
*sy = _sy;
|
*sy = _sy;
|
||||||
|
|
|
||||||
6
view.c
6
view.c
|
|
@ -57,6 +57,12 @@ view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator
|
||||||
view->for_each_surface(view, iterator, data);
|
view->for_each_surface(view, iterator, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_surface *
|
||||||
|
view_wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y)
|
||||||
|
{
|
||||||
|
return view->wlr_surface_at(view, sx, sy, sub_x, sub_y);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
view_is_primary(struct cg_view *view)
|
view_is_primary(struct cg_view *view)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
4
view.h
4
view.h
|
|
@ -43,6 +43,8 @@ struct cg_view {
|
||||||
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 (*for_each_surface)(struct cg_view *view, wlr_surface_iterator_func_t iterator,
|
||||||
void *data);
|
void *data);
|
||||||
|
struct wlr_surface *(*wlr_surface_at)(struct cg_view *view, double sx, double sy,
|
||||||
|
double *sub_x, double *sub_y);
|
||||||
bool (*is_primary)(struct cg_view *view);
|
bool (*is_primary)(struct cg_view *view);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -50,6 +52,8 @@ 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);
|
void view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data);
|
||||||
|
struct wlr_surface *view_wlr_surface_at(struct cg_view *view, double sx, double sy,
|
||||||
|
double *sub_x, double *sub_y);
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,12 @@ for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator,
|
||||||
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, data);
|
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct wlr_surface *
|
||||||
|
wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y)
|
||||||
|
{
|
||||||
|
return wlr_xdg_surface_surface_at(view->xdg_surface, sx, sy, sub_x, sub_y);
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_primary(struct cg_view *view)
|
is_primary(struct cg_view *view)
|
||||||
{
|
{
|
||||||
|
|
@ -94,5 +100,6 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data)
|
||||||
view->maximize = maximize;
|
view->maximize = maximize;
|
||||||
view->get_geometry = get_geometry;
|
view->get_geometry = get_geometry;
|
||||||
view->for_each_surface = for_each_surface;
|
view->for_each_surface = for_each_surface;
|
||||||
|
view->wlr_surface_at = wlr_surface_at;
|
||||||
view->is_primary = is_primary;
|
view->is_primary = is_primary;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator,
|
||||||
wlr_surface_for_each_surface(view->wlr_surface, iterator, data);
|
wlr_surface_for_each_surface(view->wlr_surface, iterator, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct wlr_surface *
|
||||||
|
wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y)
|
||||||
|
{
|
||||||
|
return wlr_surface_surface_at(view->wlr_surface, sx, sy, sub_x, sub_y);
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_primary(struct cg_view *view)
|
is_primary(struct cg_view *view)
|
||||||
{
|
{
|
||||||
|
|
@ -90,5 +96,6 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data)
|
||||||
view->maximize = maximize;
|
view->maximize = maximize;
|
||||||
view->get_geometry = get_geometry;
|
view->get_geometry = get_geometry;
|
||||||
view->for_each_surface = for_each_surface;
|
view->for_each_surface = for_each_surface;
|
||||||
|
view->wlr_surface_at = wlr_surface_at;
|
||||||
view->is_primary = is_primary;
|
view->is_primary = is_primary;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue