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)
7 * assignments.c: Assignments for specific windows (for_window).
13 * Checks the list of assignments for the given window and runs all matching
14 * ones (unless they have already been run for this specific window).
17 void run_assignments(i3Window *window) {
18 DLOG("Checking if any assignments match this window\n");
20 /* Check if any assignments match */
22 TAILQ_FOREACH(current, &assignments, assignments) {
23 if (!match_matches_window(&(current->match), window))
27 for (int c = 0; c < window->nr_assignments; c++) {
28 if (window->ran_assignments[c] != current)
31 DLOG("This assignment already ran for the given window, not executing it again.\n");
39 DLOG("matching assignment, would do:\n");
40 if (current->type == A_COMMAND) {
41 DLOG("execute command %s\n", current->dest.command);
43 sasprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
44 char *json_result = parse_cmd(full_command);
49 /* Store that we ran this assignment to not execute it again */
50 window->nr_assignments++;
51 window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment*) * window->nr_assignments);
52 window->ran_assignments[window->nr_assignments-1] = current;
57 * Returns the first matching assignment for the given window.
60 Assignment *assignment_for(i3Window *window, int type) {
61 Assignment *assignment;
63 TAILQ_FOREACH(assignment, &assignments, assignments) {
64 if ((type != A_ANY && (assignment->type & type) == 0) ||
65 !match_matches_window(&(assignment->match), window))
67 DLOG("got a matching assignment (to %s)\n", assignment->dest.workspace);