[PATCH v2 1/3] keyboard: fix to make it work in the presence of multiple seats

Jan Arne Petersen jpetersen at openismus.com
Mon Aug 13 14:51:14 PDT 2012


On 08/13/2012 02:35 PM, Philipp Brüschweiler wrote:
> Multiple seats imply multiple input methods. Each input method is now
> held in a keyboard_input_method struct. On a button click, a commit is
> sent to each input method.

Yes, that looks good.

> ---
>  clients/keyboard.c | 44 +++++++++++++++++++++++++++++++++++---------
>  1 Datei geändert, 35 Zeilen hinzugefügt(+), 9 Zeilen entfernt(-)
> 
> diff --git a/clients/keyboard.c b/clients/keyboard.c
> index 9fdd8cc..293c182 100644
> --- a/clients/keyboard.c
> +++ b/clients/keyboard.c
> @@ -33,11 +33,12 @@
>  
>  struct virtual_keyboard {
>  	struct input_panel *input_panel;
> -	struct input_method *input_method;
>  	struct display *display;
> +
> +	struct wl_list input_methods;
>  };
>  
> -struct keyboard {
> +struct keyboard_window {
>  	struct virtual_keyboard *keyboard;
>  	struct window *window;
>  	struct widget *widget;
> @@ -45,10 +46,17 @@ struct keyboard {
>  	int cy;
>  };
>  
> +struct keyboard_input_method {
> +	struct virtual_keyboard *keyboard;
> +	struct input_method *input_method;
> +
> +	struct wl_list link;
> +};
> +
>  static void
>  redraw_handler(struct widget *widget, void *data)
>  {
> -	struct keyboard *keyboard = data;
> +	struct keyboard_window *keyboard = data;
>  	cairo_surface_t *surface;
>  	struct rectangle allocation;
>  	cairo_t *cr;
> @@ -112,7 +120,8 @@ button_handler(struct widget *widget,
>  	       uint32_t button,
>  	       enum wl_pointer_button_state state, void *data)
>  {
> -	struct keyboard *keyboard = data;
> +	struct keyboard_window *keyboard = data;
> +	struct keyboard_input_method *im;
>  	struct rectangle allocation;
>  	int32_t x, y;	
>  	char text[] = { '0', '\0' };
> @@ -129,28 +138,43 @@ button_handler(struct widget *widget,
>  
>  	text[0] = y / keyboard->cy * 10 + x / keyboard->cx + '0';
>  
> -	input_method_commit_string(keyboard->keyboard->input_method, text, -1);
> +	wl_list_for_each(im, &keyboard->keyboard->input_methods, link)
> +		input_method_commit_string(im->input_method, text, -1);
>  
>  	widget_schedule_redraw(widget);
>  }
>  
>  static void
> +keyboard_input_method_create(struct virtual_keyboard *keyboard,
> +			     struct input_method *input_method)
> +{
> +	struct keyboard_input_method *im = malloc(sizeof *im);
> +	im->keyboard = keyboard;
> +	im->input_method = input_method;
> +
> +	wl_list_insert(&keyboard->input_methods, &im->link);
> +}
> +
> +static void
>  global_handler(struct wl_display *display, uint32_t id,
>  	       const char *interface, uint32_t version, void *data)
>  {
>  	struct virtual_keyboard *keyboard = data;
> +	struct input_method *input_method;
>  
>  	if (!strcmp(interface, "input_panel")) {
>  		keyboard->input_panel = wl_display_bind(display, id, &input_panel_interface);
>  	} else if (!strcmp(interface, "input_method")) {
> -		keyboard->input_method = wl_display_bind(display, id, &input_method_interface);
> +		input_method = wl_display_bind(display, id, &input_method_interface);
> +		keyboard_input_method_create(keyboard, input_method);
>  	}
>  }
>  
>  static void
> -keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard)
> +keyboard_window_create(struct output *output,
> +		       struct virtual_keyboard *virtual_keyboard)
>  {
> -	struct keyboard *keyboard;
> +	struct keyboard_window *keyboard;
>  
>  	keyboard = malloc(sizeof *keyboard);
>  	memset(keyboard, 0, sizeof *keyboard);
> @@ -187,7 +211,7 @@ handle_output_configure(struct output *output, void *data)
>  
>  	output_set_user_data(output, virtual_keyboard);
>  
> -	keyboard_create(output, virtual_keyboard);
> +	keyboard_window_create(output, virtual_keyboard);
>  }
>  
>  int
> @@ -201,6 +225,8 @@ main(int argc, char *argv[])
>  		return -1;
>  	}
>  
> +	wl_list_init(&virtual_keyboard.input_methods);
> +
>  	wl_display_add_global_listener(display_get_display(virtual_keyboard.display),
>  				       global_handler, &virtual_keyboard);
>  
> 



More information about the wayland-devel mailing list