window.c: Handle multiple keyboard foci
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 14 Aug 2012 02:25:53 +0000 (22:25 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 14 Aug 2012 02:28:10 +0000 (22:28 -0400)
Keep a count of number of wl_keyboard focus we have instead of
tracking the more recent wl_keyboard.

clients/terminal.c
clients/window.c
clients/window.h

index aa072cd..7e74db7 100644 (file)
@@ -404,7 +404,6 @@ struct terminal {
        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 @@ terminal_decode_attr(struct terminal *terminal, int row, int col,
        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 @@ redraw_handler(struct widget *widget, void *data)
        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 @@ keyboard_focus_handler(struct window *window,
 {
        struct terminal *terminal = data;
 
-       terminal->focused = (device != NULL);
        window_schedule_redraw(terminal->window);
 }
 
index 4e86f06..dd65328 100644 (file)
@@ -145,7 +145,8 @@ struct window {
        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 @@ window_attach_surface(struct window *window)
        }
 }
 
+int
+window_has_focus(struct window *window)
+{
+       return window->focus_count > 0;
+}
+
 void
 window_flush(struct window *window)
 {
@@ -1514,7 +1521,7 @@ frame_redraw_handler(struct widget *widget, void *data)
 
        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 @@ input_remove_keyboard_focus(struct input *input)
        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 @@ keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
        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 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
 
        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);
index da18932..779bc64 100644 (file)
@@ -205,6 +205,9 @@ window_create_transient(struct display *display, struct window *parent,
 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