set_font(&font);
#define txt(x, row, text) \
- draw_text(text, strlen(text), false, pixmap, pixmap_gc, x, (row - 1) * font.height + 4)
+ draw_text(text, strlen(text), false, pixmap, pixmap_gc,\
+ x, (row - 1) * font.height + 4, 300 - x * 2)
if (current_step == STEP_WELCOME) {
/* restore font color */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
+ set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000"));
txt(10, 2, "You have not configured i3 yet.");
txt(10, 3, "Do you want me to generate ~/.i3/config?");
txt(85, 7, "No, I will use the defaults");
/* green */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#00FF00") });
+ set_font_colors(pixmap_gc, get_colorpixel("#00FF00"), get_colorpixel("#000000"));
txt(25, 5, "<Enter>");
/* red */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") });
+ set_font_colors(pixmap_gc, get_colorpixel("#FF0000"), get_colorpixel("#000000"));
txt(31, 7, "<ESC>");
}
if (current_step == STEP_GENERATE) {
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
+ set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000"));
txt(10, 2, "Please choose either:");
txt(85, 4, "Win as default modifier");
/* the selected modifier */
set_font(&bold_font);
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ bold_font.id });
+ set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000"));
if (modifier == MOD_Mod4)
txt(31, 4, "<Win>");
else txt(31, 5, "<Alt>");
/* green */
set_font(&font);
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_FONT,
- (uint32_t[]) { get_colorpixel("#00FF00"), font.id });
-
+ set_font_colors(pixmap_gc, get_colorpixel("#00FF00"), get_colorpixel("#000000"));
txt(25, 9, "<Enter>");
/* red */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") });
+ set_font_colors(pixmap_gc, get_colorpixel("#FF0000"), get_colorpixel("#000000"));
txt(31, 10, "<ESC>");
}
xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);
font = load_font(pattern, true);
- set_font(&font);
bold_font = load_font(patternbold, true);
/* Open an input window */
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &inner);
/* restore font color */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
+ set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000"));
+
+ /* draw the text */
uint8_t *con = concat_strings(glyphs_ucs, input_position);
char *full_text = (char*)con;
if (prompt != NULL) {
memcpy(full_text + (prompt_len * 2), con, input_position * 2);
}
if (input_position + prompt_len != 0)
- draw_text(full_text, input_position + prompt_len, true, pixmap, pixmap_gc, 4, 4);
+ draw_text(full_text, input_position + prompt_len, true, pixmap, pixmap_gc, 4, 4, 492);
/* Copy the contents of the pixmap to the real window */
xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8);
* this for us) */
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
- /* Create graphics context */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
-
/* Grab the keyboard to get all input */
xcb_flush(conn);
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &rect);
/* restore font color */
- uint32_t values[3];
- values[0] = color_text;
- values[1] = color_background;
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
- draw_text(prompt, strlen(prompt), false, pixmap, pixmap_gc, 4 + 4, 4 + 4);
+ set_font_colors(pixmap_gc, color_text, color_background);
+ draw_text(prompt, strlen(prompt), false, pixmap, pixmap_gc,
+ 4 + 4, 4 + 4, rect.width - 4 - 4);
/* render close button */
int line_width = 4;
int w = 20;
int y = rect.width;
+ uint32_t values[3];
values[0] = color_button_background;
values[1] = line_width;
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
};
xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, pixmap, pixmap_gc, 5, points);
- values[0] = color_text;
- values[1] = color_button_background;
- values[2] = 1;
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_LINE_WIDTH, values);
- draw_text("X", 1, false, pixmap, pixmap_gc, y - w - line_width + w / 2 - 4, 4 + 4 - 1);
+ values[0] = 1;
+ set_font_colors(pixmap_gc, color_text, color_button_background);
+ draw_text("X", 1, false, pixmap, pixmap_gc, y - w - line_width + w / 2 - 4,
+ 4 + 4 - 1, rect.width - y + w + line_width - w / 2 + 4);
y -= w;
y -= 20;
values[0] = color_text;
values[1] = color_button_background;
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
+ set_font_colors(pixmap_gc, color_text, color_button_background);
draw_text(buttons[c].label, strlen(buttons[c].label), false, pixmap, pixmap_gc,
- y - w - line_width + 6, 4 + 3);
+ y - w - line_width + 6, 4 + 3, rect.width - y + w + line_width - 6);
y -= w;
}
xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font.height + 8);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
- /* Create graphics context */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
-
/* Grab the keyboard to get all input */
xcb_flush(conn);
xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, rect.width, rect.height);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
-
- /* Create graphics context */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
break;
}
}
xcb_rectangle_t rect = { 0, 0, xcb_screen->width_in_pixels, font.height };
xcb_poly_fill_rectangle(xcb_connection, statusline_pm, statusline_clear, 1, &rect);
- draw_text((char*)text, glyph_count, true, statusline_pm, statusline_ctx, 0, 0);
+ set_font_colors(statusline_ctx, colors.bar_fg, colors.bar_bg);
+ draw_text((char*)text, glyph_count, true, statusline_pm, statusline_ctx,
+ 0, 0, xcb_screen->width_in_pixels);
FREE(text);
}
mask,
vals);
- mask |= XCB_GC_BACKGROUND;
- vals[0] = colors.bar_fg;
statusline_ctx = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_ctx_cookie = xcb_create_gc_checked(xcb_connection,
statusline_ctx,
xcb_root,
- mask,
- vals);
+ 0,
+ NULL);
statusline_pm = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
set_font(&font);
DLOG("Calculated Font-height: %d\n", font.height);
- /* Set the font in the gc */
- xcb_change_gc(xcb_connection, statusline_ctx, XCB_GC_FONT, (uint32_t[]){ font.id });
-
xcb_flush(xcb_connection);
/* To grab modifiers without blocking other applications from receiving key-events
xcb_screen->height_in_pixels);
uint32_t mask = XCB_GC_FOREGROUND;
- uint32_t vals[3] = { colors.bar_bg, colors.bar_bg, font.id };
+ uint32_t vals[2] = { colors.bar_bg, colors.bar_bg };
xcb_free_gc(xcb_connection, statusline_clear);
statusline_clear = xcb_generate_id(xcb_connection);
xcb_void_cookie_t clear_ctx_cookie = xcb_create_gc_checked(xcb_connection,
mask,
vals);
- mask |= XCB_GC_BACKGROUND | XCB_GC_FONT;
+ mask |= XCB_GC_BACKGROUND;
vals[0] = colors.bar_fg;
statusline_ctx = xcb_generate_id(xcb_connection);
xcb_free_gc(xcb_connection, statusline_ctx);
/* We also want a graphics-context for the bars (it defines the properties
* with which we draw to them) */
walk->bargc = xcb_generate_id(xcb_connection);
- mask = XCB_GC_FONT;
- values[0] = font.id;
xcb_void_cookie_t gc_cookie = xcb_create_gc_checked(xcb_connection,
walk->bargc,
walk->bar,
- mask,
- values);
+ 0,
+ NULL);
/* We finally map the bar (display it on screen), unless the modifier-switch is on */
xcb_void_cookie_t map_cookie;
outputs_walk->bargc,
1,
&rect);
- xcb_change_gc(xcb_connection,
- outputs_walk->bargc,
- XCB_GC_FOREGROUND,
- &fg_color);
+ set_font_colors(outputs_walk->bargc, fg_color, bg_color);
draw_text((char*)ws_walk->ucs2_name, ws_walk->name_glyphs, true,
- outputs_walk->buffer, outputs_walk->bargc, i + 5, 2);
+ outputs_walk->buffer, outputs_walk->bargc, i + 5, 2, ws_walk->name_width);
i += 10 + ws_walk->name_width;
}
*/
void set_font(i3Font *font);
+/**
+ * Defines the colors to be used for the forthcoming draw_text calls.
+ *
+ */
+void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background);
+
/**
* Draws text onto the specified X drawable (normally a pixmap) at the
* specified coordinates (from the top left corner of the leftmost, uppermost
* glyph) and using the provided gc. Text can be specified as UCS-2 or UTF-8.
*
*/
-void draw_text(char *text, size_t text_len, bool is_ucs2,
- xcb_drawable_t drawable, xcb_gcontext_t gc, int x, int y);
+void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawable,
+ xcb_gcontext_t gc, int x, int y, int max_width);
/**
* Predict the text width in pixels for the given text. Text can be specified
savedFont = font;
}
+/*
+ * Defines the colors to be used for the forthcoming draw_text calls.
+ *
+ */
+void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background) {
+ assert(savedFont != NULL);
+ uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
+ uint32_t values[] = { foreground, background, savedFont->id };
+ xcb_change_gc(conn, gc, mask, values);
+}
+
/*
* Draws text onto the specified X drawable (normally a pixmap) at the
* specified coordinates (from the top left corner of the leftmost, uppermost
* glyph) and using the provided gc. Text can be specified as UCS-2 or UTF-8.
*
*/
-void draw_text(char *text, size_t text_len, bool is_ucs2,
- xcb_drawable_t drawable, xcb_gcontext_t gc, int x, int y) {
+void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawable,
+ xcb_gcontext_t gc, int x, int y, int max_width) {
assert(savedFont != NULL);
assert(text_len != 0);
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &inner);
/* restore font color */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
+ set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000"));
for (int i = 0; i < sizeof(crash_text) / sizeof(char*); i++) {
- draw_text(crash_text[i], strlen(crash_text[i]), false,
- pixmap, pixmap_gc, 8, 3 + (i - 1) * font_height);
+ draw_text(crash_text[i], strlen(crash_text[i]), false, pixmap, pixmap_gc,
+ 8, 3 + (i - 1) * font_height, width - 16);
}
/* Copy the contents of the pixmap to the real window */
xcb_create_pixmap(conn, root_depth, pixmap, win, width, height);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
- /* Create graphics context */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ config.font.id });
-
/* Grab the keyboard to get all input */
xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
xcb_poly_segment(conn, parent->pixmap, parent->pm_gc, 2, segments);
/* 6: draw the title */
- uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
- uint32_t values[] = { p->color->text, p->color->background, config.font.id };
- xcb_change_gc(conn, parent->pm_gc, mask, values);
+ set_font_colors(parent->pm_gc, p->color->text, p->color->background);
int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
struct Window *win = con->window;
// TODO: use a good description instead of just "another container"
draw_text("another container", strlen("another container"), false,
parent->pixmap, parent->pm_gc,
- con->deco_rect.x + 2, con->deco_rect.y + text_offset_y);
+ con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
+ con->deco_rect.width - 2);
goto copy_pixmaps;
}
draw_text(win->name_x, win->name_len, win->uses_net_wm_name,
parent->pixmap, parent->pm_gc,
- con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y);
+ con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y,
+ con->deco_rect.width - 2 - indent_px);
copy_pixmaps:
xcb_copy_area(conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);