desktop-shell: Fix wrong initial position of input panel

When the surface type of input panel is set as an overlay panel, it's
expected to be shown at near the input cursor. But the current
implementation shows it at center-bottom on the desktop at first then
move it to the correct position while typing.

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
dev
Takuro Ashie 3 years ago
parent eb53d7c156
commit beff0bd0f9
  1. 33
      desktop-shell/input-panel.c

@ -59,6 +59,23 @@ input_panel_slide_done(struct weston_view_animation *animation, void *data)
ipsurf->anim = NULL; ipsurf->anim = NULL;
} }
static int
calc_input_panel_position(struct input_panel_surface *ip_surface, float *x, float*y)
{
struct desktop_shell *shell = ip_surface->shell;
if (ip_surface->panel) {
struct weston_view *view = get_default_view(shell->text_input.surface);
if (view == NULL)
return -1;
*x = view->geometry.x + shell->text_input.cursor_rectangle.x2;
*y = view->geometry.y + shell->text_input.cursor_rectangle.y2;
} else {
*x = ip_surface->output->x + (ip_surface->output->width - ip_surface->surface->width) / 2;
*y = ip_surface->output->y + ip_surface->output->height - ip_surface->surface->height;
}
return 0;
}
static void static void
show_input_panel_surface(struct input_panel_surface *ipsurf) show_input_panel_surface(struct input_panel_surface *ipsurf)
{ {
@ -77,8 +94,8 @@ show_input_panel_surface(struct input_panel_surface *ipsurf)
if (!focus) if (!focus)
continue; continue;
ipsurf->output = focus->output; ipsurf->output = focus->output;
x = ipsurf->output->x + (ipsurf->output->width - ipsurf->surface->width) / 2; if (calc_input_panel_position(ipsurf, &x, &y))
y = ipsurf->output->y + ipsurf->output->height - ipsurf->surface->height; continue;
weston_view_set_position(ipsurf->view, x, y); weston_view_set_position(ipsurf->view, x, y);
} }
@ -170,23 +187,13 @@ input_panel_committed(struct weston_surface *surface, int32_t sx, int32_t sy)
{ {
struct input_panel_surface *ip_surface = surface->committed_private; struct input_panel_surface *ip_surface = surface->committed_private;
struct desktop_shell *shell = ip_surface->shell; struct desktop_shell *shell = ip_surface->shell;
struct weston_view *view;
float x, y; float x, y;
if (surface->width == 0) if (surface->width == 0)
return; return;
if (ip_surface->panel) { if (calc_input_panel_position(ip_surface, &x, &y))
view = get_default_view(shell->text_input.surface);
if (view == NULL)
return; return;
x = view->geometry.x + shell->text_input.cursor_rectangle.x2;
y = view->geometry.y + shell->text_input.cursor_rectangle.y2;
} else {
x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2;
y = ip_surface->output->y + ip_surface->output->height - surface->height;
}
weston_view_set_position(ip_surface->view, x, y); weston_view_set_position(ip_surface->view, x, y);
if (!weston_surface_is_mapped(surface) && shell->showing_input_panels) if (!weston_surface_is_mapped(surface) && shell->showing_input_panels)

Loading…
Cancel
Save