aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-09 22:33:51 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-09 22:33:51 -0400
commitbf64776864715f5fd707883625b40e61343e3df2 (patch)
tree3c436c74e02a8a72759d59797c8fcd1732691822
parente9a9a54540ec467a5435c0b16fe2d9692e22cf7a (diff)
downloadrunes-bf64776864715f5fd707883625b40e61343e3df2.tar.gz
runes-bf64776864715f5fd707883625b40e61343e3df2.zip
handle setting the terminal size properly
-rw-r--r--display.c33
-rw-r--r--display.h1
-rw-r--r--pty-unix.c13
-rw-r--r--pty-unix.h1
-rw-r--r--window-xlib.c9
-rw-r--r--window-xlib.h1
6 files changed, 56 insertions, 2 deletions
diff --git a/display.c b/display.c
index 9f3a756..c9fbad9 100644
--- a/display.c
+++ b/display.c
@@ -4,14 +4,43 @@
void runes_display_init(RunesTerm *t)
{
+ cairo_font_extents_t extents;
+
cairo_select_font_face(t->cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(t->cr, 14.0);
cairo_set_source_rgb(t->cr, 0.0, 0.0, 1.0);
- cairo_move_to(t->cr, 0.0, 14.0);
+
+ cairo_font_extents(t->cr, &extents);
+ cairo_move_to(t->cr, 0.0, extents.ascent);
+
+ runes_pty_backend_set_window_size(t);
+}
+
+static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, double *fonty)
+{
+ cairo_font_extents_t extents;
+
+ cairo_font_extents(t->cr, &extents);
+
+ *fontx = extents.max_x_advance;
+ *fonty = extents.height;
+}
+
+void runes_display_get_term_size(RunesTerm *t, int *row, int *col, int *xpixel, int *ypixel)
+{
+ double fontx, fonty;
+ runes_window_backend_get_size(t, xpixel, ypixel);
+ runes_display_get_font_dimensions(t, &fontx, &fonty);
+ *row = (int)(*ypixel / fonty);
+ *col = (int)(*xpixel / fontx);
}
void runes_display_glyph(RunesTerm *t, char *buf, size_t len)
{
+ cairo_font_extents_t extents;
+
+ cairo_font_extents(t->cr, &extents);
+
if (len) {
char *nl;
buf[len] = '\0';
@@ -21,7 +50,7 @@ void runes_display_glyph(RunesTerm *t, char *buf, size_t len)
cairo_show_text(t->cr, buf);
buf = nl + 1;
cairo_get_current_point(t->cr, &x, &y);
- cairo_move_to(t->cr, 0.0, y + 14.0);
+ cairo_move_to(t->cr, 0.0, y + extents.height);
}
cairo_show_text(t->cr, buf);
/* we have to flush manually because XNextEvent (which normally handles
diff --git a/display.h b/display.h
index 5651ccb..837032f 100644
--- a/display.h
+++ b/display.h
@@ -2,6 +2,7 @@
#define _RUNES_DISPLAY_H
void runes_display_init(RunesTerm *t);
+void runes_display_get_term_size(RunesTerm *t, int *row, int *col, int *xpixel, int *ypixel);
void runes_display_glyph(RunesTerm *t, char *buf, size_t len);
#endif
diff --git a/pty-unix.c b/pty-unix.c
index 4d27a73..c02b31f 100644
--- a/pty-unix.c
+++ b/pty-unix.c
@@ -44,6 +44,19 @@ void runes_pty_backend_init(RunesTerm *t)
}
}
+void runes_pty_backend_set_window_size(RunesTerm *t)
+{
+ struct winsize size;
+ int row, col, xpixel, ypixel;
+
+ runes_display_get_term_size(t, &row, &col, &xpixel, &ypixel);
+ size.ws_row = row;
+ size.ws_col = col;
+ size.ws_xpixel = xpixel;
+ size.ws_ypixel = ypixel;
+ ioctl(t->pty.master, TIOCSWINSZ, &size);
+}
+
static void runes_read_pty(uv_work_t *req)
{
RunesPtyLoopData *data;
diff --git a/pty-unix.h b/pty-unix.h
index c353c7e..175baa7 100644
--- a/pty-unix.h
+++ b/pty-unix.h
@@ -16,6 +16,7 @@ typedef struct {
} RunesPtyLoopData;
void runes_pty_backend_init(RunesTerm *t);
+void runes_pty_backend_set_window_size(RunesTerm *t);
void runes_pty_backend_loop_init(RunesTerm *t);
void runes_pty_backend_write(RunesTerm *t, char *buf, size_t len);
void runes_pty_backend_request_close(RunesTerm *t);
diff --git a/window-xlib.c b/window-xlib.c
index 0e2deb9..7360dde 100644
--- a/window-xlib.c
+++ b/window-xlib.c
@@ -204,6 +204,15 @@ void runes_window_backend_flush(RunesTerm *t)
XFlush(t->w.dpy);
}
+void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel)
+{
+ cairo_surface_t *surface;
+
+ surface = cairo_get_target(t->cr);
+ *xpixel = cairo_xlib_surface_get_width(surface);
+ *ypixel = cairo_xlib_surface_get_height(surface);
+}
+
void runes_window_backend_request_close(RunesTerm *t)
{
XEvent e;
diff --git a/window-xlib.h b/window-xlib.h
index e8cb0f0..9a4e28f 100644
--- a/window-xlib.h
+++ b/window-xlib.h
@@ -32,6 +32,7 @@ typedef struct {
void runes_window_backend_init(RunesTerm *t, int argc, char *argv[]);
cairo_surface_t *runes_window_backend_surface_create(RunesTerm *t);
void runes_window_backend_flush(RunesTerm *t);
+void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel);
void runes_window_backend_request_close(RunesTerm *t);
void runes_window_backend_cleanup(RunesTerm *t);