2 * util.c - useful functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 * Copyright © 2006 Pierre Habouzit <madcoder@debian.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
34 eprint(const char *fmt
, ...)
39 vfprintf(stderr
, fmt
, ap
);
45 uicb_spawn(Display
* disp
,
46 DC
*drawcontext
__attribute__ ((unused
)),
47 awesome_config
* awesomeconf
__attribute__ ((unused
)),
50 static char *shell
= NULL
;
52 if(!shell
&& !(shell
= getenv("SHELL")))
53 shell
= strdup("/bin/sh");
56 /* The double-fork construct avoids zombie processes and keeps the code
57 * clean from stupid signal handlers. */
63 close(ConnectionNumber(disp
));
65 execl(shell
, shell
, "-c", arg
, (char *) NULL
);
66 fprintf(stderr
, "awesome: execl '%s -c %s'", shell
, arg
);
75 xgettextprop(Display
*disp
, Window w
, Atom atom
, char *text
, unsigned int size
)
82 if(!text
|| size
== 0)
86 XGetTextProperty(disp
, w
, &name
, atom
);
91 if(name
.encoding
== XA_STRING
)
92 strncpy(text
, (char *) name
.value
, size
- 1);
94 else if(XmbTextPropertyToTextList(disp
, &name
, &list
, &n
) >= Success
&& n
> 0 && *list
)
96 strncpy(text
, *list
, size
- 1);
97 XFreeStringList(list
);
100 text
[size
- 1] = '\0';
107 compute_new_value_from_arg(const char *arg
, double current_value
)
111 if(arg
&& sscanf(arg
, "%lf", &delta
) == 1)
113 if(arg
[0] == '+' || arg
[0] == '-')
114 current_value
+= delta
;
116 current_value
= delta
;
119 return current_value
;