aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <RedSoxFan@users.noreply.github.com>2018-05-14 09:06:23 -0400
committerLibravatar GitHub <noreply@github.com>2018-05-14 09:06:23 -0400
commit9ba0dca7bacb0e79aeac4ea8c605713c69446d9b (patch)
tree3573981aaa61ac5c86be6ce1e8ecf5e2112b8d5b /sway/tree/view.c
parentAlways render top border for border normal (diff)
parentMerge pull request #1871 from emersion/kill-wl-shell (diff)
downloadsway-9ba0dca7bacb0e79aeac4ea8c605713c69446d9b.tar.gz
sway-9ba0dca7bacb0e79aeac4ea8c605713c69446d9b.tar.zst
sway-9ba0dca7bacb0e79aeac4ea8c605713c69446d9b.zip
Merge branch 'master' into fix-1975
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c107
1 files changed, 83 insertions, 24 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 392cd59d..8da72667 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -3,6 +3,7 @@
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"
6#include "log.h" 7#include "log.h"
7#include "sway/criteria.h" 8#include "sway/criteria.h"
8#include "sway/commands.h" 9#include "sway/commands.h"
@@ -21,6 +22,7 @@ void view_init(struct sway_view *view, enum sway_view_type type,
21 const struct sway_view_impl *impl) { 22 const struct sway_view_impl *impl) {
22 view->type = type; 23 view->type = type;
23 view->impl = impl; 24 view->impl = impl;
25 view->executed_criteria = create_list();
24 wl_signal_init(&view->events.unmap); 26 wl_signal_init(&view->events.unmap);
25} 27}
26 28
@@ -33,6 +35,8 @@ void view_destroy(struct sway_view *view) {
33 view_unmap(view); 35 view_unmap(view);
34 } 36 }
35 37
38 list_free(view->executed_criteria);
39
36 container_destroy(view->swayc); 40 container_destroy(view->swayc);
37 41
38 if (view->impl->destroy) { 42 if (view->impl->destroy) {
@@ -43,37 +47,56 @@ void view_destroy(struct sway_view *view) {
43} 47}
44 48
45const char *view_get_title(struct sway_view *view) { 49const char *view_get_title(struct sway_view *view) {
46 if (view->impl->get_prop) { 50 if (view->impl->get_string_prop) {
47 return view->impl->get_prop(view, VIEW_PROP_TITLE); 51 return view->impl->get_string_prop(view, VIEW_PROP_TITLE);
48 } 52 }
49 return NULL; 53 return NULL;
50} 54}
51 55
52const char *view_get_app_id(struct sway_view *view) { 56const char *view_get_app_id(struct sway_view *view) {
53 if (view->impl->get_prop) { 57 if (view->impl->get_string_prop) {
54 return view->impl->get_prop(view, VIEW_PROP_APP_ID); 58 return view->impl->get_string_prop(view, VIEW_PROP_APP_ID);
55 } 59 }
56 return NULL; 60 return NULL;
57} 61}
58 62
59const char *view_get_class(struct sway_view *view) { 63const char *view_get_class(struct sway_view *view) {
60 if (view->impl->get_prop) { 64 if (view->impl->get_string_prop) {
61 return view->impl->get_prop(view, VIEW_PROP_CLASS); 65 return view->impl->get_string_prop(view, VIEW_PROP_CLASS);
62 } 66 }
63 return NULL; 67 return NULL;
64} 68}
65 69
66const char *view_get_instance(struct sway_view *view) { 70const char *view_get_instance(struct sway_view *view) {
67 if (view->impl->get_prop) { 71 if (view->impl->get_string_prop) {
68 return view->impl->get_prop(view, VIEW_PROP_INSTANCE); 72 return view->impl->get_string_prop(view, VIEW_PROP_INSTANCE);
69 } 73 }
70 return NULL; 74 return NULL;
71} 75}
72 76
77uint32_t view_get_x11_window_id(struct sway_view *view) {
78 if (view->impl->get_int_prop) {
79 return view->impl->get_int_prop(view, VIEW_PROP_X11_WINDOW_ID);
80 }
81 return 0;
82}
83
84const char *view_get_window_role(struct sway_view *view) {
85 if (view->impl->get_string_prop) {
86 return view->impl->get_string_prop(view, VIEW_PROP_WINDOW_ROLE);
87 }
88 return NULL;
89}
90
91uint32_t view_get_window_type(struct sway_view *view) {
92 if (view->impl->get_int_prop) {
93 return view->impl->get_int_prop(view, VIEW_PROP_WINDOW_TYPE);
94 }
95 return 0;
96}
97
73const char *view_get_type(struct sway_view *view) { 98const char *view_get_type(struct sway_view *view) {
74 switch(view->type) { 99 switch(view->type) {
75 case SWAY_VIEW_WL_SHELL:
76 return "wl_shell";
77 case SWAY_VIEW_XDG_SHELL_V6: 100 case SWAY_VIEW_XDG_SHELL_V6:
78 return "xdg_shell_v6"; 101 return "xdg_shell_v6";
79 case SWAY_VIEW_XDG_SHELL: 102 case SWAY_VIEW_XDG_SHELL:
@@ -320,19 +343,36 @@ static void view_handle_container_reparent(struct wl_listener *listener,
320 } 343 }
321} 344}
322 345
323static void view_execute_criteria(struct sway_view *view) { 346static bool view_has_executed_criteria(struct sway_view *view,
324 if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) { 347 struct criteria *criteria) {
348 for (int i = 0; i < view->executed_criteria->length; ++i) {
349 struct criteria *item = view->executed_criteria->items[i];
350 if (item == criteria) {
351 return true;
352 }
353 }
354 return false;
355}
356
357void view_execute_criteria(struct sway_view *view) {
358 if (!view->swayc) {
325 return; 359 return;
326 } 360 }
327 struct sway_seat *seat = input_manager_current_seat(input_manager); 361 struct sway_seat *seat = input_manager_current_seat(input_manager);
328 struct sway_container *prior_workspace = 362 struct sway_container *prior_workspace =
329 container_parent(view->swayc, C_WORKSPACE); 363 container_parent(view->swayc, C_WORKSPACE);
330 list_t *criteria = criteria_for(view->swayc); 364 list_t *criterias = criteria_for_view(view, CT_COMMAND);
331 for (int i = 0; i < criteria->length; i++) { 365 for (int i = 0; i < criterias->length; i++) {
332 struct criteria *crit = criteria->items[i]; 366 struct criteria *criteria = criterias->items[i];
333 wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", 367 wlr_log(L_DEBUG, "Checking criteria %s", criteria->raw);
334 crit->crit_raw, view, crit->cmdlist); 368 if (view_has_executed_criteria(view, criteria)) {
335 struct cmd_results *res = execute_command(crit->cmdlist, NULL); 369 wlr_log(L_DEBUG, "Criteria already executed");
370 continue;
371 }
372 wlr_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'",
373 criteria->raw, view, criteria->cmdlist);
374 list_add(view->executed_criteria, criteria);
375 struct cmd_results *res = execute_command(criteria->cmdlist, NULL);
336 if (res->status != CMD_SUCCESS) { 376 if (res->status != CMD_SUCCESS) {
337 wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); 377 wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
338 } 378 }
@@ -341,7 +381,7 @@ static void view_execute_criteria(struct sway_view *view) {
341 // so always refocus in-between command lists 381 // so always refocus in-between command lists
342 seat_set_focus(seat, view->swayc); 382 seat_set_focus(seat, view->swayc);
343 } 383 }
344 list_free(criteria); 384 list_free(criterias);
345 seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); 385 seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace));
346} 386}
347 387
@@ -351,9 +391,27 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
351 } 391 }
352 392
353 struct sway_seat *seat = input_manager_current_seat(input_manager); 393 struct sway_seat *seat = input_manager_current_seat(input_manager);
354 struct sway_container *focus = seat_get_focus_inactive(seat, 394 struct sway_container *focus =
355 &root_container); 395 seat_get_focus_inactive(seat, &root_container);
356 struct sway_container *cont = container_view_create(focus, view); 396 struct sway_container *cont = NULL;
397
398 // Check if there's any `assign` criteria for the view
399 list_t *criterias = criteria_for_view(view,
400 CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT);
401 if (criterias->length) {
402 struct criteria *criteria = criterias->items[0];
403 if (criteria->type == CT_ASSIGN_WORKSPACE) {
404 struct sway_container *workspace = workspace_by_name(criteria->target);
405 if (!workspace) {
406 workspace = workspace_create(NULL, criteria->target);
407 }
408 focus = seat_get_focus_inactive(seat, workspace);
409 } else {
410 // TODO: CT_ASSIGN_OUTPUT
411 }
412 }
413 free(criterias);
414 cont = container_view_create(focus, view);
357 415
358 view->surface = wlr_surface; 416 view->surface = wlr_surface;
359 view->swayc = cont; 417 view->swayc = cont;
@@ -371,10 +429,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
371 arrange_children_of(cont->parent); 429 arrange_children_of(cont->parent);
372 input_manager_set_focus(input_manager, cont); 430 input_manager_set_focus(input_manager, cont);
373 431
432 view_update_title(view, false);
433 view_execute_criteria(view);
434
374 container_damage_whole(cont); 435 container_damage_whole(cont);
375 view_handle_container_reparent(&view->container_reparent, NULL); 436 view_handle_container_reparent(&view->container_reparent, NULL);
376
377 view_execute_criteria(view);
378} 437}
379 438
380void view_unmap(struct sway_view *view) { 439void view_unmap(struct sway_view *view) {