mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
view: reorder functions
It had gotten a bit messy. Now functions are grouped together (i.e., getters, queries, etc).
This commit is contained in:
parent
64b971a665
commit
7175100d0d
4 changed files with 95 additions and 95 deletions
60
view.c
60
view.c
|
|
@ -28,6 +28,24 @@ view_get_title(struct cg_view *view)
|
|||
return strndup(title, strlen(title));
|
||||
}
|
||||
|
||||
bool
|
||||
view_is_primary(struct cg_view *view)
|
||||
{
|
||||
return view->impl->is_primary(view);
|
||||
}
|
||||
|
||||
bool
|
||||
view_has_children(struct cg_server *server, struct cg_view *parent)
|
||||
{
|
||||
struct cg_view *child;
|
||||
wl_list_for_each(child, &server->views, link) {
|
||||
if (parent != child && parent->impl->is_parent(parent, child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
view_activate(struct cg_view *view, bool activate)
|
||||
{
|
||||
|
|
@ -59,36 +77,6 @@ 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->impl->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->impl->wlr_surface_at(view, sx, sy, sub_x, sub_y);
|
||||
}
|
||||
|
||||
bool
|
||||
view_is_primary(struct cg_view *view)
|
||||
{
|
||||
return view->impl->is_primary(view);
|
||||
}
|
||||
|
||||
bool
|
||||
view_has_children(struct cg_server *server, struct cg_view *parent)
|
||||
{
|
||||
struct cg_view *child;
|
||||
wl_list_for_each(child, &server->views, link) {
|
||||
if (parent != child && parent->impl->is_parent(parent, child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
view_position(struct cg_view *view)
|
||||
{
|
||||
|
|
@ -99,6 +87,12 @@ view_position(struct cg_view *view)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data)
|
||||
{
|
||||
view->impl->for_each_surface(view, iterator, data);
|
||||
}
|
||||
|
||||
void
|
||||
view_unmap(struct cg_view *view)
|
||||
{
|
||||
|
|
@ -160,3 +154,9 @@ view_from_wlr_surface(struct cg_server *server, struct wlr_surface *surface)
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_surface *
|
||||
view_wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y)
|
||||
{
|
||||
return view->impl->wlr_surface_at(view, sx, sy, sub_x, sub_y);
|
||||
}
|
||||
|
|
|
|||
14
view.h
14
view.h
|
|
@ -33,26 +33,24 @@ struct cg_view {
|
|||
|
||||
struct cg_view_impl {
|
||||
char *(*get_title)(struct cg_view *view);
|
||||
void (*get_geometry)(struct cg_view *view, int *width_out, int *height_out);
|
||||
bool (*is_primary)(struct cg_view *view);
|
||||
bool (*is_parent)(struct cg_view *parent, struct cg_view *child);
|
||||
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 (*destroy)(struct cg_view *view);
|
||||
void (*for_each_surface)(struct cg_view *view, wlr_surface_iterator_func_t iterator,
|
||||
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_parent)(struct cg_view *parent, struct cg_view *child);
|
||||
};
|
||||
|
||||
char *view_get_title(struct cg_view *view);
|
||||
void view_activate(struct cg_view *view, bool activate);
|
||||
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_has_children(struct cg_server *server, struct cg_view *view);
|
||||
void view_activate(struct cg_view *view, bool activate);
|
||||
void view_position(struct cg_view *view);
|
||||
void view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data);
|
||||
void view_unmap(struct cg_view *view);
|
||||
void view_map(struct cg_view *view, struct wlr_surface *surface);
|
||||
void view_destroy(struct cg_view *view);
|
||||
|
|
@ -60,5 +58,7 @@ void view_init(struct cg_view *view, struct cg_server *server, enum cg_view_type
|
|||
const struct cg_view_impl *impl);
|
||||
|
||||
struct cg_view *view_from_wlr_surface(struct cg_server *server, struct wlr_surface *surface);
|
||||
struct wlr_surface *view_wlr_surface_at(struct cg_view *view, double sx, double sy,
|
||||
double *sub_x, double *sub_y);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
62
xdg_shell.c
62
xdg_shell.c
|
|
@ -30,6 +30,37 @@ get_title(struct cg_view *view)
|
|||
return xdg_shell_view->xdg_surface->toplevel->title;
|
||||
}
|
||||
|
||||
static void
|
||||
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
||||
{
|
||||
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
||||
struct wlr_box geom;
|
||||
|
||||
wlr_xdg_surface_get_geometry(xdg_shell_view->xdg_surface, &geom);
|
||||
*width_out = geom.width;
|
||||
*height_out = geom.height;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_primary(struct cg_view *view)
|
||||
{
|
||||
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
||||
struct wlr_xdg_surface *parent = xdg_shell_view->xdg_surface->toplevel->parent;
|
||||
/* FIXME: role is 0? */
|
||||
return parent == NULL; /*&& role == WLR_XDG_SURFACE_ROLE_TOPLEVEL */
|
||||
}
|
||||
|
||||
static bool
|
||||
is_parent(struct cg_view *parent, struct cg_view *child)
|
||||
{
|
||||
if (child->type != CAGE_XDG_SHELL_VIEW) {
|
||||
return false;
|
||||
}
|
||||
struct cg_xdg_shell_view *_parent = xdg_shell_view_from_view(parent);
|
||||
struct cg_xdg_shell_view *_child = xdg_shell_view_from_view(child);
|
||||
return _child->xdg_surface->toplevel->parent == _parent->xdg_surface;
|
||||
}
|
||||
|
||||
static void
|
||||
activate(struct cg_view *view, bool activate)
|
||||
{
|
||||
|
|
@ -52,17 +83,6 @@ destroy(struct cg_view *view)
|
|||
free(xdg_shell_view);
|
||||
}
|
||||
|
||||
static void
|
||||
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
||||
{
|
||||
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
||||
struct wlr_box geom;
|
||||
|
||||
wlr_xdg_surface_get_geometry(xdg_shell_view->xdg_surface, &geom);
|
||||
*width_out = geom.width;
|
||||
*height_out = geom.height;
|
||||
}
|
||||
|
||||
static void
|
||||
for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data)
|
||||
{
|
||||
|
|
@ -77,26 +97,6 @@ wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double
|
|||
return wlr_xdg_surface_surface_at(xdg_shell_view->xdg_surface, sx, sy, sub_x, sub_y);
|
||||
}
|
||||
|
||||
static bool
|
||||
is_primary(struct cg_view *view)
|
||||
{
|
||||
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
||||
struct wlr_xdg_surface *parent = xdg_shell_view->xdg_surface->toplevel->parent;
|
||||
/* FIXME: role is 0? */
|
||||
return parent == NULL; /*&& role == WLR_XDG_SURFACE_ROLE_TOPLEVEL */
|
||||
}
|
||||
|
||||
static bool
|
||||
is_parent(struct cg_view *parent, struct cg_view *child)
|
||||
{
|
||||
if (child->type != CAGE_XDG_SHELL_VIEW) {
|
||||
return false;
|
||||
}
|
||||
struct cg_xdg_shell_view *_parent = xdg_shell_view_from_view(parent);
|
||||
struct cg_xdg_shell_view *_child = xdg_shell_view_from_view(child);
|
||||
return _child->xdg_surface->toplevel->parent == _parent->xdg_surface;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data)
|
||||
{
|
||||
|
|
|
|||
54
xwayland.c
54
xwayland.c
|
|
@ -30,6 +30,33 @@ get_title(struct cg_view *view)
|
|||
return xwayland_view->xwayland_surface->title;
|
||||
}
|
||||
|
||||
static void
|
||||
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
||||
{
|
||||
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
||||
*width_out = xwayland_view->xwayland_surface->surface->current.width;
|
||||
*height_out = xwayland_view->xwayland_surface->surface->current.height;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_primary(struct cg_view *view)
|
||||
{
|
||||
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
||||
struct wlr_xwayland_surface *parent = xwayland_view->xwayland_surface->parent;
|
||||
return parent == NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_parent(struct cg_view *parent, struct cg_view *child)
|
||||
{
|
||||
if (child->type != CAGE_XWAYLAND_VIEW) {
|
||||
return false;
|
||||
}
|
||||
struct cg_xwayland_view *_parent = xwayland_view_from_view(parent);
|
||||
struct cg_xwayland_view *_child = xwayland_view_from_view(child);
|
||||
return _child->xwayland_surface->parent == _parent->xwayland_surface;
|
||||
}
|
||||
|
||||
static void
|
||||
activate(struct cg_view *view, bool activate)
|
||||
{
|
||||
|
|
@ -52,14 +79,6 @@ destroy(struct cg_view *view)
|
|||
free(xwayland_view);
|
||||
}
|
||||
|
||||
static void
|
||||
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
||||
{
|
||||
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
||||
*width_out = xwayland_view->xwayland_surface->surface->current.width;
|
||||
*height_out = xwayland_view->xwayland_surface->surface->current.height;
|
||||
}
|
||||
|
||||
static void
|
||||
for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data)
|
||||
{
|
||||
|
|
@ -72,25 +91,6 @@ wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double
|
|||
return wlr_surface_surface_at(view->wlr_surface, sx, sy, sub_x, sub_y);
|
||||
}
|
||||
|
||||
static bool
|
||||
is_primary(struct cg_view *view)
|
||||
{
|
||||
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
||||
struct wlr_xwayland_surface *parent = xwayland_view->xwayland_surface->parent;
|
||||
return parent == NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_parent(struct cg_view *parent, struct cg_view *child)
|
||||
{
|
||||
if (child->type != CAGE_XWAYLAND_VIEW) {
|
||||
return false;
|
||||
}
|
||||
struct cg_xwayland_view *_parent = xwayland_view_from_view(parent);
|
||||
struct cg_xwayland_view *_child = xwayland_view_from_view(child);
|
||||
return _child->xwayland_surface->parent == _parent->xwayland_surface;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_xwayland_surface_unmap(struct wl_listener *listener, void *data)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue