diff --git a/common.h b/common.h index 5e75c5e41..9c4db615a 100644 --- a/common.h +++ b/common.h @@ -25,7 +25,7 @@ #include "config.h" /** Common prototype definition for ui_callback functions */ -#define UICB_PROTO(name) void name(int, const char *) +#define UICB_PROTO(name) void name(int, char *) /** Common prototype definition for layouts function */ #define LAYOUT_PROTO(name) void name(int) diff --git a/uicb.c b/uicb.c index b9e64c454..ced4c383b 100644 --- a/uicb.c +++ b/uicb.c @@ -28,6 +28,7 @@ #include "layout.h" #include "mouse.h" #include "statusbar.h" +#include "widget.h" #include "focus.h" #include "layouts/tile.h" @@ -80,6 +81,8 @@ const NameFuncLink UicbList[] = {"client_resizemouse", uicb_client_resizemouse}, /* focus.c */ {"focus_history", uicb_focus_history}, + /* widgets.c */ + {"widget_tell", uicb_widget_tell}, {NULL, NULL} }; @@ -88,6 +91,7 @@ run_uicb(char *cmd, awesome_config *awesomeconf) { char *p; const char *arg; + char *argcpy; int screen, len; void (*uicb) (int, const char *); @@ -115,11 +119,16 @@ run_uicb(char *cmd, awesome_config *awesomeconf) } if (p+strlen(p) < cmd+len) + { arg = p + strlen(p) + 1; + /* Allow our callees to modify this string. */ + argcpy = p_new(char, strlen(arg)+1); + strncpy(argcpy, arg, strlen(arg)); + uicb(screen, argcpy); + p_delete(&argcpy); + } else - arg = NULL; - - uicb(screen, arg); + uicb(screen, NULL); return 0; } @@ -137,7 +146,6 @@ parse_control(char *cmd) run_uicb(curcmd, &globalconf); curcmd = p + 1; } - return 0; } diff --git a/widget.c b/widget.c index d2c651672..043cfbc2b 100644 --- a/widget.c +++ b/widget.c @@ -1,6 +1,8 @@ #include "util.h" #include "widget.h" +extern awesome_config globalconf; + const NameFuncLink WidgetList[] = { {"taglist", taglist_new}, @@ -41,6 +43,17 @@ calculate_offset(int barwidth, int widgetwidth, int offset, int alignment) } +static Widget * +find_widget(char *name, int screen) +{ + Widget *widget; + widget = globalconf.screens[screen].statusbar.widgets; + for(; widget; widget = widget->next) + if (strcmp(name, widget->name) == 0) + return widget; + return NULL; +} + void common_new(Widget *widget, Statusbar *statusbar, const char *name) { @@ -49,5 +62,24 @@ common_new(Widget *widget, Statusbar *statusbar, const char *name) strncpy(widget->name, name, strlen(name)); } +void +uicb_widget_tell(int screen, char *arg) +{ + Widget *widget; + char *p; + p = strtok(arg, " "); + if (!p){ + warn("Ignoring malformed widget command."); + return; + } + widget = find_widget(p, screen); + if (!widget){ + warn("No such widget: %s\n", p); + return; + } + + /* To be continued... */ + +} // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/widget.h b/widget.h index baadc2470..27519fb48 100644 --- a/widget.h +++ b/widget.h @@ -3,6 +3,7 @@ #include "config.h" #include "draw.h" +#include "common.h" enum { AlignLeft, AlignRight, AlignFlex }; @@ -17,6 +18,8 @@ WidgetConstructor taglist_new; WidgetConstructor textbox_new; WidgetConstructor focustitle_new; +UICB_PROTO(uicb_widget_tell); + #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99