diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2013-05-16 16:26:45 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2013-05-16 16:26:45 -0400 |
commit | a90d8fcc23877f8e5e698f6bd59921a132213618 (patch) | |
tree | 8f291aa8517b9c4450a850275be6eb61d2a903d6 | |
parent | d9e7644f7c2f319f76de802dc3ae67f2929d2716 (diff) |
Flesh out input events, send CreateNotify
-rw-r--r-- | src/input.c | 77 | ||||
-rw-r--r-- | src/test.c | 13 | ||||
-rw-r--r-- | src/window.c | 27 |
3 files changed, 98 insertions, 19 deletions
diff --git a/src/input.c b/src/input.c index ea092a2..3274fee 100644 --- a/src/input.c +++ b/src/input.c @@ -17,44 +17,85 @@ struct csx_seat { }; void -csx_seat_send_cronssing_event(struct csx_seat *seat, int type) +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.xmap.type = type; - event->xevent.xmap.serial = display->serial; + 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->pointer_focus->id; + event->xevent.xcrossing.root = display->root->id; + event->xevent.xcrossing.subwindow = None; + event->xevent.xcrossing.time = 0; + event->xevent.xcrossing.x = wl_fixed_to_int(seat->pointer_x); + event->xevent.xcrossing.y = wl_fixed_to_int(seat->pointer_y); + event->xevent.xcrossing.x_root = wl_fixed_to_int(seat->pointer_x); + event->xevent.xcrossing.y_root = wl_fixed_to_int(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); } void -csx_seat_send_button_event(struct csx_seat *seat, int button, int type) +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.xmap.type = type; - event->xevent.xmap.serial = display->serial; + 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->pointer_focus->id; + event->xevent.xbutton.root = display->root->id; + event->xevent.xbutton.subwindow = None; + event->xevent.xbutton.time = time; + event->xevent.xbutton.x = wl_fixed_to_int(seat->pointer_x); + event->xevent.xbutton.y = wl_fixed_to_int(seat->pointer_y); + event->xevent.xbutton.x_root = wl_fixed_to_int(seat->pointer_x); + event->xevent.xbutton.y_root = wl_fixed_to_int(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); } void -csx_seat_send_motion(struct csx_seat *seat, - uint32_t time, wl_fixed_t sx, wl_fixed_t sy) +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.xmap.type = MotionNotify; - event->xevent.xmap.serial = display->serial; + 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->pointer_focus->id; + event->xevent.xmotion.root = display->root->id; + event->xevent.xmotion.subwindow = None; + event->xevent.xmotion.time = time; + event->xevent.xmotion.x = wl_fixed_to_int(seat->pointer_x); + event->xevent.xmotion.y = wl_fixed_to_int(seat->pointer_y); + event->xevent.xmotion.x_root = wl_fixed_to_int(seat->pointer_x); + event->xevent.xmotion.y_root = wl_fixed_to_int(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); } @@ -62,15 +103,17 @@ csx_seat_send_motion(struct csx_seat *seat, static void pointer_handle_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, - wl_fixed_t sx, wl_fixed_t sy) + 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 = x; + seat->pointer_y = y; window = seat->pointer_focus; if (window->event_mask & EnterWindowMask) - csx_seat_send_cronssing_event(seat, EnterNotify); + csx_seat_send_crossing_event(seat, EnterNotify); } static void @@ -83,7 +126,7 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer, seat->pointer_focus = wl_surface_get_user_data(surface); window = seat->pointer_focus; if (window->event_mask & EnterWindowMask) - csx_seat_send_cronssing_event(seat, LeaveNotify); + csx_seat_send_crossing_event(seat, LeaveNotify); } static void @@ -98,10 +141,10 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer, seat->pointer_y = y; if ((window->event_mask & PointerMotionMask) && seat->button_mask == 0) - csx_seat_send_motion(seat, time, x, y); + csx_seat_send_motion(seat, time); else if ((window->event_mask & Button1MotionMask) && seat->button_mask == 1) - csx_seat_send_motion(seat, time, x, y); + csx_seat_send_motion(seat, time); } static void @@ -121,9 +164,9 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer, window = seat->pointer_focus; if (state && (window->event_mask & ButtonPressMask)) - csx_seat_send_button_event(seat, button, ButtonPress); + csx_seat_send_button_event(seat, time, button, ButtonPress); else if (!state && (window->event_mask & ButtonPressMask)) - csx_seat_send_button_event(seat, button, ButtonRelease); + csx_seat_send_button_event(seat, time, button, ButtonRelease); } static void @@ -35,6 +35,10 @@ print_event(XEvent *e) printf("got LeaveaNotify event: window %d\n", e->xcrossing.window); break; + case CreateNotify: + printf("got CreateNotify event: window %d, parent %d\n", + e->xcreatewindow.window, e->xcreatewindow.parent); + break; default: printf("got event type %d\n", e->type); break; @@ -59,7 +63,7 @@ run(Display *display) int main(int argc, char *argv[]) { Display *display; - Window win; + Window win, sub; XID root; XSetWindowAttributes attributes; @@ -72,12 +76,17 @@ int main(int argc, char *argv[]) Button1MotionMask | ButtonPressMask | ButtonReleaseMask | + SubstructureNotifyMask | StructureNotifyMask; win = XCreateWindow(display, root, 100, 100, 200, 200, 0, 24, InputOutput, NULL, CWEventMask, &attributes); - printf("created window %d\n", win); + sub = XCreateWindow(display, win, + 50, 50, 100, 100, 0, 24, + InputOutput, NULL, CWEventMask, &attributes); + + printf("created window %d and subwindow %d\n", win, sub); XMapWindow(display, win); XFlush(display); diff --git a/src/window.c b/src/window.c index a379ee5..afd5f2f 100644 --- a/src/window.c +++ b/src/window.c @@ -29,6 +29,30 @@ csx_window_create(struct csx_display *display, struct csx_window *parent) return window; } +void +csx_window_send_create_notify(struct csx_window *window) +{ + struct csx_display *display = window->display; + struct csx_event *event; + + event = malloc(sizeof *event); + + event->xevent.xcreatewindow.type = CreateNotify; + event->xevent.xcreatewindow.serial = display->serial; + event->xevent.xcreatewindow.send_event = False; + event->xevent.xcreatewindow.display = display->xdisplay; + event->xevent.xcreatewindow.parent = window->parent->id; + event->xevent.xcreatewindow.window = window->id; + event->xevent.xcreatewindow.x = window->x; + event->xevent.xcreatewindow.y = window->y; + event->xevent.xcreatewindow.width = window->width; + event->xevent.xcreatewindow.height = window->height; + event->xevent.xcreatewindow.border_width = window->border_width; + event->xevent.xcreatewindow.override_redirect = False; + + wl_list_insert(display->event_list.prev, &event->link); +} + WL_EXPORT Window XCreateWindow(Display *xdisplay, Window xparent, int x, int y, unsigned int width, unsigned int height, @@ -84,6 +108,9 @@ XCreateWindow(Display *xdisplay, Window xparent, int x, int y, } } + if (parent->event_mask & SubstructureNotifyMask) + csx_window_send_create_notify(window); + return window->id; } |