examples: update the examples for seats

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-10-26 08:50:37 +10:00
parent 0429ca2491
commit f3a225c757
2 changed files with 40 additions and 21 deletions

View file

@ -3,21 +3,33 @@
function main():
ctx = ei_new()
ei_portal_connect(ctx)
ei_dispatch(ctx)
# let's say this is a blocking wait
event = ei_get_event();
if ei_event_get_type(event) == EI_EVENT_TYPE_DISCONNECT:
if ei_event_get_type(event) == EI_EVENT_DISCONNECT:
print("Sorry, server denied us")
return
if ei_event_get_type(event) == EI_EVENT_CONNECT:
print("We're connected")
# wait for a seat we can attach devices to
# let's assume the seat added event is in the first batch of events
event = ei_get_event();
while our_seat == NULL:
event = ei_get_event();
if ei_event_get_type(event) == EI_EVENT_SEAT_ADDED:
our_seat = ei_event_get_seat(event)
# Could also create one device here with both caps but splitting them
# means they can get suspended independently
ptr = ei_create_device(ctx)
ptr = ei_create_device(our_seat)
ei_device_configure_capability(CAP_POINTER)
ei_device_configure_name("pseudopointer")
ei_device_add(ptr)
kbd = ei_create_device(ctx)
kbd = ei_create_device(our_seat)
ei_device_configure_capability(CAP_KEYBOARD)
ei_device_configure_name("pseudokeyboard");
keymap_fd = compile_keymap("us", "dvorak")
@ -26,17 +38,17 @@ function main():
event = ei_get_event()
device = ei_event_get_device()
if ei_event_get_type(event) == EI_EVENT_TYPE_DEVICE_ADDED:
if ei_event_get_type(event) == EI_EVENT_DEVICE_ADDED:
if device == ptr:
# The server may not use the name we suggested but it does
# tell us the chosen name
print("Pointer was created: %s", ei_device_get_name(device))
else:
print("Keyboard was created: %s", ei_device_get_name(device))
if ei_device_keyboard_get_keymap_source != EI_KEYMAP_SOURCE_CLIENT:
print("Server did not accept our keymap")
# handle the keymap (if not -1)
else if ei_event_get_type(event) == EI_EVENT_TYPE_DEVICE_REMOVED:
if ei_device_keyboard_get_keymap_source != EI_KEYMAP_SOURCE_CLIENT:
print("Server did not accept our keymap")
# handle the keymap (if not -1)
else if ei_event_get_type(event) == EI_EVENT_DEVICE_REMOVED:
if device == ptr:
print("We're not allowed a pointer device")
elif device == kbd:

View file

@ -34,6 +34,13 @@ function event_client_connect(event):
eis_client_connect(client)
myclients[client] = eis_client_ref(client)
# Send a seats out to the client. Could be the list of seats the
# server uses anyway, or custom ones.
seat = eis_client_new_seat(client, "default")
eis_seat_allow_capability(seat, EIS_DEVICE_CAP_POINTER)
eis_seat_allow_capability(seat, EIS_DEVICE_CAP_KEYBOARD)
eis_seat_add(seat)
function event_client_disconnect(event):
client = eis_event_get_client(event)
@ -49,24 +56,24 @@ function event_device_added(event):
return
if disallow_touch_input:
eis_device_disable_capability(EIS_CAP_TOUCH)
eis_device_disable_capability(EIS_DEVICE_CAP_TOUCH)
if eis_device_has_capability(EIS_CAP_POINTER_ABSOLUTE):
if eis_device_has_capability(EIS_DEVICE_CAP_POINTER_ABSOLUTE):
# this is the fixed range give the client. Let's check if there's a
# monitor with those dimensions and map the device to that monitor
# That's a server private implementation detail, just used as
# example here
# monitor with those dimensions and map the device to that monitor
# That's a server private implementation detail, just used as
# example here
w = eis_device_pointer_get_width()
h = eis_device_pointer_get_height()
if (w, h) matches an output:
eis_device_set_user_data(output)
if (w, h) matches an output:
eis_device_set_user_data(output)
if eis_device_has_capability(EIS_CAP_KEYBOARD):
if eis_device_has_capability(EIS_DEVICE_CAP_KEYBOARD):
keymap = eis_device_keyboard_get_keymap()
# We do not implement per-device keymap in this pseudoserver, notify
# the client. If we did, here'd be the place to assign the map.
if keymap != -1:
eis_device_keyboard_set_keymap(device, -1)
# We do not implement per-device keymap in this pseudoserver, notify
# the client. If we did, here'd be the place to assign the map.
if keymap != -1:
eis_device_keyboard_set_keymap(device, -1)
eis_device_connect(device)
# Allow the client to send events
@ -100,7 +107,7 @@ function event_pointer_keyboard_key(event):
# double escape suspends the device, as an example
if press and key == KEY_ESC and last_key == KEY_ESC:
eis_device_suspend()
discard_events = true
discard_events = true
# We may have suspended the client but events can be in mid flight, so
# we need to process all incoming events regardless. libeis will filter