int state;
int margin;
int fullscreen;
+ int focused;
};
static char *
cairo_t *cr;
cairo_font_extents_t extents;
int i, top_margin, side_margin;
+ double d;
window_get_child_rectangle(terminal->window, &rectangle);
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);
}
}
+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)
{
&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);
int state;
int fullscreen;
struct wl_input_device *grab_device;
+ struct wl_input_device *keyboard_device;
uint32_t name;
uint32_t modifiers;
window_resize_handler_t resize_handler;
window_key_handler_t key_handler;
+ window_keyboard_focus_handler_t keyboard_focus_handler;
void *user_data;
};
uint32_t mod = 0;
uint32_t unicode = 0;
+ if (window->keyboard_device != input_device)
+ return;
+
switch (key) {
case KEY_LEFTSHIFT:
case KEY_RIGHTSHIFT:
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 = {
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)
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,
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