From: Kristian Høgsberg Date: Mon, 23 Feb 2009 04:01:35 +0000 (-0500) Subject: Paint terminal cursor hollow when focus is lost. X-Git-Tag: 0.85.0~598 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c248cc9b68d8f2850178d6b3a9560ba0669283a;p=platform%2Fupstream%2Fwayland.git Paint terminal cursor hollow when focus is lost. --- diff --git a/terminal.c b/terminal.c index 71c8803..2b1d06b 100644 --- a/terminal.c +++ b/terminal.c @@ -67,6 +67,7 @@ struct terminal { int state; int margin; int fullscreen; + int focused; }; static char * @@ -131,6 +132,7 @@ terminal_draw_contents(struct terminal *terminal) cairo_t *cr; cairo_font_extents_t extents; int i, top_margin, side_margin; + double d; window_get_child_rectangle(terminal->window, &rectangle); @@ -158,13 +160,20 @@ terminal_draw_contents(struct terminal *terminal) cairo_show_text(cr, terminal_get_row(terminal, i)); } - cairo_move_to(cr, side_margin + terminal->column * extents.max_x_advance, - top_margin + terminal->row * extents.height); - cairo_rel_line_to(cr, extents.max_x_advance, 0); - cairo_rel_line_to(cr, 0, extents.height); - cairo_rel_line_to(cr, -extents.max_x_advance, 0); + d = terminal->focused ? 0 : 0.5; + + cairo_set_line_width(cr, 1); + cairo_move_to(cr, side_margin + terminal->column * extents.max_x_advance + d, + top_margin + terminal->row * extents.height + d); + cairo_rel_line_to(cr, extents.max_x_advance - 2 * d, 0); + cairo_rel_line_to(cr, 0, extents.height - 2 * d); + cairo_rel_line_to(cr, -extents.max_x_advance + 2 * d, 0); cairo_close_path(cr); - cairo_fill(cr); + + if (terminal->focused) + cairo_fill(cr); + else + cairo_stroke(cr); cairo_destroy(cr); @@ -449,6 +458,16 @@ key_handler(struct window *window, uint32_t key, uint32_t unicode, } } +static void +keyboard_focus_handler(struct window *window, + struct wl_input_device *device, void *data) +{ + struct terminal *terminal = data; + + terminal->focused = (device != NULL); + terminal_schedule_redraw(terminal); +} + static struct terminal * terminal_create(struct display *display, int fullscreen) { @@ -474,6 +493,8 @@ terminal_create(struct display *display, int fullscreen) &compositor_listener, terminal); window_set_key_handler(terminal->window, key_handler, terminal); + window_set_keyboard_focus_handler(terminal->window, + keyboard_focus_handler, terminal); terminal_draw(terminal); diff --git a/window.c b/window.c index 52ac6e7..b306a23 100644 --- a/window.c +++ b/window.c @@ -59,6 +59,7 @@ struct window { int state; int fullscreen; struct wl_input_device *grab_device; + struct wl_input_device *keyboard_device; uint32_t name; uint32_t modifiers; @@ -66,6 +67,7 @@ struct window { window_resize_handler_t resize_handler; window_key_handler_t key_handler; + window_keyboard_focus_handler_t keyboard_focus_handler; void *user_data; }; @@ -440,6 +442,9 @@ window_handle_key(void *data, struct wl_input_device *input_device, uint32_t mod = 0; uint32_t unicode = 0; + if (window->keyboard_device != input_device) + return; + switch (key) { case KEY_LEFTSHIFT: case KEY_RIGHTSHIFT: @@ -487,6 +492,19 @@ window_handle_keyboard_focus(void *data, struct wl_input_device *input_device, struct wl_surface *surface) { + struct window *window = data; + + if (window->keyboard_device == input_device && surface != window->surface) + window->keyboard_device = NULL; + else if (window->keyboard_device == NULL && surface == window->surface) + window->keyboard_device = input_device; + else + return; + + if (window->keyboard_focus_handler) + (*window->keyboard_focus_handler)(window, + window->keyboard_device, + window->user_data); } static const struct wl_input_device_listener input_device_listener = { @@ -588,6 +606,14 @@ window_set_key_handler(struct window *window, window->user_data = data; } +void +window_set_keyboard_focus_handler(struct window *window, + window_keyboard_focus_handler_t handler, void *data) +{ + window->keyboard_focus_handler = handler; + window->user_data = data; +} + struct window * window_create(struct display *display, const char *title, int32_t x, int32_t y, int32_t width, int32_t height) diff --git a/window.h b/window.h index 28019b2..c483400 100644 --- a/window.h +++ b/window.h @@ -50,6 +50,8 @@ typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, ui typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, void *data); typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode, uint32_t state, uint32_t modifiers, void *data); +typedef void (*window_keyboard_focus_handler_t)(struct window *window, + struct wl_input_device *device, void *data); struct window * window_create(struct display *display, const char *title, @@ -93,4 +95,8 @@ void window_set_key_handler(struct window *window, window_key_handler_t handler, void *data); +void +window_set_keyboard_focus_handler(struct window *window, + window_keyboard_focus_handler_t handler, + void *data); #endif