You are not logged in.

#1 2013-11-04 09:08:30

Gradient
Member
Registered: 2013-05-19
Posts: 101

Understanding dwm's C code

I am reading dwm.c and there is one thing that I cannot understand.

struct Monitor {
	...
	unsigned int seltags;
	unsigned int tagset[2];
	...
};

which means that I can access an element of the tagset array with tagset[0] or tagset[1], right? But everywhere in the code, it is accessed with something like:

m->tagset[m->seltags]

As I understand it, seltags is not restricted to 0 or 1. What am I not understanding?

By the way, what is the meaning of this tagset array?

Offline

#2 2013-11-04 09:51:12

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Understanding dwm's C code

The only values that seltags will ever take are 0 and 1. tagset is only used to save the last tagset so you could switch between current and last tagset with Alt-Tab.

Offline

#3 2013-11-04 10:12:46

Gradient
Member
Registered: 2013-05-19
Posts: 101

Re: Understanding dwm's C code

Ok. I got it. I was confused. Thank you.

I thought seltags was a bit array representing the tags themselves. It is actually just a 0 or a 1 and the bit arrays are in the tagset array.

Last edited by Gradient (2013-11-04 10:34:17)

Offline

#4 2013-11-04 10:37:09

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Understanding dwm's C code

tagset represents the tags that are selected. There are two tagsets, the currently selected tags and the previously selected tags, seltags just saves the array index of the selected tagset. Here is an example: If you start dwm you'll have the following values:

tagset[0] = 1; 
tagset[1] = 1; 
seltags = 0;

If you select tag 4 and 5 using Control-Shift-4 and Control-Shift-5 respectively you'll have the following values:

tagset[0] = 49
tagset[1] = 1; 
seltags = 0;

If you now select tag 2 using Alt-2 dwm will switch the tagset by setting seltags to 1 and update tagset[seltags], you'll get the following values:

tagset[0] = 49; 
tagset[1] = 2; 
seltags = 1; 

You can know switch between tagset[0] (tags 1, 4, 5) and tagset[1] (tag 2) with Alt-Tab.

Offline

#5 2013-11-04 10:43:59

Gradient
Member
Registered: 2013-05-19
Posts: 101

Re: Understanding dwm's C code

Thank you!

I figured it out and edited my previous post, but you had already seen it. Your explanation is much better.

Last edited by Gradient (2013-11-04 10:44:16)

Offline

Board footer

Powered by FluxBB