diff options
author | Kristian H. Kristensen <hoegsberg@chromium.org> | 2016-12-07 15:37:15 -0800 |
---|---|---|
committer | Kristian H. Kristensen <hoegsberg@chromium.org> | 2016-12-07 15:37:29 -0800 |
commit | a0ae742ad343de399df4e4a9200b588a096c3b5b (patch) | |
tree | 7b7777f6b5f446b672ed8a017e8b2a084dd26fe4 /input.c | |
parent | d911f1d5ee8be18c7b37816084be81e0d9c7ae41 (diff) |
Diffstat (limited to 'input.c')
-rw-r--r-- | input.c | 604 |
1 files changed, 604 insertions, 0 deletions
@@ -0,0 +1,604 @@ +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include <X11/Xproto.h> +#include <X11/Xlib.h> + +#include "private.h" + +struct csx_seat { + struct wl_seat *seat; + struct wl_pointer *pointer; + struct csx_display *display; + struct csx_window *pointer_focus, *child; + uint32_t button_mask; + int pointer_x, pointer_y; + int window_x, window_y; +}; + +static void +csx_seat_send_crossing_event(struct csx_seat *seat, int type) +{ + struct csx_display *display = seat->display; + struct csx_event *event; + + event = malloc(sizeof *event); + + event->xevent.xcrossing.type = type; + event->xevent.xcrossing.serial = display->serial; + event->xevent.xcrossing.send_event = False; + event->xevent.xcrossing.display = display->xdisplay; + event->xevent.xcrossing.window = seat->child->id; + event->xevent.xcrossing.root = display->root->id; + event->xevent.xcrossing.subwindow = None; + event->xevent.xcrossing.time = 0; + event->xevent.xcrossing.x = seat->window_x; + event->xevent.xcrossing.y = seat->window_y; + event->xevent.xcrossing.x_root = seat->pointer_x; + event->xevent.xcrossing.y_root = seat->pointer_y; + event->xevent.xcrossing.mode = NotifyGrab; + event->xevent.xcrossing.detail = NotifyAncestor; + event->xevent.xcrossing.same_screen = True; + event->xevent.xcrossing.focus = True; + event->xevent.xcrossing.state = 0; /* key or button mask */ + + wl_list_insert(display->event_list.prev, &event->link); +} + +static void +csx_seat_send_button_event(struct csx_seat *seat, + uint32_t time, int button, int type) +{ + struct csx_display *display = seat->display; + struct csx_event *event; + + event = malloc(sizeof *event); + + event->xevent.xbutton.type = type; + event->xevent.xbutton.serial = display->serial; + event->xevent.xbutton.send_event = False; + event->xevent.xbutton.display = display->xdisplay; + event->xevent.xbutton.window = seat->child->id; + event->xevent.xbutton.root = display->root->id; + event->xevent.xbutton.subwindow = None; + event->xevent.xbutton.time = time; + event->xevent.xbutton.x = seat->window_x; + event->xevent.xbutton.y = seat->window_y; + event->xevent.xbutton.x_root = seat->pointer_x; + event->xevent.xbutton.y_root = seat->pointer_y; + event->xevent.xbutton.state = 0; + event->xevent.xbutton.button = button; + event->xevent.xbutton.same_screen = True; + + wl_list_insert(display->event_list.prev, &event->link); +} + +static void +csx_seat_send_motion(struct csx_seat *seat, uint32_t time) +{ + struct csx_display *display = seat->display; + struct csx_event *event; + + event = malloc(sizeof *event); + + event->xevent.xmotion.type = MotionNotify; + event->xevent.xmotion.serial = display->serial; + event->xevent.xmotion.send_event = False; + event->xevent.xmotion.display = display->xdisplay; + event->xevent.xmotion.window = seat->child->id; + event->xevent.xmotion.root = display->root->id; + event->xevent.xmotion.subwindow = None; + event->xevent.xmotion.time = time; + event->xevent.xmotion.x = seat->window_x; + event->xevent.xmotion.y = seat->window_y; + event->xevent.xmotion.x_root = seat->pointer_x; + event->xevent.xmotion.y_root = seat->pointer_y; + event->xevent.xmotion.state = 0; /* key or button mask */ + event->xevent.xmotion.is_hint = 0; /* detail */ + event->xevent.xmotion.same_screen = True; + + wl_list_insert(display->event_list.prev, &event->link); +} + +static void +pointer_handle_enter(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface, + wl_fixed_t x, wl_fixed_t y) +{ + struct csx_seat *seat = data; + struct csx_window *window; + + seat->pointer_focus = wl_surface_get_user_data(surface); + seat->pointer_x = wl_fixed_to_int(x); + seat->pointer_y = wl_fixed_to_int(y); + window = seat->pointer_focus; + seat->child = csx_window_pick(window, seat->pointer_x, seat->pointer_y, + &seat->window_x, &seat->window_y); + if (window->event_mask & EnterWindowMask) + csx_seat_send_crossing_event(seat, EnterNotify); +} + +static void +pointer_handle_leave(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface) +{ + struct csx_seat *seat = data; + struct csx_window *window; + + seat->pointer_focus = wl_surface_get_user_data(surface); + window = seat->pointer_focus; + if (window->event_mask & EnterWindowMask) + csx_seat_send_crossing_event(seat, LeaveNotify); +} + +static void +pointer_handle_motion(void *data, struct wl_pointer *pointer, + uint32_t time, wl_fixed_t x, wl_fixed_t y) +{ + struct csx_seat *seat = data; + struct csx_window *window; + + seat->pointer_x = wl_fixed_to_int(x); + seat->pointer_y = wl_fixed_to_int(y); + window = csx_window_pick(seat->pointer_focus, + seat->pointer_x, seat->pointer_y, + &seat->window_x, &seat->window_y); + + if (seat->child != window) { + if (seat->child->event_mask & LeaveWindowMask) + csx_seat_send_crossing_event(seat, LeaveNotify); + seat->child = window; + if (window->event_mask & EnterWindowMask) + csx_seat_send_crossing_event(seat, EnterNotify); + } + + if ((window->event_mask & PointerMotionMask) && + seat->button_mask == 0) + csx_seat_send_motion(seat, time); + else if ((window->event_mask & Button1MotionMask) && + seat->button_mask == 1) + csx_seat_send_motion(seat, time); +} + +static void +pointer_handle_button(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, uint32_t time, uint32_t button, + uint32_t state) +{ + struct csx_seat *seat = data; + struct csx_window *window; + uint32_t mask; + + mask = 1 << (button - 272); + if (state) + seat->button_mask |= mask; + else + seat->button_mask &= ~mask; + + seat->child = csx_window_pick(seat->pointer_focus, + seat->pointer_x, seat->pointer_y, + &seat->window_x, &seat->window_y); + window = seat->child; + if (state && (window->event_mask & ButtonPressMask)) + csx_seat_send_button_event(seat, time, button, ButtonPress); + else if (!state && (window->event_mask & ButtonPressMask)) + csx_seat_send_button_event(seat, time, button, ButtonRelease); +} + +static void +pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis, wl_fixed_t value) +{ +} + +static const struct wl_pointer_listener pointer_listener = { + pointer_handle_enter, + pointer_handle_leave, + pointer_handle_motion, + pointer_handle_button, + pointer_handle_axis, +}; + +static void +seat_handle_capabilities(void *data, struct wl_seat *wl_seat, + enum wl_seat_capability caps) +{ + struct csx_seat *seat = data; + + if ((caps & WL_SEAT_CAPABILITY_POINTER) && !seat->pointer) { + seat->pointer = wl_seat_get_pointer(seat->seat); + wl_pointer_add_listener(seat->pointer, &pointer_listener, seat); + } +} + +static const struct wl_seat_listener seat_listener = { + seat_handle_capabilities, +}; + +void +csx_display_add_seat(struct csx_display *display, + uint32_t name, uint32_t version) +{ + struct csx_seat *seat; + + seat = malloc(sizeof *seat); + + memset(seat, 0, sizeof *seat); + seat->display = display; + seat->seat = wl_registry_bind(display->registry, name, + &wl_seat_interface, 1); + wl_seat_add_listener(seat->seat, &seat_listener, seat); +} + +WL_EXPORT Bool +XQueryPointer(Display *xdisplay, + Window w, Window *root_return, Window *child_return, + int *root_x, int *root_y, int *win_x, int *win_y, + unsigned int *mask) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_QueryPointer, 0); + + STUB(); + + return 1; +} + +WL_EXPORT XTimeCoord * +XGetMotionEvents(Display *xdisplay, + Window w, Time start, Time stop, int *nevents_return) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetMotionEvents, 0); + + STUB(); + + return NULL; +} + +WL_EXPORT int +XGrabPointer(Display *xdisplay, + Window grab_window, Bool owner_events, unsigned int event_mask, + int pointer_mode, int keyboard_mode, Window confine_to, + Cursor cursor, Time time) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GrabPointer, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XUngrabPointer(Display *xdisplay, Time time) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_UngrabPointer, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGrabButton(Display *xdisplay, + unsigned int button, + unsigned int modifiers, + Window grab_window, + Bool owner_events, + unsigned int event_mask, + int pointer_mode, + int keyboard_mode, + Window confine_to, + Cursor cursor) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GrabButton, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XUngrabButton(Display *xdisplay, + unsigned int button, + unsigned int modifiers, + Window grab_window) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_UngrabButton, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XChangeActivePointerGrab(Display *xdisplay, + unsigned int event_mask, + Cursor cursor, + Time time) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_ChangeActivePointerGrab, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGrabKeyboard(Display *xdisplay, + Window grab_window, + Bool owner_events, + int pointer_mode, + int keyboard_mode, + Time time) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GrabKeyboard, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XUngrabKeyboard(Display *xdisplay, Time time) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_UngrabKeyboard, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGrabKey(Display *xdisplay, + int keycode, + unsigned int modifiers, + Window grab_window, + Bool owner_events, + int pointer_mode, + int keyboard_mode) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GrabKey, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XUngrabKey(Display *xdisplay, + int keycode, unsigned int modifiers, Window grab_window) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_UngrabKey, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XWarpPointer(Display *xdisplay, + Window src_w, + Window dest_w, + int src_x, + int src_y, + unsigned int src_width, + unsigned int src_height, + int dest_x, + int dest_y) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_WarpPointer, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XSetInputFocus(Display *xdisplay, Window focus, int revert_to, Time time) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_SetInputFocus, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGetInputFocus(Display *xdisplay, Window *focus, int *revert_to) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetInputFocus, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XQueryKeymap(Display *xdisplay, char keys[32]) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_QueryKeymap, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XChangeKeyboardMapping(Display *xdisplay, + int first_keycode, int keysyms_per_keycode, + KeySym *keysyms, int num_codes) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_ChangeKeyboardMapping, 0); + + STUB(); + + return 1; +} + +WL_EXPORT KeySym * +XGetKeyboardMapping(Display *xdisplay, + KeyCode first_keycode, + int keycode_count, + int *keysyms_per_keycode) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetKeyboardMapping, 0); + + STUB(); + + return NULL; +} + +WL_EXPORT int +XChangeKeyboardControl(Display *xdisplay, + unsigned long value_mask, + XKeyboardControl* values) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_ChangeKeyboardControl, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGetKeyboardControl(Display *xdisplay, XKeyboardState *values) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetKeyboardControl, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XBell(Display *xdisplay, int percent) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_Bell, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XChangePointerControl(Display *xdisplay, + Bool do_accel, + Bool do_threshold, + int accel_numerator, + int accel_denominator, + int threshold) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_ChangePointerControl, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGetPointerControl(Display *xdisplay, + int* accel_numerator_return, + int* accel_denominator_return, + int* threshold_return) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetPointerControl, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XSetPointerMapping(Display *xdisplay, + const unsigned char *map, int nmap) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_SetPointerMapping, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XGetPointerMapping(Display *xdisplay, unsigned char *map, int nmap) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetPointerMapping, 0); + + STUB(); + + return 1; +} + +WL_EXPORT int +XSetModifierMapping(Display *xdisplay, XModifierKeymap *modmap) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_SetModifierMapping, 0); + + STUB(); + + return 1; +} + +WL_EXPORT XModifierKeymap * +XGetModifierMapping(Display *xdisplay) +{ + struct csx_display *display = csx_display(xdisplay); + + csx_display_enter(display, X_GetModifierMapping, 0); + + STUB(); + + return NULL; +} + |