Solidify widgets.
Factor out common initialisation into a common_new function. Copy the section title into the Widget title attribute.
This commit is contained in:
parent
65fd8d48f0
commit
5923c90aaa
14
config.c
14
config.c
|
@ -268,7 +268,7 @@ create_widgets(cfg_t* cfg_statusbar, Statusbar *statusbar)
|
||||||
cfg_t* widgets, *wptr;
|
cfg_t* widgets, *wptr;
|
||||||
Widget *widget = NULL;
|
Widget *widget = NULL;
|
||||||
unsigned int i, j, numnames, numwidgets = 0;
|
unsigned int i, j, numnames, numwidgets = 0;
|
||||||
Widget *(*widget_new)(Statusbar *);
|
WidgetConstructor *widget_new;
|
||||||
|
|
||||||
numnames = sizeof(widget_names)/sizeof(widget_names[0]);
|
numnames = sizeof(widget_names)/sizeof(widget_names[0]);
|
||||||
for (i = 0; i < numnames; i++)
|
for (i = 0; i < numnames; i++)
|
||||||
|
@ -290,19 +290,21 @@ create_widgets(cfg_t* cfg_statusbar, Statusbar *statusbar)
|
||||||
|
|
||||||
for (i = 0; i < numwidgets; i++){
|
for (i = 0; i < numwidgets; i++){
|
||||||
widget_new = name_func_lookup(cfg_name(widgets + i), WidgetList);
|
widget_new = name_func_lookup(cfg_name(widgets + i), WidgetList);
|
||||||
|
|
||||||
if (widget_new)
|
if (widget_new)
|
||||||
if(!widget)
|
if(!widget){
|
||||||
statusbar->widgets = widget = widget_new(statusbar);
|
widget = widget_new(statusbar,
|
||||||
|
cfg_title(widgets + i));
|
||||||
|
statusbar->widgets = widget;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
widget->next = widget_new(statusbar);
|
widget->next = widget_new(statusbar,
|
||||||
|
cfg_title(widgets + i));
|
||||||
widget = widget->next;
|
widget = widget->next;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
warn("Ignoring unknown widget: %s.\n", cfg_name(widgets + i));
|
warn("Ignoring unknown widget: %s.\n", cfg_name(widgets + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
14
widget.c
14
widget.c
|
@ -26,7 +26,8 @@ calculate_alignments(Widget *widget)
|
||||||
if(widget)
|
if(widget)
|
||||||
for(; widget; widget = widget->next){
|
for(; widget; widget = widget->next){
|
||||||
if (widget->alignment == AlignFlex)
|
if (widget->alignment == AlignFlex)
|
||||||
warn("Multiple flex widgets in panel - ignoring flex for all but the first.");
|
warn("Multiple flex widgets in panel -"
|
||||||
|
" ignoring flex for all but the first.");
|
||||||
widget->alignment = AlignRight;
|
widget->alignment = AlignRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +37,17 @@ calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
|
||||||
{
|
{
|
||||||
if (alignment == AlignLeft || alignment == AlignFlex)
|
if (alignment == AlignLeft || alignment == AlignFlex)
|
||||||
return offset;
|
return offset;
|
||||||
|
|
||||||
return barwidth - offset - widgetwidth;
|
return barwidth - offset - widgetwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
common_new(Widget *widget, Statusbar *statusbar, const char *name)
|
||||||
|
{
|
||||||
|
widget->statusbar = statusbar;
|
||||||
|
widget->name = p_new(char, strlen(name)+1);
|
||||||
|
strncpy(widget->name, name, strlen(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|
||||||
|
|
11
widget.h
11
widget.h
|
@ -6,15 +6,16 @@
|
||||||
|
|
||||||
enum { AlignLeft, AlignRight, AlignFlex };
|
enum { AlignLeft, AlignRight, AlignFlex };
|
||||||
|
|
||||||
typedef Widget *(WidgetConstructor)(Statusbar *);
|
typedef Widget *(WidgetConstructor)(Statusbar*, const char*);
|
||||||
|
|
||||||
int calculate_offset(int, int, int, int);
|
int calculate_offset(int, int, int, int);
|
||||||
void calculate_alignments(Widget *widget);
|
void calculate_alignments(Widget *widget);
|
||||||
|
void common_new(Widget *, Statusbar *, const char *);
|
||||||
|
|
||||||
Widget *layoutinfo_new(Statusbar*);
|
WidgetConstructor layoutinfo_new;
|
||||||
Widget *taglist_new(Statusbar*);
|
WidgetConstructor taglist_new;
|
||||||
Widget *textbox_new(Statusbar*);
|
WidgetConstructor textbox_new;
|
||||||
Widget *focustitle_new(Statusbar*);
|
WidgetConstructor focustitle_new;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
|
#include <stdio.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
|
|
||||||
extern awesome_config globalconf;
|
|
||||||
|
|
||||||
static char name[] = "focustitle";
|
extern awesome_config globalconf;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
||||||
{
|
{
|
||||||
Client *sel = globalconf.focus->client;
|
Client *sel = globalconf.focus->client;
|
||||||
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
int location = calculate_offset(vscreen.statusbar.width, 0, offset, widget->alignment);
|
int location = calculate_offset(vscreen.statusbar.width,
|
||||||
|
0,
|
||||||
|
offset,
|
||||||
|
widget->alignment);
|
||||||
|
|
||||||
if(sel)
|
if(sel)
|
||||||
{
|
{
|
||||||
|
@ -31,13 +34,12 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
focustitle_new(Statusbar *statusbar)
|
focustitle_new(Statusbar *statusbar, const char *name)
|
||||||
{
|
{
|
||||||
Widget *w;
|
Widget *w;
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
w->draw = focustitle_draw;
|
w->draw = focustitle_draw;
|
||||||
w->statusbar = statusbar;
|
common_new(w, statusbar, name);
|
||||||
w->name = name;
|
|
||||||
w->alignment = AlignFlex;
|
w->alignment = AlignFlex;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,21 @@
|
||||||
|
|
||||||
extern awesome_config globalconf;
|
extern awesome_config globalconf;
|
||||||
|
|
||||||
static char name[] = "layoutinfo";
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
layoutinfo_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused)))
|
layoutinfo_draw(Widget *widget,
|
||||||
|
DrawCtx *ctx,
|
||||||
|
int offset,
|
||||||
|
int used __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
int width = 0, location;
|
int width = 0, location;
|
||||||
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
Layout *l;
|
Layout *l;
|
||||||
for(l = vscreen.layouts ; l; l = l->next)
|
for(l = vscreen.layouts ; l; l = l->next)
|
||||||
width = MAX(width, (textwidth(ctx, vscreen.font, l->symbol)));
|
width = MAX(width, (textwidth(ctx, vscreen.font, l->symbol)));
|
||||||
location = calculate_offset(vscreen.statusbar.width, width, offset, widget->alignment);
|
location = calculate_offset(vscreen.statusbar.width,
|
||||||
|
width,
|
||||||
|
offset,
|
||||||
|
widget->alignment);
|
||||||
drawtext(ctx, location, 0,
|
drawtext(ctx, location, 0,
|
||||||
width,
|
width,
|
||||||
vscreen.statusbar.height,
|
vscreen.statusbar.height,
|
||||||
|
@ -26,13 +30,12 @@ layoutinfo_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__
|
||||||
|
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
layoutinfo_new(Statusbar *statusbar)
|
layoutinfo_new(Statusbar *statusbar, const char* name)
|
||||||
{
|
{
|
||||||
Widget *w;
|
Widget *w;
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
w->draw = (void*) layoutinfo_draw;
|
w->draw = (void*) layoutinfo_draw;
|
||||||
w->statusbar = statusbar;
|
common_new(w, statusbar, name);
|
||||||
w->name = name;
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
extern awesome_config globalconf;
|
extern awesome_config globalconf;
|
||||||
|
|
||||||
static char name[] = "taglist";
|
|
||||||
|
|
||||||
/** Check if at least one client is tagged with tag number t and is on screen
|
/** Check if at least one client is tagged with tag number t and is on screen
|
||||||
* screen
|
* screen
|
||||||
* \param screen screen number
|
* \param screen screen number
|
||||||
|
@ -43,7 +41,10 @@ taglist_draw(Widget *widget,
|
||||||
{
|
{
|
||||||
width += textwidth(ctx, vscreen.font, tag->name);
|
width += textwidth(ctx, vscreen.font, tag->name);
|
||||||
}
|
}
|
||||||
location = calculate_offset(vscreen.statusbar.width, width, offset, widget->alignment);
|
location = calculate_offset(vscreen.statusbar.width,
|
||||||
|
width,
|
||||||
|
offset,
|
||||||
|
widget->alignment);
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next)
|
for(tag = vscreen.tags; tag; tag = tag->next)
|
||||||
|
@ -57,7 +58,9 @@ taglist_draw(Widget *widget,
|
||||||
vscreen.statusbar.height, vscreen.font, tag->name, colors);
|
vscreen.statusbar.height, vscreen.font, tag->name, colors);
|
||||||
if(isoccupied(widget->statusbar->screen, tag))
|
if(isoccupied(widget->statusbar->screen, tag))
|
||||||
drawrectangle(ctx, location + width, 0, flagsize, flagsize,
|
drawrectangle(ctx, location + width, 0, flagsize, flagsize,
|
||||||
sel && is_client_tagged(sel, tag, widget->statusbar->screen),
|
sel && is_client_tagged(sel,
|
||||||
|
tag,
|
||||||
|
widget->statusbar->screen),
|
||||||
colors[ColFG]);
|
colors[ColFG]);
|
||||||
width += w;
|
width += w;
|
||||||
}
|
}
|
||||||
|
@ -65,13 +68,12 @@ taglist_draw(Widget *widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
taglist_new(Statusbar *statusbar)
|
taglist_new(Statusbar *statusbar, const char *name)
|
||||||
{
|
{
|
||||||
Widget *w;
|
Widget *w;
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
w->draw = taglist_draw;
|
w->draw = taglist_draw;
|
||||||
w->statusbar = statusbar;
|
common_new(w, statusbar, name);
|
||||||
w->name = name;
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
extern awesome_config globalconf;
|
extern awesome_config globalconf;
|
||||||
|
|
||||||
static char name[] = "textbox";
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
textbox_draw(Widget *widget,
|
textbox_draw(Widget *widget,
|
||||||
DrawCtx *ctx,
|
DrawCtx *ctx,
|
||||||
|
@ -13,20 +11,22 @@ textbox_draw(Widget *widget,
|
||||||
{
|
{
|
||||||
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
int width = textwidth(ctx, vscreen.font, vscreen.statustext);
|
int width = textwidth(ctx, vscreen.font, vscreen.statustext);
|
||||||
int location = calculate_offset(vscreen.statusbar.width, width, offset, widget->alignment);
|
int location = calculate_offset(vscreen.statusbar.width,
|
||||||
|
width,
|
||||||
|
offset,
|
||||||
|
widget->alignment);
|
||||||
drawtext(ctx, location, 0, width, vscreen.statusbar.height,
|
drawtext(ctx, location, 0, width, vscreen.statusbar.height,
|
||||||
vscreen.font, vscreen.statustext, vscreen.colors_normal);
|
vscreen.font, vscreen.statustext, vscreen.colors_normal);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
textbox_new(Statusbar *statusbar)
|
textbox_new(Statusbar *statusbar, const char *name)
|
||||||
{
|
{
|
||||||
Widget *w;
|
Widget *w;
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
w->draw = textbox_draw;
|
w->draw = textbox_draw;
|
||||||
w->statusbar = statusbar;
|
common_new(w, statusbar, name);
|
||||||
w->name = name;
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue