mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 18:01:29 +00:00
Add sway_view_impl
This commit is contained in:
parent
b2c2ee693b
commit
1d68f9ecca
|
@ -66,10 +66,23 @@ enum sway_view_prop {
|
|||
VIEW_PROP_INSTANCE,
|
||||
};
|
||||
|
||||
struct sway_view_impl {
|
||||
const char *(*get_prop)(struct sway_view *view,
|
||||
enum sway_view_prop prop);
|
||||
void (*set_size)(struct sway_view *view,
|
||||
int width, int height);
|
||||
void (*set_position)(struct sway_view *view,
|
||||
double ox, double oy);
|
||||
void (*set_activated)(struct sway_view *view, bool activated);
|
||||
void (*close)(struct sway_view *view);
|
||||
};
|
||||
|
||||
struct sway_view {
|
||||
enum sway_view_type type;
|
||||
struct sway_container *swayc;
|
||||
struct wlr_surface *surface;
|
||||
const struct sway_view_impl *impl;
|
||||
|
||||
struct sway_container *swayc; // NULL for unmanaged views
|
||||
struct wlr_surface *surface; // NULL for unmapped views
|
||||
int width, height;
|
||||
|
||||
union {
|
||||
|
@ -84,22 +97,12 @@ struct sway_view {
|
|||
struct sway_wl_shell_surface *sway_wl_shell_surface;
|
||||
};
|
||||
|
||||
struct {
|
||||
const char *(*get_prop)(struct sway_view *view,
|
||||
enum sway_view_prop prop);
|
||||
void (*set_size)(struct sway_view *view,
|
||||
int width, int height);
|
||||
void (*set_position)(struct sway_view *view,
|
||||
double ox, double oy);
|
||||
void (*set_activated)(struct sway_view *view, bool activated);
|
||||
void (*close)(struct sway_view *view);
|
||||
} iface;
|
||||
|
||||
// only used for unmanaged views (shell specific)
|
||||
struct wl_list unmanaged_view_link; // sway_root::unmanaged_views
|
||||
};
|
||||
|
||||
struct sway_view *view_create(enum sway_view_type type);
|
||||
struct sway_view *view_create(enum sway_view_type type,
|
||||
const struct sway_view_impl *impl);
|
||||
|
||||
void view_destroy(struct sway_view *view);
|
||||
|
||||
|
|
|
@ -47,10 +47,6 @@ static void set_position(struct sway_view *view, double ox, double oy) {
|
|||
view->swayc->y = oy;
|
||||
}
|
||||
|
||||
static void set_activated(struct sway_view *view, bool activated) {
|
||||
// no way to activate wl_shell
|
||||
}
|
||||
|
||||
static void close(struct sway_view *view) {
|
||||
if (!assert_wl_shell(view)) {
|
||||
return;
|
||||
|
@ -59,6 +55,13 @@ static void close(struct sway_view *view) {
|
|||
wl_client_destroy(view->wlr_wl_shell_surface->client);
|
||||
}
|
||||
|
||||
static const struct sway_view_impl view_impl = {
|
||||
.get_prop = get_prop,
|
||||
.set_size = set_size,
|
||||
.set_position = set_position,
|
||||
.close = close,
|
||||
};
|
||||
|
||||
static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
struct sway_wl_shell_surface *sway_surface =
|
||||
wl_container_of(listener, sway_surface, commit);
|
||||
|
@ -101,15 +104,10 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW);
|
||||
struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW, &view_impl);
|
||||
if (!sway_assert(view, "Failed to allocate view")) {
|
||||
return;
|
||||
}
|
||||
view->iface.get_prop = get_prop;
|
||||
view->iface.set_size = set_size;
|
||||
view->iface.set_position = set_position;
|
||||
view->iface.set_activated = set_activated;
|
||||
view->iface.close = close;
|
||||
view->wlr_wl_shell_surface = shell_surface;
|
||||
view->sway_wl_shell_surface = sway_surface;
|
||||
sway_surface->view = view;
|
||||
|
|
|
@ -67,6 +67,14 @@ static void close(struct sway_view *view) {
|
|||
}
|
||||
}
|
||||
|
||||
static const struct sway_view_impl view_impl = {
|
||||
.get_prop = get_prop,
|
||||
.set_size = set_size,
|
||||
.set_position = set_position,
|
||||
.set_activated = set_activated,
|
||||
.close = close,
|
||||
};
|
||||
|
||||
static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
struct sway_xdg_surface_v6 *sway_surface =
|
||||
wl_container_of(listener, sway_surface, commit);
|
||||
|
@ -124,15 +132,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW);
|
||||
struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW, &view_impl);
|
||||
if (!sway_assert(view, "Failed to allocate view")) {
|
||||
return;
|
||||
}
|
||||
view->iface.get_prop = get_prop;
|
||||
view->iface.set_size = set_size;
|
||||
view->iface.set_position = set_position;
|
||||
view->iface.set_activated = set_activated;
|
||||
view->iface.close = close;
|
||||
view->wlr_xdg_surface_v6 = xdg_surface;
|
||||
view->sway_xdg_surface_v6 = sway_surface;
|
||||
sway_surface->view = view;
|
||||
|
|
|
@ -81,13 +81,21 @@ static void set_activated(struct sway_view *view, bool activated) {
|
|||
wlr_xwayland_surface_activate(surface, activated);
|
||||
}
|
||||
|
||||
static void close_view(struct sway_view *view) {
|
||||
static void _close(struct sway_view *view) {
|
||||
if (!assert_xwayland(view)) {
|
||||
return;
|
||||
}
|
||||
wlr_xwayland_surface_close(view->wlr_xwayland_surface);
|
||||
}
|
||||
|
||||
static const struct sway_view_impl view_impl = {
|
||||
.get_prop = get_prop,
|
||||
.set_size = set_size,
|
||||
.set_position = set_position,
|
||||
.set_activated = set_activated,
|
||||
.close = _close,
|
||||
};
|
||||
|
||||
static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
struct sway_xwayland_surface *sway_surface =
|
||||
wl_container_of(listener, sway_surface, commit);
|
||||
|
@ -159,15 +167,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW);
|
||||
struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW, &view_impl);
|
||||
if (!sway_assert(view, "Failed to allocate view")) {
|
||||
return;
|
||||
}
|
||||
view->iface.get_prop = get_prop;
|
||||
view->iface.set_size = set_size;
|
||||
view->iface.set_position = set_position;
|
||||
view->iface.set_activated = set_activated;
|
||||
view->iface.close = close_view;
|
||||
view->wlr_xwayland_surface = xsurface;
|
||||
view->sway_xwayland_surface = sway_surface;
|
||||
sway_surface->view = view;
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
#include "sway/tree/layout.h"
|
||||
#include "sway/tree/view.h"
|
||||
|
||||
struct sway_view *view_create(enum sway_view_type type) {
|
||||
struct sway_view *view_create(enum sway_view_type type,
|
||||
const struct sway_view_impl *impl) {
|
||||
struct sway_view *view = calloc(1, sizeof(struct sway_view));
|
||||
if (view == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
view->type = type;
|
||||
view->impl = impl;
|
||||
wl_list_init(&view->unmanaged_view_link);
|
||||
return view;
|
||||
}
|
||||
|
@ -33,29 +35,29 @@ void view_destroy(struct sway_view *view) {
|
|||
}
|
||||
|
||||
const char *view_get_title(struct sway_view *view) {
|
||||
if (view->iface.get_prop) {
|
||||
return view->iface.get_prop(view, VIEW_PROP_TITLE);
|
||||
if (view->impl->get_prop) {
|
||||
return view->impl->get_prop(view, VIEW_PROP_TITLE);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *view_get_app_id(struct sway_view *view) {
|
||||
if (view->iface.get_prop) {
|
||||
return view->iface.get_prop(view, VIEW_PROP_APP_ID);
|
||||
if (view->impl->get_prop) {
|
||||
return view->impl->get_prop(view, VIEW_PROP_APP_ID);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *view_get_class(struct sway_view *view) {
|
||||
if (view->iface.get_prop) {
|
||||
return view->iface.get_prop(view, VIEW_PROP_CLASS);
|
||||
if (view->impl->get_prop) {
|
||||
return view->impl->get_prop(view, VIEW_PROP_CLASS);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *view_get_instance(struct sway_view *view) {
|
||||
if (view->iface.get_prop) {
|
||||
return view->iface.get_prop(view, VIEW_PROP_INSTANCE);
|
||||
if (view->impl->get_prop) {
|
||||
return view->impl->get_prop(view, VIEW_PROP_INSTANCE);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -86,41 +88,41 @@ static void view_update_outputs(struct sway_view *view,
|
|||
}
|
||||
|
||||
void view_set_size(struct sway_view *view, int width, int height) {
|
||||
if (view->iface.set_size) {
|
||||
if (view->impl->set_size) {
|
||||
struct wlr_box box = {
|
||||
.x = view->swayc->x,
|
||||
.y = view->swayc->y,
|
||||
.width = view->width,
|
||||
.height = view->height,
|
||||
};
|
||||
view->iface.set_size(view, width, height);
|
||||
view->impl->set_size(view, width, height);
|
||||
view_update_outputs(view, &box);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make view coordinates in layout coordinates
|
||||
void view_set_position(struct sway_view *view, double ox, double oy) {
|
||||
if (view->iface.set_position) {
|
||||
if (view->impl->set_position) {
|
||||
struct wlr_box box = {
|
||||
.x = view->swayc->x,
|
||||
.y = view->swayc->y,
|
||||
.width = view->width,
|
||||
.height = view->height,
|
||||
};
|
||||
view->iface.set_position(view, ox, oy);
|
||||
view->impl->set_position(view, ox, oy);
|
||||
view_update_outputs(view, &box);
|
||||
}
|
||||
}
|
||||
|
||||
void view_set_activated(struct sway_view *view, bool activated) {
|
||||
if (view->iface.set_activated) {
|
||||
view->iface.set_activated(view, activated);
|
||||
if (view->impl->set_activated) {
|
||||
view->impl->set_activated(view, activated);
|
||||
}
|
||||
}
|
||||
|
||||
void view_close(struct sway_view *view) {
|
||||
if (view->iface.close) {
|
||||
view->iface.close(view);
|
||||
if (view->impl->close) {
|
||||
view->impl->close(view);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue