Paint terminal cursor hollow when focus is lost.

dev
Kristian Høgsberg 16 years ago
parent 0208ed4c79
commit 3c248cc9b6
  1. 33
      terminal.c
  2. 26
      window.c
  3. 6
      window.h

@ -67,6 +67,7 @@ struct terminal {
int state; int state;
int margin; int margin;
int fullscreen; int fullscreen;
int focused;
}; };
static char * static char *
@ -131,6 +132,7 @@ terminal_draw_contents(struct terminal *terminal)
cairo_t *cr; cairo_t *cr;
cairo_font_extents_t extents; cairo_font_extents_t extents;
int i, top_margin, side_margin; int i, top_margin, side_margin;
double d;
window_get_child_rectangle(terminal->window, &rectangle); 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_show_text(cr, terminal_get_row(terminal, i));
} }
cairo_move_to(cr, side_margin + terminal->column * extents.max_x_advance, d = terminal->focused ? 0 : 0.5;
top_margin + terminal->row * extents.height);
cairo_rel_line_to(cr, extents.max_x_advance, 0); cairo_set_line_width(cr, 1);
cairo_rel_line_to(cr, 0, extents.height); cairo_move_to(cr, side_margin + terminal->column * extents.max_x_advance + d,
cairo_rel_line_to(cr, -extents.max_x_advance, 0); 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_close_path(cr);
cairo_fill(cr);
if (terminal->focused)
cairo_fill(cr);
else
cairo_stroke(cr);
cairo_destroy(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 * static struct terminal *
terminal_create(struct display *display, int fullscreen) terminal_create(struct display *display, int fullscreen)
{ {
@ -474,6 +493,8 @@ terminal_create(struct display *display, int fullscreen)
&compositor_listener, terminal); &compositor_listener, terminal);
window_set_key_handler(terminal->window, key_handler, terminal); window_set_key_handler(terminal->window, key_handler, terminal);
window_set_keyboard_focus_handler(terminal->window,
keyboard_focus_handler, terminal);
terminal_draw(terminal); terminal_draw(terminal);

@ -59,6 +59,7 @@ struct window {
int state; int state;
int fullscreen; int fullscreen;
struct wl_input_device *grab_device; struct wl_input_device *grab_device;
struct wl_input_device *keyboard_device;
uint32_t name; uint32_t name;
uint32_t modifiers; uint32_t modifiers;
@ -66,6 +67,7 @@ struct window {
window_resize_handler_t resize_handler; window_resize_handler_t resize_handler;
window_key_handler_t key_handler; window_key_handler_t key_handler;
window_keyboard_focus_handler_t keyboard_focus_handler;
void *user_data; void *user_data;
}; };
@ -440,6 +442,9 @@ window_handle_key(void *data, struct wl_input_device *input_device,
uint32_t mod = 0; uint32_t mod = 0;
uint32_t unicode = 0; uint32_t unicode = 0;
if (window->keyboard_device != input_device)
return;
switch (key) { switch (key) {
case KEY_LEFTSHIFT: case KEY_LEFTSHIFT:
case KEY_RIGHTSHIFT: case KEY_RIGHTSHIFT:
@ -487,6 +492,19 @@ window_handle_keyboard_focus(void *data,
struct wl_input_device *input_device, struct wl_input_device *input_device,
struct wl_surface *surface) 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 = { 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; 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 * struct window *
window_create(struct display *display, const char *title, window_create(struct display *display, const char *title,
int32_t x, int32_t y, int32_t width, int32_t height) int32_t x, int32_t y, int32_t width, int32_t height)

@ -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_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, typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode,
uint32_t state, uint32_t modifiers, void *data); 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 * struct window *
window_create(struct display *display, const char *title, window_create(struct display *display, const char *title,
@ -93,4 +95,8 @@ void
window_set_key_handler(struct window *window, window_set_key_handler(struct window *window,
window_key_handler_t handler, void *data); 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 #endif

Loading…
Cancel
Save