2 #define I3__FILE__ "assignments.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
9 * assignments.c: Assignments for specific windows (for_window).
15 * Checks the list of assignments for the given window and runs all matching
16 * ones (unless they have already been run for this specific window).
19 void run_assignments(i3Window *window) {
20 DLOG("Checking if any assignments match this window\n");
22 bool needs_tree_render = false;
24 /* Check if any assignments match */
26 TAILQ_FOREACH(current, &assignments, assignments) {
27 if (!match_matches_window(&(current->match), window))
31 for (uint32_t c = 0; c < window->nr_assignments; c++) {
32 if (window->ran_assignments[c] != current)
35 DLOG("This assignment already ran for the given window, not executing it again.\n");
43 DLOG("matching assignment, would do:\n");
44 if (current->type == A_COMMAND) {
45 DLOG("execute command %s\n", current->dest.command);
47 sasprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
48 struct CommandResult *command_output = parse_command(full_command);
51 if (command_output->needs_tree_render)
52 needs_tree_render = true;
54 yajl_gen_free(command_output->json_gen);
57 /* Store that we ran this assignment to not execute it again */
58 window->nr_assignments++;
59 window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment*) * window->nr_assignments);
60 window->ran_assignments[window->nr_assignments-1] = current;
63 /* If any of the commands required re-rendering, we will do that now. */
64 if (needs_tree_render)
69 * Returns the first matching assignment for the given window.
72 Assignment *assignment_for(i3Window *window, int type) {
73 Assignment *assignment;
75 TAILQ_FOREACH(assignment, &assignments, assignments) {
76 if ((type != A_ANY && (assignment->type & type) == 0) ||
77 !match_matches_window(&(assignment->match), window))
79 DLOG("got a matching assignment (to %s)\n", assignment->dest.workspace);