do not die on unknown placement: take the first one
[awesome.git] / uicb.c
blobc8faf0677bce5b5dc0853f9325f91e351f31a040
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 /**
23 * @defgroup ui_callback User Interface Callbacks
26 #include "awesome.h"
27 #include "xutil.h"
28 #include "tag.h"
29 #include "mouse.h"
30 #include "statusbar.h"
31 #include "widget.h"
32 #include "focus.h"
33 #include "client.h"
34 #include "screen.h"
35 #include "layouts/tile.h"
37 extern AwesomeConf globalconf;
39 #include "uicbgen.h"
41 static int
42 run_uicb(char *cmd)
44 char *p, *argcpy;
45 const char *arg;
46 int screen;
47 ssize_t len;
48 Uicb *uicb;
50 len = a_strlen(cmd);
51 p = strtok(cmd, " ");
52 if (!p)
54 warn("Ignoring malformed command\n");
55 return -1;
57 screen = atoi(cmd);
58 if(screen >= globalconf.nscreen || screen < 0)
60 warn("Invalid screen specified: %i\n", screen);
61 return -1;
64 p = strtok(NULL, " ");
65 if (!p)
67 warn("Ignoring malformed command.\n");
68 return -1;
71 uicb = name_func_lookup(p, UicbList);
72 if (!uicb)
74 warn("Unknown UICB function: %s.\n", p);
75 return -1;
78 if (p + a_strlen(p) < cmd + len)
80 arg = p + a_strlen(p) + 1;
81 len = a_strlen(arg);
82 /* Allow our callees to modify this string. */
83 argcpy = p_new(char, len + 1);
84 a_strncpy(argcpy, len + 1, arg, len);
85 uicb(screen, argcpy);
86 p_delete(&argcpy);
88 else
89 uicb(screen, NULL);
91 return 0;
94 int
95 parse_control(char *cmd)
97 char *p, *curcmd = cmd;
99 if(!a_strlen(cmd))
100 return -1;
102 while((p = strchr(curcmd, '\n')))
104 *p = '\0';
105 run_uicb(curcmd);
106 curcmd = p + 1;
109 return 0;
112 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80