[dbus] Fix widget.set() API call

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-20 20:13:44 +02:00
parent 597719e5aa
commit 4742463cec
3 changed files with 18 additions and 24 deletions

27
dbus.c
View File

@ -54,19 +54,16 @@ static void
a_dbus_process_widget_set(DBusMessage *req) a_dbus_process_widget_set(DBusMessage *req)
{ {
char *arg, **path; char *arg, **path;
int i, screen; int i;
DBusMessageIter iter; DBusMessageIter iter;
statusbar_t *statusbar;
widget_t *widget; widget_t *widget;
if(!dbus_message_get_path_decomposed(req, &path) if(!dbus_message_get_path_decomposed(req, &path)
|| !a_dbus_path_check(path, 10) || !a_dbus_path_check(path, 6)
|| a_strcmp(path[2], "screen") || a_strcmp(path[2], "widget")
|| a_strcmp(path[4], "statusbar") || a_strcmp(path[4], "property"))
|| a_strcmp(path[6], "widget")
|| a_strcmp(path[8], "property"))
{ {
warn("invalid object path 2\n"); warn("invalid object path.\n");
dbus_error_free(&err); dbus_error_free(&err);
return; return;
} }
@ -86,16 +83,10 @@ a_dbus_process_widget_set(DBusMessage *req)
else else
dbus_message_iter_get_basic(&iter, &arg); dbus_message_iter_get_basic(&iter, &arg);
if((screen = atoi(path[3])) >= globalconf.screens_info->nscreen) if(!(widget = widget_getbyname(path[3])))
return warn("bad screen number\n"); return warn("no such widget: %s.\n", path[3]);
if(!(statusbar = statusbar_getbyname(screen, path[5]))) widget->tell(widget, path[5], arg);
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);
for(i = 0; path[i]; i++) for(i = 0; path[i]; i++)
p_delete(&path[i]); p_delete(&path[i]);
@ -119,7 +110,7 @@ a_dbus_process_requests(int *fd)
break; 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); a_dbus_process_widget_set(msg);
else if(dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected")) else if(dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
{ {

View File

@ -48,15 +48,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.
* \return A widget pointer. * \return A widget pointer.
*/ */
widget_t * widget_t *
widget_getbyname(statusbar_t *sb, char *name) widget_getbyname(const char *name)
{ {
widget_node_t *widget; widget_node_t *widget;
statusbar_t *sb;
int screen;
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) for(widget = sb->widgets; widget; widget = widget->next)
if(!a_strcmp(name, widget->widget->name)) if(!a_strcmp(name, widget->widget->name))
return widget->widget; return widget->widget;

View File

@ -35,7 +35,7 @@ typedef widget_t *(WidgetConstructor)(alignment_t);
void widget_invalidate_cache(int, int); void widget_invalidate_cache(int, int);
int widget_calculate_offset(int, int, int, int); int widget_calculate_offset(int, int, int, int);
void widget_common_new(widget_t *); 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 *); void widget_invalidate_statusbar_bywidget(widget_t *);
WidgetConstructor taglist_new; WidgetConstructor taglist_new;