i3-nagbar: Port to i3String

This commit is contained in:
Quentin Glidic 2012-08-07 19:58:55 +02:00
parent bbd1b16043
commit 50b7764ae4
1 changed files with 9 additions and 9 deletions

View File

@ -30,7 +30,7 @@
#include "i3-nagbar.h" #include "i3-nagbar.h"
typedef struct { typedef struct {
char *label; i3String *label;
char *action; char *action;
int16_t x; int16_t x;
uint16_t width; uint16_t width;
@ -41,7 +41,7 @@ static xcb_pixmap_t pixmap;
static xcb_gcontext_t pixmap_gc; static xcb_gcontext_t pixmap_gc;
static xcb_rectangle_t rect = { 0, 0, 600, 20 }; static xcb_rectangle_t rect = { 0, 0, 600, 20 };
static i3Font font; static i3Font font;
static char *prompt; static i3String *prompt;
static button_t *buttons; static button_t *buttons;
static int buttoncnt; static int buttoncnt;
@ -132,7 +132,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
/* restore font color */ /* restore font color */
set_font_colors(pixmap_gc, color_text, color_background); set_font_colors(pixmap_gc, color_text, color_background);
draw_text(prompt, strlen(prompt), false, pixmap, pixmap_gc, draw_text((char *)i3string_as_ucs2(prompt), i3string_get_num_glyphs(prompt), true, pixmap, pixmap_gc,
4 + 4, 4 + 4, rect.width - 4 - 4); 4 + 4, 4 + 4, rect.width - 4 - 4);
/* render close button */ /* render close button */
@ -190,7 +190,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
values[0] = color_text; values[0] = color_text;
values[1] = color_button_background; values[1] = color_button_background;
set_font_colors(pixmap_gc, color_text, color_button_background); set_font_colors(pixmap_gc, color_text, color_button_background);
draw_text(buttons[c].label, strlen(buttons[c].label), false, pixmap, pixmap_gc, draw_text((char *)i3string_as_ucs2(buttons[c].label), i3string_get_num_glyphs(buttons[c].label), true, pixmap, pixmap_gc,
y - w - line_width + 6, 4 + 3, rect.width - y + w + line_width - 6); y - w - line_width + 6, 4 + 3, rect.width - y + w + line_width - 6);
y -= w; y -= w;
@ -232,7 +232,7 @@ int main(int argc, char *argv[]) {
char *options_string = "b:f:m:t:vh"; char *options_string = "b:f:m:t:vh";
prompt = sstrdup("Please do not run this program."); prompt = i3string_from_utf8("Please do not run this program.");
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
switch (o) { switch (o) {
@ -244,8 +244,8 @@ int main(int argc, char *argv[]) {
pattern = sstrdup(optarg); pattern = sstrdup(optarg);
break; break;
case 'm': case 'm':
FREE(prompt); i3string_free(prompt);
prompt = sstrdup(optarg); prompt = i3string_from_utf8(optarg);
break; break;
case 't': case 't':
bar_type = (strcasecmp(optarg, "warning") == 0 ? TYPE_WARNING : TYPE_ERROR); bar_type = (strcasecmp(optarg, "warning") == 0 ? TYPE_WARNING : TYPE_ERROR);
@ -256,10 +256,10 @@ int main(int argc, char *argv[]) {
return 0; return 0;
case 'b': case 'b':
buttons = realloc(buttons, sizeof(button_t) * (buttoncnt + 1)); buttons = realloc(buttons, sizeof(button_t) * (buttoncnt + 1));
buttons[buttoncnt].label = optarg; buttons[buttoncnt].label = i3string_from_utf8(optarg);
buttons[buttoncnt].action = argv[optind]; buttons[buttoncnt].action = argv[optind];
printf("button with label *%s* and action *%s*\n", printf("button with label *%s* and action *%s*\n",
buttons[buttoncnt].label, i3string_as_utf8(buttons[buttoncnt].label),
buttons[buttoncnt].action); buttons[buttoncnt].action);
buttoncnt++; buttoncnt++;
printf("now %d buttons\n", buttoncnt); printf("now %d buttons\n", buttoncnt);