1 #line 2 "assignments.c"
3 * vim:ts=4:sw=4:expandtab
5 * i3 - an improved dynamic tiling window manager
6 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
8 * assignments.c: Assignments for specific windows (for_window).
14 * Checks the list of assignments for the given window and runs all matching
15 * ones (unless they have already been run for this specific window).
18 void run_assignments(i3Window *window) {
19 DLOG("Checking if any assignments match this window\n");
21 bool needs_tree_render = false;
23 /* Check if any assignments match */
25 TAILQ_FOREACH(current, &assignments, assignments) {
26 if (!match_matches_window(&(current->match), window))
30 for (int c = 0; c < window->nr_assignments; c++) {
31 if (window->ran_assignments[c] != current)
34 DLOG("This assignment already ran for the given window, not executing it again.\n");
42 DLOG("matching assignment, would do:\n");
43 if (current->type == A_COMMAND) {
44 DLOG("execute command %s\n", current->dest.command);
46 sasprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
47 struct CommandResult *command_output = parse_command(full_command);
50 if (command_output->needs_tree_render)
51 needs_tree_render = true;
53 yajl_gen_free(command_output->json_gen);
56 /* Store that we ran this assignment to not execute it again */
57 window->nr_assignments++;
58 window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment*) * window->nr_assignments);
59 window->ran_assignments[window->nr_assignments-1] = current;
62 /* If any of the commands required re-rendering, we will do that now. */
63 if (needs_tree_render)
68 * Returns the first matching assignment for the given window.
71 Assignment *assignment_for(i3Window *window, int type) {
72 Assignment *assignment;
74 TAILQ_FOREACH(assignment, &assignments, assignments) {
75 if ((type != A_ANY && (assignment->type & type) == 0) ||
76 !match_matches_window(&(assignment->match), window))
78 DLOG("got a matching assignment (to %s)\n", assignment->dest.workspace);