summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-01-21 09:09:53 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-01-21 09:09:53 -0500
commit0e3eae4baa7717321ec87cf2c46f6798e89e3ded (patch)
treed6624a2fa66f344d9db09e43af0fb293f2ab2d3a /sway
parentrun all commands with focused container context (diff)
downloadsway-0e3eae4baa7717321ec87cf2c46f6798e89e3ded.tar.gz
sway-0e3eae4baa7717321ec87cf2c46f6798e89e3ded.tar.zst
sway-0e3eae4baa7717321ec87cf2c46f6798e89e3ded.zip
view interface
Diffstat (limited to 'sway')
-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
7 files changed, 71 insertions, 22 deletions
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) {
15 struct sway_view *view = 15 struct sway_view *view =
16 config->handler_context.current_container->sway_view; 16 config->handler_context.current_container->sway_view;
17 17
18 if (view && view->iface.close) { 18 if (view) {
19 view->iface.close(view); 19 view_close(view);
20 } 20 }
21 21
22 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 22 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) {
299 case CRIT_ID: // TODO 299 case CRIT_ID: // TODO
300 break; 300 break;
301 case CRIT_APP_ID: 301 case CRIT_APP_ID:
302 if (!view->iface.get_prop) { 302 {
303 break; 303 const char *app_id = view_get_app_id(cont->sway_view);
304 } 304 if (!app_id) {
305 305 break;
306 const char *app_id = 306 }
307 cont->sway_view->iface.get_prop(view, VIEW_PROP_APP_ID);
308 307
309 if (!app_id) { 308 if (crit->regex && regex_cmp(app_id, crit->regex) == 0) {
309 matches++;
310 }
310 break; 311 break;
311 } 312 }
312
313 if (crit->regex && regex_cmp(app_id, crit->regex) == 0) {
314 matches++;
315 }
316 break;
317 case CRIT_INSTANCE: // TODO 313 case CRIT_INSTANCE: // TODO
318 break; 314 break;
319 case CRIT_TILING: // TODO 315 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) {
214 214
215 if (container) { 215 if (container) {
216 struct sway_view *view = container->sway_view; 216 struct sway_view *view = container->sway_view;
217 view->iface.set_activated(view, true); 217 view_set_activated(view, true);
218 wl_signal_add(&container->events.destroy, &seat->focus_destroy); 218 wl_signal_add(&container->events.destroy, &seat->focus_destroy);
219 seat->focus_destroy.notify = handle_focus_destroy; 219 seat->focus_destroy.notify = handle_focus_destroy;
220 220
@@ -234,8 +234,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
234 if (last_focus && 234 if (last_focus &&
235 !sway_input_manager_has_focus(seat->input, last_focus)) { 235 !sway_input_manager_has_focus(seat->input, last_focus)) {
236 struct sway_view *view = last_focus->sway_view; 236 struct sway_view *view = last_focus->sway_view;
237 view->iface.set_activated(view, false); 237 view_set_activated(view, false);
238
239 } 238 }
240} 239}
241 240
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(
48 'security.c', 48 'security.c',
49 'tree/container.c', 49 'tree/container.c',
50 'tree/layout.c', 50 'tree/layout.c',
51 'tree/view.c',
51 'tree/workspace.c', 52 'tree/workspace.c',
52) 53)
53 54
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) {
157 if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { 157 if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) {
158 return NULL; 158 return NULL;
159 } 159 }
160 const char *title = sway_view->iface.get_prop(sway_view, VIEW_PROP_TITLE); 160 const char *title = view_get_title(sway_view);
161 swayc_t *swayc = new_swayc(C_VIEW); 161 swayc_t *swayc = new_swayc(C_VIEW);
162 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d", 162 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d",
163 swayc, title, sibling, sibling ? sibling->type : 0); 163 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) {
191 { 191 {
192 container->width = width; 192 container->width = width;
193 container->height = height; 193 container->height = height;
194 container->sway_view->iface.set_size(container->sway_view, 194 view_set_size(container->sway_view,
195 container->width, container->height); 195 container->width, container->height);
196 wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f", 196 wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f",
197 container->width, container->height, 197 container->width, container->height,
198 container->x, container->y); 198 container->x, container->y);
@@ -251,7 +251,7 @@ static void apply_horiz_layout(swayc_t *container,
251 wlr_log(L_DEBUG, 251 wlr_log(L_DEBUG,
252 "Calculating arrangement for %p:%d (will scale %f by %f)", 252 "Calculating arrangement for %p:%d (will scale %f by %f)",
253 child, child->type, width, scale); 253 child, child->type, width, scale);
254 child->sway_view->iface.set_position(child->sway_view, child_x, y); 254 view_set_position(child->sway_view, child_x, y);
255 255
256 if (i == end - 1) { 256 if (i == end - 1) {
257 double remaining_width = x + width - child_x; 257 double remaining_width = x + width - child_x;
@@ -301,7 +301,7 @@ void apply_vert_layout(swayc_t *container,
301 wlr_log(L_DEBUG, 301 wlr_log(L_DEBUG,
302 "Calculating arrangement for %p:%d (will scale %f by %f)", 302 "Calculating arrangement for %p:%d (will scale %f by %f)",
303 child, child->type, height, scale); 303 child, child->type, height, scale);
304 child->sway_view->iface.set_position(child->sway_view, x, child_y); 304 view_set_position(child->sway_view, x, child_y);
305 305
306 if (i == end - 1) { 306 if (i == end - 1) {
307 double remaining_height = y + height - child_y; 307 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 @@
1#include "sway/view.h"
2
3const char *view_get_title(struct sway_view *view) {
4 if (view->iface.get_prop) {
5 return view->iface.get_prop(view, VIEW_PROP_TITLE);
6 }
7 return NULL;
8}
9
10const char *view_get_app_id(struct sway_view *view) {
11 if (view->iface.get_prop) {
12 return view->iface.get_prop(view, VIEW_PROP_APP_ID);
13 }
14 return NULL;
15}
16
17const char *view_get_class(struct sway_view *view) {
18 if (view->iface.get_prop) {
19 return view->iface.get_prop(view, VIEW_PROP_CLASS);
20 }
21 return NULL;
22}
23
24const char *view_get_instance(struct sway_view *view) {
25 if (view->iface.get_prop) {
26 return view->iface.get_prop(view, VIEW_PROP_INSTANCE);
27 }
28 return NULL;
29}
30
31void view_set_size(struct sway_view *view, int width, int height) {
32 if (view->iface.set_size) {
33 view->iface.set_size(view, width, height);
34 }
35}
36
37void view_set_position(struct sway_view *view, double ox, double oy) {
38 if (view->iface.set_position) {
39 view->iface.set_position(view, ox, oy);
40 }
41}
42
43void view_set_activated(struct sway_view *view, bool activated) {
44 if (view->iface.set_activated) {
45 view->iface.set_activated(view, activated);
46 }
47}
48
49void view_close(struct sway_view *view) {
50 if (view->iface.close) {
51 view->iface.close(view);
52 }
53}