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
= draw_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 char *tok
, *ntok
, buf
[8];
71 ssize_t command_len
= a_strlen(command
) + 1;
72 char* text
= p_new(char, command_len
);
74 Data
*d
= widget
->data
;
78 for(tok
= command
; tok
; tok
= ntok
, i
++)
81 ntok
= strchr(tok
+ 1, ' ');
83 /* if not first time in the loop, drop the space and put it in the
88 a_strcat(text
, command_len
, " ");
91 if(*tok
== '#' && i
< 2)
94 a_strncpy(buf
, ssizeof(buf
), tok
, ntok
- tok
);
98 d
->fg
= initxcolor(get_phys_screen(widget
->statusbar
->screen
),
102 d
->bg
= initxcolor(get_phys_screen(widget
->statusbar
->screen
),
109 a_strncat(text
, command_len
, tok
, ntok
- tok
);
111 a_strcat(text
, command_len
, tok
);
114 d
->text
= a_strdup(text
);
119 textbox_new(Statusbar
*statusbar
, cfg_t
*config
)
125 w
= p_new(Widget
, 1);
126 widget_common_new(w
, statusbar
, config
);
127 w
->draw
= textbox_draw
;
128 w
->tell
= textbox_tell
;
130 w
->data
= d
= p_new(Data
, 1);
132 if((buf
= cfg_getstr(config
, "fg")))
133 d
->fg
= initxcolor(statusbar
->screen
, buf
);
135 d
->fg
= globalconf
.screens
[statusbar
->screen
].colors_normal
[ColFG
];
137 if((buf
= cfg_getstr(config
, "bg")))
138 d
->bg
= initxcolor(get_phys_screen(statusbar
->screen
), buf
);
140 d
->bg
= globalconf
.screens
[statusbar
->screen
].colors_normal
[ColBG
];
142 d
->width
= cfg_getint(config
, "width");
143 d
->align
= draw_get_align(cfg_getstr(config
, "align"));
145 if((buf
= cfg_getstr(config
, "font")))
146 w
->font
= XftFontOpenName(globalconf
.display
, get_phys_screen(statusbar
->screen
), buf
);
149 w
->font
= globalconf
.screens
[statusbar
->screen
].font
;
151 d
->text
= a_strdup(cfg_getstr(config
, "text"));
154 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80