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.
24 #include "common/util.h"
26 extern AwesomeConf globalconf
;
38 textbox_draw(Widget
*widget
, DrawCtx
*ctx
, int offset
, int used
)
40 Data
*d
= widget
->data
;
43 widget
->area
.width
= d
->width
;
45 widget
->area
.width
= MIN(draw_textwidth(ctx
->display
, widget
->font
, d
->text
),
46 widget
->statusbar
->width
- used
);
48 widget
->area
.height
= widget
->statusbar
->height
;
50 if(!widget
->user_supplied_x
)
51 widget
->area
.x
= widget_calculate_offset(widget
->statusbar
->width
,
55 if(!widget
->user_supplied_y
)
58 draw_text(ctx
, widget
->area
, d
->align
, 0, widget
->font
, d
->text
, d
->fg
, d
->bg
);
60 return widget
->area
.width
;
64 textbox_tell(Widget
*widget
, char *command
)
67 ssize_t command_len
= a_strlen(command
);
68 int i
= 0, phys_screen
= get_phys_screen(widget
->statusbar
->screen
);
70 Data
*d
= widget
->data
;
74 for (i
= 0, tok
= command
; tok
&& i
< 2 && *tok
== '#'; i
++)
76 ntok
= strchr(tok
, ' ');
77 if((!ntok
&& command_len
- (tok
- command
) == 7) ||
83 draw_color_new(globalconf
.display
, phys_screen
, tok
, &d
->fg
);
85 draw_color_new(globalconf
.display
, phys_screen
, tok
, &d
->bg
);
88 tok
= ntok
+ (ntok
!= NULL
);
93 d
->text
= a_strdup(tok
);
97 textbox_new(Statusbar
*statusbar
, cfg_t
*config
)
103 w
= p_new(Widget
, 1);
104 widget_common_new(w
, statusbar
, config
);
105 w
->draw
= textbox_draw
;
106 w
->tell
= textbox_tell
;
107 w
->alignment
= draw_get_align(cfg_getstr(config
, "align"));
109 w
->data
= d
= p_new(Data
, 1);
111 if((buf
= cfg_getstr(config
, "fg")))
112 draw_color_new(globalconf
.display
, get_phys_screen(statusbar
->screen
), buf
, &d
->fg
);
114 d
->fg
= globalconf
.screens
[statusbar
->screen
].colors_normal
[ColFG
];
116 if((buf
= cfg_getstr(config
, "bg")))
117 draw_color_new(globalconf
.display
, get_phys_screen(statusbar
->screen
), buf
, &d
->bg
);
119 d
->bg
= globalconf
.screens
[statusbar
->screen
].colors_normal
[ColBG
];
121 d
->width
= cfg_getint(config
, "width");
122 d
->align
= draw_get_align(cfg_getstr(config
, "text_align"));
124 if((buf
= cfg_getstr(config
, "font")))
125 w
->font
= XftFontOpenName(globalconf
.display
, get_phys_screen(statusbar
->screen
), buf
);
128 w
->font
= globalconf
.screens
[statusbar
->screen
].font
;
130 d
->text
= a_strdup(cfg_getstr(config
, "text"));
134 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80