[hackers] [tabbed] added generic client support (thanks Stephen) || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Fri, 6 May 2011 22:40:59 +0200 (CEST)

changeset: 143:1f090280fc82
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Fri May 06 21:40:53 2011 +0100
files: config.def.h tabbed.c
description:
added generic client support (thanks Stephen)

diff -r f8f6841b3c1c -r 1f090280fc82 config.def.h
--- a/config.def.h Mon Aug 09 11:59:13 2010 +0100
+++ b/config.def.h Fri May 06 21:40:53 2011 +0100
@@ -12,7 +12,7 @@
 static Key keys[] = { \
         /* modifier key function argument */
         { MODKEY|ShiftMask, XK_Return, focusonce, { 0 } },
- { MODKEY|ShiftMask, XK_Return, spawn, { .v = (char*[]){ "surf", "-e", winid, NULL} } },
+ { MODKEY|ShiftMask, XK_Return, spawn, { 0 } },
         { MODKEY|ShiftMask, XK_l, rotate, { .i = +1 } },
         { MODKEY|ShiftMask, XK_h, rotate, { .i = -1 } },
         { MODKEY, XK_Tab, rotate, { .i = 0 } },
diff -r f8f6841b3c1c -r 1f090280fc82 tabbed.c
--- a/tabbed.c Mon Aug 09 11:59:13 2010 +0100
+++ b/tabbed.c Fri May 06 21:40:53 2011 +0100
@@ -39,7 +39,7 @@
 /* Macros */
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define LENGTH(x) (sizeof x / sizeof x[0])
+#define LENGTH(x) (sizeof (x) / sizeof *(x))
 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
 
@@ -116,6 +116,7 @@
 static void run(void);
 static void sendxembed(Client *c, long msg, long detail, long d1, long d2);
 static void setup(void);
+static void setcmd(int argc, char *argv[]);
 static void sigchld(int unused);
 static void spawn(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
@@ -150,6 +151,7 @@
 static Client *clients = NULL, *sel = NULL, *lastsel = NULL;
 static int (*xerrorxlib)(Display *, XErrorEvent *);
 static char winid[64];
+static char **cmd = NULL;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
@@ -189,8 +191,8 @@
         Client *c, *n;
 
         for(c = clients; c; c = n) {
+ focus(c);
                 killclient(NULL);
- focus(c);
                 XReparentWindow(dpy, c->win, root, 0, 0);
                 n = c->next;
                 unmanage(c);
@@ -203,6 +205,7 @@
         XFreeGC(dpy, dc.gc);
         XDestroyWindow(dpy, win);
         XSync(dpy, False);
+ free(cmd);
 }
 
 void
@@ -360,7 +363,7 @@
         void *p;
 
         if(!(p = calloc(1, size)))
- die(0, "tabbed: cannot malloc");
+ die("tabbed: cannot malloc\n");
         return p;
 }
 
@@ -423,7 +426,7 @@
         XColor color;
 
         if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
- die("error, cannot allocate color '%s'\n", colstr);
+ die("tabbed: cannot allocate color '%s'\n", colstr);
         return color.pixel;
 }
 
@@ -502,7 +505,7 @@
                 dc.font.xfont = NULL;
                 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
                 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
- die("error, cannot load font: '%s'\n", fontstr);
+ die("tabbed: cannot load font: '%s'\n", fontstr);
                 dc.font.ascent = dc.font.xfont->ascent;
                 dc.font.descent = dc.font.xfont->descent;
         }
@@ -578,7 +581,7 @@
                                         XGrabKey(dpy, code, keys[i].mod | modifiers[j], w,
                                                  True, GrabModeAsync, GrabModeAsync);
                 }
- c = emallocz(sizeof(Client));
+ c = emallocz(sizeof *c);
                 c->next = clients;
                 c->win = w;
                 clients = c;
@@ -703,6 +706,17 @@
 }
 
 void
+setcmd(int argc, char *argv[]) {
+ int i;
+
+ cmd = emallocz((argc+2) * sizeof *cmd);
+ for(i = 0; i < argc; i++)
+ cmd[i] = argv[i];
+ cmd[argc] = winid;
+ cmd[argc+1] = NULL;
+}
+
+void
 setup(void) {
         /* clean up any zombies immediately */
         sigchld(0);
@@ -740,7 +754,7 @@
         class_hint.res_class = "Tabbed";
         XSetClassHint(dpy, win, &class_hint);
         XSetWMProtocols(dpy, win, &wmatom[WMDelete], 1);
- snprintf(winid, LENGTH(winid), "%u", (int)win);
+ snprintf(winid, sizeof winid, "%lu", win);
         nextfocus = foreground;
         focus(clients);
 }
@@ -748,7 +762,7 @@
 void
 sigchld(int unused) {
         if(signal(SIGCHLD, sigchld) == SIG_ERR)
- die("Can't install SIGCHLD handler");
+ die("tabbed: cannot install SIGCHLD handler");
         while(0 < waitpid(-1, NULL, WNOHANG));
 }
 
@@ -758,8 +772,8 @@
                 if(dpy)
                         close(ConnectionNumber(dpy));
                 setsid();
- execvp(((char **)arg->v)[0], (char **)arg->v);
- fprintf(stderr, "tabbed: execvp %s", ((char **)arg->v)[0]);
+ execvp(cmd[0], cmd);
+ fprintf(stderr, "tabbed: execvp %s", cmd[0]);
                 perror(" failed");
                 exit(0);
         }
@@ -844,16 +858,20 @@
 
 int
 main(int argc, char *argv[]) {
- int detach = 0;
+ int i, detach = 0;
 
- if(argc == 2 && !strcmp("-v", argv[1]))
- die("tabbed-"VERSION", © 2009-2010 tabbed engineers, see LICENSE for details\n");
- else if(argc == 2 && strcmp("-d", argv[1]) == 0)
- detach = 1;
- else if(argc != 1)
- die("usage: tabbed [-d] [-v]\n");
+ for(i = 1; i < argc && !cmd; i++) {
+ if(!strcmp("-v", argv[i]))
+ die("tabbed-"VERSION", © 2009-2011 tabbed engineers, see LICENSE for details\n");
+ else if(!strcmp("-d", argv[i]))
+ detach = 1;
+ else
+ setcmd(argc-i, argv+i);
+ }
+ if(!cmd)
+ die("usage: tabbed [-d] [-v] command\n");
         if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
- fprintf(stderr, "warning: no locale support\n");
+ fprintf(stderr, "tabbed: no locale support\n");
         if(!(dpy = XOpenDisplay(NULL)))
                 die("tabbed: cannot open display\n");
         setup();
Received on Fri May 06 2011 - 22:40:59 CEST

This archive was generated by hypermail 2.2.0 : Fri May 06 2011 - 22:48:04 CEST