[widgets] Use statusbar name in widget_tell (FS#144)

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-03 14:00:46 +02:00
parent 68c14355af
commit 5f58d17d58
4 changed files with 31 additions and 37 deletions

View File

@ -28,9 +28,13 @@ collected lines into awesome with an according immediate execution.
The command format is: The command format is:
screen_number command argument screen_number command argument
For example, to change statusbar text on screen 0, you can do the following: For example, to change a statusbar textbox text on screen 0, you can do the following:
echo 0 widget_tell <widget-id> text Hello, world | awesome-client echo 0 widget_tell <statusbar-name> <textbox-name> text Hello, world | awesome-client
To change an iconbox image on screen 1, you can do the following:
echo 0 widget_tell <statusbar-name> <iconbox-name> image /home/user/image.jpg | awesome-client
To view tag number 3 on screen 1: To view tag number 3 on screen 1:

View File

@ -277,8 +277,8 @@ statusbar_refresh()
} }
} }
static Statusbar * Statusbar *
statusbar_get_byname(int screen, const char *name) statusbar_getbyname(int screen, const char *name)
{ {
Statusbar *sb; Statusbar *sb;
@ -308,7 +308,7 @@ statusbar_toggle(Statusbar *statusbar)
void void
uicb_statusbar_toggle(int screen, char *arg) uicb_statusbar_toggle(int screen, char *arg)
{ {
Statusbar *sb = statusbar_get_byname(screen, arg); Statusbar *sb = statusbar_getbyname(screen, arg);
if(sb) if(sb)
statusbar_toggle(sb); statusbar_toggle(sb);

View File

@ -28,6 +28,7 @@ void statusbar_refresh(void);
void statusbar_preinit(Statusbar *); void statusbar_preinit(Statusbar *);
void statusbar_init(Statusbar *); void statusbar_init(Statusbar *);
void statusbar_display(Statusbar *); void statusbar_display(Statusbar *);
Statusbar * statusbar_getbyname(int, const char *);
Uicb uicb_statusbar_toggle; Uicb uicb_statusbar_toggle;

View File

@ -88,20 +88,18 @@ widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment
} }
/** Find a widget on a screen by its name /** Find a widget on a screen by its name
* \param statusbar the statusbar to look into
* \param name the widget name * \param name the widget name
* \param screen the screen to look into
* \return a widget * \return a widget
*/ */
static Widget * static Widget *
widget_find(char *name, int screen) widget_getbyname(Statusbar *sb, char *name)
{ {
Widget *widget; Widget *widget;
Statusbar *sb;
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next) for(widget = sb->widgets; widget; widget = widget->next)
for(widget = sb->widgets; widget; widget = widget->next) if(!a_strcmp(name, widget->name))
if(a_strcmp(name, widget->name) == 0) return widget;
return widget;
return NULL; return NULL;
} }
@ -184,41 +182,32 @@ widget_invalidate_cache(int screen, int flags)
void void
uicb_widget_tell(int screen, char *arg) uicb_widget_tell(int screen, char *arg)
{ {
Statusbar *statusbar;
Widget *widget; Widget *widget;
char *p, *property = NULL, *command; char *p, *property = NULL, *command;
ssize_t len; ssize_t len;
widget_tell_status_t status; widget_tell_status_t status;
if (!arg) if(!(len = a_strlen(arg)))
{ return warn("must specify a statusbar and a widget.\n");
warn("Must specify a widget.\n");
return;
}
len = a_strlen(arg); if(!(p = strtok(arg, " ")))
p = strtok(arg, " "); return warn("ignoring malformed widget command (missing statusbar name).\n");
if(!p)
{
warn("Ignoring malformed widget command.\n");
return;
}
widget = widget_find(p, screen); if(!(statusbar = statusbar_getbyname(screen, p)))
if(!widget) return warn("no such statusbar: %s\n", p);
{
warn("No such widget: %s\n", p);
return;
}
p = strtok(NULL, " "); if(!(p = strtok(NULL, " ")))
if(!p) return warn("ignoring malformed widget command (missing widget name).\n");
{
warn("Ignoring malformed widget command.\n"); if(!(widget = widget_getbyname(statusbar, p)))
return; return warn("no such widget: %s in statusbar %s.\n", p, statusbar->name);
}
if(!(p = strtok(NULL, " ")))
return warn("ignoring malformed widget command (missing property name).\n");
property = p; property = p;
p = p + a_strlen(p) + 1; /* could be out of 'arg' now */ p += a_strlen(property) + 1; /* could be out of 'arg' now */
/* arg + len points to the finishing \0. /* arg + len points to the finishing \0.
* p to the char right of the first space (strtok delimiter) * p to the char right of the first space (strtok delimiter)