Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-27 Thread Premysl Hruby
On (27/04/08 20:33), yy wrote:
> To: dynamic window manager 
> From: yy <[EMAIL PROTECTED]>
> Subject: Re: [dwm] Yet another simplification, this time sel/prevtags
> Reply-To: dynamic window manager 
> List-Id: dynamic window manager 
> 
> After the last change in hg tip, viewprev is the only way to view the
> previous tags, the change when trying to view the currently selected
> tag is not working any more, if you remove viewprev you can then
> remove all the tagset stuff. Another thing, now if you press twice in
> a tag to view it you will lose your previous tags, I don't think
> that's the expected behavior.
> 

No, you will not lost anything :) I thought that too (and write it here,
too), but try it. It somewhat not so easilly imaginable code.

-Ph

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



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-27 Thread yy
2008/4/27 Anselm R. Garbe <[EMAIL PROTECTED]>:
> On Sun, Apr 27, 2008 at 07:41:08PM +0200, Anselm R. Garbe wrote:
>  > On Sun, Apr 20, 2008 at 10:24:32PM +0200, Premysl Hruby wrote:
>  > > void
>  > > view(const char *arg) {
>  > > seltags ^= 1;
>  > > memset(tagset[seltag], (NULL == arg), TAGSZ);
>  > > tagset[seltag][idxoftag(arg)] = True;
>  > > arrange();
>  > > }
>  >
>  > I simplified view() accordingly.
>
>  With the current change in mind, do we still need viewprev()?
>
>  Kind regards,
>
>
> --
>   Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>
>

After the last change in hg tip, viewprev is the only way to view the
previous tags, the change when trying to view the currently selected
tag is not working any more, if you remove viewprev you can then
remove all the tagset stuff. Another thing, now if you press twice in
a tag to view it you will lose your previous tags, I don't think
that's the expected behavior.



-- 


- yiyus || JGL .



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-27 Thread Premysl Hruby
On (27/04/08 19:58), Anselm R. Garbe wrote:
> With the current change in mind, do we still need viewprev()?

Short answer: yes, we do :)
Long answer: yes, we do because: - you are not able to see previous
tagset if you have currently selected more than one tag

- for switching to previous tagset you doesn't need to know what
  is/are current tag, you simply press key for viewprev, and it's
  simply "done" :)

-Ph

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



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-27 Thread Anselm R. Garbe
On Sun, Apr 27, 2008 at 07:41:08PM +0200, Anselm R. Garbe wrote:
> On Sun, Apr 20, 2008 at 10:24:32PM +0200, Premysl Hruby wrote:
> > void
> > view(const char *arg) {
> > seltags ^= 1;
> > memset(tagset[seltag], (NULL == arg), TAGSZ);
> > tagset[seltag][idxoftag(arg)] = True;
> > arrange();
> > }
> 
> I simplified view() accordingly.

With the current change in mind, do we still need viewprev()?

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



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-27 Thread Anselm R. Garbe
On Sun, Apr 20, 2008 at 10:24:32PM +0200, Premysl Hruby wrote:
> void
> view(const char *arg) {
>   seltags ^= 1;
>   memset(tagset[seltag], (NULL == arg), TAGSZ);
> tagset[seltag][idxoftag(arg)] = True;
> arrange();
> }

I simplified view() accordingly.

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



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-27 Thread Anselm R. Garbe
On Sun, Apr 20, 2008 at 09:49:37PM +0200, yy wrote:
> I like this change, good work Premysl! But once you are using the
> array, you don't need seltags any more. The attached patch saves 2 or
> 3 loc. It also includes the functionality of my patch to see prevtags,
> but if you do the XOR inside memcpy you can save another line of code.
> I have also changed a little your notation (because I don't like
> underscores in variable names), but maybe you can think of better
> names.
> I think I will like dwm 5.0...

Applied tagset patch
> 
> 
> -- 
> 
> 
> - yiyus || JGL .



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



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-20 Thread yy
2008/4/20, Premysl Hruby <[EMAIL PROTECTED]>:
> On (20/04/08 21:49), yy wrote:
>  > To: dynamic window manager 
>  > From: yy <[EMAIL PROTECTED]>
>  > Subject: Re: [dwm] Yet another simplification, this time sel/prevtags
>  > Reply-To: dynamic window manager 
>  > List-Id: dynamic window manager 
>
> >
>  > I like this change, good work Premysl! But once you are using the
>  > array, you don't need seltags any more. The attached patch saves 2 or
>  > 3 loc. It also includes the functionality of my patch to see prevtags,
>  > but if you do the XOR inside memcpy you can save another line of code.
>  > I have also changed a little your notation (because I don't like
>  > underscores in variable names), but maybe you can think of better
>  > names.
>  > I think I will like dwm 5.0...
>  >
>  >
>
>
>
> Hi
>
>  -   if(memcmp(seltags, tmp, TAGSZ) != 0) {
>  -   seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
>  -   memcpy(seltags, tmp, TAGSZ);
>  -   arrange();
>  -   }
>  +   seltags ^= 1;  /* toggle sel tagset */
>  +   if(memcmp(tagset[seltags ^ 1], tmp, TAGSZ) != 0)
>  +   memcpy(tagset[seltags], tmp, TAGSZ);
>  +   arrange();
>
>  This doesn't do same thing, as seltags is always toggled, even if
>  current and new tagset are same. So this will broke that "change only if
>  differ" behaviour or I miss something? :)
>
>  If we will throw away this behaviour, things can be even more simpler.
>  We then can substitute whole view with:
>
>  void
>  view(const char *arg) {
> seltags ^= 1;
> memset(tagset[seltag], (NULL == arg), TAGSZ);
> tagset[seltag][idxoftag(arg)] = True;
> arrange();
>  }
>
>  (memset can be used, because tags are always only test if they are zero
>  or nonzero, so it doesn't matter that tagset[i][j] (because Bool is defined
>  as int) can be something like 0x01010101 on x86)
>
>  -Ph
>

The idea is to have the same behavior that with my patch from April
7th. I like to view the previous tags when there is no difference.
This way you can temporally see one tag (or all of them) in a
convenient way. To sum up, the behavior would be: "change if differ,
else viewprevtag" Try it, please. This feature has become a must-have
for me. If this is not desired you could do memcpy(tagset[seltags ^=
1], tmp, TAGSZ) and remove the seltags ^= 1; line. I tried to explain
it in my previous message, I hope it is clearer now.


-- 


- yiyus || JGL .



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-20 Thread Premysl Hruby
On (20/04/08 21:49), yy wrote:
> To: dynamic window manager 
> From: yy <[EMAIL PROTECTED]>
> Subject: Re: [dwm] Yet another simplification, this time sel/prevtags
> Reply-To: dynamic window manager 
> List-Id: dynamic window manager 
> 
> I like this change, good work Premysl! But once you are using the
> array, you don't need seltags any more. The attached patch saves 2 or
> 3 loc. It also includes the functionality of my patch to see prevtags,
> but if you do the XOR inside memcpy you can save another line of code.
> I have also changed a little your notation (because I don't like
> underscores in variable names), but maybe you can think of better
> names.
> I think I will like dwm 5.0...
> 
> 


Hi

-   if(memcmp(seltags, tmp, TAGSZ) != 0) {
-   seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
-   memcpy(seltags, tmp, TAGSZ);
-   arrange();
-   }
+   seltags ^= 1;  /* toggle sel tagset */
+   if(memcmp(tagset[seltags ^ 1], tmp, TAGSZ) != 0)
+   memcpy(tagset[seltags], tmp, TAGSZ);
+   arrange();

This doesn't do same thing, as seltags is always toggled, even if
current and new tagset are same. So this will broke that "change only if
differ" behaviour or I miss something? :)

If we will throw away this behaviour, things can be even more simpler.
We then can substitute whole view with:

void
view(const char *arg) {
seltags ^= 1;
memset(tagset[seltag], (NULL == arg), TAGSZ);
tagset[seltag][idxoftag(arg)] = True;
arrange();
}

(memset can be used, because tags are always only test if they are zero
or nonzero, so it doesn't matter that tagset[i][j] (because Bool is defined 
as int) can be something like 0x01010101 on x86)

-Ph

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



Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-20 Thread yy
2008/4/20, Anselm R. Garbe <[EMAIL PROTECTED]>:
> On Sun, Apr 20, 2008 at 06:05:50PM +0200, Premysl Hruby wrote:
>  > attached patch makes one array for both sel and prevtags. So there is
>  > no need to swap them in memory in view() as we only change seltags
>  > pointer to point viewtags[0] or viewtags[1].
>  >
>  > It also with little change can support arbitrary number of saved tags
>  > set (3 save position can be usable, with modkey-shift-tab going on
>  > "next" state in queue).
>
>
> I like this solution and applied it with a slightly changed
>  order of variable declarations. I intend to declare the variables
>  in groups of same types.
>
>  Kind regards,
>
> --
>   Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>
>

I like this change, good work Premysl! But once you are using the
array, you don't need seltags any more. The attached patch saves 2 or
3 loc. It also includes the functionality of my patch to see prevtags,
but if you do the XOR inside memcpy you can save another line of code.
I have also changed a little your notation (because I don't like
underscores in variable names), but maybe you can think of better
names.
I think I will like dwm 5.0...


-- 


- yiyus || JGL .


tagset.diff
Description: Binary data


Re: [dwm] Yet another simplification, this time sel/prevtags

2008-04-20 Thread Anselm R. Garbe
On Sun, Apr 20, 2008 at 06:05:50PM +0200, Premysl Hruby wrote:
> attached patch makes one array for both sel and prevtags. So there is
> no need to swap them in memory in view() as we only change seltags
> pointer to point viewtags[0] or viewtags[1].
> 
> It also with little change can support arbitrary number of saved tags
> set (3 save position can be usable, with modkey-shift-tab going on
> "next" state in queue).

I like this solution and applied it with a slightly changed
order of variable declarations. I intend to declare the variables
in groups of same types.

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



[dwm] Yet another simplification, this time sel/prevtags

2008-04-20 Thread Premysl Hruby
Hi,

attached patch makes one array for both sel and prevtags. So there is
no need to swap them in memory in view() as we only change seltags
pointer to point viewtags[0] or viewtags[1].

It also with little change can support arbitrary number of saved tags
set (3 save position can be usable, with modkey-shift-tab going on
"next" state in queue).

-Ph
diff -r 595ed1a4447c dwm.c
--- a/dwm.c	Tue Apr 08 11:49:35 2008 +0100
+++ b/dwm.c	Sun Apr 20 17:44:51 2008 +0200
@@ -231,11 +231,12 @@ Atom wmatom[WMLast], netatom[NetLast];
 Atom wmatom[WMLast], netatom[NetLast];
 Bool otherwm, readin;
 Bool running = True;
-Bool *prevtags;
-Bool *seltags;
 Client *clients = NULL;
 Client *sel = NULL;
+Bool *seltags;
 Client *stack = NULL;
+Bool *viewtags[2];
+int viewtags_set = 0;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
@@ -246,7 +247,6 @@ Window root, barwin;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 #define TAGSZ (LENGTH(tags) * sizeof(Bool))
-static Bool tmp[LENGTH(tags)];
 
 /* function implementations */
 
@@ -1162,11 +1162,10 @@ quit(const char *arg) {
 
 void
 reapply(const char *arg) {
-	static Bool zerotags[LENGTH(tags)] = { 0 };
 	Client *c;
 
 	for(c = clients; c; c = c->next) {
-		memcpy(c->tags, zerotags, sizeof zerotags);
+		memset(c->tags, 0, TAGSZ);
 		applyrules(c);
 	}
 	arrange();
@@ -1515,9 +1514,10 @@ setup(void) {
 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 
 	/* init tags */
-	seltags = emallocz(TAGSZ);
-	prevtags = emallocz(TAGSZ);
-	seltags[0] = prevtags[0] = True;
+	viewtags[0] = emallocz(TAGSZ);
+	viewtags[1] = emallocz(TAGSZ);
+	viewtags[0][0] = viewtags[1][0] = True;
+	seltags = viewtags[0];
 
 	/* init layouts */
 	lt = &layouts[0];
@@ -1842,9 +1842,9 @@ updatewmhints(Client *c) {
 	}
 }
 
-
 void
 view(const char *arg) {
+	Bool tmp[LENGTH(tags)];
 	unsigned int i;
 
 	for(i = 0; i < LENGTH(tags); i++)
@@ -1852,7 +1852,7 @@ view(const char *arg) {
 	tmp[idxoftag(arg)] = True;
 
 	if(memcmp(seltags, tmp, TAGSZ) != 0) {
-		memcpy(prevtags, seltags, TAGSZ);
+		seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
 		memcpy(seltags, tmp, TAGSZ);
 		arrange();
 	}
@@ -1860,10 +1860,8 @@ view(const char *arg) {
 
 void
 viewprevtag(const char *arg) {
+	seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
 
-	memcpy(tmp, seltags, TAGSZ);
-	memcpy(seltags, prevtags, TAGSZ);
-	memcpy(prevtags, tmp, TAGSZ);
 	arrange();
 }