Hi,
        This is my first message to the ML.

I use tabbed so much, that I needed (wanted?) It to be able to run a program 
given as an argument whenever I press Ctrl+Return.
Something like:
        $ tabbed -x surf -e %XID%
Or:
        $ tabbed -x urxvt -embed %XID%
And having tabbed to replace the %XID% token with its winid, and then spawning 
the process.

So, I've made a patch that does exactly that. Now I can use tabbed to "tab" 
surf, urxvt, etc...
All with the same tabbed, no need to maintain more than one!
It certainly is not the most wonderful feature, nor the most secure piece of 
code, but It suits my current needs.

I've also fixed an issue I was having when running tabbed without embedding any 
client: It wouldn't recognize any keybinding, more importantly Ctrl+Return.

I hope someone will find It useful.
Any comment/observations/criticism/etc... will be welcome.
I'm always eager to improve and learn.

Thanks for all the great, less-sucking software you make.

P.S. Please forgive my poor English. It's not my first language, so please help 
me to improve on It if you can.
--
Andrés.
# HG changeset patch
# User Andrés Musetti <amuse...@internet.com.uy>
# Date 1285686174 10800
# Branch hacking
# Node ID 55cea09d675453c9330b61d2a42eb8836c23cfd1
# Parent  f8f6841b3c1cd2fa6231e1cecc8ae7064f4084d1
Fix: keybindings were not working until a client window was managed.

Keybindings with modifiers where not working until a client window was managed,
because updatenumlockmask() was not called until then.

Resolve the problem by calling updatenumlockmask() on entering the main loop.

diff -r f8f6841b3c1c -r 55cea09d6754 tabbed.c
--- a/tabbed.c	Mon Aug 09 11:59:13 2010 +0100
+++ b/tabbed.c	Tue Sep 28 12:02:54 2010 -0300
@@ -677,6 +677,7 @@
 	XEvent ev;
 
 	/* main event loop */
+	updatenumlockmask();
 	XSync(dpy, False);
 	drawbar();
 	while(running) {
# HG changeset patch
# User Andrés Musetti <amuse...@internet.com.uy>
# Date 1285689912 10800
# Branch hacking
# Node ID ac83df0bef56e1b27da8c52efe4f7d4ac822c174
# Parent  55cea09d675453c9330b61d2a42eb8836c23cfd1
Specify in the command line wint -x the program to be run by tabbed.

Bind the function cmdline(const Arg*) to some key combination in config.h.

The run tabbed like so:

    $ tabbed -x surf -e %XID%

      to embed an instance of surf whenever you press the key combination,

    $ tabbed -x urxvt -embed %XID%

      to embed an instance of urxvt, etc...

You can combine -x with -d, of course:

    $ tabbed -d -x surf -e %XID%

diff -r 55cea09d6754 -r ac83df0bef56 config.def.h
--- a/config.def.h	Tue Sep 28 12:02:54 2010 -0300
+++ b/config.def.h	Tue Sep 28 13:05:12 2010 -0300
@@ -8,11 +8,12 @@
 static const int tabwidth      = 200;
 static const Bool foreground   = False;
 
+#define XWINID "%XID%"
 #define MODKEY ControlMask
 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, cmdline,        { 0 } },
 	{ MODKEY|ShiftMask,             XK_l,      rotate,         { .i = +1 } },
 	{ MODKEY|ShiftMask,             XK_h,      rotate,         { .i = -1 } },
 	{ MODKEY,                       XK_Tab,    rotate,         { .i = 0 } },
diff -r 55cea09d6754 -r ac83df0bef56 tabbed.c
--- a/tabbed.c	Tue Sep 28 12:02:54 2010 -0300
+++ b/tabbed.c	Tue Sep 28 13:05:12 2010 -0300
@@ -123,6 +123,7 @@
 static void updatenumlockmask(void);
 static void updatetitle(Client *c);
 static int xerror(Display *dpy, XErrorEvent *ee);
+static void cmdline(const Arg *arg);
 
 /* variables */
 static int screen;
@@ -150,6 +151,11 @@
 static Client *clients = NULL, *sel = NULL, *lastsel = NULL;
 static int (*xerrorxlib)(Display *, XErrorEvent *);
 static char winid[64];
+static struct {
+  char** v; /* command line arguments */
+  int c;    /* command line arguments count */
+  int w;    /* is winid replaced? */
+} args;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
@@ -843,16 +849,46 @@
 	return xerrorxlib(dpy, ee); /* may call exit */
 }
 
+void
+cmdline(const Arg *arg) {
+  if (! args.v || ! args.c)
+    return;
+  if (! args.w) {
+    for (int i = 1; i < args.c; ++i) {
+      if (strcmp(args.v[i],XWINID) == 0) {
+	args.v[i] = winid;
+	args.w = 1;
+	break;
+      }
+    }
+  }
+  Arg a;
+  a.v = (char**)args.v;
+  spawn(&a);
+}
+
 int
 main(int argc, char *argv[]) {
 	int 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");
+	args.v = NULL;
+	args.c = 0;
+	args.w = 0;
+	for(int i = 1; i < argc; ++i) {
+	  if (strcmp(argv[i], "-v") == 0) {
+	    die("tabbed-"VERSION", © 2009-2010 tabbed engineers, see LICENSE for details\n");
+	  } else if (strcmp(argv[i], "-d") == 0) {
+	    detach = 1;
+	  } else if (strcmp(argv[i], "-x") == 0) {
+	    i++;
+	    args.v = argv + i;
+	    args.c = argc - i;
+	    break;
+	  } else {
+	    die("usage: tabbed [-d] [-v]\n");
+	  }
+	}
+
 	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		fprintf(stderr, "warning: no locale support\n");
 	if(!(dpy = XOpenDisplay(NULL)))
# HG changeset patch
# User Andrés Musetti <amuse...@internet.com.uy>
# Date 1285772189 10800
# Branch hacking
# Node ID 3d8a8e18d89b3ac55baa6825c05b0732c4ff31f2
# Parent  ac83df0bef56e1b27da8c52efe4f7d4ac822c174
Fix usage help message.

diff -r ac83df0bef56 -r 3d8a8e18d89b tabbed.c
--- a/tabbed.c	Tue Sep 28 13:05:12 2010 -0300
+++ b/tabbed.c	Wed Sep 29 11:56:29 2010 -0300
@@ -885,7 +885,7 @@
 	    args.c = argc - i;
 	    break;
 	  } else {
-	    die("usage: tabbed [-d] [-v]\n");
+	    die("usage: tabbed { -v | [-d] [-x command args...] }\n");
 	  }
 	}
 

Reply via email to