aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c97
1 files changed, 22 insertions, 75 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 7431ac06..424c1084 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -3,7 +3,6 @@
3#include <wayland-server.h> 3#include <wayland-server.h>
4#include <wlr/render/wlr_renderer.h> 4#include <wlr/render/wlr_renderer.h>
5#include <wlr/types/wlr_output_layout.h> 5#include <wlr/types/wlr_output_layout.h>
6#include "list.h"
7#include "log.h" 6#include "log.h"
8#include "sway/criteria.h" 7#include "sway/criteria.h"
9#include "sway/commands.h" 8#include "sway/commands.h"
@@ -20,7 +19,6 @@ void view_init(struct sway_view *view, enum sway_view_type type,
20 const struct sway_view_impl *impl) { 19 const struct sway_view_impl *impl) {
21 view->type = type; 20 view->type = type;
22 view->impl = impl; 21 view->impl = impl;
23 view->executed_criteria = create_list();
24 wl_signal_init(&view->events.unmap); 22 wl_signal_init(&view->events.unmap);
25} 23}
26 24
@@ -33,8 +31,6 @@ void view_destroy(struct sway_view *view) {
33 view_unmap(view); 31 view_unmap(view);
34 } 32 }
35 33
36 list_free(view->executed_criteria);
37
38 container_destroy(view->swayc); 34 container_destroy(view->swayc);
39 35
40 if (view->impl->destroy) { 36 if (view->impl->destroy) {
@@ -45,47 +41,33 @@ void view_destroy(struct sway_view *view) {
45} 41}
46 42
47const char *view_get_title(struct sway_view *view) { 43const char *view_get_title(struct sway_view *view) {
48 if (view->impl->get_string_prop) { 44 if (view->impl->get_prop) {
49 return view->impl->get_string_prop(view, VIEW_PROP_TITLE); 45 return view->impl->get_prop(view, VIEW_PROP_TITLE);
50 } 46 }
51 return NULL; 47 return NULL;
52} 48}
53 49
54const char *view_get_app_id(struct sway_view *view) { 50const char *view_get_app_id(struct sway_view *view) {
55 if (view->impl->get_string_prop) { 51 if (view->impl->get_prop) {
56 return view->impl->get_string_prop(view, VIEW_PROP_APP_ID); 52 return view->impl->get_prop(view, VIEW_PROP_APP_ID);
57 } 53 }
58 return NULL; 54 return NULL;
59} 55}
60 56
61const char *view_get_class(struct sway_view *view) { 57const char *view_get_class(struct sway_view *view) {
62 if (view->impl->get_string_prop) { 58 if (view->impl->get_prop) {
63 return view->impl->get_string_prop(view, VIEW_PROP_CLASS); 59 return view->impl->get_prop(view, VIEW_PROP_CLASS);
64 } 60 }
65 return NULL; 61 return NULL;
66} 62}
67 63
68const char *view_get_instance(struct sway_view *view) { 64const char *view_get_instance(struct sway_view *view) {
69 if (view->impl->get_string_prop) { 65 if (view->impl->get_prop) {
70 return view->impl->get_string_prop(view, VIEW_PROP_INSTANCE); 66 return view->impl->get_prop(view, VIEW_PROP_INSTANCE);
71 } 67 }
72 return NULL; 68 return NULL;
73} 69}
74 70
75uint32_t view_get_x11_window_id(struct sway_view *view) {
76 if (view->impl->get_int_prop) {
77 return view->impl->get_int_prop(view, VIEW_PROP_X11_WINDOW_ID);
78 }
79 return 0;
80}
81
82uint32_t view_get_window_type(struct sway_view *view) {
83 if (view->impl->get_int_prop) {
84 return view->impl->get_int_prop(view, VIEW_PROP_WINDOW_TYPE);
85 }
86 return 0;
87}
88
89const char *view_get_type(struct sway_view *view) { 71const char *view_get_type(struct sway_view *view) {
90 switch(view->type) { 72 switch(view->type) {
91 case SWAY_VIEW_WL_SHELL: 73 case SWAY_VIEW_WL_SHELL:
@@ -302,36 +284,19 @@ static void view_handle_container_reparent(struct wl_listener *listener,
302 } 284 }
303} 285}
304 286
305static bool view_has_executed_criteria(struct sway_view *view, 287static void view_execute_criteria(struct sway_view *view) {
306 struct criteria *criteria) { 288 if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) {
307 for (int i = 0; i < view->executed_criteria->length; ++i) {
308 struct criteria *item = view->executed_criteria->items[i];
309 if (item == criteria) {
310 return true;
311 }
312 }
313 return false;
314}
315
316void view_execute_criteria(struct sway_view *view) {
317 if (!view->swayc) {
318 return; 289 return;
319 } 290 }
320 struct sway_seat *seat = input_manager_current_seat(input_manager); 291 struct sway_seat *seat = input_manager_current_seat(input_manager);
321 struct sway_container *prior_workspace = 292 struct sway_container *prior_workspace =
322 container_parent(view->swayc, C_WORKSPACE); 293 container_parent(view->swayc, C_WORKSPACE);
323 list_t *criterias = criteria_for_view(view, CT_COMMAND); 294 list_t *criteria = criteria_for(view->swayc);
324 for (int i = 0; i < criterias->length; i++) { 295 for (int i = 0; i < criteria->length; i++) {
325 struct criteria *criteria = criterias->items[i]; 296 struct criteria *crit = criteria->items[i];
326 wlr_log(L_DEBUG, "Checking criteria %s", criteria->raw); 297 wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'",
327 if (view_has_executed_criteria(view, criteria)) { 298 crit->crit_raw, view, crit->cmdlist);
328 wlr_log(L_DEBUG, "Criteria already executed"); 299 struct cmd_results *res = execute_command(crit->cmdlist, NULL);
329 continue;
330 }
331 wlr_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'",
332 criteria->raw, view, criteria->cmdlist);
333 list_add(view->executed_criteria, criteria);
334 struct cmd_results *res = execute_command(criteria->cmdlist, NULL);
335 if (res->status != CMD_SUCCESS) { 300 if (res->status != CMD_SUCCESS) {
336 wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); 301 wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
337 } 302 }
@@ -340,7 +305,7 @@ void view_execute_criteria(struct sway_view *view) {
340 // so always refocus in-between command lists 305 // so always refocus in-between command lists
341 seat_set_focus(seat, view->swayc); 306 seat_set_focus(seat, view->swayc);
342 } 307 }
343 list_free(criterias); 308 list_free(criteria);
344 seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); 309 seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace));
345} 310}
346 311
@@ -350,26 +315,9 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
350 } 315 }
351 316
352 struct sway_seat *seat = input_manager_current_seat(input_manager); 317 struct sway_seat *seat = input_manager_current_seat(input_manager);
353 struct sway_container *focus = seat_get_focus(seat); 318 struct sway_container *focus = seat_get_focus_inactive(seat,
354 struct sway_container *cont = NULL; 319 &root_container);
355 320 struct sway_container *cont = container_view_create(focus, view);
356 // Check if there's any `assign` criteria for the view
357 list_t *criterias = criteria_for_view(view,
358 CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT);
359 if (criterias->length) {
360 struct criteria *criteria = criterias->items[0];
361 if (criteria->type == CT_ASSIGN_WORKSPACE) {
362 struct sway_container *workspace = workspace_by_name(criteria->target);
363 if (!workspace) {
364 workspace = workspace_create(NULL, criteria->target);
365 }
366 focus = seat_get_focus_inactive(seat, workspace);
367 } else {
368 // TODO: CT_ASSIGN_OUTPUT
369 }
370 }
371 free(criterias);
372 cont = container_view_create(focus, view);
373 321
374 view->surface = wlr_surface; 322 view->surface = wlr_surface;
375 view->swayc = cont; 323 view->swayc = cont;
@@ -387,11 +335,10 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
387 arrange_children_of(cont->parent); 335 arrange_children_of(cont->parent);
388 input_manager_set_focus(input_manager, cont); 336 input_manager_set_focus(input_manager, cont);
389 337
390 view_update_title(view, false);
391 view_execute_criteria(view);
392
393 container_damage_whole(cont); 338 container_damage_whole(cont);
394 view_handle_container_reparent(&view->container_reparent, NULL); 339 view_handle_container_reparent(&view->container_reparent, NULL);
340
341 view_execute_criteria(view);
395} 342}
396 343
397void view_unmap(struct sway_view *view) { 344void view_unmap(struct sway_view *view) {