terminal: clear unused margins on each frame
authorDavid Herrmann <dh.herrmann@gmail.com>
Sat, 9 Mar 2013 12:47:00 +0000 (13:47 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Sat, 9 Mar 2013 12:47:00 +0000 (13:47 +0100)
If the terminal screen is smaller than the real screen, we never paint to
the margins. This doesn't hurt as long as we never resize the terminal.
The uterm layer clears all framebuffers during allocation.

However, uterm behavior may change and our terminal may get resized (eg.,
during hotplugging) so we really should clear all the margins.

We now clear them on every frame as it is a trivial task. However, if we
speed up rendering, we should probably set a "needs_clear" flag that
simply clears the framebuffer.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
src/kmscon_terminal.c

index e476df6..d917fc7 100644 (file)
@@ -85,6 +85,33 @@ struct kmscon_terminal {
        struct kmscon_font *bold_font;
 };
 
+static void do_clear_margins(struct screen *scr)
+{
+       unsigned int w, h, sw, sh;
+       struct uterm_mode *mode;
+       int dw, dh;
+
+       mode = uterm_display_get_current(scr->disp);
+       if (!mode)
+               return;
+
+       sw = uterm_mode_get_width(mode);
+       sh = uterm_mode_get_height(mode);
+       w = scr->txt->font->attr.width * scr->txt->cols;
+       h = scr->txt->font->attr.height * scr->txt->rows;
+       dw = sw - w;
+       dh = sh - h;
+
+       if (dw > 0)
+               uterm_display_fill(scr->disp, 0, 0, 0,
+                                  w, 0,
+                                  dw, h);
+       if (dh > 0)
+               uterm_display_fill(scr->disp, 0, 0, 0,
+                                  0, h,
+                                  sw, dh);
+}
+
 static void do_redraw_screen(struct screen *scr)
 {
        int ret;
@@ -93,6 +120,7 @@ static void do_redraw_screen(struct screen *scr)
                return;
 
        scr->pending = false;
+       do_clear_margins(scr);
        tsm_screen_draw(scr->term->console, kmscon_text_prepare_cb,
                        kmscon_text_draw_cb, kmscon_text_render_cb, scr->txt);
        ret = uterm_display_swap(scr->disp, false);