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.
27 extern AwesomeConf globalconf
;
39 textbox_draw(Widget
*widget
, DrawCtx
*ctx
, int offset
,
40 int used
__attribute__ ((unused
)))
42 Data
*d
= widget
->data
;
45 widget
->area
.width
= d
->width
;
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
,
56 if(!widget
->user_supplied_y
)
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
;
67 textbox_tell(Widget
*widget
, char *command
)
69 Data
*d
= widget
->data
;
72 d
->text
= a_strdup(command
);
76 textbox_new(Statusbar
*statusbar
, cfg_t
*config
)
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
);
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
);
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
);
106 w
->font
= globalconf
.screens
[statusbar
->screen
].font
;
108 d
->text
= a_strdup(cfg_getstr(config
, "text"));
111 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80