mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2025-12-20 04:30:07 +01:00
This is the outline of the API intended with a minimal compiler just to verify there are no immediate parsing issues.
117 lines
3.4 KiB
Text
117 lines
3.4 KiB
Text
# This is pseudocode, illustrating a libeis server implementation
|
|
#
|
|
# This pseudocode assumes to be part of a compositor that can handle
|
|
# input events. It assumes policy decisions as to whether a client may
|
|
# connect are made in the portal or the compositor.
|
|
#
|
|
|
|
function main():
|
|
ctx = eis_new()
|
|
eis_portal_init(ctx)
|
|
|
|
while True:
|
|
poll(eis_get_fd()):
|
|
event = eis_get_event();
|
|
handler = functions[eis_event_get_type(event)]
|
|
handler(event)
|
|
|
|
for client in myclients:
|
|
eis_client_disconnect(client)
|
|
|
|
eis_unref(ctx)
|
|
|
|
|
|
function event_client_connect(event):
|
|
client = eis_event_get_client(event)
|
|
|
|
if do_not_allow_emulated_input:
|
|
eis_client_disconnect(client)
|
|
return
|
|
|
|
# for the portal backend we're assuming that the client has been
|
|
# authenticated by the user, otherwise some authentication needs to
|
|
# be done here
|
|
eis_client_connect(client)
|
|
myclients[client] = eis_client_ref(client)
|
|
|
|
|
|
function event_client_disconnect(event):
|
|
client = eis_event_get_client(event)
|
|
eis_client_unref(client)
|
|
|
|
|
|
function event_device_added(event):
|
|
client = eis_event_get_client(event)
|
|
device = eis_event_get_device(event)
|
|
|
|
if client has too many devices:
|
|
eis_device_disconnect(device)
|
|
return
|
|
|
|
capabilities = eis_device_get_capabilties()
|
|
if disallow_touch_input:
|
|
capabilities &= ~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)
|
|
|
|
eis_device_connect(device)
|
|
# Allow the client to send events for all capabilities
|
|
eis_device_resume_capability(capabilities)
|
|
|
|
|
|
function event_pointer_motion(event):
|
|
x = eis_event_pointer_get_x(event)
|
|
y = eis_event_pointer_get_y(event)
|
|
compositor_handle_pointer_motion(x, y)
|
|
|
|
|
|
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
|
|
|
|
compositor_handle_pointer_motion_absolute(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
|
|
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
|
|
|
|
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)
|
|
else
|
|
eis_device_suspend_capability(all_caps)
|
|
|
|
|
|
# Compositor callback if no more emulated input should be handled
|
|
# from a specific client
|
|
function compositor_callback_terminate_EI(condition):
|
|
for client in myclients:
|
|
if client matches condition:
|
|
eis_client_disconnect(client)
|