diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2013-07-03 02:35:47 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2013-07-03 02:35:47 -0400 |
commit | f16331c8e819be11379566ceaa391b7a1c3e1487 (patch) | |
tree | b9dbab66d50537edb1e17996b0f3f7680e05995a | |
parent | a50cbcf1c476321842c98e7f90c7203e37c05b4e (diff) |
Turn on warnings and fix them, many other fixes
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/display.c | 7 | ||||
-rw-r--r-- | src/input.c | 9 | ||||
-rw-r--r-- | src/pixmap.c | 28 | ||||
-rw-r--r-- | src/private.h | 11 | ||||
-rw-r--r-- | src/resource.c | 2 | ||||
-rw-r--r-- | src/test.c | 30 | ||||
-rw-r--r-- | src/window.c | 118 |
8 files changed, 135 insertions, 74 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 69577e8..7afdd11 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,7 @@ +AM_CFLAGS = -Wall -Wextra -Wno-unused-parameter \ + -Wno-missing-field-initializers -g -fvisibility=hidden \ + -Wstrict-prototypes -Wmissing-prototypes + lib_LTLIBRARIES = libX11-wayland.la libX11_wayland_la_LIBADD = $(CSX_LIBS) diff --git a/src/display.c b/src/display.c index 8a32a96..d5c3bff 100644 --- a/src/display.c +++ b/src/display.c @@ -19,13 +19,14 @@ default_error_handler(Display *xdisplay, XErrorEvent *event) exit(1); } -static XErrorHandler error_handler; +static XErrorHandler error_handler = default_error_handler; void csx_display_enter(struct csx_display *display, int major, int minor) { display->major = major; display->minor = minor; + display->serial++; } void @@ -246,7 +247,7 @@ WL_EXPORT int XCloseDisplay(Display *xdisplay) { struct csx_display *display = csx_display(xdisplay); - int i; + Atom i; if (display->shm) wl_shm_destroy(display->shm); @@ -265,6 +266,8 @@ XCloseDisplay(Display *xdisplay) free(display->atom_map[i]); free(xdisplay); + + return 0; } WL_EXPORT XErrorHandler diff --git a/src/input.c b/src/input.c index 8422d2f..93102ed 100644 --- a/src/input.c +++ b/src/input.c @@ -17,7 +17,7 @@ struct csx_seat { int window_x, window_y; }; -void +static void csx_seat_send_crossing_event(struct csx_seat *seat, int type) { struct csx_display *display = seat->display; @@ -46,7 +46,7 @@ csx_seat_send_crossing_event(struct csx_seat *seat, int type) wl_list_insert(display->event_list.prev, &event->link); } -void +static void csx_seat_send_button_event(struct csx_seat *seat, uint32_t time, int button, int type) { @@ -74,7 +74,7 @@ csx_seat_send_button_event(struct csx_seat *seat, wl_list_insert(display->event_list.prev, &event->link); } -void +static void csx_seat_send_motion(struct csx_seat *seat, uint32_t time) { struct csx_display *display = seat->display; @@ -107,8 +107,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer, wl_fixed_t x, wl_fixed_t y) { struct csx_seat *seat = data; - struct csx_window *window, *child; - int child_x, child_y; + struct csx_window *window; seat->pointer_focus = wl_surface_get_user_data(surface); seat->pointer_x = wl_fixed_to_int(x); diff --git a/src/pixmap.c b/src/pixmap.c index b6f1a94..8c35dff 100644 --- a/src/pixmap.c +++ b/src/pixmap.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include <stdlib.h> #include <unistd.h> #include <fcntl.h> @@ -7,6 +9,7 @@ #include <limits.h> #include <sys/mman.h> +#include <X11/Xproto.h> #include <X11/Xlib.h> #include "private.h" @@ -14,7 +17,6 @@ static void buffer_release(void *data, struct wl_buffer *buffer) { - struct csx_pixmap *pixmap = data; } static const struct wl_buffer_listener buffer_listener = { @@ -26,7 +28,6 @@ create_shm_buffer(struct csx_display *display, struct csx_pixmap *pixmap) { struct wl_shm_pool *pool; int fd, size, stride, i; - void *data; const char *path; char name[PATH_MAX]; uint32_t *p; @@ -53,7 +54,7 @@ create_shm_buffer(struct csx_display *display, struct csx_pixmap *pixmap) pixmap->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) { + if (pixmap->data == MAP_FAILED) { fprintf(stderr, "mmap failed: %m\n"); close(fd); return -1; @@ -84,9 +85,9 @@ csx_pixmap_create(struct csx_display *display, pixmap = malloc(sizeof *pixmap); if (pixmap == NULL) - /* BadAlloc */; + return NULL; - memset(pixmap, 0, sizeof pixmap); + memset(pixmap, 0, sizeof *pixmap); pixmap->width = width; pixmap->height = height; pixmap->depth = depth; @@ -126,14 +127,27 @@ XCreatePixmap(Display *xdisplay, Drawable drawable, void *resource; Pixmap id; + csx_display_enter(display, X_CreatePixmap, 0); + resource = csx_display_lookup_resource(display, drawable); /* FIXME: Need to check resource type too */ if (resource == NULL) { - /* Raise error */; - return 0; /* need to return valid id */ + csx_display_error(display, drawable, BadDrawable); + return None; + } + + pixmap = csx_pixmap_create(display, width, height, depth); + if (pixmap == NULL) { + csx_display_error(display, drawable, BadAlloc); + return None; } id = csx_display_add_resource(display, pixmap); + if (id == None) { + csx_pixmap_unref(pixmap); + csx_display_error(display, drawable, BadAlloc); + return None; + } return id; } diff --git a/src/private.h b/src/private.h index 27f18de..0f595d3 100644 --- a/src/private.h +++ b/src/private.h @@ -30,8 +30,8 @@ struct csx_display { uint32_t shm_formats; union entry *resource_map; - int resource_size; - int resource_count, free_resource; + uint32_t resource_size; + uint32_t resource_count, free_resource; struct wl_list event_list; @@ -59,7 +59,8 @@ csx_display(Display *display) return (struct csx_display *) ((_XPrivDisplay) display + 1); } -XID cxs_display_add_resource(struct csx_display *display, void *p); +void csx_display_enter(struct csx_display *display, int major, int minor); +XID csx_display_add_resource(struct csx_display *display, void *p); void csx_display_remove_resource(struct csx_display *display, XID id); void *csx_display_lookup_resource(struct csx_display *display, XID id); @@ -73,8 +74,8 @@ struct csx_window { struct csx_window *parent; int x; int y; - unsigned int width; - unsigned int height; + int width; + int height; unsigned int border_width; int depth; unsigned int class; diff --git a/src/resource.c b/src/resource.c index e60632a..38f16be 100644 --- a/src/resource.c +++ b/src/resource.c @@ -30,7 +30,7 @@ csx_display_add_resource(struct csx_display *display, void *p) map = realloc(display->resource_map, size * sizeof *e); if (map == NULL) - abort(); /* FIXME: how do we handle OOM? */ + return None; display->resource_map = map; display->resource_size = size; } @@ -8,45 +8,45 @@ print_event(XEvent *e) { switch (e->type) { case MapNotify: - printf("got MapNotify event: window %d event %d\n", + printf("got MapNotify event: window %lu event %lu\n", e->xmap.window, e->xmap.event); break; case ReparentNotify: - printf("got ReparentNotify event: window %d\n", + printf("got ReparentNotify event: window %lu\n", e->xreparent.window); break; case MotionNotify: - printf("got MotionNotify event: window %d (%d,%d)\n", + printf("got MotionNotify event: window %lu (%d,%d)\n", e->xmotion.window, e->xmotion.x, e->xmotion.y); break; case ButtonPress: - printf("got ButtonPress event: window %d (%d,%d)\n", + printf("got ButtonPress event: window %lu (%d,%d)\n", e->xbutton.window, e->xbutton.x, e->xbutton.y); break; case ButtonRelease: - printf("got ButtonRelease event: window %d (%d,%d)\n", + printf("got ButtonRelease event: window %lu (%d,%d)\n", e->xbutton.window, e->xbutton.x, e->xbutton.y); break; case EnterNotify: - printf("got EnterNotify event: window %d (%d,%d)\n", + printf("got EnterNotify event: window %lu (%d,%d)\n", e->xcrossing.window, e->xcrossing.x, e->xcrossing.y); break; case LeaveNotify: - printf("got LeaveaNotify event: window %d\n", + printf("got LeaveaNotify event: window %lu\n", e->xcrossing.window); break; case CreateNotify: - printf("got CreateNotify event: window %d, parent %d\n", + printf("got CreateNotify event: window %lu, parent %lu\n", e->xcreatewindow.window, e->xcreatewindow.parent); break; case Expose: - printf("got Expose event: window %d at %d,%d size %dx%d\n", + printf("got Expose event: window %lu at %d,%d size %dx%d\n", e->xexpose.window, e->xexpose.x, e->xexpose.y, e->xexpose.width, e->xexpose.height); break; case ConfigureNotify: - printf("got ConfigureNotify event: window %d event %d at %d,%d size %dx%d\n", + printf("got ConfigureNotify event: window %lu event %lu at %d,%d size %dx%d\n", e->xconfigure.window, e->xconfigure.event, e->xconfigure.x, e->xconfigure.y, e->xconfigure.width, e->xconfigure.height); @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) display = XOpenDisplay(NULL); root = XRootWindow(display, 0); - printf("opened display %p, root window is %d\n", display, root); + printf("opened display %p, root window is %lu\n", display, root); attributes.event_mask = ExposureMask | LeaveWindowMask | @@ -99,14 +99,14 @@ int main(int argc, char *argv[]) 50, 50, 100, 100, 0, 24, InputOutput, NULL, CWEventMask, &attributes); - printf("created window %d and subwindow %d\n", win, sub); + printf("created window %lu and subwindow %lu\n", win, sub); atom = XInternAtom(display, "FOO", False); - printf("FOO atom is %u\n", atom); + printf("FOO atom is %lu\n", atom); atom = XInternAtom(display, "BAR", False); - printf("BAR atom is %u\n", atom); + printf("BAR atom is %lu\n", atom); atom = XInternAtom(display, "WINDOW", False); - printf("WINDOW atom is %u\n", atom); + printf("WINDOW atom is %lu\n", atom); XMapWindow(display, win); diff --git a/src/window.c b/src/window.c index 914efdf..d438555 100644 --- a/src/window.c +++ b/src/window.c @@ -39,7 +39,7 @@ csx_window_pick(struct csx_window *window, struct csx_window *w; wl_list_for_each(w, &window->child_list, link) { - if (w->mapped && w->x <= x & w->y <= y && + if (w->mapped && w->x <= x && w->y <= y && x < w->x + w->width && y < w->y + w->height) return csx_window_pick(w, x - w->x, y - w->y, local_x, local_y); @@ -51,7 +51,7 @@ csx_window_pick(struct csx_window *window, return window; } -void +static void csx_window_send_create_notify(struct csx_window *window) { struct csx_display *display = window->display; @@ -75,6 +75,25 @@ csx_window_send_create_notify(struct csx_window *window) wl_list_insert(display->event_list.prev, &event->link); } +static void +csx_window_send_destroy_notify(struct csx_window *window, + struct csx_window *event_window) +{ + struct csx_display *display = window->display; + struct csx_event *event; + + event = malloc(sizeof *event); + + event->xevent.xdestroywindow.type = DestroyNotify; + event->xevent.xdestroywindow.serial = display->serial; + event->xevent.xdestroywindow.send_event = False; + event->xevent.xdestroywindow.display = display->xdisplay; + event->xevent.xdestroywindow.event = event_window->id; + event->xevent.xdestroywindow.window = window->id; + + 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, @@ -90,8 +109,11 @@ XCreateWindow(Display *xdisplay, Window xparent, int x, int y, csx_display_enter(display, X_CreateWindow, 0); parent = csx_display_lookup_resource(display, xparent); - if (parent == NULL) - /* do something, really */; + if (parent == NULL) { + csx_display_error(display, xparent, BadWindow); + /* FIXME: I'm sure we can't just return None here. */ + return None; + } window = csx_window_create(display, parent); if (window == NULL) { @@ -144,7 +166,6 @@ XCreateSimpleWindow(Display *xdisplay, Window parent, int x, int y, unsigned int border_width, unsigned long border, unsigned long background) { - unsigned long valuemask; XSetWindowAttributes attributes; attributes.background_pixel = background; @@ -178,7 +199,7 @@ static const struct wl_shell_surface_listener shell_surface_listener = { handle_popup_done }; -void +static void csx_window_send_map_notify(struct csx_window *window, struct csx_window *event_window) { @@ -201,7 +222,7 @@ csx_window_send_map_notify(struct csx_window *window, wl_list_insert(display->event_list.prev, &event->link); } -void +static void csx_window_send_expose(struct csx_window *window, pixman_box32_t *rect, int count) { @@ -224,7 +245,7 @@ csx_window_send_expose(struct csx_window *window, wl_list_insert(display->event_list.prev, &event->link); } -void +static void csx_window_calculate_output_clip(struct csx_window *window) { pixman_region32_t output_clip, expose_region; @@ -261,7 +282,7 @@ csx_window_calculate_output_clip(struct csx_window *window) pixman_region32_fini(&output_clip); } -void +static void csx_window_map_tree(struct csx_window *window, struct csx_pixmap *pixmap) { struct csx_window *child; @@ -272,7 +293,7 @@ csx_window_map_tree(struct csx_window *window, struct csx_pixmap *pixmap) window->pixmap = pixmap; } -void +static void csx_window_map_toplevel(struct csx_window *window) { struct csx_display *display = window->display; @@ -303,7 +324,6 @@ XMapWindow(Display *xdisplay, Window xwindow) { struct csx_display *display = csx_display(xdisplay); struct csx_window *window; - struct csx_pixmap *pixmap; csx_display_enter(display, X_MapWindow, 0); @@ -335,11 +355,15 @@ XMapWindow(Display *xdisplay, Window xwindow) } WL_EXPORT int -XMapSubwindows(Display *display, Window xwindow) +XMapSubwindows(Display *xdisplay, Window xwindow) { + struct csx_display *display = csx_display(xdisplay); + csx_display_enter(display, X_MapSubwindows, 0); STUB(); + + return 1; } WL_EXPORT int @@ -354,11 +378,13 @@ XChangeWindowAttributes(Display *xdisplay, Window xwindow, window = csx_display_lookup_resource(display, xwindow); if (window == NULL) { csx_display_error(display, xwindow, BadWindow); - return 0; /* what's the return value? */ + return 1; } + + return 1; } -void +static void csx_window_send_configure_notify(struct csx_window *window, struct csx_window *event_window) { @@ -396,12 +422,12 @@ XConfigureWindow(Display *xdisplay, Window xwindow, window = csx_display_lookup_resource(display, xwindow); if (window == NULL) { csx_display_error(display, xwindow, BadWindow); - return 0; /* what's the return value? */ + return 1; } if ((mask & CWSibling) && !(mask & CWStackMode)) { csx_display_error(display, mask, BadMatch); - return 0; /* what's the return value? */ + return 1; } if (mask & CWX) @@ -425,6 +451,8 @@ XConfigureWindow(Display *xdisplay, Window xwindow, csx_window_send_configure_notify(window, window); if (window->parent && window->parent->event_mask & StructureNotifyMask) csx_window_send_configure_notify(window, window->parent); + + return 1; } WL_EXPORT int @@ -439,18 +467,20 @@ XReparentWindow(Display *xdisplay, Window xwindow, window = csx_display_lookup_resource(display, xwindow); if (window == NULL) { csx_display_error(display, xwindow, BadWindow); - return 0; /* what's the return value? */ + return 1; } parent = csx_display_lookup_resource(display, xparent); if (parent == NULL) { csx_display_error(display, xparent, BadWindow); - return 0; /* what's the return value? */ + return 1; } /* FIXME: Lot more to do here... */ wl_list_remove(&window->link); wl_list_insert(&parent->child_list, &window->link); + + return 1; } WL_EXPORT int @@ -495,20 +525,21 @@ XMoveWindow(Display *xdisplay, Window xwindow, int x, int y) WL_EXPORT int XLowerWindow(Display *xdisplay, Window xwindow) { - struct csx_display *display = csx_display(xdisplay); - struct csx_window *window; + XWindowChanges values; - window = csx_display_lookup_resource(display, xwindow); - if (window == NULL) { - csx_display_error(display, xwindow, BadWindow); - return 0; /* what's the return value? */ - } + values.stack_mode = Below; + + return XConfigureWindow(xdisplay, xwindow, CWStackMode, &values); } WL_EXPORT int -XRaiseWindow(Display *display, Window xwindow) +XRaiseWindow(Display *xdisplay, Window xwindow) { - STUB(); + XWindowChanges values; + + values.stack_mode = Above; + + return XConfigureWindow(xdisplay, xwindow, CWStackMode, &values); } WL_EXPORT int @@ -520,25 +551,26 @@ XMapRaised(Display *xdisplay, Window xwindow) window = csx_display_lookup_resource(display, xwindow); if (window == NULL) { csx_display_error(display, xwindow, BadWindow); - return 0; /* what's the return value? */ + return 1; } STUB(); + + return 1; } void csx_window_destroy(struct csx_window *window) { struct csx_window *child, *next; - struct csx_event *event; wl_list_for_each_safe(child, next, &window->child_list, link) csx_window_destroy(child); -#if 0 - event = csx_display_create_event(display); - event->xevent.type = DestroyNotify; -#endif + if (window->event_mask & StructureNotifyMask) + csx_window_send_destroy_notify(window, window); + if (window->parent->event_mask & SubstructureNotifyMask) + csx_window_send_map_notify(window, window->parent); csx_display_remove_resource(window->display, window->id); wl_list_remove(&window->link); @@ -554,14 +586,16 @@ XDestroyWindow(Display *xdisplay, Window xwindow) csx_display_enter(display, X_DestroyWindow, 0); window = csx_display_lookup_resource(display, xwindow); - if (window == NULL) - /* BadWindow */; + if (window == NULL) { + csx_display_error(display, xwindow, BadWindow); + return 1; + } if (window == display->root) - return; + return 1; csx_window_destroy(window); - return 0; /* return what? */ + return 1; } WL_EXPORT int @@ -573,11 +607,15 @@ XDestroySubwindows(Display *xdisplay, Window xwindow) csx_display_enter(display, X_DestroySubwindows, 0); window = csx_display_lookup_resource(display, xwindow); - if (window == NULL) - /* BadWindow */; + if (window == NULL) { + csx_display_error(display, xwindow, BadWindow); + return 1; + } wl_list_for_each_reverse_safe(child, next, &window->child_list, link) csx_window_destroy(child); + + return 1; } WL_EXPORT int @@ -590,4 +628,6 @@ XChangeProperty(Display *xdisplay, Window xwindow, csx_display_enter(display, X_ChangeProperty, 0); STUB(); + + return 1; } |