tags uicb function does not take arg name anymore, but tag index number

This commit is contained in:
Julien Danjou 2007-11-11 11:30:07 +01:00
parent 0f840d2eec
commit 8b048ec6fe
2 changed files with 17 additions and 31 deletions

View File

@ -144,6 +144,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
unsigned int udummy; unsigned int udummy;
Client *c; Client *c;
Window wdummy; Window wdummy;
char buf[256];
XButtonPressedEvent *ev = &e->xbutton; XButtonPressedEvent *ev = &e->xbutton;
for(screen = 0; screen < get_screen_count(e->xany.display); screen++) for(screen = 0; screen < get_screen_count(e->xany.display); screen++)
@ -154,12 +155,13 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
x += textwidth(e->xany.display, awesomeconf[screen].font, awesomeconf[screen].tags[i].name); x += textwidth(e->xany.display, awesomeconf[screen].font, awesomeconf[screen].tags[i].name);
if(ev->x < x) if(ev->x < x)
{ {
snprintf(buf, sizeof(buf), "%d", i + 1);
if(ev->button == Button1) if(ev->button == Button1)
{ {
if(ev->state & awesomeconf[screen].modkey) if(ev->state & awesomeconf[screen].modkey)
uicb_tag(&awesomeconf[screen], awesomeconf[screen].tags[i].name); uicb_tag(&awesomeconf[screen], buf);
else else
uicb_view(&awesomeconf[screen], awesomeconf[screen].tags[i].name); uicb_view(&awesomeconf[screen], buf);
} }
else if(ev->button == Button3) else if(ev->button == Button3)
{ {

38
tag.c
View File

@ -26,28 +26,6 @@
#include "tag.h" #include "tag.h"
#include "util.h" #include "util.h"
/** This function returns the index of
* the tag given un argument in *tags
* \param tag_to_find tag name
* \param tags tag list
* \param ntags number of tags in tag list
* \return index of tag
*/
static int
idxoftag(const char *tag_to_find, Tag *tags, int ntags)
{
int i;
if(!tag_to_find)
return 0;
for(i = 0; i < ntags; i++)
if(!a_strcmp(tags[i].name, tag_to_find))
return i;
return 0;
}
void void
applyrules(Client * c, awesome_config *awesomeconf) applyrules(Client * c, awesome_config *awesomeconf)
{ {
@ -152,11 +130,15 @@ uicb_tag(awesome_config *awesomeconf,
if(!sel) if(!sel)
return; return;
for(i = 0; i < awesomeconf->ntags; i++) for(i = 0; i < awesomeconf->ntags; i++)
sel->tags[i] = arg == NULL; sel->tags[i] = arg == NULL;
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags);
i = arg ? atoi(arg) - 1 : 0;
if(i >= 0 && i < awesomeconf->ntags) if(i >= 0 && i < awesomeconf->ntags)
sel->tags[i] = True; sel->tags[i] = True;
saveprops(sel, awesomeconf->ntags); saveprops(sel, awesomeconf->ntags);
arrange(awesomeconf); arrange(awesomeconf);
} }
@ -199,7 +181,7 @@ uicb_toggletag(awesome_config *awesomeconf,
if(!sel) if(!sel)
return; return;
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags); i = arg ? atoi(arg) - 1 : 0;
sel->tags[i] = !sel->tags[i]; sel->tags[i] = !sel->tags[i];
for(j = 0; j < awesomeconf->ntags && !sel->tags[j]; j++); for(j = 0; j < awesomeconf->ntags && !sel->tags[j]; j++);
if(j == awesomeconf->ntags) if(j == awesomeconf->ntags)
@ -219,7 +201,7 @@ uicb_toggleview(awesome_config *awesomeconf,
unsigned int i; unsigned int i;
int j; int j;
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags); i = arg ? atoi(arg) - 1: 0;
awesomeconf->tags[i].selected = !awesomeconf->tags[i].selected; awesomeconf->tags[i].selected = !awesomeconf->tags[i].selected;
for(j = 0; j < awesomeconf->ntags && !awesomeconf->tags[j].selected; j++); for(j = 0; j < awesomeconf->ntags && !awesomeconf->tags[j].selected; j++);
if(j == awesomeconf->ntags) if(j == awesomeconf->ntags)
@ -245,10 +227,12 @@ uicb_view(awesome_config *awesomeconf,
awesomeconf->tags[i].selected = arg == NULL; awesomeconf->tags[i].selected = arg == NULL;
} }
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags); if(arg)
{
i = atoi(arg) - 1;
if(i >= 0 && i < awesomeconf->ntags) if(i >= 0 && i < awesomeconf->ntags)
awesomeconf->tags[i].selected = True; awesomeconf->tags[i].selected = True;
}
saveawesomeprops(awesomeconf); saveawesomeprops(awesomeconf);
arrange(awesomeconf); arrange(awesomeconf);