[PATCH] shell: Enhance the basic random positioning algorithm

Kristian Høgsberg hoegsberg at gmail.com
Mon Aug 13 06:59:33 PDT 2012


On Mon, Aug 13, 2012 at 02:07:52PM +0100, Rob Bradford wrote:
> From: Rob Bradford <rob at linux.intel.com>
> 
> Place the window in a random position on the output where the first seat with
> a pointer is. When calculating the random position limit the range to the
> area that would ensure that the whole surface is visible. If the surface is
> larger than the output then the surface is placed at the origin of the
> output.

That's a nice improvement indeed.  I've committed it since it's
obviously a step forward, but I think we could use the input region
extents for placement.  There's been talk of a outline region or such,
something to define the "edge" of the window for snapping and
placement, but I haven't yet been able to think of a case where that's
different from the input region.  So we can just use the input region
for now, and if a case for an outline region comes up, we can add that
then.

Kristian

> This change is based on the good work of Scott Moreau <oreaus at gmail.com>
> ---
>  src/shell.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 63 insertions(+), 2 deletions(-)
> 
> diff --git a/src/shell.c b/src/shell.c
> index 87e688c..df4636e 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -2587,6 +2587,68 @@ center_on_output(struct weston_surface *surface, struct weston_output *output)
>  }
>  
>  static void
> +weston_surface_set_initial_position (struct weston_surface *surface,
> +				     struct desktop_shell *shell)
> +{
> +	struct weston_compositor *compositor = shell->compositor;
> +	int ix = 0, iy = 0;
> +	int range_x, range_y;
> +	int dx, dy, x, y, panel_height;
> +	struct weston_output *output, *target_output = NULL;
> +	struct weston_seat *seat;
> +
> +	/* As a heuristic place the new window on the same output as the
> +	 * pointer. Falling back to the output containing 0, 0.
> +	 *
> +	 * TODO: Do something clever for touch too?
> +	 */
> +	wl_list_for_each(seat, &compositor->seat_list, link){
> +		if (seat->has_pointer) {
> +			ix = wl_fixed_to_int(seat->pointer.x);
> +			iy = wl_fixed_to_int(seat->pointer.y);
> +			break;
> +		}
> +	}
> +
> +	wl_list_for_each(output, &compositor->output_list, link){
> +		if (pixman_region32_contains_point(&output->region, ix, iy, NULL)){
> +			target_output = output;
> +			break;
> +		}
> +	}
> +
> +	if (!target_output) {
> +		weston_surface_set_position(surface, 10 + random() % 400,
> +					   10 + random() % 400);
> +		return;
> +	}
> +
> +	/* Valid range within output where the surface will still be onscreen.
> +	 * If this is negative it means that the surface is bigger than
> +	 * output.
> +	 */
> +	panel_height = get_output_panel_height(shell, target_output);
> +	range_x = target_output->current->width - surface->geometry.width;
> +	range_y = (target_output->current->height - panel_height) -
> +		  surface->geometry.height;
> +
> +	if (range_x < 0)
> +		dx = 0;
> +	else
> +		dx = random() % range_x;
> +
> +	if (range_y < 0)
> +		dy = panel_height;
> +	else
> +		dy = panel_height + random() % range_y;
> +
> +	x = target_output->x + dx;
> +	y = target_output->y + dy;
> +
> +	weston_surface_set_position (surface, x, y);
> +}
> +
> +static void
>  map(struct desktop_shell *shell, struct weston_surface *surface,
>      int32_t width, int32_t height, int32_t sx, int32_t sy)
>  {
> @@ -2605,8 +2667,7 @@ map(struct desktop_shell *shell, struct weston_surface *surface,
>  	/* initial positioning, see also configure() */
>  	switch (surface_type) {
>  	case SHELL_SURFACE_TOPLEVEL:
> -		weston_surface_set_position(surface, 10 + random() % 400,
> -					    10 + random() % 400);
> +		weston_surface_set_initial_position(surface, shell);
>  		break;
>  	case SHELL_SURFACE_FULLSCREEN:
>  		center_on_output(surface, shsurf->fullscreen_output);
> -- 
> 1.7.11.2
> 
> _______________________________________________
> 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