add various autostuff to ignore
[awesome.git] / uicb.c
blob8ec06d4c16f0dc6142a0250f099e2964e197deae
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, AwesomeConf *awesomeconf __attribute ((unused)))
90 char *p;
91 const char *arg;
92 char *argcpy;
93 int screen, len;
94 void (*uicb) (int, const char *);
96 len = strlen(cmd);
97 p = strtok(cmd, " ");
98 if (!p){
99 warn("Ignoring malformed command\n");
100 return -1;
102 screen = atoi(cmd);
103 if(screen >= get_screen_count() || screen < 0){
104 warn("Invalid screen specified: %i\n", screen);
105 return -1;
108 p = strtok(NULL, " ");
109 if (!p){
110 warn("Ignoring malformed command.\n");
111 return -1;
113 uicb = name_func_lookup(p, UicbList);
114 if (!uicb){
115 warn("Unknown UICB function: %s.\n", p);
116 return -1;
119 if (p+strlen(p) < cmd+len)
121 arg = p + strlen(p) + 1;
122 /* Allow our callees to modify this string. */
123 argcpy = p_new(char, strlen(arg)+1);
124 strncpy(argcpy, arg, strlen(arg));
125 uicb(screen, argcpy);
126 p_delete(&argcpy);
128 else
129 uicb(screen, NULL);
130 return 0;
134 parse_control(char *cmd)
136 char *p, *curcmd = cmd;
138 if(!a_strlen(cmd))
139 return -1;
141 while((p = strchr(curcmd, '\n')))
143 *p = '\0';
144 run_uicb(curcmd, &globalconf);
145 curcmd = p + 1;
147 return 0;
150 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80