don't stick textbox size to the first textsize sent via widget_tell
[awesome.git] / uicb.c
blobb44ae55226c7731d761125f6ac87d57f259803b4
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 "uicb.h"
26 #include "screen.h"
27 #include "tag.h"
28 #include "layout.h"
29 #include "mouse.h"
30 #include "statusbar.h"
31 #include "widget.h"
32 #include "focus.h"
33 #include "layouts/tile.h"
35 extern AwesomeConf globalconf;
37 const NameFuncLink UicbList[] =
39 /* xutil.c */
40 {"spawn", uicb_spawn},
41 {"exec", uicb_exec},
42 /* client.c */
43 {"client_kill", uicb_client_kill},
44 {"client_moveresize", uicb_client_moveresize},
45 {"client_settrans", uicb_client_settrans},
46 {"setborder", uicb_setborder},
47 {"client_swapnext", uicb_client_swapnext},
48 {"client_swapprev", uicb_client_swapprev},
49 /* tag.c */
50 {"client_tag", uicb_client_tag},
51 {"client_togglefloating", uicb_client_togglefloating},
52 {"tag_toggleview", uicb_tag_toggleview},
53 {"client_toggletag", uicb_client_toggletag},
54 {"tag_view", uicb_tag_view},
55 {"tag_viewprev_selected", uicb_tag_prev_selected},
56 {"tag_viewprev", uicb_tag_viewprev},
57 {"tag_viewnext", uicb_tag_viewnext},
58 /* layout.c */
59 {"tag_setlayout", uicb_tag_setlayout},
60 {"client_focusnext", uicb_client_focusnext},
61 {"client_focusprev", uicb_client_focusprev},
62 {"client_togglemax", uicb_client_togglemax},
63 {"client_toggleverticalmax", uicb_client_toggleverticalmax},
64 {"client_togglehorizontalmax", uicb_client_togglehorizontalmax},
65 {"client_zoom", uicb_client_zoom},
66 /* layouts/tile.c */
67 {"tag_setmwfact", uicb_tag_setmwfact},
68 {"tag_setnmaster", uicb_tag_setnmaster},
69 {"tag_setncol", uicb_tag_setncol},
70 /* screen.c */
71 {"screen_focus", uicb_screen_focus},
72 {"client_movetoscreen", uicb_client_movetoscreen},
73 /* awesome.c */
74 {"quit", uicb_quit},
75 /* statusbar.c */
76 {"statusbar_toggle", uicb_statusbar_toggle},
77 /* mouse.c */
78 {"client_movemouse", uicb_client_movemouse},
79 {"client_resizemouse", uicb_client_resizemouse},
80 /* focus.c */
81 {"focus_history", uicb_focus_history},
82 {"focus_client_byname", uicb_focus_client_byname},
83 /* widgets.c */
84 {"widget_tell", uicb_widget_tell},
85 {NULL, NULL}
88 static int
89 run_uicb(char *cmd, AwesomeConf *awesomeconf __attribute ((unused)))
91 char *p;
92 const char *arg;
93 char *argcpy;
94 int screen, len;
95 void (*uicb) (int, const char *);
97 len = strlen(cmd);
98 p = strtok(cmd, " ");
99 if (!p){
100 warn("Ignoring malformed command\n");
101 return -1;
103 screen = atoi(cmd);
104 if(screen >= get_screen_count() || screen < 0){
105 warn("Invalid screen specified: %i\n", screen);
106 return -1;
109 p = strtok(NULL, " ");
110 if (!p){
111 warn("Ignoring malformed command.\n");
112 return -1;
114 uicb = name_func_lookup(p, UicbList);
115 if (!uicb){
116 warn("Unknown UICB function: %s.\n", p);
117 return -1;
120 if (p+strlen(p) < cmd+len)
122 arg = p + strlen(p) + 1;
123 /* Allow our callees to modify this string. */
124 argcpy = p_new(char, strlen(arg)+1);
125 strncpy(argcpy, arg, strlen(arg));
126 uicb(screen, argcpy);
127 p_delete(&argcpy);
129 else
130 uicb(screen, NULL);
131 return 0;
135 parse_control(char *cmd)
137 char *p, *curcmd = cmd;
139 if(!a_strlen(cmd))
140 return -1;
142 while((p = strchr(curcmd, '\n')))
144 *p = '\0';
145 run_uicb(curcmd, &globalconf);
146 curcmd = p + 1;
148 return 0;
151 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80