Re: [dwm] bitarray and void *arg (was: using bitaray for tags (PATCH))

2008-05-21 Thread Enno "Gottox" Boland
There was a mistake in config.def.h. Here's the fixed on.

2008/5/21, Enno Gottox Boland <[EMAIL PROTECTED]>:
> Hi!
>
>  I added the void *arg feature to dwm and diffed it together with the
>  other changes. Please review the patch carefully, as I changed a lot.
>
>  Thanks!
>
>  2008/5/21, Enno Gottox Boland <[EMAIL PROTECTED]>:
>  > Here is yet another update to the patch which includes chances
>  >  discussed on #dwm.
>  >
>  >  2008/5/21, Anselm R. Garbe <[EMAIL PROTECTED]>:
>  >
>  > > Hi I like your patches (also the version of anydot).
>  >  >
>  >  >
>  >  >  On Wed, May 21, 2008 at 10:49:16AM +0200, Enno Gottox Boland wrote:
>  >  >  > 2008/5/21, Szabolcs Nagy <[EMAIL PROTECTED]>:
>  >  >  > > in config.h referencing tags has changed in rules but not in keys.
>  >  >  > Yes, arg has discussed yesterday if it's possible to change const 
> char
>  >  >  > *arg to void *arg. if this works, i'll change the key behavior too.
>  >  >
>  >  >
>  >  > Ok, I won't touch the code until the evening today, so feel free
>  >  >  to use the (int[]) 1 syntax, we are going to change the
>  >  >  argument of Key-functions to void *.
>  >  >
>  >  >
>  >  >  > >  the (1 << tagnum) in rules is a bit nasty
>  >  >  > >  it is probably nicer to do the shifting in setup();
>  >  >  > you mean in applyrules? - No I don't think so. It adds much more
>  >  >  > flexibility. You can define bitmasks as 0b10001 to tag a client to 
> the
>  >  >  > first and the fifth tag or you can use ~0 to make it "sticky".
>  >  >
>  >  >
>  >  > I agree, that allows also to get rid of cloned rules.
>  >  >
>  >  >
>  >  >  > >  instead of
>  >  >  > >   i < LENGTH(tags) && i < sizeof(int) * 8;
>  >  >  > >  what about checking once
>  >  >  > >   if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
>  >  >  > >  eprint("Maximum number of tags: %d\n", sizeof(int) * 
> CHAR_BIT);
>  >  >  > >  in setup();
>  >  >  > The problem about this is it denies users from using one config.h 
> with
>  >  >  > many tags on different architectures. Furthermore I wouldn't check
>  >  >  > this at runtime but at compiletime. (maybe we can use "#warning" as
>  >  >  > compromise)
>  >  >
>  >  >
>  >  > Well, regarding to
>  >  >
>  >  >  http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2005-01/1697.html
>  >  >
>  >  >  a compile time evaluation isn't possible. So I think we should
>  >  >  stick to Szabolcs proposal to reject the setup in setup():
>  >  >
>  >  > if(sizeof(unsigned int) * CHAR_BIT < LENGTH(tags))
>  >  > eprint("error: number of tags is restricted to: %u\n", 
> sizeof(unsigned int) * CHAR_BIT);
>  >  >
>  >  >  Usually nobody will use more than 16 tags imho, so that we
>  >  >  should not expect a problem here if sizeof(int) is only 2 on
>  >  >  some exotic hosts.
>  >  >
>  >  >  Kind regards,
>  >  >
>  >  > --
>  >  >   Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>  >  >
>  >  >
>  >
>  >
>  >
>  > --
>  >  http://www.gnuffy.org - Real Community Distro
>  >  http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
>  >
>  >
>
>
>
>  --
>  http://www.gnuffy.org - Real Community Distro
>  http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
>
>


-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
diff -r cd9fd0986555 config.def.h
--- a/config.def.h  Mon May 19 20:29:57 2008 +0100
+++ b/config.def.h  Wed May 21 19:42:30 2008 +0200
@@ -18,7 +18,8 @@
 
 Rule rules[] = {
/* class  instancetitle   tags ref  isfloating */
-   { "Gimp", NULL,   NULL,   NULL, True },
+   { "Gimp", NULL,   NULL,   0,True },
+   { "Firefox",  NULL,   NULL,   1 << 8,   True },
 };
 
 /* layout(s) */
@@ -35,55 +36,55 @@
 #define MODKEY Mod1Mask
 Key keys[] = {
/* modifier keyfunctionargument */
-   { MODKEY,   XK_p,  spawn,  "exec 
dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb 
'"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
-   { MODKEY|ShiftMask, XK_Return, spawn,  "exec 
uxterm" },
+   { MODKEY,   XK_p,  spawn,  (char 
*)"exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb 
'"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
+   { MODKEY|ShiftMask, XK_Return, spawn,  (char 
*)"exec uxterm" },
{ MODKEY,   XK_b,  togglebar,  NULL },
{ MODKEY,   XK_j,  focusnext,  NULL },
{ MODKEY,   XK_k,  focusprev,  NULL },
-   { MODKEY,   XK_h,  setmfact,   "-0.05" },
-   { MODKEY,   XK_l,  setmfact,   "+0.05" },
+   { MODKEY,   XK_h,  setmfact,   
(doub

Re: [dwm] bitarray and void *arg (was: using bitaray for tags (PATCH))

2008-05-21 Thread Enno "Gottox" Boland
Hi!

I added the void *arg feature to dwm and diffed it together with the
other changes. Please review the patch carefully, as I changed a lot.

Thanks!

2008/5/21, Enno Gottox Boland <[EMAIL PROTECTED]>:
> Here is yet another update to the patch which includes chances
>  discussed on #dwm.
>
>  2008/5/21, Anselm R. Garbe <[EMAIL PROTECTED]>:
>
> > Hi I like your patches (also the version of anydot).
>  >
>  >
>  >  On Wed, May 21, 2008 at 10:49:16AM +0200, Enno Gottox Boland wrote:
>  >  > 2008/5/21, Szabolcs Nagy <[EMAIL PROTECTED]>:
>  >  > > in config.h referencing tags has changed in rules but not in keys.
>  >  > Yes, arg has discussed yesterday if it's possible to change const char
>  >  > *arg to void *arg. if this works, i'll change the key behavior too.
>  >
>  >
>  > Ok, I won't touch the code until the evening today, so feel free
>  >  to use the (int[]) 1 syntax, we are going to change the
>  >  argument of Key-functions to void *.
>  >
>  >
>  >  > >  the (1 << tagnum) in rules is a bit nasty
>  >  > >  it is probably nicer to do the shifting in setup();
>  >  > you mean in applyrules? - No I don't think so. It adds much more
>  >  > flexibility. You can define bitmasks as 0b10001 to tag a client to the
>  >  > first and the fifth tag or you can use ~0 to make it "sticky".
>  >
>  >
>  > I agree, that allows also to get rid of cloned rules.
>  >
>  >
>  >  > >  instead of
>  >  > >   i < LENGTH(tags) && i < sizeof(int) * 8;
>  >  > >  what about checking once
>  >  > >   if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
>  >  > >  eprint("Maximum number of tags: %d\n", sizeof(int) * CHAR_BIT);
>  >  > >  in setup();
>  >  > The problem about this is it denies users from using one config.h with
>  >  > many tags on different architectures. Furthermore I wouldn't check
>  >  > this at runtime but at compiletime. (maybe we can use "#warning" as
>  >  > compromise)
>  >
>  >
>  > Well, regarding to
>  >
>  >  http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2005-01/1697.html
>  >
>  >  a compile time evaluation isn't possible. So I think we should
>  >  stick to Szabolcs proposal to reject the setup in setup():
>  >
>  > if(sizeof(unsigned int) * CHAR_BIT < LENGTH(tags))
>  > eprint("error: number of tags is restricted to: %u\n", 
> sizeof(unsigned int) * CHAR_BIT);
>  >
>  >  Usually nobody will use more than 16 tags imho, so that we
>  >  should not expect a problem here if sizeof(int) is only 2 on
>  >  some exotic hosts.
>  >
>  >  Kind regards,
>  >
>  > --
>  >   Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>  >
>  >
>
>
>
> --
>  http://www.gnuffy.org - Real Community Distro
>  http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
>
>


-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
diff -r cd9fd0986555 config.def.h
--- a/config.def.h  Mon May 19 20:29:57 2008 +0100
+++ b/config.def.h  Wed May 21 19:39:22 2008 +0200
@@ -18,7 +18,8 @@
 
 Rule rules[] = {
/* class  instancetitle   tags ref  isfloating */
-   { "Gimp", NULL,   NULL,   NULL, True },
+   { "Gimp", NULL,   NULL,   0,True },
+   { "Firefox",  NULL,   NULL,   1 << 8,   True },
 };
 
 /* layout(s) */
@@ -35,55 +36,55 @@
 #define MODKEY Mod1Mask
 Key keys[] = {
/* modifier keyfunctionargument */
-   { MODKEY,   XK_p,  spawn,  "exec 
dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb 
'"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
-   { MODKEY|ShiftMask, XK_Return, spawn,  "exec 
uxterm" },
+   { MODKEY,   XK_p,  spawn,  (char 
*)"exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb 
'"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
+   { MODKEY|ShiftMask, XK_Return, spawn,  (char 
*)"exec uxterm" },
{ MODKEY,   XK_b,  togglebar,  NULL },
{ MODKEY,   XK_j,  focusnext,  NULL },
{ MODKEY,   XK_k,  focusprev,  NULL },
-   { MODKEY,   XK_h,  setmfact,   "-0.05" },
-   { MODKEY,   XK_l,  setmfact,   "+0.05" },
+   { MODKEY,   XK_h,  setmfact,   
(double[]){+0.05} },
+   { MODKEY,   XK_l,  setmfact,   
(double[]){-0.05} },
{ MODKEY,   XK_Return, zoom,   NULL },
{ MODKEY,   XK_Tab,viewprevtag,NULL },
{ MODKEY|ShiftMask, XK_c,  killclient, NULL },
{ MODKEY,   XK_space,  togglelayout,   NULL },
{ MODKEY|ShiftMask, XK_space,  togglefloating, NULL },
-   {

Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Enno "Gottox" Boland
Here is yet another update to the patch which includes chances
discussed on #dwm.

2008/5/21, Anselm R. Garbe <[EMAIL PROTECTED]>:
> Hi I like your patches (also the version of anydot).
>
>
>  On Wed, May 21, 2008 at 10:49:16AM +0200, Enno Gottox Boland wrote:
>  > 2008/5/21, Szabolcs Nagy <[EMAIL PROTECTED]>:
>  > > in config.h referencing tags has changed in rules but not in keys.
>  > Yes, arg has discussed yesterday if it's possible to change const char
>  > *arg to void *arg. if this works, i'll change the key behavior too.
>
>
> Ok, I won't touch the code until the evening today, so feel free
>  to use the (int[]) 1 syntax, we are going to change the
>  argument of Key-functions to void *.
>
>
>  > >  the (1 << tagnum) in rules is a bit nasty
>  > >  it is probably nicer to do the shifting in setup();
>  > you mean in applyrules? - No I don't think so. It adds much more
>  > flexibility. You can define bitmasks as 0b10001 to tag a client to the
>  > first and the fifth tag or you can use ~0 to make it "sticky".
>
>
> I agree, that allows also to get rid of cloned rules.
>
>
>  > >  instead of
>  > >   i < LENGTH(tags) && i < sizeof(int) * 8;
>  > >  what about checking once
>  > >   if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
>  > >  eprint("Maximum number of tags: %d\n", sizeof(int) * CHAR_BIT);
>  > >  in setup();
>  > The problem about this is it denies users from using one config.h with
>  > many tags on different architectures. Furthermore I wouldn't check
>  > this at runtime but at compiletime. (maybe we can use "#warning" as
>  > compromise)
>
>
> Well, regarding to
>
>  http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2005-01/1697.html
>
>  a compile time evaluation isn't possible. So I think we should
>  stick to Szabolcs proposal to reject the setup in setup():
>
> if(sizeof(unsigned int) * CHAR_BIT < LENGTH(tags))
> eprint("error: number of tags is restricted to: %u\n", 
> sizeof(unsigned int) * CHAR_BIT);
>
>  Usually nobody will use more than 16 tags imho, so that we
>  should not expect a problem here if sizeof(int) is only 2 on
>  some exotic hosts.
>
>  Kind regards,
>
> --
>   Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>
>


-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
diff -r cd9fd0986555 config.def.h
--- a/config.def.h  Mon May 19 20:29:57 2008 +0100
+++ b/config.def.h  Wed May 21 13:04:59 2008 +0200
@@ -19,6 +19,7 @@
 Rule rules[] = {
/* class  instancetitle   tags ref  isfloating */
{ "Gimp", NULL,   NULL,   NULL, True },
+   { "Firefox",  NULL,   NULL,   1 << 8,   True },
 };
 
 /* layout(s) */
diff -r cd9fd0986555 dwm.c
--- a/dwm.c Mon May 19 20:29:57 2008 +0100
+++ b/dwm.c Wed May 21 13:04:59 2008 +0200
@@ -51,6 +51,7 @@
 #define LENGTH(x)   (sizeof x / sizeof x[0])
 #define MAXTAGLEN   16
 #define MOUSEMASK   (BUTTONMASK|PointerMotionMask)
+#define TAGMASK ((int)((1LL << LENGTH(tags) + 1) - 1))
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };/* cursor */
@@ -68,7 +69,7 @@
long flags;
unsigned int bw, oldbw;
Bool isbanned, isfixed, isfloating, isurgent;
-   Bool *tags;
+   unsigned int tags;
Client *next;
Client *prev;
Client *snext;
@@ -107,7 +108,7 @@
const char *class;
const char *instance;
const char *title;
-   const char *tag;
+   unsigned int tags;
Bool isfloating;
 } Rule;
 
@@ -198,7 +199,7 @@
 int screen, sx, sy, sw, sh;
 int bx, by, bw, bh, blw, wx, wy, ww, wh;
 int mx, my, mw, mh, tx, ty, tw, th;
-int seltags = 0;
+unsigned int seltags = 0;
 int (*xerrorxlib)(Display *, XErrorEvent *);
 unsigned int numlockmask = 0;
 void (*handler[LASTEvent]) (XEvent *) = {
@@ -218,7 +219,7 @@
 Atom wmatom[WMLast], netatom[NetLast];
 Bool otherwm, readin;
 Bool running = True;
-Bool *tagset[2];
+unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
 Client *clients = NULL;
 Client *sel = NULL;
 Client *stack = NULL;
@@ -231,14 +232,15 @@
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
-#define TAGSZ (LENGTH(tags) * sizeof(Bool))
+
+/* check if all tags will fit into a unsigned int bitarray. */
+static char tags_is_a_sign_that_your_IQ[sizeof(int) * 8 < LENGTH(tags) ? -1 : 
1];
 
 /* function implementations */
 
 void
 applyrules(Client *c) {
unsigned int i;
-   Bool matched = False;
Rule *r;
XClassHint ch = { 0 };
 
@@ -250,18 +252,15 @@
&& (!r->class || (ch.res_class && strstr(ch.res_class, 
r->class)))
&& (!r->instance || (ch.res_name && strstr(ch.res_name, 
r->instance {
c->isfloating = r->isfloating;
-   if(r->tag) {
-   c->tags[idxoft

Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Premysl Hruby
On (20/05/08 11:22), Kurt H Maier wrote:
> To: dynamic window manager 
> From: Kurt H Maier <[EMAIL PROTECTED]>
> 
> C has bitfield support inside structs:
> 
> unsigned tagsapplied :8;
> 
> and replace 8 with whatever value you want

Not really with whatever value, only that values so whole variable will
fit into int/long long 

> 
> Bitfields are a bad idea imo; code has to be changed pretty severely
> to handle a varying-sized bitfield.  You'd have to either limit the
> number of tags a user can create or else do a lot of work to
> generalize the code.
>

Yes, we solved this by not using variable-sized bitfields. ;)

-- 
Premysl "Anydot" Hruby, http://www.redrum.cz/



Re: [dwm] setwmname 0.1

2008-05-21 Thread Jeroen Schot
Hi Anselm,

On Tue, May 20, 2008 at 04:13:35PM +0200, Anselm R. Garbe wrote:
> please recheck attached version of setmwname as a binary with
> the JDK grey blob issue.
> 
> Use
> 
> ; ./setwmname LG3D
> 
> and see if it works. If so, then consider this for getting rid
> of Xmonad patches as well.

For me it doesn't work. Perhaps my java version is to old? Detailed info:
 * matlab r2007a
 * java version "1.6.0_05"
 * centos 5 (final)

'export AWT_TOOLKIT="MTOOLKIT"' does work.

Attached is a patch that makes setwmname print the _NET_WM_NAME when no
arguments are given, similar to hostname(1).

Regards,
-- 
Jeroen Schot
diff -ur setwmname-0.1.orig/setwmname.c setwmname-0.1/setwmname.c
--- setwmname-0.1.orig/setwmname.c	2008-05-21 12:44:43.678505000 +0200
+++ setwmname-0.1/setwmname.c	2008-05-21 12:36:25.560506000 +0200
@@ -19,16 +19,17 @@
 
 int
 main(int argc, char **argv) {
+	int status, format;
+	unsigned char *data = NULL;
+	unsigned long n, extra;
 	Display *dpy;
 	Window root, dummy;
-	Atom netwmcheck, netwmname, utf8_string;
+	Atom netwmcheck, netwmname, utf8_string, real;
 
-	if(argc == 2) {
-		if(!strncmp(argv[1], "-v", 3))
+	if(argc > 2)
+		eprint("usage: setwmname [name] [-v]\n");
+	if(argc == 2 && !strncmp(argv[1], "-v", 3))
 			eprint("setwmname-"VERSION", © 2008 Anselm R Garbe\n", stdout);
-	}
-	else
-		eprint("usage: setwmname  [-v]\n");
 
 	if(!(dpy = XOpenDisplay(0)))
 		eprint("setwmname: cannot open display\n");
@@ -36,8 +37,15 @@
 	netwmcheck = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
 	netwmname = XInternAtom(dpy, "_NET_WM_NAME", False);
 	utf8_string = XInternAtom(dpy, "UTF8_STRING", False);
-	XChangeProperty(dpy, root, netwmcheck, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&root, 1);
-	XChangeProperty(dpy, root, netwmname, utf8_string, 8, PropModeReplace, (unsigned char *)argv[1], strlen(argv[1]));
+	if(argc == 1) {
+		status = XGetWindowProperty(dpy, root, netwmname, 0L, 32L, False, utf8_string, &real, &format, &n, &extra, (unsigned char **) &data);
+		if(status == Success && data != NULL)
+			printf("%s\n", data);
+		XFree(data);
+	} else {
+		XChangeProperty(dpy, root, netwmcheck, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&root, 1);
+		XChangeProperty(dpy, root, netwmname, utf8_string, 8, PropModeReplace, (unsigned char *)argv[1], strlen(argv[1]));
+	}
 	XSync(dpy, False);
 	XCloseDisplay(dpy);
 	return 0;


Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Szabolcs Nagy
On 5/21/08, markus schnalke <[EMAIL PROTECTED]> wrote:
> I read, that bit-arrays are not very portable between different
> architectures. (It was in "The practice of programming", I think)

it's not exactly a bit array (arbitrary number of bits implemented eg.
as char array), it's only one int (with bit flags)

this is portable (a possible caveat is that some bit operations on
negative values are implementation defined by c89 (eg. -1 >> 1) so
unsigned int is recommended in those cases)



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Anselm R. Garbe
On Wed, May 21, 2008 at 12:14:27PM +0200, Premysl Hruby wrote:
> That's the reason why i wrote it as macros. That bitops can also be
> written as inline functions, without any harm to binary size or
> performance.
> 
> And yes, with bitarrays there are some portability issues. But asside of
> limiting number of possible tags, there's no portability downside for
> dwm, imho. (it will compile, but maximum of tags is architecture
> dependent)

Well, if someone needs more than 32 tags, buy a 64bit machine.

We should definately get sponsored by the hardware industry at
some point. ;)

dwm encourages users to buy bigger screens and 64bit hardware.

Kind regards,
-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Premysl Hruby
On (21/05/08 12:06), markus schnalke wrote:
> To: dwm@suckless.org
> From: markus schnalke <[EMAIL PROTECTED]>
> Subject: Re: [dwm] using bitaray for tags (PATCH)
> Mail-Followup-To: dwm@suckless.org
> User-Agent: Mutt/1.5.13 (2006-08-11)
> Reply-To: dynamic window manager 
> List-Id: dynamic window manager 
> 
> Premysl Hruby <[EMAIL PROTECTED]> wrote:
> > 
> > This is realization of Gottox's proposal discuted on IRC today.
> > It handles tags not as Bool [], but as bit-array saved in int.
> 
> I read, that bit-arrays are not very portable between different
> architectures. (It was in "The practice of programming", I think)
> 
> Maybe this is not relevant here; also I cannot recall the exact
> explanaition, why one should avoid it.
> Please check if there is any thruth in that statement.
> 
> 
> Second, I want to mention, that bit-shifts might look really leet, but
> _do_ obfuscate, what could be written much more clearly!
> 
> Please stick to _clear_ code.
> 
> 
> meillo

That's the reason why i wrote it as macros. That bitops can also be
written as inline functions, without any harm to binary size or
performance.

And yes, with bitarrays there are some portability issues. But asside of
limiting number of possible tags, there's no portability downside for
dwm, imho. (it will compile, but maximum of tags is architecture
dependent)


-- 
Premysl "Anydot" Hruby, http://www.redrum.cz/



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread markus schnalke
Premysl Hruby <[EMAIL PROTECTED]> wrote:
> 
> This is realization of Gottox's proposal discuted on IRC today.
> It handles tags not as Bool [], but as bit-array saved in int.

I read, that bit-arrays are not very portable between different
architectures. (It was in "The practice of programming", I think)

Maybe this is not relevant here; also I cannot recall the exact
explanaition, why one should avoid it.
Please check if there is any thruth in that statement.


Second, I want to mention, that bit-shifts might look really leet, but
_do_ obfuscate, what could be written much more clearly!

Please stick to _clear_ code.


meillo


signature.asc
Description: Digital signature


Re: [dwm] Freedom (was: Re: sic ipv6 patch)

2008-05-21 Thread Sylvain Bertrand
On Wed, May 21, 2008 at 10:58 AM, Matthias Kirschner <[EMAIL PROTECTED]> wrote:
> * hiro <[EMAIL PROTECTED]> [2008-05-20 19:13:11 -0400]:
>
>> > yes
>> >  lack of knowledge can mean lack of freedom (with my definition)
>>
>> So you have you own definition?
> [...]
>
> That's our freedom (in your definition). Szabolcs and I can use terms in
> another way than you, you hiro can curse on public mailing lists, and I
> can decide to stop discussing with people who swear and get personal.

Matthias, don't loose your time on that hairy troll.
This is a Microsoft paid guy trying to push BSD licences (they have a
shortage of code to put in there products).
:D

-- 
use single GPL licensed software, use Linux and secure your digital freedom!



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Anselm R. Garbe
Hi I like your patches (also the version of anydot).

On Wed, May 21, 2008 at 10:49:16AM +0200, Enno Gottox Boland wrote:
> 2008/5/21, Szabolcs Nagy <[EMAIL PROTECTED]>:
> > in config.h referencing tags has changed in rules but not in keys.
> Yes, arg has discussed yesterday if it's possible to change const char
> *arg to void *arg. if this works, i'll change the key behavior too.

Ok, I won't touch the code until the evening today, so feel free
to use the (int[]) 1 syntax, we are going to change the
argument of Key-functions to void *.

> >  the (1 << tagnum) in rules is a bit nasty
> >  it is probably nicer to do the shifting in setup();
> you mean in applyrules? - No I don't think so. It adds much more
> flexibility. You can define bitmasks as 0b10001 to tag a client to the
> first and the fifth tag or you can use ~0 to make it "sticky".

I agree, that allows also to get rid of cloned rules.

> >  instead of
> >   i < LENGTH(tags) && i < sizeof(int) * 8;
> >  what about checking once
> >   if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
> >  eprint("Maximum number of tags: %d\n", sizeof(int) * CHAR_BIT);
> >  in setup();
> The problem about this is it denies users from using one config.h with
> many tags on different architectures. Furthermore I wouldn't check
> this at runtime but at compiletime. (maybe we can use "#warning" as
> compromise)

Well, regarding to

http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2005-01/1697.html

a compile time evaluation isn't possible. So I think we should
stick to Szabolcs proposal to reject the setup in setup():

if(sizeof(unsigned int) * CHAR_BIT < LENGTH(tags))
eprint("error: number of tags is restricted to: %u\n", 
sizeof(unsigned int) * CHAR_BIT);

Usually nobody will use more than 16 tags imho, so that we
should not expect a problem here if sizeof(int) is only 2 on
some exotic hosts.

Kind regards,
-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361



Re: [dwm] Freedom (was: Re: sic ipv6 patch)

2008-05-21 Thread hiro
>  That's our freedom (in your definition). Szabolcs and I can use terms in
>  another way than you, you hiro can curse on public mailing lists, and I
>  can decide to stop discussing with people who swear and get personal.

This is not politics, it's the internet, boy. Though you could nee
some political understanding. I hope you will stay in the software
business only.

-- 
hiro



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Enno "Gottox" Boland
2008/5/21, Premysl Hruby <[EMAIL PROTECTED]>:
> tagmask can be #define:
>
>  #define TAGMASK ((int)(1LL << (LENGTH(tags) + 1) - 1))
Thanks! Here's the updated patch

-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
diff -r cd9fd0986555 config.def.h
--- a/config.def.h  Mon May 19 20:29:57 2008 +0100
+++ b/config.def.h  Wed May 21 11:23:38 2008 +0200
@@ -19,6 +19,7 @@
 Rule rules[] = {
/* class  instancetitle   tags ref  isfloating */
{ "Gimp", NULL,   NULL,   NULL, True },
+   { "Firefox",  NULL,   NULL,   1 << 8,   True },
 };
 
 /* layout(s) */
diff -r cd9fd0986555 dwm.c
--- a/dwm.c Mon May 19 20:29:57 2008 +0100
+++ b/dwm.c Wed May 21 11:23:38 2008 +0200
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -51,6 +52,7 @@
 #define LENGTH(x)   (sizeof x / sizeof x[0])
 #define MAXTAGLEN   16
 #define MOUSEMASK   (BUTTONMASK|PointerMotionMask)
+#define TAGMASK ((int)(1LL << (LENGTH(tags) + 1) - 1))
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };/* cursor */
@@ -68,7 +70,7 @@
long flags;
unsigned int bw, oldbw;
Bool isbanned, isfixed, isfloating, isurgent;
-   Bool *tags;
+   unsigned int tags;
Client *next;
Client *prev;
Client *snext;
@@ -107,7 +109,7 @@
const char *class;
const char *instance;
const char *title;
-   const char *tag;
+   unsigned int tags;
Bool isfloating;
 } Rule;
 
@@ -198,7 +200,7 @@
 int screen, sx, sy, sw, sh;
 int bx, by, bw, bh, blw, wx, wy, ww, wh;
 int mx, my, mw, mh, tx, ty, tw, th;
-int seltags = 0;
+unsigned int seltags = 0;
 int (*xerrorxlib)(Display *, XErrorEvent *);
 unsigned int numlockmask = 0;
 void (*handler[LASTEvent]) (XEvent *) = {
@@ -218,7 +220,7 @@
 Atom wmatom[WMLast], netatom[NetLast];
 Bool otherwm, readin;
 Bool running = True;
-Bool *tagset[2];
+unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
 Client *clients = NULL;
 Client *sel = NULL;
 Client *stack = NULL;
@@ -231,14 +233,12 @@
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
-#define TAGSZ (LENGTH(tags) * sizeof(Bool))
 
 /* function implementations */
 
 void
 applyrules(Client *c) {
unsigned int i;
-   Bool matched = False;
Rule *r;
XClassHint ch = { 0 };
 
@@ -250,18 +250,15 @@
&& (!r->class || (ch.res_class && strstr(ch.res_class, 
r->class)))
&& (!r->instance || (ch.res_name && strstr(ch.res_name, 
r->instance {
c->isfloating = r->isfloating;
-   if(r->tag) {
-   c->tags[idxoftag(r->tag)] = True;
-   matched = True;
-   }
+   c->tags |= r->tags & TAGMASK;
}
}
if(ch.res_class)
XFree(ch.res_class);
if(ch.res_name)
XFree(ch.res_name);
-   if(!matched)
-   memcpy(c->tags, tagset[seltags], TAGSZ);
+   if(!c->tags)
+   c->tags = tagset[seltags];
 }
 
 void
@@ -313,7 +310,7 @@
 
if(ev->window == barwin) {
x = 0;
-   for(i = 0; i < LENGTH(tags); i++) {
+   for(i = 0; i < LENGTH(tags) && i < sizeof(int) * CHAR_BIT; i++) 
{
x += textw(tags[i]);
if(ev->x < x) {
if(ev->button == Button1) {
@@ -499,15 +496,15 @@
 
dc.x = 0;
for(c = stack; c && !isvisible(c); c = c->snext);
-   for(i = 0; i < LENGTH(tags); i++) {
+   for(i = 0; i < LENGTH(tags) && i < sizeof(int) * CHAR_BIT; i++) {
dc.w = textw(tags[i]);
-   if(tagset[seltags][i]) {
+   if(tagset[seltags] & 1 << i) {
drawtext(tags[i], dc.sel, isurgent(i));
-   drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), 
dc.sel);
+   drawsquare(c && c->tags & 1 << i, isoccupied(i), 
isurgent(i), dc.sel);
}
else {
drawtext(tags[i], dc.norm, isurgent(i));
-   drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), 
dc.norm);
+   drawsquare(c && c->tags & 1 << i, isoccupied(i), 
isurgent(i), dc.norm);
}
dc.x += dc.w;
}
@@ -861,7 +858,7 @@
Client *c;
 
for(c = clients; c; c = c->next)
-   if(c->tags[t])
+   if(c->tags & 1 << t)
return True;
return False;
 }
@@ -886,19 +883,14 @@
Client *c;
 
for(c = clients; c; c = c->next)
-   if(c->isurgent && c->tags[t])
+   if(c->isurgen

Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Szabolcs Nagy
On 5/21/08, Enno Gottox Boland <[EMAIL PROTECTED]> wrote:
>>  the (1 << tagnum) in rules is a bit nasty
>>  it is probably nicer to do the shifting in setup();
> you mean in applyrules? - No I don't think so. It adds much more
> flexibility. You can define bitmasks as 0b10001 to tag a client to the
> first and the fifth tag or you can use ~0 to make it "sticky".

i see

(it would be so nice if c had 0bXXX binary int literals..)

>>  instead of
>>   i < LENGTH(tags) && i < sizeof(int) * 8;
>>  what about checking once
>>   if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
>>  eprint("Maximum number of tags: %d\n", sizeof(int) * CHAR_BIT);
>>  in setup();
> The problem about this is it denies users from using one config.h with
> many tags on different architectures. Furthermore I wouldn't check

i thought LENGTH(tags) > INT_BIT does not make sense, but in that case it's ok

probably limiting LENGTH(tags) to 16 is better (simpler, without too
much compromise (i doubt anyone uses more than 16 tags or X on an
architecture with less int bits))

> this at runtime but at compiletime. (maybe we can use "#warning" as
> compromise)

sizeof(type) is not expanded in the preprocessor so
 #if LENGTH(tags) > INT_BIT
 #error too many tags..
 #endif
doesn't work (so compiletime check with compiler warning/error is not
possible (imho))

> Anyway, the CHAR_BIT constant is a good idea.

it's a bit paranoid, but more conform ;)



Re: [dwm] Freedom (was: Re: sic ipv6 patch)

2008-05-21 Thread Matthias Kirschner
* hiro <[EMAIL PROTECTED]> [2008-05-20 19:13:11 -0400]:

> > yes
> >  lack of knowledge can mean lack of freedom (with my definition)
> 
> So you have you own definition? 
[...] 

That's our freedom (in your definition). Szabolcs and I can use terms in
another way than you, you hiro can curse on public mailing lists, and I
can decide to stop discussing with people who swear and get personal.



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Premysl Hruby
On (21/05/08 08:27), Enno Gottox Boland wrote:
> To: dynamic window manager 
> From: Enno Gottox Boland <[EMAIL PROTECTED]>
> Subject: Re: [dwm] using bitaray for tags (PATCH)
> Reply-To: dynamic window manager 
> List-Id: dynamic window manager 
> 
> Here's my version of a bitarray patch. Please review and comment.
> 

tagmask can be #define:

#define TAGMASK ((int)(1LL << (LENGTH(tags) + 1) - 1))

-Ph



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Enno "Gottox" Boland
Hi!

2008/5/21, Szabolcs Nagy <[EMAIL PROTECTED]>:
> in config.h referencing tags has changed in rules but not in keys.
Yes, arg has discussed yesterday if it's possible to change const char
*arg to void *arg. if this works, i'll change the key behavior too.
>  the (1 << tagnum) in rules is a bit nasty
>  it is probably nicer to do the shifting in setup();
you mean in applyrules? - No I don't think so. It adds much more
flexibility. You can define bitmasks as 0b10001 to tag a client to the
first and the fifth tag or you can use ~0 to make it "sticky".
>  instead of
>   i < LENGTH(tags) && i < sizeof(int) * 8;
>  what about checking once
>   if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
>  eprint("Maximum number of tags: %d\n", sizeof(int) * CHAR_BIT);
>  in setup();
The problem about this is it denies users from using one config.h with
many tags on different architectures. Furthermore I wouldn't check
this at runtime but at compiletime. (maybe we can use "#warning" as
compromise)
Anyway, the CHAR_BIT constant is a good idea.

Thanks!


-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)



Re: [dwm] Freedom (was: Re: sic ipv6 patch)

2008-05-21 Thread Sander van Dijk
On Tue, May 20, 2008 at 11:03 PM, Szabolcs Nagy <[EMAIL PROTECTED]> wrote:
> i deliberately used an alternative definition of freedom (and included
> all the dictatorship), because it makes sense to me.

Well, I guess that sums it all up nicely. I think that at this point
further argument is obviously useless, so I'm calling it quits.

Gr. Sander.



Re: [dwm] using bitaray for tags (PATCH)

2008-05-21 Thread Szabolcs Nagy
On 5/21/08, Enno Gottox Boland <[EMAIL PROTECTED]> wrote:
> Here's my version of a bitarray patch. Please review and comment.

in config.h referencing tags has changed in rules but not in keys.

the (1 << tagnum) in rules is a bit nasty
it is probably nicer to do the shifting in setup();

instead of
 i < LENGTH(tags) && i < sizeof(int) * 8;
what about checking once
 if(LENGTH(tags) > sizeof(int) * CHAR_BIT)
 eprint("Maximum number of tags: %d\n", sizeof(int) * CHAR_BIT);
in setup();