From 3569ab617dfb45a096b548456255a01a9192bcba Mon Sep 17 00:00:00 2001 From: marco candrian Date: Sun, 17 Feb 2008 08:16:40 +0100 Subject: [PATCH] new property argument to widget _tell functions actually the _tell function won't handle the new argument. Coming patches will handle them. it will need now something like this: echo '0 widget_tell widget property value' where property can be anything used in the awesomerc file, that means what will be supported. Like: fg, fg_end, width, font... (actually it ignores the property value and changes what have been changed in the past as well.) --- structs.h | 2 +- widget.c | 18 ++++++++++++++---- widgets/graph.c | 4 ++-- widgets/iconbox.c | 5 ++++- widgets/progressbar.c | 4 ++-- widgets/textbox.c | 5 ++++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/structs.h b/structs.h index 7ce0e4a2f..f618ba01a 100644 --- a/structs.h +++ b/structs.h @@ -101,7 +101,7 @@ struct Widget /** Draw function */ int (*draw)(Widget *, DrawCtx *, int, int); /** Update function */ - void (*tell)(Widget *, char *); + void (*tell)(Widget *, char *, char *); /** ButtonPressedEvent handler */ void (*button_press)(Widget *, XButtonPressedEvent *); /** Statusbar */ diff --git a/widget.c b/widget.c index 508cc7d10..7b561d88a 100644 --- a/widget.c +++ b/widget.c @@ -130,7 +130,8 @@ widget_common_button_press(Widget *widget, XButtonPressedEvent *ev) * \param command unused argument */ static void -widget_common_tell(Widget *widget, char *command __attribute__ ((unused))) +widget_common_tell(Widget *widget, char *property __attribute__ ((unused)), + char *command __attribute__ ((unused))) { warn("%s widget does not accept commands.\n", widget->name); } @@ -182,7 +183,7 @@ void uicb_widget_tell(int screen, char *arg) { Widget *widget; - char *p, *command; + char *p, *property = NULL, *command; ssize_t len; if (!arg) @@ -206,17 +207,26 @@ uicb_widget_tell(int screen, char *arg) return; } + p = strtok(NULL, " "); + if(!p) + { + warn("Ignoring malformed widget command.\n"); + return; + } + + property = p; + if(p + a_strlen(p) < arg + len) { p = p + a_strlen(p) + 1; len = a_strlen(p); command = p_new(char, len + 1); a_strncpy(command, len + 1, p, len); - widget->tell(widget, command); + widget->tell(widget, property, command); p_delete(&command); } else - widget->tell(widget, NULL); + widget->tell(widget, property, NULL); widget->cache.needs_update = True; diff --git a/widgets/graph.c b/widgets/graph.c index 804471c82..5577a627b 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -170,14 +170,14 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset, } static void -graph_tell(Widget *widget, char *command) +graph_tell(Widget *widget, char *property, char *command) { Data *d = widget->data; int i, z; float *value; char *tok; - if(!command || d->width < 1 || !(d->data_items > 0)) + if(!property || !command || d->width < 1 || !(d->data_items > 0)) return; value = p_new(float, d->data_items); diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 7c999bad9..e9d6e6f90 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -64,10 +64,13 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, } static void -iconbox_tell(Widget *widget, char *command) +iconbox_tell(Widget *widget, char *property, char *command) { Data *d = widget->data; + if(!property || !command) + return; + if(d->image) p_delete(&d->image); d->image = a_strdup(command); diff --git a/widgets/progressbar.c b/widgets/progressbar.c index a2fbc6789..5f50ce738 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -118,13 +118,13 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, } static void -progressbar_tell(Widget *widget, char *command) +progressbar_tell(Widget *widget, char *property, char *command) { Data *d = widget->data; int i = 0, percent; char * tok; - if(!command || !d->bars) + if(!property || !command || !d->bars) return; for (tok = strtok(command, ","); tok && i < d->bars; tok = strtok(NULL, ","), i++) diff --git a/widgets/textbox.c b/widgets/textbox.c index 689a08810..f57f1e5e6 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -65,12 +65,15 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used) } static void -textbox_tell(Widget *widget, char *command) +textbox_tell(Widget *widget, char *property, char *command) { char *ntok, *tok; ssize_t command_len = a_strlen(command); int i = 0, phys_screen = get_phys_screen(widget->statusbar->screen); + if(!property || !command) + return; + Data *d = widget->data; if (d->text) p_delete(&d->text);