diff options
author | Jeremy Huddleston <jeremyhu@apple.com> | 2012-03-23 02:46:59 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2012-03-23 02:46:59 -0700 |
commit | 13caeba5ba76c9aaf402460555b2aa2c512865e5 (patch) | |
tree | 6e896e940dca346eea4c842fb6f529f4f59cc985 | |
parent | 7594454b1c3d33ba498dd421a8345b1ae2743531 (diff) |
libxcwm: Formatting changes from modular/x-indent.sh
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r-- | include/xcwm/event.h | 13 | ||||
-rw-r--r-- | include/xcwm/xcwm.h | 2 | ||||
-rw-r--r-- | include/xcwm/xtoq.h | 59 | ||||
-rw-r--r-- | src/libxcwm/context_list.c | 29 | ||||
-rw-r--r-- | src/libxcwm/data.h | 1 | ||||
-rw-r--r-- | src/libxcwm/event_loop.c | 349 | ||||
-rw-r--r-- | src/libxcwm/init.c | 137 | ||||
-rw-r--r-- | src/libxcwm/input.c | 74 | ||||
-rw-r--r-- | src/libxcwm/util.c | 63 | ||||
-rw-r--r-- | src/libxcwm/window.c | 322 | ||||
-rw-r--r-- | src/libxcwm/xcwm.c | 214 | ||||
-rw-r--r-- | src/libxcwm/xcwm_internal.h | 79 |
12 files changed, 711 insertions, 631 deletions
diff --git a/include/xcwm/event.h b/include/xcwm/event.h index d9d2b00..4957845 100644 --- a/include/xcwm/event.h +++ b/include/xcwm/event.h @@ -23,7 +23,6 @@ * SOFTWARE. */ - #ifndef _XCWM_EVENT_H_ #define _XCWM_EVENT_H_ @@ -33,6 +32,7 @@ /* Abstract types for xcwm data types */ struct xcwm_event_t; + typedef struct xcwm_event_t xcwm_event_t; typedef void (*xcwm_event_cb_t) (xcwm_event_t const *event); @@ -51,7 +51,7 @@ int xcwm_event_get_type(xcwm_event_t const *event); /** * Return the context for the given event. */ -xcwm_context_t * xcwm_event_get_context(xcwm_event_t const *event); +xcwm_context_t *xcwm_event_get_context(xcwm_event_t const *event); /** * Starts the event loop and listens on the connection specified in @@ -66,7 +66,7 @@ xcwm_context_t * xcwm_event_get_context(xcwm_event_t const *event); * the return value. */ int -xcwm_start_event_loop (xcwm_context_t *context, xcwm_event_cb_t callback); + xcwm_start_event_loop(xcwm_context_t * context, xcwm_event_cb_t callback); /** * Request a lock on the mutex for the event loop thread. Blocks @@ -74,14 +74,13 @@ xcwm_start_event_loop (xcwm_context_t *context, xcwm_event_cb_t callback); * @return 0 if successful, otherwise non-zero */ int -xcwm_get_event_thread_lock (void); + xcwm_get_event_thread_lock(void); /** * Release the lock on the mutex for the event loop thread. * @return 0 if successsful, otherwise non-zero */ int -xcwm_release_event_thread_lock(void); - + xcwm_release_event_thread_lock(void); -#endif /* _XCWM_EVENT_H_ */ +#endif /* _XCWM_EVENT_H_ */ diff --git a/include/xcwm/xcwm.h b/include/xcwm/xcwm.h index bdafbcd..2a08eda 100644 --- a/include/xcwm/xcwm.h +++ b/include/xcwm/xcwm.h @@ -33,4 +33,4 @@ #include <xcwm/xtoq.h> #include <xcwm/event.h> -#endif /* _XCWM_XCWM_H_ */ +#endif /* _XCWM_XCWM_H_ */ diff --git a/include/xcwm/xtoq.h b/include/xcwm/xtoq.h index ce37575..80b681a 100644 --- a/include/xcwm/xtoq.h +++ b/include/xcwm/xtoq.h @@ -60,16 +60,18 @@ struct xcwm_context_t { int damaged_y; int damaged_width; int damaged_height; - char *name; /* The name of the window */ - int wm_delete_set; /* Flag for WM_DELETE_WINDOW, 1 if set */ - void *local_data; /* Area for data client cares about */ + char *name; /* The name of the window */ + int wm_delete_set; /* Flag for WM_DELETE_WINDOW, 1 if set */ + void *local_data; /* Area for data client cares about */ }; + typedef struct xcwm_context_t xcwm_context_t; struct image_data_t { uint8_t *data; int length; }; + typedef struct image_data_t image_data_t; struct xcwm_image_t { @@ -79,6 +81,7 @@ struct xcwm_image_t { int width; int height; }; + typedef struct xcwm_image_t xcwm_image_t; /** @@ -94,8 +97,7 @@ extern xcwm_context_t *root_context; * @param display the display to connect to * @return The root context which contains the root window */ -xcwm_context_t * -xcwm_init(char *display); +xcwm_context_t *xcwm_init(char *display); /** * Returns a window's entire image @@ -103,8 +105,7 @@ xcwm_init(char *display); * FIXME: this might be for the root window * @return an xcwm_image_t with an the image of a window */ -xcwm_image_t * -xcwm_get_image(xcwm_context_t *context); +xcwm_image_t *xcwm_get_image(xcwm_context_t * context); /** * Intended for servicing to a client's reaction to a damage notification @@ -112,52 +113,50 @@ xcwm_get_image(xcwm_context_t *context); * @param an xcwm_context_t of the damaged window * @return an xcwm_image_t with partial image window contents */ -xcwm_image_t * -test_xcwm_get_image(xcwm_context_t * context); - +xcwm_image_t *test_xcwm_get_image(xcwm_context_t * context); /** * free the memory used by an xcwm_image_t created * during a call to test_xcwm_image_create * @param xcwm_image an image to be freed */ -void -xcwm_image_destroy(xcwm_image_t * xcwm_image); +void + xcwm_image_destroy(xcwm_image_t * xcwm_image); /** * Set input focus to the window in context * @param context The context containing the window */ void -xcwm_set_input_focus(xcwm_context_t *context); + xcwm_set_input_focus(xcwm_context_t * context); /** * Set a window to the bottom of the window stack. * @param context The context containing the window */ void -xcwm_set_window_to_bottom(xcwm_context_t *context); + xcwm_set_window_to_bottom(xcwm_context_t * context); /** * Set a window to the top of the window stack. * @param context The context containing the window */ void -xcwm_set_window_to_top(xcwm_context_t *context); + xcwm_set_window_to_top(xcwm_context_t * context); /** * Remove the damage from the given context. * @param context The context to remove the damage from */ void -xcwm_remove_context_damage(xcwm_context_t *context); + xcwm_remove_context_damage(xcwm_context_t * context); /** * Closes the windows open on the X Server, the connection, and the event * loop. */ -void -xcwm_close(void); +void + xcwm_close(void); /** * function @@ -166,7 +165,7 @@ xcwm_close(void); * @param keyCode The key pressed. */ void -xcwm_key_press (xcwm_context_t *context, int window, uint8_t code); + xcwm_key_press(xcwm_context_t * context, int window, uint8_t code); /** * function @@ -175,7 +174,7 @@ xcwm_key_press (xcwm_context_t *context, int window, uint8_t code); * @param keyCode The key released. */ void -xcwm_key_release (xcwm_context_t *context, int window, uint8_t code); + xcwm_key_release(xcwm_context_t * context, int window, uint8_t code); /** * Uses the XTEST protocol to send input events to the X Server (The X Server @@ -188,7 +187,9 @@ xcwm_key_release (xcwm_context_t *context, int window, uint8_t code); * @param window The window that the key press was made in. */ void -xcwm_button_press (xcwm_context_t *context, long x, long y, int window, int button); + +xcwm_button_press(xcwm_context_t * context, long x, long y, int window, + int button); /** * Uses the XTEST protocol to send input events to the X Server (The X Server @@ -201,7 +202,9 @@ xcwm_button_press (xcwm_context_t *context, long x, long y, int window, int butt * @param window The window that the key release was made in. */ void -xcwm_button_release (xcwm_context_t *context, long x, long y, int window, int button); + +xcwm_button_release(xcwm_context_t * context, long x, long y, int window, + int button); /** * function @@ -211,7 +214,9 @@ xcwm_button_release (xcwm_context_t *context, long x, long y, int window, int bu * @param window The window that the key release was made in. */ void -xcwm_mouse_motion (xcwm_context_t *context, long x, long y, int window, int button); + +xcwm_mouse_motion(xcwm_context_t * context, long x, long y, int window, + int button); /**************** * window.c @@ -223,7 +228,7 @@ xcwm_mouse_motion (xcwm_context_t *context, long x, long y, int window, int butt * @param context The context of the window to be killed */ void -xcwm_request_close(xcwm_context_t *context); + xcwm_request_close(xcwm_context_t * context); /** * move and/or resize the window, update the context @@ -234,6 +239,8 @@ xcwm_request_close(xcwm_context_t *context); * @param width The new width */ void -xcwm_configure_window(xcwm_context_t *context, int x, int y, int height, int width); -#endif // _XTOQ_H_ +xcwm_configure_window(xcwm_context_t * context, int x, int y, int height, + int width); + +#endif // _XTOQ_H_ diff --git a/src/libxcwm/context_list.c b/src/libxcwm/context_list.c index 61f88e5..702f395 100644 --- a/src/libxcwm/context_list.c +++ b/src/libxcwm/context_list.c @@ -36,37 +36,40 @@ _xcwm_add_context_t(struct xcwm_context_t *context) { /* temp pointers for traversing */ _xcwm_context_node *new_node; + _xcwm_context_node *curr; + _xcwm_context_node *prev; - + /* Create node to hold the new window */ new_node = malloc(sizeof(_xcwm_context_node)); if (!new_node) { exit(1); } new_node->context = context; - + /* Handle the case where this is the first node added */ if (!_xcwm_window_list_head) { new_node->prev = NULL; new_node->next = NULL; _xcwm_window_list_head = new_node; - } else { + } + else { /* Add the new node to the beginning of the list */ new_node->next = _xcwm_window_list_head; _xcwm_window_list_head->prev = new_node; new_node->prev = NULL; _xcwm_window_list_head = new_node; - + } return new_node->context; -} +} xcwm_context_t * -_xcwm_get_context_node_by_window_id (xcb_window_t window_id) +_xcwm_get_context_node_by_window_id(xcb_window_t window_id) { _xcwm_context_node *curr; - + curr = _xcwm_window_list_head; while (curr) { if (curr->context->window == window_id) { @@ -77,26 +80,26 @@ _xcwm_get_context_node_by_window_id (xcb_window_t window_id) return NULL; } - void -_xcwm_remove_context_node(xcb_window_t window_id) { +_xcwm_remove_context_node(xcb_window_t window_id) +{ _xcwm_context_node *curr; - + curr = _xcwm_window_list_head; while (curr != NULL) { if (curr->context->window == window_id) { // this will be freed in the event_loop - if(curr->next){ + if (curr->next) { curr->next->prev = curr->prev; } if (curr->prev) { curr->prev->next = curr->next; } - else{ + else { _xcwm_window_list_head = curr->next; } - + free(curr); return; } diff --git a/src/libxcwm/data.h b/src/libxcwm/data.h index fc1e911..3556d0b 100644 --- a/src/libxcwm/data.h +++ b/src/libxcwm/data.h @@ -24,7 +24,6 @@ * SOFTWARE. */ - #ifndef _DATA_H_ #define _DATA_H_ diff --git a/src/libxcwm/event_loop.c b/src/libxcwm/event_loop.c index e3f9913..afa6fb5 100644 --- a/src/libxcwm/event_loop.c +++ b/src/libxcwm/event_loop.c @@ -33,8 +33,8 @@ #include "xcwm_internal.h" typedef struct _connection_data { - xcb_connection_t *conn; - xcwm_event_cb_t callback; + xcb_connection_t *conn; + xcwm_event_cb_t callback; } _connection_data; /* The thread that is running the event loop */ @@ -51,184 +51,197 @@ void /* Functions included in xcwm.h */ int -xcwm_get_event_thread_lock (void) +xcwm_get_event_thread_lock(void) { - return pthread_mutex_lock(&_event_thread_lock); + return pthread_mutex_lock(&_event_thread_lock); } int xcwm_release_event_thread_lock(void) { - return pthread_mutex_unlock(&_event_thread_lock); + return pthread_mutex_unlock(&_event_thread_lock); } /* Functions included in xcwm_internal.h */ int -_xcwm_start_event_loop (xcb_connection_t *conn, - xcwm_event_cb_t event_callback) +_xcwm_start_event_loop(xcb_connection_t * conn, xcwm_event_cb_t event_callback) { - _connection_data *conn_data; - int ret_val; - int oldstate; - + _connection_data *conn_data; + + int ret_val; + + int oldstate; + conn_data = malloc(sizeof(_connection_data)); assert(conn_data); - - conn_data->conn = conn; - conn_data->callback = event_callback; - - pthread_mutex_init(&_event_thread_lock, NULL); + + conn_data->conn = conn; + conn_data->callback = event_callback; + + pthread_mutex_init(&_event_thread_lock, NULL); ret_val = pthread_create(&_event_thread, - NULL, - run_event_loop, - (void *) conn_data); + NULL, run_event_loop, (void *) conn_data); - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); - return ret_val; + return ret_val; } int _xcwm_stop_event_loop(void) { - if (_event_thread) { - return pthread_cancel(_event_thread); - } - return 1; + if (_event_thread) { + return pthread_cancel(_event_thread); + } + return 1; } -void *run_event_loop (void *thread_arg_struct) +void * +run_event_loop(void *thread_arg_struct) { _connection_data *conn_data; + xcb_connection_t *event_conn; + xcb_generic_event_t *evt; + xcwm_event_t *return_evt; + xcwm_event_cb_t callback_ptr; - + conn_data = thread_arg_struct; event_conn = conn_data->conn; callback_ptr = conn_data->callback; - + free(thread_arg_struct); - - /* Start the event loop, and flush if first */ + + /* Start the event loop, and flush if first */ xcb_flush(event_conn); - + while ((evt = xcb_wait_for_event(event_conn))) { - if ((evt->response_type & ~0x80) == _damage_event) { - xcb_damage_notify_event_t *dmgevnt = (xcb_damage_notify_event_t *)evt; - int old_x; - int old_y; - int old_height; - int old_width; - - return_evt = malloc(sizeof(xcwm_event_t)); - return_evt->event_type = XTOQ_DAMAGE; + if ((evt->response_type & ~0x80) == _damage_event) { + xcb_damage_notify_event_t *dmgevnt = + (xcb_damage_notify_event_t *) evt; + int old_x; + + int old_y; + + int old_height; + + int old_width; + + return_evt = malloc(sizeof(xcwm_event_t)); + return_evt->event_type = XTOQ_DAMAGE; return_evt->context = - _xcwm_get_context_node_by_window_id(dmgevnt->drawable); - if (!return_evt->context) { - free(return_evt); - continue; - } - - /* Increase the damaged area if new damage is outside the - * area already marked - this should be set back to 0 by 0 - * when area is actually redrawn. This is likely to be - * done in another thread that handles window redraws */ - xcwm_get_event_thread_lock(); - - old_x = return_evt->context->damaged_x; - old_y = return_evt->context->damaged_y; - old_width = return_evt->context->damaged_width; - old_height = return_evt->context->damaged_height; - - if (return_evt->context->damaged_width == 0) { - /* We know something is damaged */ - return_evt->context->damaged_x = dmgevnt->area.x; - return_evt->context->damaged_y = dmgevnt->area.y; - return_evt->context->damaged_width = dmgevnt->area.width; - return_evt->context->damaged_height = dmgevnt->area.height; - } else { - /* Is the new damage bigger than the old */ - if (old_x > dmgevnt->area.x) { - return_evt->context->damaged_x = dmgevnt->area.x; - } - if ( old_y > dmgevnt->area.y) { - return_evt->context->damaged_y = dmgevnt->area.y; - } - if ( old_width < dmgevnt->area.width) { - return_evt->context->damaged_width = dmgevnt->area.width; - } - if ( old_height < dmgevnt->area.height) { - return_evt->context->damaged_height = dmgevnt->area.height; - } - } + _xcwm_get_context_node_by_window_id(dmgevnt->drawable); + if (!return_evt->context) { + free(return_evt); + continue; + } + + /* Increase the damaged area if new damage is outside the + * area already marked - this should be set back to 0 by 0 + * when area is actually redrawn. This is likely to be + * done in another thread that handles window redraws */ + xcwm_get_event_thread_lock(); + + old_x = return_evt->context->damaged_x; + old_y = return_evt->context->damaged_y; + old_width = return_evt->context->damaged_width; + old_height = return_evt->context->damaged_height; + + if (return_evt->context->damaged_width == 0) { + /* We know something is damaged */ + return_evt->context->damaged_x = dmgevnt->area.x; + return_evt->context->damaged_y = dmgevnt->area.y; + return_evt->context->damaged_width = dmgevnt->area.width; + return_evt->context->damaged_height = dmgevnt->area.height; + } + else { + /* Is the new damage bigger than the old */ + if (old_x > dmgevnt->area.x) { + return_evt->context->damaged_x = dmgevnt->area.x; + } + if (old_y > dmgevnt->area.y) { + return_evt->context->damaged_y = dmgevnt->area.y; + } + if (old_width < dmgevnt->area.width) { + return_evt->context->damaged_width = dmgevnt->area.width; + } + if (old_height < dmgevnt->area.height) { + return_evt->context->damaged_height = dmgevnt->area.height; + } + } xcwm_release_event_thread_lock(); - if (((old_x > dmgevnt->area.x) || (old_y > dmgevnt->area.y)) - || ((old_width < dmgevnt->area.width) - || (old_height < dmgevnt->area.height))) { - /* We should only reach here if this damage event - * actually increases that area of the window marked - * for damage. */ - callback_ptr(return_evt); - } - } else { - switch (evt->response_type & ~0x80) { - case 0: { - /* Error case. Something very bad has happened. Spit - * out some hopefully useful information and then - * die. */ - xcb_generic_error_t *err = (xcb_generic_error_t *)evt; - fprintf(stderr, "Error received in event loop.\n" - "Error code: %i\n", - err->error_code); - if ((err->error_code >= XCB_VALUE) - && (err->error_code <= XCB_FONT)) { - xcb_value_error_t *val_err = (xcb_value_error_t *)evt; - fprintf(stderr, "Bad value: %i\n" - "Major opcode: %i\n" - "Minor opcode: %i\n", - val_err->bad_value, - val_err->major_opcode, - val_err->minor_opcode); - } + if (((old_x > dmgevnt->area.x) || (old_y > dmgevnt->area.y)) + || ((old_width < dmgevnt->area.width) + || (old_height < dmgevnt->area.height))) { + /* We should only reach here if this damage event + * actually increases that area of the window marked + * for damage. */ + callback_ptr(return_evt); + } + } + else { + switch (evt->response_type & ~0x80) { + case 0:{ + /* Error case. Something very bad has happened. Spit + * out some hopefully useful information and then + * die. */ + xcb_generic_error_t *err = (xcb_generic_error_t *) evt; + + fprintf(stderr, "Error received in event loop.\n" + "Error code: %i\n", err->error_code); + if ((err->error_code >= XCB_VALUE) + && (err->error_code <= XCB_FONT)) { + xcb_value_error_t *val_err = (xcb_value_error_t *) evt; + + fprintf(stderr, "Bad value: %i\n" + "Major opcode: %i\n" + "Minor opcode: %i\n", + val_err->bad_value, + val_err->major_opcode, val_err->minor_opcode); + } /* fprintf(stderr, "Exiting....\n"); */ /* free(evt); */ /* exit(1); */ - break; - } - case XCB_EXPOSE: { - xcb_expose_event_t *exevnt = (xcb_expose_event_t *)evt; - - printf("Window %u exposed. Region to be redrawn at location (%d, %d), ", - exevnt->window, exevnt->x, exevnt->y); - printf("with dimentions (%d, %d).\n", exevnt->width, exevnt->height); - - return_evt = malloc(sizeof(xcwm_event_t)); + break; + } + case XCB_EXPOSE:{ + xcb_expose_event_t *exevnt = (xcb_expose_event_t *) evt; + + printf + ("Window %u exposed. Region to be redrawn at location (%d, %d), ", + exevnt->window, exevnt->x, exevnt->y); + printf("with dimentions (%d, %d).\n", exevnt->width, + exevnt->height); + + return_evt = malloc(sizeof(xcwm_event_t)); return_evt->event_type = XTOQ_EXPOSE; callback_ptr(return_evt); break; } - case XCB_CREATE_NOTIFY: { - /* We don't actually allow our client to create its - * window here, wait until the XCB_MAP_REQUEST */ + case XCB_CREATE_NOTIFY:{ + /* We don't actually allow our client to create its + * window here, wait until the XCB_MAP_REQUEST */ printf("Got create notify\n"); break; } - case XCB_DESTROY_NOTIFY: { + case XCB_DESTROY_NOTIFY:{ // Window destroyed in root window - xcb_destroy_notify_event_t *notify = (xcb_destroy_notify_event_t *)evt; + xcb_destroy_notify_event_t *notify = + (xcb_destroy_notify_event_t *) evt; xcwm_context_t *context = _xcwm_destroy_window(notify); - if (!context) { - /* Not a window in the list, don't try and destroy */ - break; - } - + if (!context) { + /* Not a window in the list, don't try and destroy */ + break; + } + return_evt = malloc(sizeof(xcwm_event_t)); return_evt->event_type = XTOQ_DESTROY; return_evt->context = context; @@ -237,79 +250,87 @@ void *run_event_loop (void *thread_arg_struct) free(context); break; } - case XCB_MAP_REQUEST: { - xcb_map_request_event_t *request = (xcb_map_request_event_t *)evt; + case XCB_MAP_REQUEST:{ + xcb_map_request_event_t *request = + (xcb_map_request_event_t *) evt; return_evt = malloc(sizeof(xcwm_event_t)); return_evt->context = _xcwm_window_created(event_conn, request); if (!return_evt->context) { free(return_evt); - break; + break; } _xcwm_map_window(return_evt->context); return_evt->event_type = XTOQ_CREATE; callback_ptr(return_evt); break; } - case XCB_CONFIGURE_NOTIFY: { - break; - } - case XCB_CONFIGURE_REQUEST: { + case XCB_CONFIGURE_NOTIFY:{ + break; + } + case XCB_CONFIGURE_REQUEST:{ xcb_configure_request_event_t *request = - (xcb_configure_request_event_t *)evt; + (xcb_configure_request_event_t *) evt; printf("Got configure request: "); - printf("x = %i, y = %i, w = %i, h = %i\n", request->x, request->y, - request->width, request->height); + printf("x = %i, y = %i, w = %i, h = %i\n", request->x, + request->y, request->width, request->height); /* Change the size of the window, but not its position */ _xcwm_resize_window(event_conn, request->window, - request->width, request->height); + request->width, request->height); break; - } - case XCB_KEY_PRESS: { + } + case XCB_KEY_PRESS:{ printf("X Key press from xserver-"); - xcb_button_press_event_t *kp = (xcb_button_press_event_t *)evt; - printf ("Key pressed in window %u detail %c\n", - kp->event, kp->detail); + xcb_button_press_event_t *kp = (xcb_button_press_event_t *) evt; + + printf("Key pressed in window %u detail %c\n", + kp->event, kp->detail); break; } - case XCB_BUTTON_PRESS: { + case XCB_BUTTON_PRESS:{ printf("X Button press from xserver "); - xcb_button_press_event_t *bp = (xcb_button_press_event_t *)evt; - printf ("in window %u, at coordinates (%d,%d)\n", - bp->event, bp->event_x, bp->event_y ); + xcb_button_press_event_t *bp = (xcb_button_press_event_t *) evt; + + printf("in window %u, at coordinates (%d,%d)\n", + bp->event, bp->event_x, bp->event_y); break; } - case XCB_BUTTON_RELEASE: { + case XCB_BUTTON_RELEASE:{ printf("X Button release from xserver "); - xcb_button_press_event_t *bp = (xcb_button_press_event_t *)evt; - printf ("in window %u, at coordinates (%d,%d)\n", - bp->event, bp->event_x, bp->event_y ); + xcb_button_press_event_t *bp = (xcb_button_press_event_t *) evt; + + printf("in window %u, at coordinates (%d,%d)\n", + bp->event, bp->event_x, bp->event_y); break; - } - case XCB_MOTION_NOTIFY: { + } + case XCB_MOTION_NOTIFY:{ //printf("X mouse motion from from xserver-"); - xcb_button_press_event_t *bp = (xcb_button_press_event_t *)evt; - // printf ("mouse motion in window %ld, at coordinates (%d,%d)\n", + xcb_button_press_event_t *bp = (xcb_button_press_event_t *) evt; + + // printf ("mouse motion in window %ld, at coordinates (%d,%d)\n", // bp->event, bp->event_x, bp->event_y ); break; } - default: { + default:{ printf("UNKNOWN EVENT: %i\n", (evt->response_type & ~0x80)); break; } - } - } - /* Free the event */ - free(evt); - } + } + } + /* Free the event */ + free(evt); + } return NULL; } -int xcwm_event_get_type(xcwm_event_t const *event) { +int +xcwm_event_get_type(xcwm_event_t const *event) +{ return event->event_type; } -xcwm_context_t * xcwm_event_get_context(xcwm_event_t const *event) { +xcwm_context_t * +xcwm_event_get_context(xcwm_event_t const *event) +{ return event->context; } - diff --git a/src/libxcwm/init.c b/src/libxcwm/init.c index fdb89fd..70cc5e1 100644 --- a/src/libxcwm/init.c +++ b/src/libxcwm/init.c @@ -35,113 +35,120 @@ int _damage_event = 0; xcwm_wm_atoms *_wm_atoms = NULL; xcb_query_extension_reply_t * -_xcwm_init_extension (xcb_connection_t *conn, char *extension_name) +_xcwm_init_extension(xcb_connection_t * conn, char *extension_name) { - xcb_query_extension_cookie_t cookie = xcb_query_extension(conn, strlen(extension_name), extension_name); - xcb_query_extension_reply_t *reply = xcb_query_extension_reply(conn, cookie, NULL); - if (!reply->present) { - free(reply); + xcb_query_extension_cookie_t cookie = + xcb_query_extension(conn, strlen(extension_name), extension_name); + xcb_query_extension_reply_t *reply = + xcb_query_extension_reply(conn, cookie, NULL); + if (!reply->present) { + free(reply); printf("%s extension not present\n", extension_name); exit(1); - } else { + } + else { printf("%s extension present\n", extension_name); } - - return reply; + + return reply; } void -_xcwm_init_damage(xcwm_context_t *contxt) +_xcwm_init_damage(xcwm_context_t * contxt) { - - xcb_query_extension_reply_t *reply =_xcwm_init_extension(contxt->conn, "DAMAGE"); - - xcb_damage_query_version_cookie_t version_cookie = - xcb_damage_query_version(contxt->conn, - XCB_DAMAGE_MAJOR_VERSION, - XCB_DAMAGE_MINOR_VERSION); - xcb_damage_query_version_reply_t* version_reply = xcb_damage_query_version_reply(contxt->conn, version_cookie, NULL); - + + xcb_query_extension_reply_t *reply = + _xcwm_init_extension(contxt->conn, "DAMAGE"); + + xcb_damage_query_version_cookie_t version_cookie = + xcb_damage_query_version(contxt->conn, + XCB_DAMAGE_MAJOR_VERSION, + XCB_DAMAGE_MINOR_VERSION); + + xcb_damage_query_version_reply_t *version_reply = + xcb_damage_query_version_reply(contxt->conn, version_cookie, NULL); + _damage_event = reply->first_event + XCB_DAMAGE_NOTIFY; - - free(version_reply); - free(reply); - + + free(version_reply); + free(reply); + xcb_damage_damage_t damage = xcb_generate_id(contxt->conn); - + // Refer to the Damage Protocol. level = 0 corresponds to the level // DamageReportRawRectangles. Another level may be more appropriate. uint8_t level = XCB_DAMAGE_REPORT_LEVEL_BOUNDING_BOX; + xcb_void_cookie_t cookie = xcb_damage_create(contxt->conn, damage, contxt->window, level); - + /* Assign this damage object to the roots window's context */ contxt->damage = damage; - + } -void -_xcwm_init_composite(xcwm_context_t *contxt) { - xcb_query_extension_reply_t *reply = _xcwm_init_extension(contxt->conn, "Composite"); - - xcb_composite_query_version_cookie_t cookie = xcb_composite_query_version (contxt->conn, XCB_COMPOSITE_MAJOR_VERSION, XCB_COMPOSITE_MINOR_VERSION); - - xcb_composite_query_version_reply_t *version_reply = xcb_composite_query_version_reply (contxt->conn, cookie, NULL); - - xcb_composite_redirect_subwindows_checked(contxt->conn, contxt->window, XCB_COMPOSITE_REDIRECT_MANUAL); - +void +_xcwm_init_composite(xcwm_context_t * contxt) +{ + xcb_query_extension_reply_t *reply = + _xcwm_init_extension(contxt->conn, "Composite"); + + xcb_composite_query_version_cookie_t cookie = + xcb_composite_query_version(contxt->conn, XCB_COMPOSITE_MAJOR_VERSION, + XCB_COMPOSITE_MINOR_VERSION); + + xcb_composite_query_version_reply_t *version_reply = + xcb_composite_query_version_reply(contxt->conn, cookie, NULL); + + xcb_composite_redirect_subwindows_checked(contxt->conn, contxt->window, + XCB_COMPOSITE_REDIRECT_MANUAL); + free(version_reply); free(reply); - + } void -_xcwm_init_xfixes (xcwm_context_t *contxt) +_xcwm_init_xfixes(xcwm_context_t * contxt) { - xcb_xfixes_query_version_cookie_t cookie = - xcb_xfixes_query_version(contxt->conn, 4, 0); - - xcb_xfixes_query_version_reply_t *reply = - xcb_xfixes_query_version_reply(contxt->conn, cookie, NULL); - + xcb_xfixes_query_version_cookie_t cookie = + xcb_xfixes_query_version(contxt->conn, 4, 0); + + xcb_xfixes_query_version_reply_t *reply = + xcb_xfixes_query_version_reply(contxt->conn, cookie, NULL); + free(reply); } void -_xcwm_get_wm_atoms (xcwm_context_t *context) +_xcwm_get_wm_atoms(xcwm_context_t * context) { - xcb_intern_atom_reply_t *atom_reply; - xcb_intern_atom_cookie_t atom_cookie; - xcb_generic_error_t *error; + xcb_intern_atom_reply_t *atom_reply; + + xcb_intern_atom_cookie_t atom_cookie; + + xcb_generic_error_t *error; _wm_atoms = malloc(sizeof(xcwm_wm_atoms)); /* WM_PROTOCOLS */ - atom_cookie = xcb_intern_atom(context->conn, - 0, - 12, - "WM_PROTOCOLS"); - atom_reply = xcb_intern_atom_reply(context->conn, - atom_cookie, - NULL); - if (!atom_reply) { + atom_cookie = xcb_intern_atom(context->conn, 0, 12, "WM_PROTOCOLS"); + atom_reply = xcb_intern_atom_reply(context->conn, atom_cookie, NULL); + if (!atom_reply) { _wm_atoms->wm_protocols_atom = 0; - } else { + } + else { _wm_atoms->wm_protocols_atom = atom_reply->atom; free(atom_reply); } - /* WM_DELETE_WINDOW atom */ - atom_cookie = xcb_intern_atom(context->conn, - 0, - 16, - "WM_DELETE_WINDOW"); - atom_reply = xcb_intern_atom_reply(context->conn, - atom_cookie, - NULL); + /* WM_DELETE_WINDOW atom */ + atom_cookie = xcb_intern_atom(context->conn, 0, 16, "WM_DELETE_WINDOW"); + atom_reply = xcb_intern_atom_reply(context->conn, atom_cookie, NULL); if (!atom_reply) { _wm_atoms->wm_delete_window_atom = 0; - } else { + } + else { _wm_atoms->wm_delete_window_atom = atom_reply->atom; free(atom_reply); } diff --git a/src/libxcwm/input.c b/src/libxcwm/input.c index bbe00e2..99b0a28 100644 --- a/src/libxcwm/input.c +++ b/src/libxcwm/input.c @@ -29,70 +29,78 @@ #include "xcwm_internal.h" void -xcwm_key_press (xcwm_context_t *context, int window, uint8_t code) +xcwm_key_press(xcwm_context_t * context, int window, uint8_t code) { xcb_generic_error_t *err; + xcb_void_cookie_t cookie; xcb_window_t none = { XCB_NONE }; - - cookie = xcb_test_fake_input( context->conn, XCB_KEY_PRESS, code, - XCB_CURRENT_TIME, none, 0, 0, 1 ); - + + cookie = xcb_test_fake_input(context->conn, XCB_KEY_PRESS, code, + XCB_CURRENT_TIME, none, 0, 0, 1); + err = xcb_request_check(context->conn, cookie); - if (err) - { + if (err) { printf("err "); free(err); - } + } xcb_flush(context->conn); - printf("xcwm.c received key down - uint8_t '%i', from Mac window #%i to context.window %u\n", code, window, context->window); + printf + ("xcwm.c received key down - uint8_t '%i', from Mac window #%i to context.window %u\n", + code, window, context->window); } void -xcwm_key_release (xcwm_context_t *context, int window, uint8_t code) +xcwm_key_release(xcwm_context_t * context, int window, uint8_t code) { xcb_generic_error_t *err; + xcb_void_cookie_t cookie; xcb_window_t none = { XCB_NONE }; - - xcb_test_fake_input( context->conn, XCB_KEY_RELEASE, code, - XCB_CURRENT_TIME, none,0 ,0 , 1 ); - + + xcb_test_fake_input(context->conn, XCB_KEY_RELEASE, code, + XCB_CURRENT_TIME, none, 0, 0, 1); + err = xcb_request_check(context->conn, cookie); - if (err) - { + if (err) { printf("err "); free(err); - } + } xcb_flush(context->conn); - printf("xcwm.c received key release- uint8_t '%i', from Mac window #%i to context.window %u\n", code, window, context->window); + printf + ("xcwm.c received key release- uint8_t '%i', from Mac window #%i to context.window %u\n", + code, window, context->window); } void -xcwm_button_press (xcwm_context_t *context, long x, long y, int window, int button) +xcwm_button_press(xcwm_context_t * context, long x, long y, int window, + int button) { //xcb_window_t none = { XCB_NONE }; - xcb_test_fake_input (context->conn, XCB_BUTTON_PRESS, 1, XCB_CURRENT_TIME, - context->window, 0, 0, 0); - xcb_flush(context->conn); - printf("button down received by xcwm.c - (%ld,%ld) in Mac window #%i\n", x, y, window); + xcb_test_fake_input(context->conn, XCB_BUTTON_PRESS, 1, XCB_CURRENT_TIME, + context->window, 0, 0, 0); + xcb_flush(context->conn); + printf("button down received by xcwm.c - (%ld,%ld) in Mac window #%i\n", x, + y, window); } void -xcwm_button_release (xcwm_context_t *context, long x, long y, int window, int button) +xcwm_button_release(xcwm_context_t * context, long x, long y, int window, + int button) { - xcb_test_fake_input (context->conn, XCB_BUTTON_RELEASE, 1, XCB_CURRENT_TIME, - context->window, 0, 0, 0); - xcb_flush(context->conn); - printf("button release received by xcwm.c - (%ld,%ld) in Mac window #%i\n", x, y, window); + xcb_test_fake_input(context->conn, XCB_BUTTON_RELEASE, 1, XCB_CURRENT_TIME, + context->window, 0, 0, 0); + xcb_flush(context->conn); + printf("button release received by xcwm.c - (%ld,%ld) in Mac window #%i\n", + x, y, window); } void -xcwm_mouse_motion (xcwm_context_t *context, long x, long y, int window, int button) +xcwm_mouse_motion(xcwm_context_t * context, long x, long y, int window, + int button) { - xcb_test_fake_input (context->conn, XCB_MOTION_NOTIFY, 0, XCB_CURRENT_TIME, - root_context->window//root_context->window//none//context->parent - ,x, y, 0); - xcb_flush(context->conn); + xcb_test_fake_input(context->conn, XCB_MOTION_NOTIFY, 0, XCB_CURRENT_TIME, root_context->window //root_context->window//none//context->parent + , x, y, 0); + xcb_flush(context->conn); //printf("mouse motion received by xcwm.c - (%ld,%ld) in Mac window #%i\n", x, y, window); } diff --git a/src/libxcwm/util.c b/src/libxcwm/util.c index 227fe06..ffc6291 100644 --- a/src/libxcwm/util.c +++ b/src/libxcwm/util.c @@ -30,12 +30,13 @@ #include "xcwm_internal.h" #include <xcb/xcb.h> - xcb_get_window_attributes_reply_t * -_xcwm_get_window_attributes (xcb_connection_t *conn, xcb_window_t window) +_xcwm_get_window_attributes(xcb_connection_t * conn, xcb_window_t window) { xcb_get_window_attributes_reply_t *reply; + xcb_generic_error_t *error; + xcb_get_window_attributes_cookie_t cookie; cookie = xcb_get_window_attributes(conn, window); @@ -49,25 +50,30 @@ _xcwm_get_window_attributes (xcb_connection_t *conn, xcb_window_t window) } xcb_get_geometry_reply_t * -_xcwm_get_window_geometry (xcb_connection_t *conn, xcb_window_t window) +_xcwm_get_window_geometry(xcb_connection_t * conn, xcb_window_t window) { xcb_get_geometry_cookie_t cookie; + cookie = xcb_get_geometry(conn, window); return xcb_get_geometry_reply(conn, cookie, NULL); } - void -_xcwm_write_all_children_window_info (xcb_connection_t *conn, - xcb_window_t root) +_xcwm_write_all_children_window_info(xcb_connection_t * conn, xcb_window_t root) { xcb_query_tree_reply_t *reply; + xcb_query_tree_cookie_t tree_cookie; + xcb_window_t *children; /* The children of the given root */ - image_data_t img_data; - xcb_generic_error_t *error; + + image_data_t img_data; + + xcb_generic_error_t *error; + int len; + int i; tree_cookie = xcb_query_tree(conn, root); @@ -82,28 +88,31 @@ _xcwm_write_all_children_window_info (xcb_connection_t *conn, children = xcb_query_tree_children(reply); /* Iterate thorough all the children and get their pixmap (hopefully) */ - printf("--- Iterating through children of window %u ---\n", - root); + printf("--- Iterating through children of window %u ---\n", root); for (i = 0; i < len; i++) { _xcwm_write_window_info(conn, children[i]); - img_data = _xcwm_get_window_image_data(conn, children[i]); - if (!img_data.data) { - printf("Image data is empty\n"); - } + img_data = _xcwm_get_window_image_data(conn, children[i]); + if (!img_data.data) { + printf("Image data is empty\n"); + } } - printf("--- End window iteration ---\n"); - + printf("--- End window iteration ---\n"); + /* Free the stuff allocated by XCB */ free(reply); } image_data_t -_xcwm_get_window_image_data (xcb_connection_t *conn, xcb_drawable_t window) +_xcwm_get_window_image_data(xcb_connection_t * conn, xcb_drawable_t window) { image_data_t image_data; + xcb_get_image_cookie_t img_cookie; + xcb_get_image_reply_t *reply; + xcb_generic_error_t *error; + xcb_get_geometry_reply_t *geom_reply; image_data.data = NULL; @@ -121,8 +130,7 @@ _xcwm_get_window_image_data (xcb_connection_t *conn, xcb_drawable_t window) 0, 0, geom_reply->width, - geom_reply->height, - (unsigned int) ~0L); + geom_reply->height, (unsigned int) ~0L); reply = xcb_get_image_reply(conn, img_cookie, &error); if (error) { @@ -140,9 +148,10 @@ _xcwm_get_window_image_data (xcb_connection_t *conn, xcb_drawable_t window) } void -_xcwm_write_window_info (xcb_connection_t *conn, xcb_window_t window) +_xcwm_write_window_info(xcb_connection_t * conn, xcb_window_t window) { xcb_get_geometry_reply_t *geom_reply; + xcb_get_window_attributes_reply_t *attr_reply; geom_reply = _xcwm_get_window_geometry(conn, window); @@ -162,11 +171,13 @@ _xcwm_write_window_info (xcb_connection_t *conn, xcb_window_t window) printf("width: %d\theight: %d\n", geom_reply->width, geom_reply->height); printf("Map state: "); - if (attr_reply->map_state == XCB_MAP_STATE_UNMAPPED) { + if (attr_reply->map_state == XCB_MAP_STATE_UNMAPPED) { printf("Unmapped\n"); - } else if (attr_reply->map_state == XCB_MAP_STATE_UNVIEWABLE) { + } + else if (attr_reply->map_state == XCB_MAP_STATE_UNVIEWABLE) { printf("Unviewable\n"); - } else { + } + else { printf("Viewable\n"); } @@ -175,8 +186,8 @@ _xcwm_write_window_info (xcb_connection_t *conn, xcb_window_t window) } int -_xcwm_request_check (xcb_connection_t *conn, xcb_void_cookie_t cookie, - char *msg) +_xcwm_request_check(xcb_connection_t * conn, xcb_void_cookie_t cookie, + char *msg) { xcb_generic_error_t *error; @@ -184,7 +195,7 @@ _xcwm_request_check (xcb_connection_t *conn, xcb_void_cookie_t cookie, if (error) { if (msg) { fprintf(stderr, "ERROR: "); - fprintf(stderr,"%s", msg); + fprintf(stderr, "%s", msg); fprintf(stderr, "\nError code: %d\n", error->error_code); } return error->error_code; diff --git a/src/libxcwm/window.c b/src/libxcwm/window.c index d02c871..90d2ba2 100644 --- a/src/libxcwm/window.c +++ b/src/libxcwm/window.c @@ -34,71 +34,81 @@ /* Sets the WM_* properties we care about in context */ void -set_icccm_properties (xcwm_context_t *context); + set_icccm_properties(xcwm_context_t * context); /* Set the WM_NAME property in context */ void -set_wm_name_in_context (xcwm_context_t *context); + set_wm_name_in_context(xcwm_context_t * context); /* Find out of the WM_DELETE_WINDOW property is set */ void -set_wm_delete_win_in_context (xcwm_context_t *context); + set_wm_delete_win_in_context(xcwm_context_t * context); /* Initialize damage on a window */ void -init_damage_on_window (xcwm_context_t *context); - + init_damage_on_window(xcwm_context_t * context); /* Set window to the top of the stack */ void -xcwm_set_window_to_top(xcwm_context_t *context) { +xcwm_set_window_to_top(xcwm_context_t * context) +{ const static uint32_t values[] = { XCB_STACK_MODE_ABOVE }; - + /* Move the window on the top of the stack */ - xcb_configure_window (context->conn, context->window, XCB_CONFIG_WINDOW_STACK_MODE, values); + xcb_configure_window(context->conn, context->window, + XCB_CONFIG_WINDOW_STACK_MODE, values); } /* Set window to the bottom of the stack */ void -xcwm_set_window_to_bottom(xcwm_context_t *context) { - +xcwm_set_window_to_bottom(xcwm_context_t * context) +{ + const static uint32_t values[] = { XCB_STACK_MODE_BELOW }; - + /* Move the window on the top of the stack */ - xcb_configure_window (context->conn, context->window, XCB_CONFIG_WINDOW_STACK_MODE, values); + xcb_configure_window(context->conn, context->window, + XCB_CONFIG_WINDOW_STACK_MODE, values); } -/* Set input focus to window */ +/* Set input focus to window */ void -xcwm_set_input_focus(xcwm_context_t *context) { - +xcwm_set_input_focus(xcwm_context_t * context) +{ + // Test -- David xcb_get_input_focus_cookie_t cookie = xcb_get_input_focus(context->conn); - xcb_get_input_focus_reply_t *reply = xcb_get_input_focus_reply(context->conn, cookie, NULL); - printf("Focus was in window #%d, now in #%d (window.c)\n", reply->focus, context->window); + + xcb_get_input_focus_reply_t *reply = + xcb_get_input_focus_reply(context->conn, cookie, NULL); + printf("Focus was in window #%d, now in #%d (window.c)\n", reply->focus, + context->window); free(reply); - + // End test -- David - - xcb_set_input_focus(context->conn, XCB_INPUT_FOCUS_PARENT, context->window, XCB_CURRENT_TIME); - xcb_flush(context->conn); + + xcb_set_input_focus(context->conn, XCB_INPUT_FOCUS_PARENT, context->window, + XCB_CURRENT_TIME); + xcb_flush(context->conn); } xcwm_context_t * -_xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t *event) { +_xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t * event) +{ /* Check to see if the window is already created */ if (_xcwm_get_context_node_by_window_id(event->window)) { return NULL; - } - + } + /* allocate memory for new xcwm_context_t */ xcwm_context_t *context = malloc(sizeof(xcwm_context_t)); - + xcb_get_geometry_reply_t *geom; + geom = _xcwm_get_window_geometry(conn, event->window); - + /* set any available values from xcb_create_notify_event_t object pointer and geom pointer */ context->conn = conn; @@ -109,187 +119,195 @@ _xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t *event) { context->width = geom->width; context->height = geom->height; - free (geom); + free(geom); + + /* Set the ICCCM properties we care about */ + set_icccm_properties(context); - /* Set the ICCCM properties we care about */ - set_icccm_properties(context); - /* register for damage */ init_damage_on_window(context); /* add context to context_list */ context = _xcwm_add_context_t(context); - + return context; } xcwm_context_t * -_xcwm_destroy_window(xcb_destroy_notify_event_t *event) { - - xcwm_context_t *context = _xcwm_get_context_node_by_window_id(event->window); +_xcwm_destroy_window(xcb_destroy_notify_event_t * event) +{ + + xcwm_context_t *context = + _xcwm_get_context_node_by_window_id(event->window); if (!context) { - /* Window isn't being managed */ - return NULL; - } + /* Window isn't being managed */ + return NULL; + } /* Destroy the damage object associated with the window. */ - xcb_damage_destroy(context->conn,context->damage); - + xcb_damage_destroy(context->conn, context->damage); + /* Call the remove function in context_list.c */ _xcwm_remove_context_node(context->window); - + /* Return the pointer for the context that was removed from the list. */ return context; } + void -xcwm_configure_window(xcwm_context_t *context, int x, int y, int height, int width) { - +xcwm_configure_window(xcwm_context_t * context, int x, int y, int height, + int width) +{ + /* Set values for xcwm_context_t */ context->x = x; context->y = y; context->width = width; context->height = height; - - uint32_t values[] = {(uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height }; - - xcb_configure_window (context->conn, context->window, XCB_CONFIG_WINDOW_X - | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); - /* Set the damage area to the new window size so its redrawn properly */ - context->damaged_width = width; - context->damaged_height = height; + uint32_t values[] = + { (uint32_t) x, (uint32_t) y, (uint32_t) width, (uint32_t) height }; + + xcb_configure_window(context->conn, context->window, XCB_CONFIG_WINDOW_X + | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | + XCB_CONFIG_WINDOW_HEIGHT, values); + + /* Set the damage area to the new window size so its redrawn properly */ + context->damaged_width = width; + context->damaged_height = height; xcb_flush(context->conn); return; } void -xcwm_request_close(xcwm_context_t *context) { - +xcwm_request_close(xcwm_context_t * context) +{ + /* check to see if the context is in the list */ context = _xcwm_get_context_node_by_window_id(context->window); if (!context) return; - - /* kill using xcb_kill_client */ + + /* kill using xcb_kill_client */ if (!context->wm_delete_set == 1) { xcb_kill_client(context->conn, context->window); xcb_flush(context->conn); return; } /* kill using WM_DELETE_WINDOW */ - if (context->wm_delete_set == 1){ + if (context->wm_delete_set == 1) { xcb_client_message_event_t event; - + memset(&event, 0, sizeof(xcb_client_message_event_t)); - + event.response_type = XCB_CLIENT_MESSAGE; event.window = context->window; event.type = _wm_atoms->wm_protocols_atom; event.format = 32; event.data.data32[0] = _wm_atoms->wm_delete_window_atom; event.data.data32[1] = XCB_CURRENT_TIME; - - xcb_send_event(context->conn, 0, context->window, XCB_EVENT_MASK_NO_EVENT, - (char*)&event); + + xcb_send_event(context->conn, 0, context->window, + XCB_EVENT_MASK_NO_EVENT, (char *) &event); xcb_flush(context->conn); return; - + } return; } /* Resize the window on server side */ void -_xcwm_resize_window (xcb_connection_t *conn, xcb_window_t window, - int width, int height) +_xcwm_resize_window(xcb_connection_t * conn, xcb_window_t window, + int width, int height) { - uint32_t values[2] = { width, height }; - - xcb_configure_window(conn, - window, - XCB_CONFIG_WINDOW_WIDTH | - XCB_CONFIG_WINDOW_HEIGHT, - values); - xcb_flush(conn); + uint32_t values[2] = { width, height }; + + xcb_configure_window(conn, + window, + XCB_CONFIG_WINDOW_WIDTH | + XCB_CONFIG_WINDOW_HEIGHT, values); + xcb_flush(conn); } void -_xcwm_map_window (xcwm_context_t *context) +_xcwm_map_window(xcwm_context_t * context) { - /* Map the window. May want to handle other things here */ - xcb_map_window(context->conn, context->window); - xcb_flush(context->conn); + /* Map the window. May want to handle other things here */ + xcb_map_window(context->conn, context->window); + xcb_flush(context->conn); } void -set_icccm_properties (xcwm_context_t *context) +set_icccm_properties(xcwm_context_t * context) { - set_wm_name_in_context(context); - set_wm_delete_win_in_context(context); + set_wm_name_in_context(context); + set_wm_delete_win_in_context(context); } void -set_wm_name_in_context (xcwm_context_t *context) +set_wm_name_in_context(xcwm_context_t * context) { - xcb_get_property_cookie_t cookie; - xcb_get_property_reply_t *reply; - xcb_generic_error_t *error; - char *value; - int length; - - cookie = xcb_get_property(context->conn, - 0, - context->window, - XCB_ATOM_WM_NAME, - XCB_GET_PROPERTY_TYPE_ANY, - 0, - 128); - reply = xcb_get_property_reply(context->conn, - cookie, - &error); - if (!reply) { - context->name = NULL; - return; - } - length = xcb_get_property_value_length(reply); - value = (char *) xcb_get_property_value(reply); - - context->name = malloc(sizeof(char) * (length + 1)); - strncpy(context->name, value, length); - context->name[length] = '\0'; + xcb_get_property_cookie_t cookie; + + xcb_get_property_reply_t *reply; + + xcb_generic_error_t *error; + + char *value; + + int length; + + cookie = xcb_get_property(context->conn, + 0, + context->window, + XCB_ATOM_WM_NAME, + XCB_GET_PROPERTY_TYPE_ANY, 0, 128); + reply = xcb_get_property_reply(context->conn, cookie, &error); + if (!reply) { + context->name = NULL; + return; + } + length = xcb_get_property_value_length(reply); + value = (char *) xcb_get_property_value(reply); + + context->name = malloc(sizeof(char) * (length + 1)); + strncpy(context->name, value, length); + context->name[length] = '\0'; } void -set_wm_delete_win_in_context (xcwm_context_t *context) +set_wm_delete_win_in_context(xcwm_context_t * context) { - xcb_get_property_cookie_t cookie; - xcb_get_property_reply_t *reply; - xcb_atom_t *prop_atoms; - int prop_length; - xcb_generic_error_t *error; + xcb_get_property_cookie_t cookie; + + xcb_get_property_reply_t *reply; + + xcb_atom_t *prop_atoms; + + int prop_length; + + xcb_generic_error_t *error; + int i; - /* Get the WM_PROTOCOLS */ - cookie = xcb_get_property(context->conn, - 0, - context->window, - _wm_atoms->wm_protocols_atom, - XCB_ATOM_ATOM, - 0, - UINT_MAX); - - reply = xcb_get_property_reply(context->conn, - cookie, - &error); - - if (!reply) { - context->wm_delete_set = 0; - return; - } - prop_length = xcb_get_property_value_length(reply); - prop_atoms = (xcb_atom_t *) xcb_get_property_value(reply); - free(reply); + /* Get the WM_PROTOCOLS */ + cookie = xcb_get_property(context->conn, + 0, + context->window, + _wm_atoms->wm_protocols_atom, + XCB_ATOM_ATOM, 0, UINT_MAX); + + reply = xcb_get_property_reply(context->conn, cookie, &error); + + if (!reply) { + context->wm_delete_set = 0; + return; + } + prop_length = xcb_get_property_value_length(reply); + prop_atoms = (xcb_atom_t *) xcb_get_property_value(reply); + free(reply); /* See if the WM_DELETE_WINDOW is in WM_PROTOCOLS */ for (i = 0; i < prop_length; i++) { @@ -300,39 +318,37 @@ set_wm_delete_win_in_context (xcwm_context_t *context) } context->wm_delete_set = 0; - return; + return; } void -init_damage_on_window (xcwm_context_t *context) +init_damage_on_window(xcwm_context_t * context) { - xcb_damage_damage_t damage_id; - uint8_t level; + xcb_damage_damage_t damage_id; + + uint8_t level; + xcb_void_cookie_t cookie; - damage_id = xcb_generate_id(context->conn); - + damage_id = xcb_generate_id(context->conn); + // Refer to the Damage Protocol. level = 0 corresponds to the level // DamageReportRawRectangles. Another level may be more appropriate. level = XCB_DAMAGE_REPORT_LEVEL_BOUNDING_BOX; cookie = xcb_damage_create(context->conn, - damage_id, - context->window, - level); - - if (_xcwm_request_check(context->conn, cookie, - "Could not create damage for window")) { - context->damage = 0; - return; - } + damage_id, context->window, level); + + if (_xcwm_request_check(context->conn, cookie, + "Could not create damage for window")) { + context->damage = 0; + return; + } /* Assign this damage object to the roots window's context */ context->damage = damage_id; - /* Set the damage area in the context to zero */ - context->damaged_x = 0; - context->damaged_y = 0; - context->damaged_width = 0; - context->damaged_height = 0; + /* Set the damage area in the context to zero */ + context->damaged_x = 0; + context->damaged_y = 0; + context->damaged_width = 0; + context->damaged_height = 0; } - - diff --git a/src/libxcwm/xcwm.c b/src/libxcwm/xcwm.c index 161bdcc..eee8a7e 100644 --- a/src/libxcwm/xcwm.c +++ b/src/libxcwm/xcwm.c @@ -35,55 +35,61 @@ // aaron key stuff #define XK_Shift_L 0xffe1 xcb_key_symbols_t *syms = NULL; + // end aaron key stuff xcwm_context_t *root_context = NULL; // This init function needs set the window to be registered for events! // First one we should handle is damage xcwm_context_t * -xcwm_init(char *display) { - +xcwm_init(char *display) +{ + xcb_connection_t *conn; + int conn_screen; + xcb_screen_t *root_screen; + xcb_drawable_t root_window; - xcb_void_cookie_t cookie; + + xcb_void_cookie_t cookie; + uint32_t mask_values[1]; - + conn = xcb_connect(display, &conn_screen); - + root_screen = xcb_aux_get_screen(conn, conn_screen); root_window = root_screen->root; - + // Set the mask for the root window so we know when new windows // are created on the root. This is where we add masks for the events // we care about catching on the root window. mask_values[0] = XCB_EVENT_MASK_KEY_PRESS | - XCB_EVENT_MASK_KEY_RELEASE | - XCB_EVENT_MASK_BUTTON_PRESS | - XCB_EVENT_MASK_BUTTON_RELEASE | - XCB_EVENT_MASK_POINTER_MOTION | - XCB_EVENT_MASK_STRUCTURE_NOTIFY | - XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | - XCB_EVENT_MASK_ENTER_WINDOW | - XCB_EVENT_MASK_LEAVE_WINDOW | - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; + XCB_EVENT_MASK_KEY_RELEASE | + XCB_EVENT_MASK_BUTTON_PRESS | + XCB_EVENT_MASK_BUTTON_RELEASE | + XCB_EVENT_MASK_POINTER_MOTION | + XCB_EVENT_MASK_STRUCTURE_NOTIFY | + XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | + XCB_EVENT_MASK_ENTER_WINDOW | + XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; cookie = xcb_change_window_attributes_checked(conn, root_window, - XCB_CW_EVENT_MASK, - mask_values); - if (_xcwm_request_check(conn, cookie, "Could not set root window mask.")) { - fprintf(stderr, "Is another window manager running?\n"); - xcb_disconnect(conn); - exit(1); - } + XCB_CW_EVENT_MASK, + mask_values); + if (_xcwm_request_check(conn, cookie, "Could not set root window mask.")) { + fprintf(stderr, "Is another window manager running?\n"); + xcb_disconnect(conn); + exit(1); + } - xcb_flush(conn); + xcb_flush(conn); root_context = malloc(sizeof(xcwm_context_t)); root_context->conn = conn; root_context->parent = 0; root_context->window = root_window; - + // Set width, height, x, & y from root_screen into the xcwm_context_t root_context->width = root_screen->width_in_pixels; root_context->height = root_screen->height_in_pixels; @@ -91,35 +97,37 @@ xcwm_init(char *display) { root_context->y = 0; _xcwm_init_composite(root_context); - + _xcwm_init_damage(root_context); - + _xcwm_init_xfixes(root_context); - + _xcwm_add_context_t(root_context); - + syms = xcb_key_symbols_alloc(conn); _xcwm_init_extension(conn, "XTEST"); - _xcwm_init_extension(conn, "XKEYBOARD"); + _xcwm_init_extension(conn, "XKEYBOARD"); - _xcwm_get_wm_atoms(root_context); + _xcwm_get_wm_atoms(root_context); return root_context; } xcwm_image_t * -xcwm_get_image(xcwm_context_t *context) { - +xcwm_get_image(xcwm_context_t * context) +{ + xcb_get_geometry_reply_t *geom_reply; - + xcb_image_t *image; - + geom_reply = _xcwm_get_window_geometry(context->conn, context->window); - + //FIXME - right size - xcwm_image_t * xcwm_image = (xcwm_image_t *) malloc(10 * sizeof (xcwm_image_t)); - - xcb_flush(context->conn); + xcwm_image_t *xcwm_image = + (xcwm_image_t *) malloc(10 * sizeof(xcwm_image_t)); + + xcb_flush(context->conn); /* Get the image of the root window */ image = xcb_image_get(context->conn, context->window, @@ -127,34 +135,33 @@ xcwm_get_image(xcwm_context_t *context) { geom_reply->y, geom_reply->width, geom_reply->height, - (unsigned int) ~0L, - XCB_IMAGE_FORMAT_Z_PIXMAP); - + (unsigned int) ~0L, XCB_IMAGE_FORMAT_Z_PIXMAP); + xcwm_image->image = image; xcwm_image->x = geom_reply->x; xcwm_image->y = geom_reply->y; xcwm_image->width = geom_reply->width; xcwm_image->height = geom_reply->height; - + free(geom_reply); - + return xcwm_image; } -int -xcwm_start_event_loop (xcwm_context_t *context, - xcwm_event_cb_t callback) +int +xcwm_start_event_loop(xcwm_context_t * context, xcwm_event_cb_t callback) { - /* Simply call our internal function to do the actual setup */ - return _xcwm_start_event_loop(context->conn, callback); + /* Simply call our internal function to do the actual setup */ + return _xcwm_start_event_loop(context->conn, callback); } xcwm_image_t * -test_xcwm_get_image(xcwm_context_t *context) { - +test_xcwm_get_image(xcwm_context_t * context) +{ + xcb_image_t *image; - - xcb_flush(context->conn); + + xcb_flush(context->conn); /* Get the image of the root window */ image = xcb_image_get(context->conn, context->window, @@ -162,12 +169,12 @@ test_xcwm_get_image(xcwm_context_t *context) { context->damaged_y, context->damaged_width, context->damaged_height, - (unsigned int) ~0L, - XCB_IMAGE_FORMAT_Z_PIXMAP); - + (unsigned int) ~0L, XCB_IMAGE_FORMAT_Z_PIXMAP); + //FIXME - Calculate memory size correctly - xcwm_image_t * xcwm_image = (xcwm_image_t *) malloc(10 * sizeof (xcwm_image_t)); - + xcwm_image_t *xcwm_image = + (xcwm_image_t *) malloc(10 * sizeof(xcwm_image_t)); + xcwm_image->image = image; xcwm_image->x = context->damaged_x; xcwm_image->y = context->damaged_y; @@ -177,74 +184,75 @@ test_xcwm_get_image(xcwm_context_t *context) { return xcwm_image; } - -void -xcwm_image_destroy(xcwm_image_t * xcwm_image){ +void +xcwm_image_destroy(xcwm_image_t * xcwm_image) +{ xcb_image_destroy(xcwm_image->image); free(xcwm_image); } - void -xcwm_remove_context_damage(xcwm_context_t *context) +xcwm_remove_context_damage(xcwm_context_t * context) { - xcb_xfixes_region_t region = xcb_generate_id(context->conn); - xcb_rectangle_t rect; - xcb_void_cookie_t cookie; - - if (!context) { - return; - } - - rect.x = context->damaged_x; - rect.y = context->damaged_y; - rect.width = context->damaged_width; - rect.height = context->damaged_height; - - xcb_xfixes_create_region(root_context->conn, - region, - 1, - &rect); - - cookie = xcb_damage_subtract_checked (context->conn, - context->damage, - region, - 0); - - if (!(_xcwm_request_check(context->conn, cookie, - "Failed to subtract damage"))) { - context->damaged_x = 0; - context->damaged_y = 0; - context->damaged_width = 0; - context->damaged_height = 0; - } - return; + xcb_xfixes_region_t region = xcb_generate_id(context->conn); + + xcb_rectangle_t rect; + + xcb_void_cookie_t cookie; + + if (!context) { + return; + } + + rect.x = context->damaged_x; + rect.y = context->damaged_y; + rect.width = context->damaged_width; + rect.height = context->damaged_height; + + xcb_xfixes_create_region(root_context->conn, region, 1, &rect); + + cookie = xcb_damage_subtract_checked(context->conn, + context->damage, region, 0); + + if (!(_xcwm_request_check(context->conn, cookie, + "Failed to subtract damage"))) { + context->damaged_x = 0; + context->damaged_y = 0; + context->damaged_width = 0; + context->damaged_height = 0; + } + return; } /* Close all windows, the connection, as well as the event loop */ -void xcwm_close(void) { - +void +xcwm_close(void) +{ + _xcwm_context_node *head = _xcwm_window_list_head; + xcb_connection_t *conn = head->context->conn; + xcb_flush(conn); - + // Close all windows - while(head) { + while (head) { xcwm_request_close(head->context); _xcwm_window_list_head = head->next; free(head); head = _xcwm_window_list_head; } - + // Disconnect from the display xcb_disconnect(conn); - + // Terminate the event loop int ret = _xcwm_stop_event_loop(); - if (ret != 1) printf("Event loop failed to close\n"); - + + if (ret != 1) + printf("Event loop failed to close\n"); + return; - -} +} diff --git a/src/libxcwm/xcwm_internal.h b/src/libxcwm/xcwm_internal.h index 94081c7..ed99b58 100644 --- a/src/libxcwm/xcwm_internal.h +++ b/src/libxcwm/xcwm_internal.h @@ -44,8 +44,8 @@ * Strucuture used to pass nesessary data to xcwm_start_event_loop. */ typedef struct xcwm_event_connetion { - xcb_connection_t *conn; /* Connection to listen to events on */ - xcwm_event_cb_t event_callback; /* Fuction to call when event caught */ + xcb_connection_t *conn; /* Connection to listen to events on */ + xcwm_event_cb_t event_callback; /* Fuction to call when event caught */ } xcwm_event_connection; /** @@ -75,8 +75,10 @@ extern pthread_mutex_t event_thread_lock; * @param window The window. * @return The window attributes reply. Null if the request fails. */ -xcb_get_window_attributes_reply_t * -_xcwm_get_window_attributes (xcb_connection_t *conn, xcb_window_t window); +xcb_get_window_attributes_reply_t *_xcwm_get_window_attributes(xcb_connection_t + * conn, + xcb_window_t + window); /** * Return the geometry of the window in a geometry reply. Caller must free @@ -85,8 +87,8 @@ _xcwm_get_window_attributes (xcb_connection_t *conn, xcb_window_t window); * @param window The window. * @return The window's geometry reply. Null if the request for reply fails. */ -xcb_get_geometry_reply_t * -_xcwm_get_window_geometry (xcb_connection_t *conn, xcb_window_t window); +xcb_get_geometry_reply_t *_xcwm_get_window_geometry(xcb_connection_t * conn, + xcb_window_t window); /** * Print out information about the existing windows attached to our @@ -97,8 +99,9 @@ _xcwm_get_window_geometry (xcb_connection_t *conn, xcb_window_t window); * @return the geometry of the window */ void -_xcwm_write_all_children_window_info (xcb_connection_t *conn, - xcb_window_t root); + +_xcwm_write_all_children_window_info(xcb_connection_t * conn, + xcb_window_t root); /** * Get the image data for a window. @@ -107,7 +110,7 @@ _xcwm_write_all_children_window_info (xcb_connection_t *conn, * @return a structure containing data and data length. */ image_data_t -_xcwm_get_window_image_data (xcb_connection_t *conn, xcb_window_t window); +_xcwm_get_window_image_data(xcb_connection_t * conn, xcb_window_t window); /** * Write information about a window out to stdio. @@ -116,7 +119,7 @@ _xcwm_get_window_image_data (xcb_connection_t *conn, xcb_window_t window); * @param window The window. */ void -_xcwm_write_window_info (xcb_connection_t *conn, xcb_window_t window); + _xcwm_write_window_info(xcb_connection_t * conn, xcb_window_t window); /** * Check the request cookie and determine if there is an error. @@ -126,8 +129,9 @@ _xcwm_write_window_info (xcb_connection_t *conn, xcb_window_t window); * @return int The number of the error code, if any. Otherwise zero. */ int -_xcwm_request_check (xcb_connection_t *conn, xcb_void_cookie_t cookie, - char *msg); + +_xcwm_request_check(xcb_connection_t * conn, xcb_void_cookie_t cookie, + char *msg); /**************** * init.c @@ -139,38 +143,38 @@ _xcwm_request_check (xcb_connection_t *conn, xcb_void_cookie_t cookie, * @param extension_name The string specifying the name of the extension. * @return The reply structure */ -xcb_query_extension_reply_t * -_xcwm_init_extension(xcb_connection_t *conn, char *extension_name); +xcb_query_extension_reply_t *_xcwm_init_extension(xcb_connection_t * conn, + char *extension_name); /** * Initializes damage on a window contained in a context. * The context will likely contain the root window. * @param contxt A context containing a window */ -void -_xcwm_init_damage(xcwm_context_t *contxt); +void + _xcwm_init_damage(xcwm_context_t * contxt); /** * Initializes the composite extension on the context containg * the root window. * @param contxt The contxt containing the root window */ -void -_xcwm_init_composite(xcwm_context_t *contxt); +void + _xcwm_init_composite(xcwm_context_t * contxt); /** * Initialize the xfixes extension. * @param contxt The context */ void -_xcwm_init_xfixes (xcwm_context_t *contxt); + _xcwm_init_xfixes(xcwm_context_t * contxt); /** * Get the values for the WM_* atoms that we need. * @param contxt The context */ void -_xcwm_get_wm_atoms (xcwm_context_t *contxt); + _xcwm_get_wm_atoms(xcwm_context_t * contxt); /**************** * event_loop.c @@ -184,15 +188,15 @@ _xcwm_get_wm_atoms (xcwm_context_t *contxt); * @return 0 on success, nonzero on failure. */ int -_xcwm_start_event_loop (xcb_connection_t *conn, - xcwm_event_cb_t event_callback); + +_xcwm_start_event_loop(xcb_connection_t * conn, xcwm_event_cb_t event_callback); /** * Stops the thread running the event loop. * @return 0 on success, otherwise zero. */ int -_xcwm_stop_event_loop (void); + _xcwm_stop_event_loop(void); /**************** * context_list.c @@ -204,8 +208,8 @@ _xcwm_stop_event_loop (void); */ typedef struct _xcwm_context_node { struct xcwm_context_t *context; /**< Pointer to a context */ - struct _xcwm_context_node * next; /**< Pointer to the next context node */ - struct _xcwm_context_node * prev; /**< Pointer to the previous context node */ + struct _xcwm_context_node *next; /**< Pointer to the next context node */ + struct _xcwm_context_node *prev; /**< Pointer to the previous context node */ } _xcwm_context_node; /* this is the head pointer */ @@ -216,8 +220,7 @@ extern _xcwm_context_node *_xcwm_window_list_head; * @param context The context to be added to the linked list * @return Pointer to context added to the list. */ -xcwm_context_t * -_xcwm_add_context_t(struct xcwm_context_t *context); +xcwm_context_t *_xcwm_add_context_t(struct xcwm_context_t *context); /** * Remove a context to the context_list using the window's id. @@ -225,15 +228,14 @@ _xcwm_add_context_t(struct xcwm_context_t *context); * be removed from the context_list */ void -_xcwm_remove_context_node(xcb_window_t window_id); + _xcwm_remove_context_node(xcb_window_t window_id); /** * Find a context in the doubly linked list using its window_id. * @param window_id The window_id of the context which should * @return Pointer to context (if found), NULL if not found. */ -xcwm_context_t * -_xcwm_get_context_node_by_window_id (xcb_window_t window_id); +xcwm_context_t *_xcwm_get_context_node_by_window_id(xcb_window_t window_id); /**************** * window.c @@ -245,9 +247,8 @@ _xcwm_get_context_node_by_window_id (xcb_window_t window_id); * @param evt The map event for the window * @return Pointer to new context. NULL if window already exists. */ -xcwm_context_t * -_xcwm_window_created(xcb_connection_t * conn, - xcb_map_request_event_t *evt); +xcwm_context_t *_xcwm_window_created(xcb_connection_t * conn, + xcb_map_request_event_t * evt); /** * Destroy the damage object associated with the window. * Call the remove function in context_list.c @@ -256,8 +257,7 @@ _xcwm_window_created(xcb_connection_t * conn, * @return Pointer to the context that was removed from the list, NULL if * window isn't being managed by context_list */ -xcwm_context_t * -_xcwm_destroy_window(xcb_destroy_notify_event_t *event); +xcwm_context_t *_xcwm_destroy_window(xcb_destroy_notify_event_t * event); /** * Resize the window to given width and height. @@ -267,14 +267,15 @@ _xcwm_destroy_window(xcb_destroy_notify_event_t *event); * @param height The new height */ void -_xcwm_resize_window (xcb_connection_t *conn, xcb_window_t window, - int width, int height); + +_xcwm_resize_window(xcb_connection_t * conn, xcb_window_t window, + int width, int height); /** * Map the given window. * @param context The context of the window to map */ void -_xcwm_map_window (xcwm_context_t *context); + _xcwm_map_window(xcwm_context_t * context); -#endif /* _XTOQ_INTERNAL_H_ */ +#endif /* _XTOQ_INTERNAL_H_ */ |