Client: Add client_get_{next, prev} to simplify some functions.

This commit is contained in:
Martin Duquesnoy 2009-07-22 20:56:53 +02:00
parent 8251de7096
commit ec2ccea884
4 changed files with 56 additions and 55 deletions

View File

@ -84,16 +84,34 @@ client_detach(Client *c)
return;
}
/** Switch to the previous client
* \param cmd uicb_t type unused
*/
void
uicb_client_prev(uicb_t cmd)
/** Get the next client
*\return The next client or NULL
*/
Client*
client_get_next(void)
{
Client *c = NULL;
if(!sel || ishide(sel, selscreen))
return NULL;
for(c = sel->next; c && ishide(c, selscreen); c = c->next);
if(!c)
for(c = clients; c && ishide(c, selscreen); c = c->next);
return c;
}
/** Get the previous client
*\return The previous client or NULL
*/
Client*
client_get_prev(void)
{
Client *c = NULL, *d;
if(!sel || ishide(sel, selscreen))
return;
return NULL;
for(d = clients; d != sel; d = d->next)
if(!ishide(d, selscreen))
@ -103,7 +121,19 @@ uicb_client_prev(uicb_t cmd)
for(; d; d = d->next)
if(!ishide(d, selscreen))
c = d;
if(c)
return c;
}
/** Switch to the previous client
* \param cmd uicb_t type unused
*/
void
uicb_client_prev(uicb_t cmd)
{
Client *c;
if((c = client_get_prev()))
{
client_focus(c);
client_raise(c);
@ -118,15 +148,9 @@ uicb_client_prev(uicb_t cmd)
void
uicb_client_next(uicb_t cmd)
{
Client *c = NULL;
Client *c;
if(!sel || ishide(sel, selscreen))
return;
for(c = sel->next; c && ishide(c, selscreen); c = c->next);
if(!c)
for(c = clients; c && ishide(c, selscreen); c = c->next);
if(c)
if((c = client_get_next()))
{
client_focus(c);
client_raise(c);
@ -141,17 +165,9 @@ uicb_client_next(uicb_t cmd)
void
uicb_client_swap_next(uicb_t cmd)
{
Client *c = NULL;
Client *c;
if(!sel || !sel->tile)
return;
/* Find the next client */
for(c = sel->next; c && ishide(c, selscreen); c = c->next);
if(!c)
for(c = clients; c && ishide(c, selscreen); c = c->next);
if(c)
if((c = client_get_next()))
{
client_swap(sel, c);
client_focus(c);
@ -166,22 +182,9 @@ uicb_client_swap_next(uicb_t cmd)
void
uicb_client_swap_prev(uicb_t cmd)
{
Client *c = NULL, *d;
Client *c;
if(!sel || !sel->tile)
return;
/* Find the previous client */
for(d = clients; d != sel; d = d->next)
if(!ishide(d, selscreen))
c = d;
if(!c)
for(; d; d = d->next)
if(!ishide(d, selscreen))
c = d;
if(c)
if((c = client_get_prev()))
{
client_swap(sel, c);
client_focus(c);

View File

@ -43,8 +43,16 @@ buttonpress(XButtonEvent *ev)
screen_get_sel();
/* If the mouse is on a not selected client and you click on it. */
if(((c = client_gb_win(ev->window)) || (c = client_gb_titlebar(ev->window))) && c != sel
&& (ev->button == Button1 || ev->button == Button2 || ev->button == Button3))
{
client_focus(c);
client_raise(c);
}
/* Titlebar */
if((c = client_gb_titlebar(ev->window)))
if((c = client_gb_titlebar(ev->window)) && c == sel)
for(i = 0; i < conf.titlebar.nmouse; ++i)
if(ev->button == conf.titlebar.mouse[i].button)
if(conf.titlebar.mouse[i].func)
@ -67,18 +75,6 @@ buttonpress(XButtonEvent *ev)
if(ev->button == conf.client.mouse[i].button)
if(conf.client.mouse[i].func)
conf.client.mouse[i].func(conf.client.mouse[i].cmd);
/* If the mouse is on a client that is not selected
and you click on it. */
if((c = client_gb_win(ev->window)) && c != sel
&& (ev->button == Button1
|| ev->button == Button2
|| ev->button == Button3))
{
client_focus(c);
client_raise(c);
}
/* Root */
if(ev->window == ROOT)
for(i = 0; i < conf.root.nmouse; ++i)

View File

@ -151,9 +151,9 @@ maxlayout(int screen)
c->lmax = True;
client_maximize(c);
/* Focus the first client */
/* Focus the first client
if(!i)
client_focus(c);
client_focus(c); */
}
ewmh_update_current_tag_prop();

View File

@ -139,6 +139,8 @@ void client_attach(Client *c);
void client_configure(Client *c);
void client_detach(Client *c);
void client_focus(Client *c);
Client* client_get_next(void);
Client* client_get_prev(void);
/* client_gb_*() {{{ */
Client* client_gb_win(Window w);
Client* client_gb_frame(Window w);