[RFC] shell: modifier bindings configurable

Kristian Hoegsberg hoegsberg at gmail.com
Fri Apr 20 13:58:20 PDT 2012


On Fri, Apr 20, 2012 at 06:54:25PM +0300, Tiago Vignatti wrote:
> Weston under X in Ubuntu has this bad behavior, mixing Unity's key bindings
> with the ones in Weston. So I'd like to see the modifiers configurable on
> Weston.

I like it!

> - I changed two key combination bindings, the rotation and the brightness.
> 
> - would be cool also to make surface_opacity and zoom bindings configurable,
>   But for both it's just awesome to use the vertical scroll, and if we want to
>   make configurable then we would need two modifiers keys in weston.ini

I think we can say that one of them is mod+scroll and the other is
mod+shift+scroll.

> - you see that the binding-modifier key on weston.ini's in under screensaver
>   section, which is quite weird. We probably want to rename that section for
>   something better.

Yeah, that's weird, I moved it to the shell section in a follow on commit.

> -  (BTW, the fact of being opening three times weston.ini in a regular session
>    is not cool either. Ideas?)

Not a big deal.  It's only going to do IO the first time we read it
in.  The alternative would be to parse it into a data structure and
then you could do

  shell->binding_modifier =
	get_int_option(options, "shell", "binding-modifier", MODIFIER_SUPER);

which isn't half bad either.

> this is sensible? Or should I just forget about this all and disable the
> bindings in Ubuntu somehow when doing my hacking?

Yeah, I committed it, with a few changes as described below.

thanks
Kristian

> Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
> ---
>  src/shell.c |   98 +++++++++++++++++++++++++++++++++++++++--------------------
>  weston.ini  |    1 +
>  2 files changed, 66 insertions(+), 33 deletions(-)
> 
> diff --git a/src/shell.c b/src/shell.c
> index e5870b4..ab5e7ff 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -77,6 +77,7 @@ struct desktop_shell {
>  		struct weston_process process;
>  	} screensaver;
>  
> +	uint32_t binding_modifier;
>  	struct weston_surface *debug_repaint_surface;
>  };
>  
> @@ -227,16 +228,34 @@ static void
>  center_on_output(struct weston_surface *surface,
>  		 struct weston_output *output);
>  
> +static uint32_t
> +get_modifier(char *modifier)
> +{
> +	if (!modifier)
> +		return -1;
> +
> +	if (!strcmp("MODIFIER_CTRL", modifier))
> +		return MODIFIER_CTRL;
> +	else if (!strcmp("MODIFIER_ALT", modifier))
> +		return MODIFIER_ALT;
> +	else if (!strcmp("MODIFIER_SUPER", modifier))
> +		return MODIFIER_SUPER;
> +	else
> +		return -1;
> +}
> +
>  static void
>  shell_configuration(struct desktop_shell *shell)
>  {
>  	char *config_file;
>  	char *path = NULL;
>  	int duration = 60;
> +	char *modifier = NULL;
>  
>  	struct config_key saver_keys[] = {
>  		{ "path",       CONFIG_KEY_STRING,  &path },
>  		{ "duration",   CONFIG_KEY_INTEGER, &duration },
> +		{ "binding-modifier",   CONFIG_KEY_STRING, &modifier },
>  	};
>  
>  	struct config_section cs[] = {
> @@ -249,6 +268,9 @@ shell_configuration(struct desktop_shell *shell)
>  
>  	shell->screensaver.path = path;
>  	shell->screensaver.duration = duration;
> +	if (!modifier)
> +		modifier = "MODIFIER_SUPER";
> +	shell->binding_modifier = get_modifier(modifier);
>  }
>  
>  static void
> @@ -2276,7 +2298,7 @@ switcher_key(struct wl_keyboard_grab *grab,
>  	struct weston_input_device *device =
>  		(struct weston_input_device *) grab->input_device;
>  
> -	if ((device->modifier_state & MODIFIER_SUPER) == 0) {
> +	if ((device->modifier_state & switcher->shell->binding_modifier) == 0) {
>  		switcher_destroy(switcher, time);
>  	} else if (key == KEY_TAB && state) {
>  		switcher_next(switcher);
> @@ -2387,6 +2409,47 @@ shell_destroy(struct wl_listener *listener, void *data)
>  	free(shell);
>  }
>  
> +static void
> +shell_add_binding(struct weston_compositor *ec, struct desktop_shell *shell)
> +{
> +	uint32_t mod;
> +
> +	/* fixed bindings */
> +	weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
> +				      MODIFIER_CTRL | MODIFIER_ALT,
> +				      terminate_binding, ec);
> +	weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
> +				      click_to_activate_binding, shell);
> +	weston_compositor_add_binding(ec, 0, 0,
> +				      WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
> +				      MODIFIER_SUPER | MODIFIER_ALT,
> +				      surface_opacity_binding, NULL);
> +	weston_compositor_add_binding(ec, 0, 0,
> +				      WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
> +				      MODIFIER_SUPER, zoom_binding, NULL);
> +
> +	/* configurable bindings */
> +	mod = shell->binding_modifier;
> +	weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, mod,
> +				      move_binding, shell);
> +	weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, mod,
> +				      resize_binding, shell);
> +	weston_compositor_add_binding(ec, 0, BTN_RIGHT, 0, mod,
> +				      rotate_binding, NULL);
> +	weston_compositor_add_binding(ec, KEY_TAB, 0, 0, mod,
> +				      switcher_binding, shell);
> +	weston_compositor_add_binding(ec, KEY_F9, 0, 0, mod,
> +				      backlight_binding, ec);
> +	weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
> +				      backlight_binding, ec);
> +	weston_compositor_add_binding(ec, KEY_F10, 0, 0, mod,
> +				      backlight_binding, ec);
> +	weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
> +				      backlight_binding, ec);
> +	weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, mod,
> +				      debug_repaint_binding, shell);
> +}
> +
>  int
>  shell_init(struct weston_compositor *ec);
>  
> @@ -2440,38 +2503,7 @@ shell_init(struct weston_compositor *ec)
>  	if (launch_desktop_shell_process(shell) != 0)
>  		return -1;
>  
> -	weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, MODIFIER_SUPER,
> -					move_binding, shell);
> -	weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, MODIFIER_SUPER,
> -					resize_binding, shell);
> -	weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
> -					MODIFIER_CTRL | MODIFIER_ALT,
> -					terminate_binding, ec);
> -	weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
> -					click_to_activate_binding, shell);
> -	weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
> -					MODIFIER_SUPER | MODIFIER_ALT,
> -					surface_opacity_binding, NULL);
> -	weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
> -					MODIFIER_SUPER, zoom_binding, NULL);
> -	weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
> -					MODIFIER_SUPER | MODIFIER_ALT,
> -					rotate_binding, NULL);
> -	weston_compositor_add_binding(ec, KEY_TAB, 0, 0, MODIFIER_SUPER,
> -					switcher_binding, shell);
> -
> -	/* brightness */
> -	weston_compositor_add_binding(ec, KEY_F9, 0, 0, MODIFIER_CTRL,
> -					backlight_binding, ec);
> -	weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
> -					backlight_binding, ec);
> -	weston_compositor_add_binding(ec, KEY_F10, 0, 0, MODIFIER_CTRL,
> -					backlight_binding, ec);
> -	weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
> -					backlight_binding, ec);
> -
> -	weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, MODIFIER_SUPER,
> -					debug_repaint_binding, shell);
> +	shell_add_binding(ec, shell);
>  
>  	return 0;
>  }
> diff --git a/weston.ini b/weston.ini
> index 69c7321..197e9b4 100644
> --- a/weston.ini
> +++ b/weston.ini
> @@ -28,4 +28,5 @@ path=./clients/flower
>  [screensaver]
>  #path=./clients/wscreensaver
>  duration=600
> +#binding-modifier=MODIFIER_CTRL
>  
> -- 
> 1.7.5.4
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list