keyboard: Only set toplevel when there is a valid output

Currently, the keyboard client is created and the input
panel surface is set as toplevel on the first output it
finds. This does not work in a scenario when there are
no outputs, resulting in weston-keyboard to crash at
startup due to operating on an invalid output pointer.

This makes input panel toplevel setting depend on a
valid output, and if there was no output present at
startup, it will be set toplevel as soon as an output
gets plugged in.

v2:

- Remove dependency on output pointer at startup
- Only setup output_configure_handler after the
  keyboard has been created
- Let the output_configure_handler handle toplevel
  setting in all cases

Signed-off-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
[Pekka: fixed a line break]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Armin Krezović 9 years ago committed by Pekka Paalanen
parent 70487cd404
commit ea0316a54c
  1. 42
      clients/keyboard.c

@ -24,6 +24,7 @@
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -56,6 +57,7 @@ struct virtual_keyboard {
char *surrounding_text;
uint32_t surrounding_cursor;
struct keyboard *keyboard;
bool toplevel;
};
enum key_type {
@ -953,11 +955,34 @@ global_handler(struct display *display, uint32_t name,
}
static void
keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard)
set_toplevel(struct output *output, struct virtual_keyboard *virtual_keyboard)
{
struct zwp_input_panel_surface_v1 *ips;
struct keyboard *keyboard = virtual_keyboard->keyboard;
ips = zwp_input_panel_v1_get_input_panel_surface(virtual_keyboard->input_panel,
window_get_wl_surface(keyboard->window));
zwp_input_panel_surface_v1_set_toplevel(ips,
output_get_wl_output(output),
ZWP_INPUT_PANEL_SURFACE_V1_POSITION_CENTER_BOTTOM);
virtual_keyboard->toplevel = true;
}
static void
display_output_handler(struct output *output, void *data) {
struct virtual_keyboard *keyboard = data;
if (!keyboard->toplevel)
set_toplevel(output, keyboard);
}
static void
keyboard_create(struct virtual_keyboard *virtual_keyboard)
{
struct keyboard *keyboard;
const struct layout *layout;
struct zwp_input_panel_surface_v1 *ips;
layout = get_current_layout(virtual_keyboard);
@ -981,20 +1006,14 @@ keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard
layout->columns * key_width,
layout->rows * key_height);
ips = zwp_input_panel_v1_get_input_panel_surface(virtual_keyboard->input_panel,
window_get_wl_surface(keyboard->window));
zwp_input_panel_surface_v1_set_toplevel(ips,
output_get_wl_output(output),
ZWP_INPUT_PANEL_SURFACE_V1_POSITION_CENTER_BOTTOM);
display_set_output_configure_handler(virtual_keyboard->display,
display_output_handler);
}
int
main(int argc, char *argv[])
{
struct virtual_keyboard virtual_keyboard;
struct output *output;
memset(&virtual_keyboard, 0, sizeof virtual_keyboard);
@ -1012,8 +1031,7 @@ main(int argc, char *argv[])
return -1;
}
output = display_get_output(virtual_keyboard.display);
keyboard_create(output, &virtual_keyboard);
keyboard_create(&virtual_keyboard);
display_run(virtual_keyboard.display);

Loading…
Cancel
Save