[client] Merge focus{prev,next} and swap{prev,next}

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-30 20:13:49 +02:00
parent deadca321c
commit d5859c60f7
3 changed files with 49 additions and 65 deletions

View File

@ -115,24 +115,28 @@ screen 0
mouse mouse
{ {
button = "4" button = "4"
command = "client_focusnext" command = "client_focus"
arg = "+1"
} }
mouse mouse
{ {
button = "5" button = "5"
command = "client_focusprev" command = "client_focus"
arg = "-1"
} }
mouse mouse
{ {
modkey = {"Mod4"} modkey = {"Mod4"}
button = "4" button = "4"
command = "client_swapnext" command = "client_swap"
arg = "+1"
} }
mouse mouse
{ {
modkey = {"Mod4"} modkey = {"Mod4"}
button = "5" button = "5"
command = "client_swapprev" command = "client_swap"
arg = "-1"
} }
} }
iconbox logo iconbox logo
@ -258,13 +262,15 @@ keys
{ {
modkey = {"Mod4"} modkey = {"Mod4"}
key = "j" key = "j"
command = "client_focusnext" command = "client_focus"
arg = "+1"
} }
key key
{ {
modkey = {"Mod4"} modkey = {"Mod4"}
key = "k" key = "k"
command = "client_focusprev" command = "client_focus"
arg = "-1"
} }
key key
{ {
@ -277,13 +283,15 @@ keys
{ {
modkey = {"Mod4", "Shift"} modkey = {"Mod4", "Shift"}
key = "j" key = "j"
command = "client_swapnext" command = "client_swap"
arg = "+1"
} }
key key
{ {
modkey = {"Mod4", "Shift"} modkey = {"Mod4", "Shift"}
key = "k" key = "k"
command = "client_swapprev" command = "client_swap"
arg = "-1"
} }
key key
{ {

View File

@ -195,7 +195,7 @@ client_updatetitle(client_t *c)
xutil_intern_atom(globalconf.connection, "WM_NAME"), xutil_intern_atom(globalconf.connection, "WM_NAME"),
&name)) &name))
return; return;
p_delete(&c->name); p_delete(&c->name);
c->name = name; c->name = name;
titlebar_draw(c); titlebar_draw(c);
@ -910,58 +910,49 @@ uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
* \return next or previous client * \return next or previous client
*/ */
static client_t * static client_t *
client_find_visible(client_t *sel, bool reverse) client_find_visible(client_t *sel, int nindex)
{ {
int i = 0;
client_t *next; client_t *next;
client_t *(*client_iter)(client_t **, client_t *) = client_list_next_cycle; client_t *(*client_iter)(client_t **, client_t *) = client_list_next_cycle;
if(!sel) return NULL; if(!sel || nindex == 0)
return NULL;
if(reverse) else if(nindex < 0)
client_iter = client_list_prev_cycle; client_iter = client_list_prev_cycle;
nindex = abs(nindex);
/* look for previous or next starting at sel */ /* look for previous or next starting at sel */
for(next = client_iter(&globalconf.clients, sel); for(next = client_iter(&globalconf.clients, sel);
next && next != sel && (next->skip || !client_isvisible(next, sel->screen)); next && next != sel;
next = client_iter(&globalconf.clients, next)); next = client_iter(&globalconf.clients, next))
return next;
}
/** Swap the currently focused client with the previous visible one.
* \param screen Screen ID
* \param arg nothing
* \ingroup ui_callback
*/
void
uicb_client_swapprev(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
{
client_t *prev;
if((prev = client_find_visible(globalconf.focus->client, true)))
{ {
client_list_swap(&globalconf.clients, prev, globalconf.focus->client); if(!next->skip && client_isvisible(next, sel->screen))
globalconf.screens[prev->screen].need_arrange = true; i++;
widget_invalidate_cache(prev->screen, WIDGET_CACHE_CLIENTS); if(i >= nindex)
return next;
} }
return NULL;
} }
/** Swap the currently focused client with the next visible one. /** Swap the currently focused client with another one.
* \param screen Screen ID * \param screen Virtual screen number.
* \param arg nothing * \param arg Relative number in the client stack.
* \ingroup ui_callback * \ingroup ui_callback
*/ */
void void
uicb_client_swapnext(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused))) uicb_client_swap(int screen, char *arg)
{ {
client_t *next; client_t *next;
int i = atoi(arg);
if((next = client_find_visible(globalconf.focus->client, false))) if((next = client_find_visible(globalconf.focus->client, i)))
{ {
client_list_swap(&globalconf.clients, globalconf.focus->client, next); client_list_swap(&globalconf.clients, next, globalconf.focus->client);
globalconf.screens[next->screen].need_arrange = true; globalconf.screens[screen].need_arrange = true;
widget_invalidate_cache(next->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
} }
} }
@ -1200,34 +1191,21 @@ uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
} }
} }
/** Give focus to the next visible client in the stack. /** Give focus to the next or previous visible client in the stack.
* \param screen Screen ID * \param screen Virtual screen number.
* \param arg Unused * \param arg Relative number in the client stack.
* \ingroup ui_callback * \ingroup ui_callback
*/ */
void void
uicb_client_focusnext(int screen, char *arg __attribute__ ((unused))) uicb_client_focus(int screen, char *arg)
{ {
client_t *next; client_t *next;
int i = atoi(arg);
if((next = client_find_visible(globalconf.focus->client, false))) if((next = client_find_visible(globalconf.focus->client, i)))
client_focus(next, screen, true); client_focus(next, screen, true);
} }
/** Give focus to the previous visible client in the stack.
* \param screen Screen ID
* \param arg Unused
* \ingroup ui_callback
*/
void
uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
{
client_t *prev;
if((prev = client_find_visible(globalconf.focus->client, true)))
client_focus(prev, screen, true);
}
/** Toggle the floating state of the focused client. /** Toggle the floating state of the focused client.
* \param screen Screen ID * \param screen Screen ID
* \param arg unused * \param arg unused

View File

@ -48,14 +48,12 @@ style_t * client_style_get(client_t *);
uicb_t uicb_client_kill; uicb_t uicb_client_kill;
uicb_t uicb_client_moveresize; uicb_t uicb_client_moveresize;
uicb_t uicb_client_settrans; uicb_t uicb_client_settrans;
uicb_t uicb_client_swapnext; uicb_t uicb_client_swap;
uicb_t uicb_client_swapprev;
uicb_t uicb_client_togglemax; uicb_t uicb_client_togglemax;
uicb_t uicb_client_toggleverticalmax; uicb_t uicb_client_toggleverticalmax;
uicb_t uicb_client_togglehorizontalmax; uicb_t uicb_client_togglehorizontalmax;
uicb_t uicb_client_zoom; uicb_t uicb_client_zoom;
uicb_t uicb_client_focusnext; uicb_t uicb_client_focus;
uicb_t uicb_client_focusprev;
uicb_t uicb_client_togglefloating; uicb_t uicb_client_togglefloating;
uicb_t uicb_client_togglescratch; uicb_t uicb_client_togglescratch;
uicb_t uicb_client_setscratch; uicb_t uicb_client_setscratch;