terminal: Window size ioctls
authorCallum Lowcay <callum@callumscode.com>
Fri, 7 Jan 2011 19:46:56 +0000 (19:46 +0000)
committerKristian Høgsberg <krh@bitplanet.net>
Sat, 8 Jan 2011 20:15:09 +0000 (15:15 -0500)
Use TIOCSWINSZ ioctl to set window size on terminal resize.
This causes applications to be notified of the resize event.

Signed-off-by: Callum Lowcay <callum@callumscode.com>
clients/terminal.c

index 6864967..3c7be25 100644 (file)
@@ -268,6 +268,8 @@ terminal_resize(struct terminal *terminal, int width, int height)
        struct attr *data_attr;
        int data_pitch, attr_pitch;
        int i, l, total_rows, start;
+       struct rectangle rectangle;
+       struct winsize ws;
 
        if (terminal->width == width && terminal->height == height)
                return;
@@ -318,6 +320,22 @@ terminal_resize(struct terminal *terminal, int width, int height)
        if (terminal->column >= terminal->width)
                terminal->column = terminal->width - 1;
        terminal->start = 0;
+       
+       if (!terminal->fullscreen) {
+               rectangle.width = terminal->width *
+                       terminal->extents.max_x_advance + 2 * terminal->margin;
+               rectangle.height = terminal->height *
+                       terminal->extents.height + 2 * terminal->margin;
+               window_set_child_size(terminal->window, &rectangle);
+       }
+
+       /* Update the window size */
+       ws.ws_row = terminal->height;
+       ws.ws_col = terminal->width;
+       window_get_child_rectangle(terminal->window, &rectangle);
+       ws.ws_xpixel = rectangle.width;
+       ws.ws_ypixel = rectangle.height;
+       ioctl(terminal->master, TIOCSWINSZ, &ws);
 }
 
 struct color_scheme DEFAULT_COLORS = {
@@ -480,14 +498,6 @@ terminal_draw(struct terminal *terminal)
                (int32_t) terminal->extents.height;
        terminal_resize(terminal, width, height);
 
-       if (!terminal->fullscreen) {
-               rectangle.width = terminal->width *
-                       terminal->extents.max_x_advance + 2 * terminal->margin;
-               rectangle.height = terminal->height *
-                       terminal->extents.height + 2 * terminal->margin;
-               window_set_child_size(terminal->window, &rectangle);
-       }
-
        window_draw(terminal->window);
        terminal_draw_contents(terminal);
        window_flush(terminal->window);
@@ -893,6 +903,7 @@ terminal_create(struct display *display, int fullscreen)
        cairo_destroy(cr);
        cairo_surface_destroy(surface);
 
+       terminal_resize(terminal, 80, 24);
        terminal_draw(terminal);
 
        return terminal;