diff options
author | Kristian Høgsberg <krh@redhat.com> | 2008-12-08 12:59:37 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2008-12-08 12:59:37 -0500 |
commit | 1584c57edcbeb34a628afe12fd6e527fda8ec486 (patch) | |
tree | 3edc58e6d9512e2ca23d66b3c63fd89fdad253f6 /terminal.c | |
parent | 17809b1e4373ea9e3635d224c5ef1efda6889cfb (diff) | |
download | wayland-1584c57edcbeb34a628afe12fd6e527fda8ec486.tar.gz wayland-1584c57edcbeb34a628afe12fd6e527fda8ec486.tar.xz wayland-1584c57edcbeb34a628afe12fd6e527fda8ec486.zip |
Snap terminal size to an integer number of character cells.
Diffstat (limited to 'terminal.c')
-rw-r--r-- | terminal.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -63,6 +63,7 @@ struct terminal { char escape[64]; int escape_length; int state; + int margin; }; static void @@ -93,7 +94,8 @@ terminal_draw_contents(struct terminal *terminal) cairo_font_extents(cr, &extents); for (i = 0; i < terminal->total_rows; i++) { row = (terminal->tail + i) % terminal->height; - cairo_move_to(cr, 0, extents.ascent + extents.height * i); + cairo_move_to(cr, terminal->margin, + terminal->margin + extents.ascent + extents.height * i); cairo_show_text(cr, &terminal->data[row * (terminal->width + 1)]); } cairo_destroy(cr); @@ -232,9 +234,29 @@ terminal_data(struct terminal *terminal, const char *data, size_t length) } static void -resize_handler(struct window *window, int32_t width, int32_t height, void *data) +resize_handler(struct window *window, struct rectangle *rectangle, void *data) { struct terminal *terminal = data; + cairo_surface_t *surface; + cairo_font_extents_t extents; + cairo_t *cr; + + /* Adjust the size to an integer number of character cells. + * Maybe this is better done in the redraw path, as we're + * creating the cr and setting the font there anyway. */ + + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); + cr = cairo_create(surface); + cairo_select_font_face (cr, "mono", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cr, 14); + cairo_font_extents(cr, &extents); + cairo_destroy(cr); + cairo_surface_destroy(surface); + + rectangle->width -= (rectangle->width - 2 * terminal->margin) % (int32_t) extents.max_x_advance; + rectangle->height -= (rectangle->height - 2 * terminal->margin) % (int32_t) extents.height; terminal_schedule_redraw(terminal); } @@ -383,6 +405,7 @@ terminal_create(struct wl_display *display, int fd) terminal->width = 80; terminal->height = 25; terminal->total_rows = 1; + terminal->margin = 5; size = (terminal->width + 1) * terminal->height; terminal->data = malloc(size); memset(terminal->data, 0, size); |