diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-04-12 18:24:47 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-04-12 19:17:05 -0400 |
commit | ac972f2c2a080305d0c1a3dacd7fd72666e3d4b0 (patch) | |
tree | d8baa4282e99934cbde558c56e8fb0eae2fe719f | |
parent | 5b2b1de7b7f559287ed59cad757907efdf8fcb7d (diff) | |
download | runes-ac972f2c2a080305d0c1a3dacd7fd72666e3d4b0.tar.gz runes-ac972f2c2a080305d0c1a3dacd7fd72666e3d4b0.zip |
handle window resizing
-rw-r--r-- | display.c | 61 | ||||
-rw-r--r-- | display.h | 1 | ||||
-rw-r--r-- | window-xlib.c | 18 |
3 files changed, 66 insertions, 14 deletions
@@ -9,14 +9,11 @@ static cairo_scaled_font_t *runes_display_make_font(RunesTerm *t); void runes_display_init(RunesTerm *t) { int x, y; - double fontx, fonty, ascent; t->backend_cr = cairo_create(runes_window_backend_surface_create(t)); runes_window_backend_get_size(t, &x, &y); - t->cr = cairo_create( - cairo_surface_create_similar_image( - cairo_get_target(t->backend_cr), CAIRO_FORMAT_RGB24, x, y)); + t->cr = NULL; t->colors[0] = cairo_pattern_create_rgb(0.0, 0.0, 0.0); t->colors[1] = cairo_pattern_create_rgb(1.0, 0.0, 0.0); @@ -26,6 +23,8 @@ void runes_display_init(RunesTerm *t) t->colors[5] = cairo_pattern_create_rgb(1.0, 0.0, 1.0); t->colors[6] = cairo_pattern_create_rgb(1.0, 1.0, 1.0); t->colors[7] = cairo_pattern_create_rgb(1.0, 1.0, 1.0); + t->fgcolor = t->colors[7]; + t->bgcolor = t->colors[0]; t->cursorcolor = cairo_pattern_create_rgb(0.0, 1.0, 0.0); t->show_cursor = 1; @@ -36,23 +35,57 @@ void runes_display_init(RunesTerm *t) t->font_italic = 0; t->font_underline = 0; - cairo_set_scaled_font(t->cr, runes_display_make_font(t)); + t->xpixel = -1; + t->ypixel = -1; + runes_display_set_window_size(t, x, y); runes_display_reset_text_attributes(t); + runes_display_move_to(t, 0, 0); +} - cairo_save(t->cr); - cairo_set_source(t->cr, t->bgcolor); - cairo_paint(t->cr); - cairo_restore(t->cr); +void runes_display_set_window_size(RunesTerm *t, int width, int height) +{ + double fontx, fonty, ascent; + cairo_t *old_cr = NULL; - runes_display_move_to(t, 0, 0); + if (width == t->xpixel && height == t->ypixel) { + return; + } - t->xpixel = x; - t->ypixel = y; + t->xpixel = width; + t->ypixel = height; runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent); t->rows = t->ypixel / fonty; t->cols = t->xpixel / fontx; + + old_cr = t->cr; + + t->cr = cairo_create( + cairo_surface_create_similar_image( + cairo_get_target(t->backend_cr), CAIRO_FORMAT_RGB24, + t->xpixel, t->ypixel)); + cairo_set_source(t->cr, t->fgcolor); + cairo_set_scaled_font(t->cr, runes_display_make_font(t)); + + cairo_save(t->cr); + cairo_set_source(t->cr, t->bgcolor); + cairo_move_to(t->cr, 0.0, 0.0); + cairo_paint(t->cr); + + if (old_cr) { + cairo_set_source_surface(t->cr, cairo_get_target(old_cr), 0.0, 0.0); + cairo_move_to(t->cr, 0.0, 0.0); + cairo_paint(t->cr); + } + + cairo_restore(t->cr); + + if (old_cr) { + cairo_destroy(old_cr); + } + + runes_window_backend_flush(t); } /* note: this uses the backend cairo context because it should be redrawn every @@ -267,7 +300,7 @@ static void runes_display_get_font_dimensions( { cairo_font_extents_t extents; - cairo_font_extents(t->cr, &extents); + cairo_scaled_font_extents(runes_display_make_font(t), &extents); *fontx = extents.max_x_advance; *fonty = extents.height; @@ -284,7 +317,7 @@ static cairo_scaled_font_t *runes_display_make_font(RunesTerm *t) t->font_italic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL, t->font_bold ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); cairo_matrix_init_scale(&font_matrix, t->font_size, t->font_size); - cairo_get_matrix(t->cr, &ctm); + cairo_get_matrix(t->backend_cr, &ctm); return cairo_scaled_font_create( font_face, &font_matrix, &ctm, cairo_font_options_create()); } @@ -2,6 +2,7 @@ #define _RUNES_DISPLAY_H void runes_display_init(RunesTerm *t); +void runes_display_set_window_size(RunesTerm *t, int width, int height); void runes_display_draw_cursor(RunesTerm *t); void runes_display_move_to(RunesTerm *t, int row, int col); void runes_display_show_string(RunesTerm *t, char *buf, size_t len); diff --git a/window-xlib.c b/window-xlib.c index 8023eb2..d89af2e 100644 --- a/window-xlib.c +++ b/window-xlib.c @@ -23,6 +23,8 @@ static void runes_window_backend_process_event(uv_work_t *req, int status); static void runes_window_backend_map_window(RunesTerm *t); static void runes_window_backend_init_wm_properties( RunesTerm *t, int argc, char *argv[]); +static void runes_window_backend_resize_window( + RunesTerm *t, int width, int height); void runes_window_backend_init(RunesTerm *t) { @@ -208,6 +210,11 @@ static void runes_window_backend_process_event(uv_work_t *req, int status) case Expose: runes_window_backend_flush(t); break; + case ConfigureNotify: + while (XCheckTypedWindowEvent(w->dpy, w->w, ConfigureNotify, e)); + runes_window_backend_resize_window( + t, e->xconfigure.width, e->xconfigure.height); + break; case ClientMessage: { Atom a = e->xclient.data.l[0]; if (a == w->atoms[RUNES_ATOM_WM_DELETE_WINDOW]) { @@ -287,3 +294,14 @@ static void runes_window_backend_init_wm_properties( runes_window_backend_set_icon_name(t, "runes", 5); runes_window_backend_set_window_title(t, "runes", 5); } + +static void runes_window_backend_resize_window( + RunesTerm *t, int width, int height) +{ + if (width != t->xpixel || height != t->ypixel) { + cairo_xlib_surface_set_size( + cairo_get_target(t->backend_cr), width, height); + runes_display_set_window_size(t, width, height); + runes_pty_backend_set_window_size(t); + } +} |