Felix Leckow <[EMAIL PROTECTED]> writes:

> On Sun, Dec 09, 2007 at 01:49:27AM +0100, Engin Tola wrote:
>>
>> comments are welcome.
>
> I've bound next_client and prev_client to Shift-j and Shift-k respectively,
> and I think this functionality integrates quite nicely with dwm. It saves a
> keystroke zooming in the last client in the stack. :)
> I think I've found a bug though:
>
> If I have three clients a,b, and c
>
> +----+---+
> |    | b |
> |    |   |
> | a  +---+
> |    | c |
> |    |   |
> +----+---+
>
> and then bring c to the master area by calling prev_client
>
> +----+---+
> |    | a |
> |    |   |
> | c  +---+
> |    | b |
> |    |   |
> +----+---+
>
> most of the time a and c both will have their border colored SELBORDERCOLOR.
>
> Regards,
>       Felix Leckow
>

sorry, i forgot to attach the fixed patch :)

Client *next_visible(Client *c);
Client *prev_visible(Client *c);
Client *last_client();
void attach_to_end(Client *c);
void next_client(const char *arg);
void prev_client(const char *arg);

void
attach_to_end(Client *c) {
   Client *last = last_client();
   if( last == NULL )
   {
      attach(c);
      return;
   }
   last->next = c;
   c->prev = last;
   c->next = NULL;
}

Client*
prev_visible(Client *c)
{
   Client* dum = c;
   while( dum &&  !isvisible(dum) )
      dum = dum->prev;
   return dum;
}

Client* 
next_visible(Client *c)
{
   Client *dum = c;
   while( dum && !isvisible(dum) )
      dum = dum->next;
   return dum;
}

void
next_client(const char *arg)
{
   Client *c = next_visible(clients);
   if( !c ) return;
   detach(c);
   attach_to_end(c);

   Client *nc = next_visible(clients);
   focus(nc);
   arrange();
}

void
prev_client(const char *arg)
{
   Client *c  = last_client();
   if(!c) return;
   while( !isvisible(c) )
      c = prev_visible(c);
   if(!c) return;

   detach(c);
   attach(c);
   focus(c);
   arrange();
}

Client* last_client() {
   Client* dum = clients;
   if( !dum ) return NULL;

   while( dum->next )
      dum=dum->next;
   return dum;
}

-- 
engin tola - http://cvlab.epfl.ch/~tola
emacs      - http://www.gnu.org/software/emacs/tour

Reply via email to