00001
00002
00003
00004
00005
00006
00007
00008 #include "all.h"
00009
00010
00011
00012
00013
00014
00015 void run_assignments(i3Window *window) {
00016 DLOG("Checking assignments...\n");
00017
00018
00019 Assignment *current;
00020 TAILQ_FOREACH(current, &assignments, assignments) {
00021 if (!match_matches_window(&(current->match), window))
00022 continue;
00023
00024 bool skip = false;
00025 for (int c = 0; c < window->nr_assignments; c++) {
00026 if (window->ran_assignments[c] != current)
00027 continue;
00028
00029 DLOG("This assignment already ran for the given window, not executing it again.\n");
00030 skip = true;
00031 break;
00032 }
00033
00034 if (skip)
00035 continue;
00036
00037 DLOG("matching assignment, would do:\n");
00038 if (current->type == A_COMMAND) {
00039 DLOG("execute command %s\n", current->dest.command);
00040 char *full_command;
00041 asprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
00042 parse_cmd(full_command);
00043 }
00044
00045
00046 window->nr_assignments++;
00047 window->ran_assignments = srealloc(window->ran_assignments, sizeof(Assignment*) * window->nr_assignments);
00048 window->ran_assignments[window->nr_assignments-1] = current;
00049 }
00050 }
00051
00052
00053
00054
00055
00056 Assignment *assignment_for(i3Window *window, int type) {
00057 Assignment *assignment;
00058
00059 TAILQ_FOREACH(assignment, &assignments, assignments) {
00060 if ((type != A_ANY && (assignment->type & type) == 0) ||
00061 !match_matches_window(&(assignment->match), window))
00062 continue;
00063 DLOG("got a matching assignment (to %s)\n", assignment->dest.workspace);
00064 return assignment;
00065 }
00066
00067 return NULL;
00068 }