mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
Split x-related util functions to a separate xutil.{c,h} file pair.
Hi there. awesome-client is now linked against the whole hog of x-related libs that awesome depends on. These get pulled in by awesome-client using the same LDFLAGS as awesome. Removing x-related libs from the LDFLAGS for awesome-client is only half of the story, as it also depends on util.c which now has a couple of x-related functions. The attached patch also splits these functions into a separate xutil.{c,h} file pair and teaches the rest of the files to use them. Apart from the small difference in file size (I see a 3-3.5% decrease in file size, both for a stripped and a non-stripped awesome-client binary), this should also somewhat reduce the startup time (since awesome-client won't have to map all of these libraries). Cheers... \n\n
This commit is contained in:
parent
279baed9c6
commit
ac188235ed
9 changed files with 131 additions and 97 deletions
4
Makefile
4
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 $@
|
||||
|
|
2
client.c
2
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"
|
||||
|
|
|
@ -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
|
||||
|
|
2
layout.c
2
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"
|
||||
|
||||
|
|
2
uicb.c
2
uicb.c
|
@ -22,7 +22,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "awesome.h"
|
||||
#include "util.h"
|
||||
#include "xutil.h"
|
||||
#include "uicb.h"
|
||||
#include "screen.h"
|
||||
#include "tag.h"
|
||||
|
|
89
util.c
89
util.c
|
@ -26,10 +26,6 @@
|
|||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
3
util.h
3
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
|
||||
|
|
92
xutil.c
Normal file
92
xutil.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
33
xutil.h
Normal file
33
xutil.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* xutil.c - X-related useful functions header
|
||||
*
|
||||
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
||||
* Copyright © 2006 Pierre Habouzit <madcoder@debian.org>
|
||||
*
|
||||
* 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
|
Loading…
Reference in a new issue