From 5f58d17d587fe7f319f9c1b7c467ba2763fcbcf3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 3 Apr 2008 14:00:46 +0200 Subject: [PATCH] [widgets] Use statusbar name in widget_tell (FS#144) Signed-off-by: Julien Danjou --- awesome-client.1.txt | 8 +++++-- statusbar.c | 6 ++--- statusbar.h | 1 + widget.c | 53 ++++++++++++++++++-------------------------- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/awesome-client.1.txt b/awesome-client.1.txt index c5bc95f32..5c73ce025 100644 --- a/awesome-client.1.txt +++ b/awesome-client.1.txt @@ -28,9 +28,13 @@ collected lines into awesome with an according immediate execution. The command format is: 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 text Hello, world | awesome-client + echo 0 widget_tell text Hello, world | awesome-client + +To change an iconbox image on screen 1, you can do the following: + + echo 0 widget_tell image /home/user/image.jpg | awesome-client To view tag number 3 on screen 1: diff --git a/statusbar.c b/statusbar.c index afd296035..4ac845631 100644 --- a/statusbar.c +++ b/statusbar.c @@ -277,8 +277,8 @@ statusbar_refresh() } } -static Statusbar * -statusbar_get_byname(int screen, const char *name) +Statusbar * +statusbar_getbyname(int screen, const char *name) { Statusbar *sb; @@ -308,7 +308,7 @@ statusbar_toggle(Statusbar *statusbar) void uicb_statusbar_toggle(int screen, char *arg) { - Statusbar *sb = statusbar_get_byname(screen, arg); + Statusbar *sb = statusbar_getbyname(screen, arg); if(sb) statusbar_toggle(sb); diff --git a/statusbar.h b/statusbar.h index fdca26185..c091fb7f2 100644 --- a/statusbar.h +++ b/statusbar.h @@ -28,6 +28,7 @@ void statusbar_refresh(void); void statusbar_preinit(Statusbar *); void statusbar_init(Statusbar *); void statusbar_display(Statusbar *); +Statusbar * statusbar_getbyname(int, const char *); Uicb uicb_statusbar_toggle; diff --git a/widget.c b/widget.c index 72f7586cf..e1dc579d5 100644 --- a/widget.c +++ b/widget.c @@ -88,20 +88,18 @@ widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment } /** Find a widget on a screen by its name + * \param statusbar the statusbar to look into * \param name the widget name - * \param screen the screen to look into * \return a widget */ static Widget * -widget_find(char *name, int screen) +widget_getbyname(Statusbar *sb, char *name) { Widget *widget; - Statusbar *sb; - for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next) - for(widget = sb->widgets; widget; widget = widget->next) - if(a_strcmp(name, widget->name) == 0) - return widget; + for(widget = sb->widgets; widget; widget = widget->next) + if(!a_strcmp(name, widget->name)) + return widget; return NULL; } @@ -184,41 +182,32 @@ widget_invalidate_cache(int screen, int flags) void uicb_widget_tell(int screen, char *arg) { + Statusbar *statusbar; Widget *widget; char *p, *property = NULL, *command; ssize_t len; widget_tell_status_t status; - if (!arg) - { - warn("Must specify a widget.\n"); - return; - } + if(!(len = a_strlen(arg))) + return warn("must specify a statusbar and a widget.\n"); - len = a_strlen(arg); - p = strtok(arg, " "); - if(!p) - { - warn("Ignoring malformed widget command.\n"); - return; - } + if(!(p = strtok(arg, " "))) + return warn("ignoring malformed widget command (missing statusbar name).\n"); - widget = widget_find(p, screen); - if(!widget) - { - warn("No such widget: %s\n", p); - return; - } + if(!(statusbar = statusbar_getbyname(screen, p))) + return warn("no such statusbar: %s\n", p); - p = strtok(NULL, " "); - if(!p) - { - warn("Ignoring malformed widget command.\n"); - return; - } + if(!(p = strtok(NULL, " "))) + return warn("ignoring malformed widget command (missing widget name).\n"); + + if(!(widget = widget_getbyname(statusbar, p))) + 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; - 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. * p to the char right of the first space (strtok delimiter)