add various autostuff to ignore
[awesome.git] / widgets / textbox.c
blobfaea73e48740478aa082c95325950a50050f046b
1 /*
2 * textbox.c - text box widget
4 * Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "util.h"
23 #include "widget.h"
24 #include "xutil.h"
25 #include "screen.h"
27 extern AwesomeConf globalconf;
29 typedef struct
31 char *text;
32 int width;
33 Alignment align;
34 XColor fg;
35 XColor bg;
36 } Data;
38 static int
39 textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
40 int used __attribute__ ((unused)))
42 Data *d = widget->data;
44 if(d->width)
45 widget->area.width = d->width;
46 else
47 widget->area.width = textwidth(widget->font, d->text);
49 widget->area.height = widget->statusbar->height;
51 if(!widget->user_supplied_x)
52 widget->area.x = widget_calculate_offset(widget->statusbar->width,
53 widget->area.width,
54 offset,
55 widget->alignment);
56 if(!widget->user_supplied_y)
57 widget->area.y = 0;
59 draw_text(ctx, widget->area.x, widget->area.y, widget->area.width,
60 widget->statusbar->height, d->align, 0, widget->font,
61 d->text, d->fg, d->bg);
63 return widget->area.width;
66 static void
67 textbox_tell(Widget *widget, char *command)
69 Data *d = widget->data;
70 if (d->text)
71 p_delete(&d->text);
72 d->text = a_strdup(command);
75 Widget *
76 textbox_new(Statusbar *statusbar, cfg_t *config)
78 Widget *w;
79 Data *d;
80 char *buf;
82 w = p_new(Widget, 1);
83 widget_common_new(w, statusbar, config);
84 w->draw = textbox_draw;
85 w->tell = textbox_tell;
87 w->data = d = p_new(Data, 1);
89 if((buf = cfg_getstr(config, "fg")))
90 d->fg = initxcolor(statusbar->screen, buf);
91 else
92 d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
94 if((buf = cfg_getstr(config, "bg")))
95 d->bg = initxcolor(get_phys_screen(statusbar->screen), buf);
96 else
97 d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
99 d->width = cfg_getint(config, "width");
100 d->align = draw_get_align(cfg_getstr(config, "align"));
102 if((buf = cfg_getstr(config, "font")))
103 w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf);
105 if(!w->font)
106 w->font = globalconf.screens[statusbar->screen].font;
108 d->text = a_strdup(cfg_getstr(config, "text"));
109 return w;
111 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80