mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-02 10:58:01 +02:00
examples: update for the latest API changes
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
1fea949114
commit
5ba5f7d015
2 changed files with 52 additions and 31 deletions
|
|
@ -10,11 +10,19 @@ function main():
|
|||
print("Sorry, server denied us")
|
||||
return
|
||||
|
||||
# Could also create one device here with both caps
|
||||
ptr = ei_create_device(ctx, CAP_POINTER, "pseudopointer");
|
||||
kbd = ei_create_device(ctx, CAP_KEYBOARD, "pseudokeyboard");
|
||||
# Could also create one device here with both caps but splitting them
|
||||
# means they can get suspended independently
|
||||
ptr = ei_create_device(ctx)
|
||||
ei_device_configure_capability(CAP_POINTER)
|
||||
ei_device_configure_name("pseudopointer")
|
||||
ei_device_add(ptr)
|
||||
|
||||
kbd = ei_create_device(ctx)
|
||||
ei_device_configure_capability(CAP_KEYBOARD)
|
||||
ei_device_configure_name("pseudokeyboard");
|
||||
keymap_fd = compile_keymap("us", "dvorak")
|
||||
ei_device_keyboard_set_keymap(kbd, FORMAT_XKB, keymap_fd);
|
||||
ei_device_configure_keymap(kbd, FORMAT_XKB, keymap_fd);
|
||||
ei_device_add(kbd)
|
||||
|
||||
event = ei_get_event()
|
||||
device = ei_event_get_device()
|
||||
|
|
@ -25,6 +33,9 @@ function main():
|
|||
print("Pointer was created: %s", ei_device_get_name(device))
|
||||
else:
|
||||
print("Keyboard was created: %s", ei_device_get_name(device))
|
||||
if ei_device_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 device == ptr:
|
||||
print("We're not allowed a pointer device")
|
||||
|
|
@ -38,8 +49,8 @@ function main():
|
|||
while True:
|
||||
poll(ei_get_fd()):
|
||||
if suspended:
|
||||
wait_for_event(EI_EVENT_POINTER_RESUME or
|
||||
EI_EVENT_KEYBOARD_RESUME)
|
||||
wait_for_event(EI_EVENT_DEVICE_RESUMED)
|
||||
wait_for_event(EI_EVENT_DEVICE_RESUMED)
|
||||
suspended = False
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -48,19 +48,29 @@ function event_device_added(event):
|
|||
eis_device_disconnect(device)
|
||||
return
|
||||
|
||||
capabilities = eis_device_get_capabilties()
|
||||
if disallow_touch_input:
|
||||
capabilities &= ~EIS_CAP_TOUCH
|
||||
eis_device_disable_capability(EIS_CAP_TOUCH)
|
||||
|
||||
if capabilities & EIS_CAP_POINTER_ABSOLUTE:
|
||||
# this is the fixed range we give the client, actual screen
|
||||
# mapping is performed by us later
|
||||
eis_device_pointer_set_width(1024)
|
||||
eis_device_pointer_set_height(768)
|
||||
if eis_device_has_capability(EIS_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
|
||||
w = eis_device_get_pointer_width()
|
||||
h = eis_device_get_pointer_height()
|
||||
if (w, h) matches an output:
|
||||
eis_device_set_user_data(output)
|
||||
|
||||
if eis_device_has_capability(EIS_CAP_KEYBOARD):
|
||||
keymap = eis_device_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_set_keymap(device, -1)
|
||||
|
||||
eis_device_connect(device)
|
||||
# Allow the client to send events for all capabilities
|
||||
eis_device_resume_capability(capabilities)
|
||||
# Allow the client to send events
|
||||
eis_device_resume(capabilities)
|
||||
|
||||
|
||||
function event_pointer_motion(event):
|
||||
|
|
@ -73,40 +83,40 @@ function event_pointer_motion_absolute(event):
|
|||
x = eis_event_pointer_get_absolute_x(event)
|
||||
y = eis_event_pointer_get_absolute_y(event)
|
||||
|
||||
screen = compositor_get_screen()
|
||||
sx = x/1024 * screen->width
|
||||
sy = y/768 * screen->height
|
||||
# the output we map to, see event_device_added
|
||||
output = eis_device_get_userdata()
|
||||
sx = x/1000
|
||||
sy = y/1000
|
||||
|
||||
compositor_handle_pointer_motion_absolute(sx, sy)
|
||||
compositor_handle_pointer_motion_absolute(output, sx, sy)
|
||||
|
||||
|
||||
function event_pointer_keyboard_key(event):
|
||||
device = eis_event_get_device(event)
|
||||
keymap = eis_device_keyboard_get_keymap(device)
|
||||
# do some libxkbcommon stuff if need be, or send the keymap down the
|
||||
# wire
|
||||
|
||||
key = eis_event_keyboard_get_key(event)
|
||||
press = eis_event_keyboard_get_key_is_press(event)
|
||||
|
||||
# double escape toggles pointer input, as an example
|
||||
# double escape suspends the device, as an example
|
||||
if press and key == KEY_ESC and last_key == KEY_ESC:
|
||||
if pointer_is_suspended:
|
||||
eis_device_resume_capability(EIS_CAP_POINTER_ABSOLUTE|EIS_CAP_POINTER)
|
||||
else
|
||||
eis_device_suspend_capability(EIS_CAP_POINTER_ABSOLUTE|EIS_CAP_POINTER)
|
||||
return
|
||||
eis_device_suspend()
|
||||
discard_events = true
|
||||
|
||||
compositor_handle_key(key, press)
|
||||
# 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
|
||||
# only once the client has received the suspend notification.
|
||||
update_client_key_state(key, press)
|
||||
if not discard_events:
|
||||
compositor_handle_key(key, press)
|
||||
|
||||
|
||||
function compositor_vt_switch_callback():
|
||||
for client in myclients:
|
||||
for device in devices[client]:
|
||||
if vt_in:
|
||||
eis_device_resume_capability(all_caps)
|
||||
eis_device_resume(device)
|
||||
else
|
||||
eis_device_suspend_capability(all_caps)
|
||||
eis_device_suspend(device)
|
||||
|
||||
|
||||
# Compositor callback if no more emulated input should be handled
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue