i3
|
00001 /* 00002 * vim:ts=4:sw=4:expandtab 00003 * 00004 * i3 - an improved dynamic tiling window manager 00005 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) 00006 * 00007 */ 00008 #include "all.h" 00009 00010 /* 00011 * Checks the list of assignments for the given window and runs all matching 00012 * ones (unless they have already been run for this specific window). 00013 * 00014 */ 00015 void run_assignments(i3Window *window) { 00016 DLOG("Checking assignments...\n"); 00017 00018 /* Check if any assignments match */ 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 /* Store that we ran this assignment to not execute it again */ 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 * Returns the first matching assignment for the given window. 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 }