From 4742463cec27338888fedfd1a71c7827278d084d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 20 May 2008 20:13:44 +0200 Subject: [PATCH] [dbus] Fix widget.set() API call Signed-off-by: Julien Danjou --- dbus.c | 27 +++++++++------------------ widget.c | 13 ++++++++----- widget.h | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/dbus.c b/dbus.c index 88f259e5b..7b8a62d86 100644 --- a/dbus.c +++ b/dbus.c @@ -54,19 +54,16 @@ static void a_dbus_process_widget_set(DBusMessage *req) { char *arg, **path; - int i, screen; + int i; DBusMessageIter iter; - statusbar_t *statusbar; widget_t *widget; if(!dbus_message_get_path_decomposed(req, &path) - || !a_dbus_path_check(path, 10) - || a_strcmp(path[2], "screen") - || a_strcmp(path[4], "statusbar") - || a_strcmp(path[6], "widget") - || a_strcmp(path[8], "property")) + || !a_dbus_path_check(path, 6) + || a_strcmp(path[2], "widget") + || a_strcmp(path[4], "property")) { - warn("invalid object path 2\n"); + warn("invalid object path.\n"); dbus_error_free(&err); return; } @@ -86,16 +83,10 @@ a_dbus_process_widget_set(DBusMessage *req) else dbus_message_iter_get_basic(&iter, &arg); - if((screen = atoi(path[3])) >= globalconf.screens_info->nscreen) - return warn("bad screen number\n"); + if(!(widget = widget_getbyname(path[3]))) + return warn("no such widget: %s.\n", path[3]); - if(!(statusbar = statusbar_getbyname(screen, path[5]))) - return warn("no such statusbar: %s\n", path[5]); - - if(!(widget = widget_getbyname(statusbar, path[7]))) - return warn("no such widget: %s in statusbar %s.\n", path[7], statusbar->name); - - widget->tell(widget, path[9], arg); + widget->tell(widget, path[5], arg); for(i = 0; path[i]; i++) p_delete(&path[i]); @@ -119,7 +110,7 @@ a_dbus_process_requests(int *fd) break; - if(dbus_message_is_method_call(msg, "org.awesome.statusbar.widget", "set")) + if(dbus_message_is_method_call(msg, "org.awesome.widget", "set")) a_dbus_process_widget_set(msg); else if(dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected")) { diff --git a/widget.c b/widget.c index c99b900c6..1e2af3f4c 100644 --- a/widget.c +++ b/widget.c @@ -48,18 +48,21 @@ 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. * \return A widget pointer. */ widget_t * -widget_getbyname(statusbar_t *sb, char *name) +widget_getbyname(const char *name) { widget_node_t *widget; + statusbar_t *sb; + int screen; - for(widget = sb->widgets; widget; widget = widget->next) - if(!a_strcmp(name, widget->widget->name)) - return widget->widget; + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) + for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next) + for(widget = sb->widgets; widget; widget = widget->next) + if(!a_strcmp(name, widget->widget->name)) + return widget->widget; return NULL; } diff --git a/widget.h b/widget.h index f3164160c..47e4260e9 100644 --- a/widget.h +++ b/widget.h @@ -35,7 +35,7 @@ typedef widget_t *(WidgetConstructor)(alignment_t); void widget_invalidate_cache(int, int); int widget_calculate_offset(int, int, int, int); void widget_common_new(widget_t *); -widget_t * widget_getbyname(statusbar_t *, char *); +widget_t * widget_getbyname(const char *); void widget_invalidate_statusbar_bywidget(widget_t *); WidgetConstructor taglist_new;