invalidate cache
[awesome.git] / uicb.c
blobef89f1791aebbce146850bef709be146f9f7c713
1 /*
2 * uicb.c - user interface callbacks management
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "awesome.h"
23 #include "util.h"
24 #include "xutil.h"
25 #include "tag.h"
26 #include "mouse.h"
27 #include "statusbar.h"
28 #include "widget.h"
29 #include "focus.h"
30 #include "client.h"
31 #include "screen.h"
32 #include "layouts/tile.h"
34 extern AwesomeConf globalconf;
36 const NameFuncLink UicbList[] =
38 /* xutil.c */
39 {"spawn", uicb_spawn},
40 {"exec", uicb_exec},
41 /* client.c */
42 {"client_kill", uicb_client_kill},
43 {"client_moveresize", uicb_client_moveresize},
44 {"client_settrans", uicb_client_settrans},
45 {"client_swapnext", uicb_client_swapnext},
46 {"client_swapprev", uicb_client_swapprev},
47 /* tag.c */
48 {"client_tag", uicb_client_tag},
49 {"client_togglefloating", uicb_client_togglefloating},
50 {"tag_toggleview", uicb_tag_toggleview},
51 {"client_toggletag", uicb_client_toggletag},
52 {"tag_view", uicb_tag_view},
53 {"tag_viewprev_selected", uicb_tag_prev_selected},
54 {"tag_viewprev", uicb_tag_viewprev},
55 {"tag_viewnext", uicb_tag_viewnext},
56 {"tag_create", uicb_tag_create},
57 /* layout.c */
58 {"tag_setlayout", uicb_tag_setlayout},
59 {"client_focusnext", uicb_client_focusnext},
60 {"client_focusprev", uicb_client_focusprev},
61 {"client_togglemax", uicb_client_togglemax},
62 {"client_toggleverticalmax", uicb_client_toggleverticalmax},
63 {"client_togglehorizontalmax", uicb_client_togglehorizontalmax},
64 {"client_zoom", uicb_client_zoom},
65 /* layouts/tile.c */
66 {"tag_setmwfact", uicb_tag_setmwfact},
67 {"tag_setnmaster", uicb_tag_setnmaster},
68 {"tag_setncol", uicb_tag_setncol},
69 /* screen.c */
70 {"screen_focus", uicb_screen_focus},
71 {"client_movetoscreen", uicb_client_movetoscreen},
72 /* awesome.c */
73 {"quit", uicb_quit},
74 /* statusbar.c */
75 {"statusbar_toggle", uicb_statusbar_toggle},
76 /* mouse.c */
77 {"client_movemouse", uicb_client_movemouse},
78 {"client_resizemouse", uicb_client_resizemouse},
79 /* focus.c */
80 {"focus_history", uicb_focus_history},
81 {"focus_client_byname", uicb_focus_client_byname},
82 /* widgets.c */
83 {"widget_tell", uicb_widget_tell},
84 {NULL, NULL}
87 static int
88 run_uicb(char *cmd)
90 char *p, *argcpy;
91 const char *arg;
92 int screen;
93 ssize_t len;
94 Uicb *uicb;
96 len = a_strlen(cmd);
97 p = strtok(cmd, " ");
98 if (!p)
100 warn("Ignoring malformed command\n");
101 return -1;
103 screen = atoi(cmd);
104 if(screen >= globalconf.nscreens || screen < 0)
106 warn("Invalid screen specified: %i\n", screen);
107 return -1;
110 p = strtok(NULL, " ");
111 if (!p)
113 warn("Ignoring malformed command.\n");
114 return -1;
117 uicb = name_func_lookup(p, UicbList);
118 if (!uicb)
120 warn("Unknown UICB function: %s.\n", p);
121 return -1;
124 if (p + a_strlen(p) < cmd + len)
126 arg = p + a_strlen(p) + 1;
127 len = a_strlen(arg);
128 /* Allow our callees to modify this string. */
129 argcpy = p_new(char, len + 1);
130 a_strncpy(argcpy, len + 1, arg, len);
131 uicb(screen, argcpy);
132 p_delete(&argcpy);
134 else
135 uicb(screen, NULL);
137 return 0;
141 parse_control(char *cmd)
143 char *p, *curcmd = cmd;
145 if(!a_strlen(cmd))
146 return -1;
148 while((p = strchr(curcmd, '\n')))
150 *p = '\0';
151 run_uicb(curcmd);
152 curcmd = p + 1;
155 return 0;
158 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80