aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/view.h16
-rw-r--r--sway/commands/kill.c4
-rw-r--r--sway/criteria.c20
-rw-r--r--sway/input/seat.c5
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/container.c2
-rw-r--r--sway/tree/layout.c8
-rw-r--r--sway/tree/view.c53
8 files changed, 87 insertions, 22 deletions
diff --git a/include/sway/view.h b/include/sway/view.h
index 240ffaa5..ac33e11a 100644
--- a/include/sway/view.h
+++ b/include/sway/view.h
@@ -99,4 +99,20 @@ struct sway_view {
struct wl_list unmanaged_view_link; // sway_root::unmanaged views
};
+const char *view_get_title(struct sway_view *view);
+
+const char *view_get_app_id(struct sway_view *view);
+
+const char *view_get_class(struct sway_view *view);
+
+const char *view_get_instance(struct sway_view *view);
+
+void view_set_size(struct sway_view *view, int width, int height);
+
+void view_set_position(struct sway_view *view, double ox, double oy);
+
+void view_set_activated(struct sway_view *view, bool activated);
+
+void view_close(struct sway_view *view);
+
#endif
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index a04c21f3..62a3a514 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -15,8 +15,8 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
struct sway_view *view =
config->handler_context.current_container->sway_view;
- if (view && view->iface.close) {
- view->iface.close(view);
+ if (view) {
+ view_close(view);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/criteria.c b/sway/criteria.c
index c15f6354..21278a94 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -299,21 +299,17 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
case CRIT_ID: // TODO
break;
case CRIT_APP_ID:
- if (!view->iface.get_prop) {
- break;
- }
-
- const char *app_id =
- cont->sway_view->iface.get_prop(view, VIEW_PROP_APP_ID);
+ {
+ const char *app_id = view_get_app_id(cont->sway_view);
+ if (!app_id) {
+ break;
+ }
- if (!app_id) {
+ if (crit->regex && regex_cmp(app_id, crit->regex) == 0) {
+ matches++;
+ }
break;
}
-
- if (crit->regex && regex_cmp(app_id, crit->regex) == 0) {
- matches++;
- }
- break;
case CRIT_INSTANCE: // TODO
break;
case CRIT_TILING: // TODO
diff --git a/sway/input/seat.c b/sway/input/seat.c
index d24a6c7a..ae6dc7c4 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -214,7 +214,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
if (container) {
struct sway_view *view = container->sway_view;
- view->iface.set_activated(view, true);
+ view_set_activated(view, true);
wl_signal_add(&container->events.destroy, &seat->focus_destroy);
seat->focus_destroy.notify = handle_focus_destroy;
@@ -234,8 +234,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
if (last_focus &&
!sway_input_manager_has_focus(seat->input, last_focus)) {
struct sway_view *view = last_focus->sway_view;
- view->iface.set_activated(view, false);
-
+ view_set_activated(view, false);
}
}
diff --git a/sway/meson.build b/sway/meson.build
index 46d79d44..80ccc01d 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -48,6 +48,7 @@ sway_sources = files(
'security.c',
'tree/container.c',
'tree/layout.c',
+ 'tree/view.c',
'tree/workspace.c',
)
diff --git a/sway/tree/container.c b/sway/tree/container.c
index e224539f..b7b9bc68 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -157,7 +157,7 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) {
return NULL;
}
- const char *title = sway_view->iface.get_prop(sway_view, VIEW_PROP_TITLE);
+ const char *title = view_get_title(sway_view);
swayc_t *swayc = new_swayc(C_VIEW);
wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d",
swayc, title, sibling, sibling ? sibling->type : 0);
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 01535f2d..41ff81b2 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -191,8 +191,8 @@ void arrange_windows(swayc_t *container, double width, double height) {
{
container->width = width;
container->height = height;
- container->sway_view->iface.set_size(container->sway_view,
- container->width, container->height);
+ view_set_size(container->sway_view,
+ container->width, container->height);
wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f",
container->width, container->height,
container->x, container->y);
@@ -251,7 +251,7 @@ static void apply_horiz_layout(swayc_t *container,
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, width, scale);
- child->sway_view->iface.set_position(child->sway_view, child_x, y);
+ view_set_position(child->sway_view, child_x, y);
if (i == end - 1) {
double remaining_width = x + width - child_x;
@@ -301,7 +301,7 @@ void apply_vert_layout(swayc_t *container,
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, height, scale);
- child->sway_view->iface.set_position(child->sway_view, x, child_y);
+ view_set_position(child->sway_view, x, child_y);
if (i == end - 1) {
double remaining_height = y + height - child_y;
diff --git a/sway/tree/view.c b/sway/tree/view.c
new file mode 100644
index 00000000..b46c3b17
--- /dev/null
+++ b/sway/tree/view.c
@@ -0,0 +1,53 @@
+#include "sway/view.h"
+
+const char *view_get_title(struct sway_view *view) {
+ if (view->iface.get_prop) {
+ return view->iface.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);
+ }
+ 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);
+ }
+ 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);
+ }
+ return NULL;
+}
+
+void view_set_size(struct sway_view *view, int width, int height) {
+ if (view->iface.set_size) {
+ view->iface.set_size(view, width, height);
+ }
+}
+
+void view_set_position(struct sway_view *view, double ox, double oy) {
+ if (view->iface.set_position) {
+ view->iface.set_position(view, ox, oy);
+ }
+}
+
+void view_set_activated(struct sway_view *view, bool activated) {
+ if (view->iface.set_activated) {
+ view->iface.set_activated(view, activated);
+ }
+}
+
+void view_close(struct sway_view *view) {
+ if (view->iface.close) {
+ view->iface.close(view);
+ }
+}