window.c: Handle multiple keyboard foci
Keep a count of number of wl_keyboard focus we have instead of
tracking the more recent wl_keyboard.
diff --git a/clients/terminal.c b/clients/terminal.c
index aa072cd..7e74db7 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -404,7 +404,6 @@
struct utf8_state_machine state_machine;
int margin;
int fullscreen;
- int focused;
struct color_scheme *color_scheme;
struct terminal_color color_table[256];
cairo_font_extents_t extents;
@@ -537,7 +536,7 @@
if ((attr.a & ATTRMASK_INVERSE) ||
decoded->attr.s ||
((terminal->mode & MODE_SHOW_CURSOR) &&
- terminal->focused && terminal->row == row &&
+ window_has_focus(terminal->window) && terminal->row == row &&
terminal->column == col)) {
foreground = attr.bg;
background = attr.fg;
@@ -999,7 +998,8 @@
attr.key = ~0;
glyph_run_flush(&run, attr);
- if ((terminal->mode & MODE_SHOW_CURSOR) && !terminal->focused) {
+ if ((terminal->mode & MODE_SHOW_CURSOR) &&
+ !window_has_focus(terminal->window)) {
d = 0.5;
cairo_set_line_width(cr, 1);
@@ -2260,7 +2260,6 @@
{
struct terminal *terminal = data;
- terminal->focused = (device != NULL);
window_schedule_redraw(terminal->window);
}
diff --git a/clients/window.c b/clients/window.c
index 4e86f06..dd65328 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -145,7 +145,8 @@
int resize_needed;
int type;
int transparent;
- struct input *keyboard_device;
+ int focus_count;
+
enum window_buffer_type buffer_type;
cairo_surface_t *cairo_surface;
@@ -769,6 +770,12 @@
}
}
+int
+window_has_focus(struct window *window)
+{
+ return window->focus_count > 0;
+}
+
void
window_flush(struct window *window)
{
@@ -1514,7 +1521,7 @@
cr = cairo_create(window->cairo_surface);
- if (window->keyboard_device)
+ if (window->focus_count)
flags |= THEME_FRAME_ACTIVE;
theme_render_frame(t, cr, widget->allocation.width,
widget->allocation.height, window->title, flags);
@@ -1938,7 +1945,7 @@
if (!window)
return;
- window->keyboard_device = NULL;
+ window->focus_count--;
if (window->keyboard_focus_handler)
(*window->keyboard_focus_handler)(window, NULL,
window->user_data);
@@ -2031,11 +2038,10 @@
input->keyboard_focus = wl_surface_get_user_data(surface);
window = input->keyboard_focus;
- window->keyboard_device = input;
+ window->focus_count++;
if (window->keyboard_focus_handler)
(*window->keyboard_focus_handler)(window,
- window->keyboard_device,
- window->user_data);
+ input, window->user_data);
}
static void
@@ -2064,7 +2070,7 @@
input->display->serial = serial;
code = key + 8;
- if (!window || window->keyboard_device != input || !input->xkb.state)
+ if (!window || !input->xkb.state)
return;
num_syms = xkb_key_get_syms(input->xkb.state, code, &syms);
diff --git a/clients/window.h b/clients/window.h
index da18932..779bc64 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -205,6 +205,9 @@
struct window *
window_create_custom(struct display *display);
+int
+window_has_focus(struct window *window);
+
typedef void (*menu_func_t)(struct window *window, int index, void *data);
void