2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
11 * Checks the list of assignments for the given window and runs all matching
12 * ones (unless they have already been run for this specific window).
15 void run_assignments(i3Window *window) {
16 DLOG("Checking assignments...\n");
18 /* Check if any assignments match */
20 TAILQ_FOREACH(current, &assignments, assignments) {
21 if (!match_matches_window(&(current->match), window))
25 for (int c = 0; c < window->nr_assignments; c++) {
26 if (window->ran_assignments[c] != current)
29 DLOG("This assignment already ran for the given window, not executing it again.\n");
37 DLOG("matching assignment, would do:\n");
38 if (current->type == A_COMMAND) {
39 DLOG("execute command %s\n", current->dest.command);
41 asprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
42 parse_cmd(full_command);
45 /* Store that we ran this assignment to not execute it again */
46 window->nr_assignments++;
47 window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment*) * window->nr_assignments);
48 window->ran_assignments[window->nr_assignments-1] = current;
53 * Returns the first matching assignment for the given window.
56 Assignment *assignment_for(i3Window *window, int type) {
57 Assignment *assignment;
59 TAILQ_FOREACH(assignment, &assignments, assignments) {
60 if ((type != A_ANY && (assignment->type & type) == 0) ||
61 !match_matches_window(&(assignment->match), window))
63 DLOG("got a matching assignment (to %s)\n", assignment->dest.workspace);