diff options
-rw-r--r-- | display.c | 12 | ||||
-rw-r--r-- | window-xlib.c | 32 | ||||
-rw-r--r-- | window-xlib.h | 3 |
3 files changed, 35 insertions, 12 deletions
@@ -85,7 +85,7 @@ void runes_display_set_window_size(RunesTerm *t, int width, int height) cairo_destroy(old_cr); } - runes_window_backend_flush(t); + runes_window_backend_request_flush(t); } /* note: this uses the backend cairo context because it should be redrawn every @@ -146,7 +146,7 @@ void runes_display_show_string(RunesTerm *t, char *buf, size_t len) /* we have to flush manually because XNextEvent (which normally handles * flushing) will most likely be called again before the keystroke is * handled */ - runes_window_backend_flush(t); + runes_window_backend_request_flush(t); } } @@ -163,7 +163,7 @@ void runes_display_backspace(RunesTerm *t) runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent); cairo_rectangle(t->cr, x, y - ascent, fontx, fonty); cairo_fill(t->cr); - runes_window_backend_flush(t); + runes_window_backend_request_flush(t); cairo_restore(t->cr); runes_display_move_to(t, t->row, t->col); @@ -174,7 +174,7 @@ void runes_display_clear_screen(RunesTerm *t) cairo_save(t->cr); cairo_set_source(t->cr, t->bgcolor); cairo_paint(t->cr); - runes_window_backend_flush(t); + runes_window_backend_request_flush(t); cairo_restore(t->cr); runes_display_move_to(t, t->row, t->col); @@ -196,7 +196,7 @@ void runes_display_clear_screen_forward(RunesTerm *t) 0, y - ascent + fonty, t->xpixel, t->ypixel - y + ascent - fonty); cairo_fill(t->cr); - runes_window_backend_flush(t); + runes_window_backend_request_flush(t); cairo_restore(t->cr); runes_display_move_to(t, t->row, t->col); @@ -213,7 +213,7 @@ void runes_display_kill_line_forward(RunesTerm *t) runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent); cairo_rectangle(t->cr, x, y - ascent, t->xpixel - x, fonty); cairo_fill(t->cr); - runes_window_backend_flush(t); + runes_window_backend_request_flush(t); cairo_restore(t->cr); runes_display_move_to(t, t->row, t->col); diff --git a/window-xlib.c b/window-xlib.c index d89af2e..8320d13 100644 --- a/window-xlib.c +++ b/window-xlib.c @@ -15,7 +15,8 @@ static char *atom_names[RUNES_NUM_ATOMS] = { "_NET_WM_ICON_NAME", "_NET_WM_NAME", "UTF8_STRING", - "WM_PROTOCOLS" + "WM_PROTOCOLS", + "RUNES_FLUSH" }; static void runes_window_backend_get_next_event(uv_work_t *req); @@ -25,6 +26,7 @@ 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); +static void runes_window_backend_flush(RunesTerm *t); void runes_window_backend_init(RunesTerm *t) { @@ -32,6 +34,8 @@ void runes_window_backend_init(RunesTerm *t) unsigned long white; XIM im; + XInitThreads(); + w->dpy = XOpenDisplay(NULL); white = WhitePixel(w->dpy, DefaultScreen(w->dpy)); w->w = XCreateSimpleWindow( @@ -91,12 +95,19 @@ cairo_surface_t *runes_window_backend_surface_create(RunesTerm *t) w->dpy, w->w, vis, attrs.width, attrs.height); } -void runes_window_backend_flush(RunesTerm *t) +void runes_window_backend_request_flush(RunesTerm *t) { - cairo_set_source_surface(t->backend_cr, cairo_get_target(t->cr), 0.0, 0.0); - cairo_paint(t->backend_cr); - runes_display_draw_cursor(t); + XEvent e; + + e.xclient.type = ClientMessage; + e.xclient.window = t->w.w; + e.xclient.format = 32; + e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_RUNES_FLUSH]; + + XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e); + XLockDisplay(t->w.dpy); XFlush(t->w.dpy); + XUnlockDisplay(t->w.dpy); } void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel) @@ -228,6 +239,9 @@ static void runes_window_backend_process_event(uv_work_t *req, int status) e ); } + else if (a == w->atoms[RUNES_ATOM_RUNES_FLUSH]) { + runes_window_backend_flush(t); + } break; } default: @@ -305,3 +319,11 @@ static void runes_window_backend_resize_window( runes_pty_backend_set_window_size(t); } } + +static void runes_window_backend_flush(RunesTerm *t) +{ + cairo_set_source_surface(t->backend_cr, cairo_get_target(t->cr), 0.0, 0.0); + cairo_paint(t->backend_cr); + runes_display_draw_cursor(t); + XFlush(t->w.dpy); +} diff --git a/window-xlib.h b/window-xlib.h index 7c0bf85..edcd24b 100644 --- a/window-xlib.h +++ b/window-xlib.h @@ -12,6 +12,7 @@ enum runes_atoms { RUNES_ATOM_NET_WM_NAME, RUNES_ATOM_UTF8_STRING, RUNES_ATOM_WM_PROTOCOLS, + RUNES_ATOM_RUNES_FLUSH, RUNES_NUM_ATOMS }; @@ -31,7 +32,7 @@ typedef struct { void runes_window_backend_init(RunesTerm *t); void runes_window_backend_loop_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_request_flush(RunesTerm *t); void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel); void runes_window_backend_set_icon_name(RunesTerm *t, char *name, size_t len); void runes_window_backend_set_window_title( |