2007-12-17 10:57:17 +01:00
|
|
|
#include <confuse.h>
|
2007-12-15 18:21:02 +01:00
|
|
|
#include "util.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2007-12-17 10:57:17 +01:00
|
|
|
#include "statusbar.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2007-12-16 10:25:13 +01:00
|
|
|
extern awesome_config globalconf;
|
|
|
|
|
2007-12-15 18:21:02 +01:00
|
|
|
const NameFuncLink WidgetList[] =
|
|
|
|
{
|
|
|
|
{"taglist", taglist_new},
|
|
|
|
{"layoutinfo", layoutinfo_new},
|
|
|
|
{"focustitle", focustitle_new},
|
2007-12-15 20:22:20 +01:00
|
|
|
{"textbox", textbox_new},
|
|
|
|
{NULL, NULL}
|
2007-12-15 18:21:02 +01:00
|
|
|
};
|
|
|
|
|
2007-12-15 07:53:53 +01:00
|
|
|
void
|
|
|
|
calculate_alignments(Widget *widget)
|
|
|
|
{
|
2007-12-15 13:37:34 +01:00
|
|
|
for(; widget; widget = widget->next)
|
|
|
|
{
|
|
|
|
if(widget->alignment == AlignFlex)
|
|
|
|
{
|
2007-12-15 07:53:53 +01:00
|
|
|
widget = widget->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
widget->alignment = AlignLeft;
|
|
|
|
}
|
2007-12-15 13:37:34 +01:00
|
|
|
|
|
|
|
if(widget)
|
2007-12-16 04:28:29 +01:00
|
|
|
for(; widget; widget = widget->next){
|
|
|
|
if (widget->alignment == AlignFlex)
|
2007-12-16 09:34:33 +01:00
|
|
|
warn("Multiple flex widgets in panel -"
|
|
|
|
" ignoring flex for all but the first.");
|
2007-12-15 07:53:53 +01:00
|
|
|
widget->alignment = AlignRight;
|
2007-12-16 04:28:29 +01:00
|
|
|
}
|
2007-12-15 07:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
|
|
|
|
{
|
|
|
|
if (alignment == AlignLeft || alignment == AlignFlex)
|
|
|
|
return offset;
|
2007-12-15 13:37:34 +01:00
|
|
|
return barwidth - offset - widgetwidth;
|
2007-12-15 07:53:53 +01:00
|
|
|
}
|
|
|
|
|
2007-12-16 09:34:33 +01:00
|
|
|
|
2007-12-16 10:25:13 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-12-17 10:57:17 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
common_tell(Widget *widget, char *command __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
warn("%s widget does not accept commands.\n", widget->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-16 09:34:33 +01:00
|
|
|
void
|
2007-12-17 10:57:17 +01:00
|
|
|
common_new(Widget *widget, Statusbar *statusbar, cfg_t* config)
|
2007-12-16 09:34:33 +01:00
|
|
|
{
|
2007-12-17 10:57:17 +01:00
|
|
|
const char *name;
|
2007-12-16 09:34:33 +01:00
|
|
|
widget->statusbar = statusbar;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
|
|
|
name = cfg_title(config);
|
2007-12-16 09:34:33 +01:00
|
|
|
widget->name = p_new(char, strlen(name)+1);
|
2007-12-17 10:57:17 +01:00
|
|
|
widget->tell = common_tell;
|
2007-12-16 09:34:33 +01:00
|
|
|
strncpy(widget->name, name, strlen(name));
|
|
|
|
}
|
|
|
|
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2007-12-16 10:25:13 +01:00
|
|
|
void
|
|
|
|
uicb_widget_tell(int screen, char *arg)
|
|
|
|
{
|
|
|
|
Widget *widget;
|
2007-12-17 10:57:17 +01:00
|
|
|
char *p, *command;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!arg){
|
|
|
|
warn("Must specify a widget.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(arg);
|
2007-12-16 10:25:13 +01:00
|
|
|
p = strtok(arg, " ");
|
|
|
|
if (!p){
|
2007-12-17 10:57:17 +01:00
|
|
|
warn("Ignoring malformed widget command.\n");
|
2007-12-16 10:25:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
widget = find_widget(p, screen);
|
|
|
|
if (!widget){
|
|
|
|
warn("No such widget: %s\n", p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-17 10:57:17 +01:00
|
|
|
if (p+strlen(p) < arg+len)
|
|
|
|
{
|
|
|
|
p = p + strlen(p) + 1;
|
|
|
|
command = p_new(char, strlen(p)+1);
|
|
|
|
strncpy(command, p, strlen(p));
|
|
|
|
widget->tell(widget, command);
|
|
|
|
p_delete(&command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
widget->tell(widget, NULL);
|
|
|
|
statusbar_draw(screen);
|
|
|
|
return;
|
2007-12-16 10:25:13 +01:00
|
|
|
}
|
2007-12-16 09:34:33 +01:00
|
|
|
|
2007-12-15 07:53:53 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|