diff --git a/Makefile b/Makefile index 06b790c7..9badb61f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c window.c rules.c mouse.c awesome-client-common.c +SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c xutil.c config.c screen.c statusbar.c uicb.c window.c rules.c mouse.c awesome-client-common.c OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o} SRCCLIENT = awesome-client.c awesome-client-common.c util.c @@ -28,7 +28,7 @@ ${OBJCLIENT}: config.mk awesome-client: ${OBJCLIENT} @echo -e \\t\(CC\) ${OBJCLIENT} -o $@ - @${CC} -o $@ ${OBJCLIENT} ${LDFLAGS} + @${CC} -o $@ ${OBJCLIENT} ${CLIENTLDFLAGS} awesome: ${OBJ} @echo -e \\t\(CC\) ${OBJ} -o $@ diff --git a/client.c b/client.c index 84a41f2f..fd27df40 100644 --- a/client.c +++ b/client.c @@ -28,7 +28,7 @@ #include "layout.h" #include "tag.h" #include "rules.h" -#include "util.h" +#include "xutil.h" #include "statusbar.h" #include "window.h" #include "layouts/floating.h" diff --git a/config.mk b/config.mk index 912559b4..d0c8899d 100644 --- a/config.mk +++ b/config.mk @@ -21,6 +21,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfuse xft cairo` # flags CFLAGS = -fgnu89-inline -std=gnu99 -ggdb3 -pipe -Wall -Wextra -W -Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wsign-compare -Wunused -Wuninitialized -Winit-self -Wpointer-arith -Wredundant-decls -Wno-format-zero-length -Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn -O3 ${INCS} -DVERSION=\"${VERSION}\" -DRELEASE=\"${RELEASE}\" LDFLAGS = -ggdb3 ${LIBS} +CLIENTLDFLAGS = -ggdb3 # compiler and linker CC = cc diff --git a/layout.c b/layout.c index 90f6c2a4..c67e9953 100644 --- a/layout.c +++ b/layout.c @@ -25,7 +25,7 @@ #include "screen.h" #include "layout.h" #include "tag.h" -#include "util.h" +#include "xutil.h" #include "statusbar.h" #include "layouts/floating.h" diff --git a/uicb.c b/uicb.c index bb4d55ef..3e850abe 100644 --- a/uicb.c +++ b/uicb.c @@ -22,7 +22,7 @@ #include #include "awesome.h" -#include "util.h" +#include "xutil.h" #include "uicb.h" #include "screen.h" #include "tag.h" diff --git a/util.c b/util.c index 4721344f..eca6e30c 100644 --- a/util.c +++ b/util.c @@ -26,10 +26,6 @@ #include #include -#include -#include -#include - #include "util.h" void @@ -54,91 +50,6 @@ eprint(const char *fmt, ...) exit(EXIT_FAILURE); } -void -uicb_exec(awesome_config * awesomeconf, - const char *arg) -{ - char path[PATH_MAX]; - if(awesomeconf->display) - close(ConnectionNumber(awesomeconf->display)); - - sscanf(arg, "%s", path); - execlp(path, arg, NULL); -} - -void -uicb_spawn(awesome_config * awesomeconf, - const char *arg) -{ - static char *shell = NULL; - char *display = NULL; - char *tmp, newdisplay[128]; - - if(!shell && !(shell = getenv("SHELL"))) - shell = a_strdup("/bin/sh"); - if(!arg) - return; - - if(!XineramaIsActive(awesomeconf->display) && (tmp = getenv("DISPLAY"))) - { - display = a_strdup(tmp); - if((tmp = strrchr(display, '.'))) - *tmp = '\0'; - snprintf(newdisplay, sizeof(newdisplay), "%s.%d", display, awesomeconf->screen); - setenv("DISPLAY", newdisplay, 1); - } - - - /* The double-fork construct avoids zombie processes and keeps the code - * clean from stupid signal handlers. */ - if(fork() == 0) - { - if(fork() == 0) - { - if(awesomeconf->display) - close(ConnectionNumber(awesomeconf->display)); - setsid(); - execl(shell, shell, "-c", arg, (char *) NULL); - fprintf(stderr, "awesome: execl '%s -c %s'", shell, arg); - perror(" failed"); - } - exit(EXIT_SUCCESS); - } - wait(0); -} - -Bool -xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen) -{ - char **list = NULL; - int n; - - XTextProperty name; - - if(!text || !textlen) - return False; - - text[0] = '\0'; - XGetTextProperty(disp, w, &name, atom); - - if(!name.nitems) - return False; - - if(name.encoding == XA_STRING) - a_strncpy(text, textlen, (char *) name.value, textlen - 1); - - else if(XmbTextPropertyToTextList(disp, &name, &list, &n) >= Success && n > 0 && *list) - { - a_strncpy(text, textlen, *list, textlen - 1); - XFreeStringList(list); - } - - text[textlen - 1] = '\0'; - XFree(name.value); - - return True; -} - double compute_new_value_from_arg(const char *arg, double current_value) { diff --git a/util.h b/util.h index 88b0a402..daf88a54 100644 --- a/util.h +++ b/util.h @@ -200,11 +200,8 @@ static inline ssize_t a_strcat(char *dst, ssize_t n, const char *src) void die(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); void eprint(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); -Bool xgettextprop(Display *, Window, Atom, char *, ssize_t); double compute_new_value_from_arg(const char *, double); void *name_func_lookup(const char *, const NameFuncLink *); -UICB_PROTO(uicb_spawn); -UICB_PROTO(uicb_exec); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/xutil.c b/xutil.c new file mode 100644 index 00000000..889e7291 --- /dev/null +++ b/xutil.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +#include "xutil.h" + +void +uicb_exec(awesome_config * awesomeconf, + const char *arg) +{ + char path[PATH_MAX]; + if(awesomeconf->display) + close(ConnectionNumber(awesomeconf->display)); + + sscanf(arg, "%s", path); + execlp(path, arg, NULL); +} + +void +uicb_spawn(awesome_config * awesomeconf, + const char *arg) +{ + static char *shell = NULL; + char *display = NULL; + char *tmp, newdisplay[128]; + + if(!shell && !(shell = getenv("SHELL"))) + shell = a_strdup("/bin/sh"); + if(!arg) + return; + + if(!XineramaIsActive(awesomeconf->display) && (tmp = getenv("DISPLAY"))) + { + display = a_strdup(tmp); + if((tmp = strrchr(display, '.'))) + *tmp = '\0'; + snprintf(newdisplay, sizeof(newdisplay), "%s.%d", display, awesomeconf->screen); + setenv("DISPLAY", newdisplay, 1); + } + + + /* The double-fork construct avoids zombie processes and keeps the code + * clean from stupid signal handlers. */ + if(fork() == 0) + { + if(fork() == 0) + { + if(awesomeconf->display) + close(ConnectionNumber(awesomeconf->display)); + setsid(); + execl(shell, shell, "-c", arg, (char *) NULL); + fprintf(stderr, "awesome: execl '%s -c %s'", shell, arg); + perror(" failed"); + } + exit(EXIT_SUCCESS); + } + wait(0); +} + +Bool +xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen) +{ + char **list = NULL; + int n; + + XTextProperty name; + + if(!text || !textlen) + return False; + + text[0] = '\0'; + XGetTextProperty(disp, w, &name, atom); + + if(!name.nitems) + return False; + + if(name.encoding == XA_STRING) + a_strncpy(text, textlen, (char *) name.value, textlen - 1); + + else if(XmbTextPropertyToTextList(disp, &name, &list, &n) >= Success && n > 0 && *list) + { + a_strncpy(text, textlen, *list, textlen - 1); + XFreeStringList(list); + } + + text[textlen - 1] = '\0'; + XFree(name.value); + + return True; +} + diff --git a/xutil.h b/xutil.h new file mode 100644 index 00000000..d3fef311 --- /dev/null +++ b/xutil.h @@ -0,0 +1,33 @@ +/* + * xutil.c - X-related useful functions header + * + * Copyright © 2007 Julien Danjou + * Copyright © 2006 Pierre Habouzit + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_XUTIL_H +#define AWESOME_XUTIL_H + +#include "util.h" + +Bool xgettextprop(Display *, Window, Atom, char *, ssize_t); +UICB_PROTO(uicb_spawn); +UICB_PROTO(uicb_exec); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99