summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess VanDerwalker <washu@sonic.net>2012-04-04 15:24:00 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2012-04-05 11:55:55 -0700
commitdc0096d06db812fe3dd028c62acedf487982b098 (patch)
tree47110dcc2cc7e45c5d938675272570369d095284
parent9bd6cfc3e9316c8545f465d416031369d278ebf8 (diff)
Separate xcwm_context_t into two types, a context and a window
xcwm_context_t is now broken into xcwm_context_t which holds connection data, and xcwm_window_t which holds window specific data. Signed-off-by: Jess VanDerwalker <washu@sonic.net>
-rw-r--r--include/xcwm/event.h8
-rw-r--r--include/xcwm/xtoq.h68
-rw-r--r--src/libxcwm/context_list.c33
-rw-r--r--src/libxcwm/data.h1
-rw-r--r--src/libxcwm/event_loop.c55
-rw-r--r--src/libxcwm/init.c35
-rw-r--r--src/libxcwm/input.c12
-rw-r--r--src/libxcwm/window.c175
-rw-r--r--src/libxcwm/xcwm.c103
-rw-r--r--src/libxcwm/xcwm_internal.h58
-rw-r--r--src/xtoq/XtoqController.h18
-rw-r--r--src/xtoq/XtoqController.m101
-rw-r--r--src/xtoq/XtoqView.h12
-rw-r--r--src/xtoq/XtoqView.m18
-rw-r--r--src/xtoq/XtoqWindow.h16
-rw-r--r--src/xtoq/XtoqWindow.m14
16 files changed, 398 insertions, 329 deletions
diff --git a/include/xcwm/event.h b/include/xcwm/event.h
index d9d2b00..a8259f8 100644
--- a/include/xcwm/event.h
+++ b/include/xcwm/event.h
@@ -54,6 +54,14 @@ int xcwm_event_get_type(xcwm_event_t const *event);
xcwm_context_t * xcwm_event_get_context(xcwm_event_t const *event);
/**
+ * Return the window for the given event.
+ * @param event The event
+ * @return The window connected to the event.
+ */
+xcwm_window_t *
+xcwm_event_get_window(xcwm_event_t const *event);
+
+/**
* Starts the event loop and listens on the connection specified in
* the given xcwm_context_t. Uses callback as the function to call
* when an event of interest is received. Callback must be able to
diff --git a/include/xcwm/xtoq.h b/include/xcwm/xtoq.h
index 70bc4de..31bfad4 100644
--- a/include/xcwm/xtoq.h
+++ b/include/xcwm/xtoq.h
@@ -46,11 +46,9 @@
/* Abstract types for xcwm data types */
-/* FIXME: Obfuscate these */
-struct xcwm_context_t {
- xcb_connection_t *conn;
- xcb_drawable_t window;
- xcb_window_t parent;
+struct xcwm_window_t {
+ xcb_drawable_t window_id;
+ struct xcwm_window_t *parent;
xcb_damage_damage_t damage;
int x;
int y;
@@ -64,6 +62,12 @@ struct xcwm_context_t {
int wm_delete_set; /* Flag for WM_DELETE_WINDOW, 1 if set */
void *local_data; /* Area for data client cares about */
};
+typedef struct xcwm_window_t xcwm_window_t;
+
+struct xcwm_context_t {
+ xcb_connection_t *conn;
+ xcwm_window_t *root_window;
+};
typedef struct xcwm_context_t xcwm_context_t;
struct image_data_t {
@@ -82,14 +86,6 @@ struct xcwm_image_t {
typedef struct xcwm_image_t xcwm_image_t;
/**
- * Context which contains the display's root window.
- *
- * FIXME: We should avoid having global state where at all possible, and
- * certainly not export such state for client access
- */
-extern xcwm_context_t *root_context;
-
-/**
* Sets up the connection and grabs the root window from the specified screen
* @param display the display to connect to
* @return The root context which contains the root window
@@ -100,20 +96,21 @@ xcwm_init(char *display);
/**
* Returns a window's entire image
* @param an xcwm_context_t
- * FIXME: this might be for the root window
+ * @param window The window to get image from.
* @return an xcwm_image_t with an the image of a window
*/
xcwm_image_t *
-xcwm_get_image(xcwm_context_t *context);
+xcwm_get_image(xcwm_context_t *context, xcwm_window_t *window);
/**
* Intended for servicing to a client's reaction to a damage notification
* this window returns the modified subrectangle of a window
- * @param an xcwm_context_t of the damaged window
+ * @param context The context of the window
+ * @param window The window to get image from
* @return an xcwm_image_t with partial image window contents
*/
xcwm_image_t *
-test_xcwm_get_image(xcwm_context_t * context);
+test_xcwm_get_image(xcwm_context_t *context, xcwm_window_t *window);
/**
@@ -127,37 +124,42 @@ xcwm_image_destroy(xcwm_image_t * xcwm_image);
/**
* Set input focus to the window in context
* @param context The context containing the window
+ * @param window The window to set focus to
*/
void
-xcwm_set_input_focus(xcwm_context_t *context);
+xcwm_set_input_focus(xcwm_context_t *context, xcwm_window_t *window);
/**
* Set a window to the bottom of the window stack.
* @param context The context containing the window
+ * @param window The window to move to bottom
*/
void
-xcwm_set_window_to_bottom(xcwm_context_t *context);
+xcwm_set_window_to_bottom(xcwm_context_t *context, xcwm_window_t *window);
/**
* Set a window to the top of the window stack.
- * @param context The context containing the window
+ * @param context The context containing the window.
+ * @param window The window to move.
*/
void
-xcwm_set_window_to_top(xcwm_context_t *context);
+xcwm_set_window_to_top(xcwm_context_t *context, xcwm_window_t *window);
/**
- * Remove the damage from the given context.
- * @param context The context to remove the damage from
+ * Remove the damage from a given window.
+ * @param context The context of the window.
+ * @param window The window to remove damage from
*/
void
-xcwm_remove_context_damage(xcwm_context_t *context);
+xcwm_remove_window_damage (xcwm_context_t *context, xcwm_window_t *window);
/**
* Closes the windows open on the X Server, the connection, and the event
* loop.
+ * @param context The context to close.
*/
-void
-xcwm_close(void);
+void
+xcwm_close (xcwm_context_t *context);
/**
* Send key event to the X server.
@@ -174,13 +176,15 @@ xcwm_input_key_event (xcwm_context_t *context, uint8_t code, int state);
* will often choose to send coordinates through mouse motion and set the params
* x & y to 0 here.
* @param context xcwm_context_t
+ * @param window The window the event occured in.
* @param x - x coordinate
* @param y - y coordinate
* @param button The mouse button pressed.
* @param state 1 if the mouse button is pressed down, 0 if released.
*/
void
-xcwm_input_mouse_button_event (xcwm_context_t *context, long x, long y,
+xcwm_input_mouse_button_event (xcwm_context_t *context, xcwm_window_t *window,
+ long x, long y,
int button, int state);
/**
@@ -199,20 +203,24 @@ xcwm_input_mouse_motion (xcwm_context_t *context, long x, long y, int button);
/**
* kill the window, if possible using WM_DELETE_WINDOW (icccm)
* otherwise using xcb_kill_client.
- * @param context The context of the window to be killed
+ * @param context The context of the window
+ * @param window The window to be closed.
*/
void
-xcwm_request_close(xcwm_context_t *context);
+xcwm_request_close(xcwm_context_t *context, xcwm_window_t *window);
/**
* move and/or resize the window, update the context
* @param context the context of the window to configure
+ * @param window The window to configure
* @param x The new x coordinate
* @param y The new y coordinate
* @param height The new height
* @param width The new width
*/
void
-xcwm_configure_window(xcwm_context_t *context, int x, int y, int height, int width);
+xcwm_configure_window(xcwm_context_t *context, xcwm_window_t *window,
+ 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..6cb899c 100644
--- a/src/libxcwm/context_list.c
+++ b/src/libxcwm/context_list.c
@@ -29,22 +29,19 @@
#include "xcwm_internal.h"
-_xcwm_context_node *_xcwm_window_list_head = NULL;
+_xcwm_window_node *_xcwm_window_list_head = NULL;
-xcwm_context_t *
-_xcwm_add_context_t(struct xcwm_context_t *context)
+xcwm_window_t *
+_xcwm_add_window(xcwm_window_t *window)
{
- /* temp pointers for traversing */
- _xcwm_context_node *new_node;
- _xcwm_context_node *curr;
- _xcwm_context_node *prev;
+ _xcwm_window_node *new_node;
/* Create node to hold the new window */
- new_node = malloc(sizeof(_xcwm_context_node));
+ new_node = malloc(sizeof(_xcwm_window_node));
if (!new_node) {
exit(1);
}
- new_node->context = context;
+ new_node->window = window;
/* Handle the case where this is the first node added */
if (!_xcwm_window_list_head) {
@@ -59,18 +56,18 @@ _xcwm_add_context_t(struct xcwm_context_t *context)
_xcwm_window_list_head = new_node;
}
- return new_node->context;
+ return new_node->window;
}
-xcwm_context_t *
-_xcwm_get_context_node_by_window_id (xcb_window_t window_id)
+xcwm_window_t *
+_xcwm_get_window_node_by_window_id (xcb_window_t window_id)
{
- _xcwm_context_node *curr;
+ _xcwm_window_node *curr;
curr = _xcwm_window_list_head;
while (curr) {
- if (curr->context->window == window_id) {
- return curr->context;
+ if (curr->window->window_id == window_id) {
+ return curr->window;
}
curr = curr->next;
}
@@ -79,13 +76,13 @@ _xcwm_get_context_node_by_window_id (xcb_window_t window_id)
void
-_xcwm_remove_context_node(xcb_window_t window_id) {
+_xcwm_remove_window_node(xcb_window_t window_id) {
- _xcwm_context_node *curr;
+ _xcwm_window_node *curr;
curr = _xcwm_window_list_head;
while (curr != NULL) {
- if (curr->context->window == window_id) {
+ if (curr->window->window_id == window_id) {
// this will be freed in the event_loop
if(curr->next){
curr->next->prev = curr->prev;
diff --git a/src/libxcwm/data.h b/src/libxcwm/data.h
index fc1e911..ce0f8dd 100644
--- a/src/libxcwm/data.h
+++ b/src/libxcwm/data.h
@@ -30,6 +30,7 @@
struct xcwm_event_t {
xcwm_context_t *context;
+ xcwm_window_t *window;
int event_type;
};
diff --git a/src/libxcwm/event_loop.c b/src/libxcwm/event_loop.c
index 681c168..247acf8 100644
--- a/src/libxcwm/event_loop.c
+++ b/src/libxcwm/event_loop.c
@@ -124,9 +124,9 @@ void *run_event_loop (void *thread_arg_struct)
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) {
+ return_evt->window =
+ _xcwm_get_window_node_by_window_id(dmgevnt->drawable);
+ if (!return_evt->window) {
free(return_evt);
continue;
}
@@ -137,30 +137,30 @@ void *run_event_loop (void *thread_arg_struct)
* 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;
+ old_x = return_evt->window->damaged_x;
+ old_y = return_evt->window->damaged_y;
+ old_width = return_evt->window->damaged_width;
+ old_height = return_evt->window->damaged_height;
- if (return_evt->context->damaged_width == 0) {
+ if (return_evt->window->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;
+ return_evt->window->damaged_x = dmgevnt->area.x;
+ return_evt->window->damaged_y = dmgevnt->area.y;
+ return_evt->window->damaged_width = dmgevnt->area.width;
+ return_evt->window->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;
+ return_evt->window->damaged_x = dmgevnt->area.x;
}
if ( old_y > dmgevnt->area.y) {
- return_evt->context->damaged_y = dmgevnt->area.y;
+ return_evt->window->damaged_y = dmgevnt->area.y;
}
if ( old_width < dmgevnt->area.width) {
- return_evt->context->damaged_width = dmgevnt->area.width;
+ return_evt->window->damaged_width = dmgevnt->area.width;
}
if ( old_height < dmgevnt->area.height) {
- return_evt->context->damaged_height = dmgevnt->area.height;
+ return_evt->window->damaged_height = dmgevnt->area.height;
}
}
xcwm_release_event_thread_lock();
@@ -217,31 +217,33 @@ void *run_event_loop (void *thread_arg_struct)
}
case XCB_DESTROY_NOTIFY: {
// Window destroyed in root window
- xcb_destroy_notify_event_t *notify = (xcb_destroy_notify_event_t *)evt;
- xcwm_context_t *context = _xcwm_destroy_window(notify);
+ xcb_destroy_notify_event_t *notify =
+ (xcb_destroy_notify_event_t *)evt;
+ xcwm_window_t *window =
+ _xcwm_destroy_window(event_conn, notify);
- if (!context) {
+ if (!window) {
/* 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;
+ return_evt->window = window;
callback_ptr(return_evt);
- free(context);
+ free(window);
break;
}
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) {
+ return_evt->window = _xcwm_window_created(event_conn, request);
+ if (!return_evt->window) {
free(return_evt);
break;
}
- _xcwm_map_window(return_evt->context);
+ _xcwm_map_window(event_conn, return_evt->window);
return_evt->event_type = XTOQ_CREATE;
callback_ptr(return_evt);
break;
@@ -306,8 +308,13 @@ xcwm_event_get_type(xcwm_event_t const *event) {
return event->event_type;
}
+/* FIXME: Do we still need a context in the event? Probably not... */
xcwm_context_t *
xcwm_event_get_context(xcwm_event_t const *event) {
return event->context;
}
+xcwm_window_t *
+xcwm_event_get_window(xcwm_event_t const *event) {
+ return event->window;
+}
diff --git a/src/libxcwm/init.c b/src/libxcwm/init.c
index fdb89fd..14f2593 100644
--- a/src/libxcwm/init.c
+++ b/src/libxcwm/init.c
@@ -54,13 +54,15 @@ void
_xcwm_init_damage(xcwm_context_t *contxt)
{
- xcb_query_extension_reply_t *reply =_xcwm_init_extension(contxt->conn, "DAMAGE");
+ 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_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;
@@ -69,26 +71,36 @@ _xcwm_init_damage(xcwm_context_t *contxt)
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.
+ /* Refer to the Damage Protocol. Using
+ * DamageReportLevelBoundingBox. 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);
+ xcb_damage_create(contxt->conn,
+ damage,
+ contxt->root_window->window_id,
+ level);
/* Assign this damage object to the roots window's context */
- contxt->damage = damage;
+ contxt->root_window->damage = damage;
}
void
_xcwm_init_composite(xcwm_context_t *contxt) {
- xcb_query_extension_reply_t *reply = _xcwm_init_extension(contxt->conn, "Composite");
+ 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_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_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);
+ xcb_composite_redirect_subwindows_checked(contxt->conn,
+ contxt->root_window->window_id,
+ XCB_COMPOSITE_REDIRECT_MANUAL);
free(version_reply);
free(reply);
@@ -112,7 +124,6 @@ _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;
_wm_atoms = malloc(sizeof(xcwm_wm_atoms));
diff --git a/src/libxcwm/input.c b/src/libxcwm/input.c
index b156053..0ff717d 100644
--- a/src/libxcwm/input.c
+++ b/src/libxcwm/input.c
@@ -44,11 +44,11 @@ xcwm_input_key_event (xcwm_context_t *context, uint8_t code, int state)
XCB_CURRENT_TIME, none, 0, 0, 1 );
xcb_flush(context->conn);
- printf("xcwm.c received key event - uint8_t '%i', to context.window %u\n", code, context->window);
+ printf("xcwm.c received key event - uint8_t '%i'\n", code);
}
void
-xcwm_input_mouse_button_event (xcwm_context_t *context,
+xcwm_input_mouse_button_event (xcwm_context_t *context, xcwm_window_t *window,
long x, long y,
int button, int state)
{
@@ -59,17 +59,19 @@ xcwm_input_mouse_button_event (xcwm_context_t *context,
} else {
button_state = XCB_BUTTON_RELEASE;
}
+ /* FIXME: Why are we passing a specifing window ID here, when
+ * other handlers use either the root window or none. */
xcb_test_fake_input (context->conn, button_state, button, XCB_CURRENT_TIME,
- context->window, 0, 0, 0);
+ window->window_id, 0, 0, 0);
xcb_flush(context->conn);
printf("Mouse event received by xtoq.c - (%ld,%ld), state: %d\n",
x, y, state);
}
void
-xcwm_input_mouse_motion (xcwm_context_t *context, long x, long y,int button)
+xcwm_input_mouse_motion (xcwm_context_t *context, long x, long y, int button)
{
xcb_test_fake_input (context->conn, XCB_MOTION_NOTIFY, 0, XCB_CURRENT_TIME,
- root_context->window, x, y, 0);
+ context->root_window->window_id, x, y, 0);
xcb_flush(context->conn);
}
diff --git a/src/libxcwm/window.c b/src/libxcwm/window.c
index 5dbf1c0..88a7bd9 100644
--- a/src/libxcwm/window.c
+++ b/src/libxcwm/window.c
@@ -34,133 +34,137 @@
/* Sets the WM_* properties we care about in context */
void
-set_icccm_properties (xcwm_context_t *context);
+set_icccm_properties (xcb_connection_t *conn, xcwm_window_t *window);
/* Set the WM_NAME property in context */
void
-set_wm_name_in_context (xcwm_context_t *context);
+set_wm_name_in_context (xcb_connection_t *conn, xcwm_window_t *window);
/* 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 (xcb_connection_t *conn, xcwm_window_t *window);
/* Initialize damage on a window */
void
-init_damage_on_window (xcwm_context_t *context);
+init_damage_on_window (xcb_connection_t *conn, xcwm_window_t *window);
/* 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, xcwm_window_t *window) {
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_configure_window (context->conn, window->window_id,
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, xcwm_window_t *window) {
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_configure_window (context->conn, window->window_id,
XCB_CONFIG_WINDOW_STACK_MODE, values);
}
/* Set input focus to window */
void
-xcwm_set_input_focus(xcwm_context_t *context) {
+xcwm_set_input_focus(xcwm_context_t *context, xcwm_window_t *window) {
// 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);
+ reply->focus, window->window_id);
free(reply);
// End test -- David
xcb_set_input_focus(context->conn, XCB_INPUT_FOCUS_PARENT,
- context->window, XCB_CURRENT_TIME);
+ window->window_id, XCB_CURRENT_TIME);
xcb_flush(context->conn);
}
-xcwm_context_t *
+xcwm_window_t *
_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)) {
+ if (_xcwm_get_window_node_by_window_id(event->window)) {
return NULL;
}
- /* allocate memory for new xcwm_context_t */
- xcwm_context_t *context = malloc(sizeof(xcwm_context_t));
+ /* allocate memory for new xcwm_window_t */
+ xcwm_window_t *window = malloc(sizeof(xcwm_window_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;
- context->window = event->window;
- context->parent = event->parent;
- context->x = geom->x;
- context->y = geom->y;
- context->width = geom->width;
- context->height = geom->height;
+ window->window_id = event->window;
+ window->x = geom->x;
+ window->y = geom->y;
+ window->width = geom->width;
+ window->height = geom->height;
+
+ /* Find an set the parent */
+ window->parent = _xcwm_get_window_node_by_window_id(event->parent);
free (geom);
/* Set the ICCCM properties we care about */
- set_icccm_properties(context);
+ set_icccm_properties(conn, window);
/* register for damage */
- init_damage_on_window(context);
+ init_damage_on_window(conn, window);
/* add context to context_list */
- context = _xcwm_add_context_t(context);
+ window = _xcwm_add_window(window);
- return context;
+ return window;
}
-xcwm_context_t *
-_xcwm_destroy_window(xcb_destroy_notify_event_t *event) {
+xcwm_window_t *
+_xcwm_destroy_window(xcb_connection_t *conn,
+ xcb_destroy_notify_event_t *event) {
- xcwm_context_t *context =
- _xcwm_get_context_node_by_window_id(event->window);
- if (!context) {
+ xcwm_window_t *window =
+ _xcwm_get_window_node_by_window_id(event->window);
+ if (!window) {
/* 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(conn, window->damage);
/* Call the remove function in context_list.c */
- _xcwm_remove_context_node(context->window);
+ _xcwm_remove_window_node(window->window_id);
/* Return the pointer for the context that was removed from the list. */
- return context;
+ return window;
}
void
-xcwm_configure_window(xcwm_context_t *context, int x, int y, int height, int width) {
+xcwm_configure_window(xcwm_context_t *context, xcwm_window_t *window,
+ 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;
+ /* Set values for xcwm_window_t */
+ window->x = x;
+ window->y = y;
+ window->width = width;
+ window->height = height;
uint32_t values[] = {(uint32_t)x, (uint32_t)y,
(uint32_t)width, (uint32_t)height };
xcb_configure_window (context->conn,
- context->window,
+ window->window_id,
XCB_CONFIG_WINDOW_X |
XCB_CONFIG_WINDOW_Y |
XCB_CONFIG_WINDOW_WIDTH |
@@ -168,41 +172,42 @@ xcwm_configure_window(xcwm_context_t *context, int x, int y, int height, int wid
values);
/* Set the damage area to the new window size so its redrawn properly */
- context->damaged_width = width;
- context->damaged_height = height;
+ window->damaged_width = width;
+ window->damaged_height = height;
xcb_flush(context->conn);
return;
}
void
-xcwm_request_close(xcwm_context_t *context) {
+xcwm_request_close(xcwm_context_t *context, xcwm_window_t *window) {
/* check to see if the context is in the list */
- context = _xcwm_get_context_node_by_window_id(context->window);
- if (!context)
+
+ if (!_xcwm_get_window_node_by_window_id(window->window_id))
return;
/* kill using xcb_kill_client */
- if (!context->wm_delete_set == 1) {
- xcb_kill_client(context->conn, context->window);
+ if (!window->wm_delete_set == 1) {
+ xcb_kill_client(context->conn, window->window_id);
xcb_flush(context->conn);
return;
}
/* kill using WM_DELETE_WINDOW */
- if (context->wm_delete_set == 1){
+ if (window->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.window = window->window_id;
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,
+ xcb_send_event(context->conn, 0, window->window_id,
+ XCB_EVENT_MASK_NO_EVENT,
(char*)&event);
xcb_flush(context->conn);
return;
@@ -227,22 +232,22 @@ _xcwm_resize_window (xcb_connection_t *conn, xcb_window_t window,
}
void
-_xcwm_map_window (xcwm_context_t *context)
+_xcwm_map_window (xcb_connection_t *conn, xcwm_window_t *window)
{
/* Map the window. May want to handle other things here */
- xcb_map_window(context->conn, context->window);
- xcb_flush(context->conn);
+ xcb_map_window(conn, window->window_id);
+ xcb_flush(conn);
}
void
-set_icccm_properties (xcwm_context_t *context)
+set_icccm_properties (xcb_connection_t *conn, xcwm_window_t *window)
{
- set_wm_name_in_context(context);
- set_wm_delete_win_in_context(context);
+ set_wm_name_in_context(conn, window);
+ set_wm_delete_win_in_context(conn, window);
}
void
-set_wm_name_in_context (xcwm_context_t *context)
+set_wm_name_in_context (xcb_connection_t *conn, xcwm_window_t *window)
{
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply;
@@ -250,30 +255,28 @@ set_wm_name_in_context (xcwm_context_t *context)
char *value;
int length;
- cookie = xcb_get_property(context->conn,
+ cookie = xcb_get_property(conn,
0,
- context->window,
+ window->window_id,
XCB_ATOM_WM_NAME,
XCB_GET_PROPERTY_TYPE_ANY,
0,
128);
- reply = xcb_get_property_reply(context->conn,
- cookie,
- &error);
+ reply = xcb_get_property_reply(conn, cookie, &error);
if (!reply) {
- context->name = NULL;
+ window->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';
+ window->name = malloc(sizeof(char) * (length + 1));
+ strncpy(window->name, value, length);
+ window->name[length] = '\0';
}
void
-set_wm_delete_win_in_context (xcwm_context_t *context)
+set_wm_delete_win_in_context (xcb_connection_t *conn, xcwm_window_t *window)
{
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply;
@@ -283,20 +286,18 @@ set_wm_delete_win_in_context (xcwm_context_t *context)
int i;
/* Get the WM_PROTOCOLS */
- cookie = xcb_get_property(context->conn,
+ cookie = xcb_get_property(conn,
0,
- context->window,
+ window->window_id,
_wm_atoms->wm_protocols_atom,
XCB_ATOM_ATOM,
0,
UINT_MAX);
- reply = xcb_get_property_reply(context->conn,
- cookie,
- &error);
+ reply = xcb_get_property_reply(conn, cookie, &error);
if (!reply) {
- context->wm_delete_set = 0;
+ window->wm_delete_set = 0;
return;
}
prop_length = xcb_get_property_value_length(reply);
@@ -306,45 +307,45 @@ set_wm_delete_win_in_context (xcwm_context_t *context)
/* See if the WM_DELETE_WINDOW is in WM_PROTOCOLS */
for (i = 0; i < prop_length; i++) {
if (prop_atoms[i] == _wm_atoms->wm_delete_window_atom) {
- context->wm_delete_set = 1;
+ window->wm_delete_set = 1;
return;
}
}
- context->wm_delete_set = 0;
+ window->wm_delete_set = 0;
return;
}
void
-init_damage_on_window (xcwm_context_t *context)
+init_damage_on_window (xcb_connection_t *conn, xcwm_window_t *window)
{
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(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,
+ cookie = xcb_damage_create(conn,
damage_id,
- context->window,
+ window->window_id,
level);
- if (_xcwm_request_check(context->conn, cookie,
+ if (_xcwm_request_check(conn, cookie,
"Could not create damage for window")) {
- context->damage = 0;
+ window->damage = 0;
return;
}
/* Assign this damage object to the roots window's context */
- context->damage = damage_id;
+ window->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;
+ window->damaged_x = 0;
+ window->damaged_y = 0;
+ window->damaged_width = 0;
+ window->damaged_height = 0;
}
diff --git a/src/libxcwm/xcwm.c b/src/libxcwm/xcwm.c
index 161bdcc..fec2da3 100644
--- a/src/libxcwm/xcwm.c
+++ b/src/libxcwm/xcwm.c
@@ -35,25 +35,24 @@
// 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_context_t *root_context;
xcb_connection_t *conn;
int conn_screen;
xcb_screen_t *root_screen;
- xcb_drawable_t root_window;
+ xcb_window_t root_window_id;
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;
+ root_window_id = 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
@@ -68,7 +67,8 @@ xcwm_init(char *display) {
XCB_EVENT_MASK_ENTER_WINDOW |
XCB_EVENT_MASK_LEAVE_WINDOW |
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
- cookie = xcb_change_window_attributes_checked(conn, root_window,
+ cookie = xcb_change_window_attributes_checked(conn,
+ root_window_id,
XCB_CW_EVENT_MASK,
mask_values);
if (_xcwm_request_check(conn, cookie, "Could not set root window mask.")) {
@@ -80,15 +80,19 @@ xcwm_init(char *display) {
xcb_flush(conn);
root_context = malloc(sizeof(xcwm_context_t));
+ assert(root_context);
+ root_context->root_window = malloc(sizeof(xcwm_window_t));
+ assert(root_context);
+
root_context->conn = conn;
- root_context->parent = 0;
- root_context->window = root_window;
+ root_context->root_window->parent = 0;
+ root_context->root_window->window_id = root_window_id;
// 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;
- root_context->x = 0;
- root_context->y = 0;
+ root_context->root_window->width = root_screen->width_in_pixels;
+ root_context->root_window->height = root_screen->height_in_pixels;
+ root_context->root_window->x = 0;
+ root_context->root_window->y = 0;
_xcwm_init_composite(root_context);
@@ -96,7 +100,8 @@ xcwm_init(char *display) {
_xcwm_init_xfixes(root_context);
- _xcwm_add_context_t(root_context);
+ /* Add the root window to our list of windows being managed */
+ _xcwm_add_window(root_context->root_window);
syms = xcb_key_symbols_alloc(conn);
_xcwm_init_extension(conn, "XTEST");
@@ -108,21 +113,21 @@ xcwm_init(char *display) {
}
xcwm_image_t *
-xcwm_get_image(xcwm_context_t *context) {
+xcwm_get_image(xcwm_context_t *context, xcwm_window_t *window) {
xcb_get_geometry_reply_t *geom_reply;
xcb_image_t *image;
- geom_reply = _xcwm_get_window_geometry(context->conn, context->window);
+ geom_reply = _xcwm_get_window_geometry(context->conn, window->window_id);
//FIXME - right size
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 */
+ /* Get the full image of the window */
image = xcb_image_get(context->conn,
- context->window,
+ window->window_id,
geom_reply->x,
geom_reply->y,
geom_reply->width,
@@ -150,18 +155,18 @@ xcwm_start_event_loop (xcwm_context_t *context,
}
xcwm_image_t *
-test_xcwm_get_image(xcwm_context_t *context) {
+test_xcwm_get_image(xcwm_context_t *context, xcwm_window_t *window) {
xcb_image_t *image;
xcb_flush(context->conn);
/* Get the image of the root window */
image = xcb_image_get(context->conn,
- context->window,
- context->damaged_x,
- context->damaged_y,
- context->damaged_width,
- context->damaged_height,
+ window->window_id,
+ window->damaged_x,
+ window->damaged_y,
+ window->damaged_width,
+ window->damaged_height,
(unsigned int) ~0L,
XCB_IMAGE_FORMAT_Z_PIXMAP);
@@ -169,10 +174,10 @@ test_xcwm_get_image(xcwm_context_t *context) {
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;
- xcwm_image->width = context->damaged_width;
- xcwm_image->height = context->damaged_height;
+ xcwm_image->x = window->damaged_x;
+ xcwm_image->y = window->damaged_y;
+ xcwm_image->width = window->damaged_width;
+ xcwm_image->height = window->damaged_height;
return xcwm_image;
}
@@ -187,62 +192,64 @@ xcwm_image_destroy(xcwm_image_t * xcwm_image){
void
-xcwm_remove_context_damage(xcwm_context_t *context)
+xcwm_remove_window_damage(xcwm_context_t *context, xcwm_window_t *window)
{
xcb_xfixes_region_t region = xcb_generate_id(context->conn);
xcb_rectangle_t rect;
xcb_void_cookie_t cookie;
- if (!context) {
+ if (!window) {
return;
}
- rect.x = context->damaged_x;
- rect.y = context->damaged_y;
- rect.width = context->damaged_width;
- rect.height = context->damaged_height;
+ rect.x = window->damaged_x;
+ rect.y = window->damaged_y;
+ rect.width = window->damaged_width;
+ rect.height = window->damaged_height;
- xcb_xfixes_create_region(root_context->conn,
+ xcb_xfixes_create_region(context->conn,
region,
1,
&rect);
cookie = xcb_damage_subtract_checked (context->conn,
- context->damage,
+ window->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;
+ window->damaged_x = 0;
+ window->damaged_y = 0;
+ window->damaged_width = 0;
+ window->damaged_height = 0;
}
return;
}
/* Close all windows, the connection, as well as the event loop */
-void xcwm_close(void) {
+void
+xcwm_close(xcwm_context_t *context) {
- _xcwm_context_node *head = _xcwm_window_list_head;
- xcb_connection_t *conn = head->context->conn;
- xcb_flush(conn);
+ _xcwm_window_node *head = _xcwm_window_list_head;
+
+ xcb_flush(context->conn);
// Close all windows
while(head) {
- xcwm_request_close(head->context);
+ xcwm_request_close(context, head->window);
_xcwm_window_list_head = head->next;
free(head);
head = _xcwm_window_list_head;
}
+
+ // Terminate the event loop
+ if (_xcwm_stop_event_loop() != 1) {
+ printf("Event loop failed to close\n");
+ }
// 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");
+ xcb_disconnect(context->conn);
return;
diff --git a/src/libxcwm/xcwm_internal.h b/src/libxcwm/xcwm_internal.h
index 94081c7..b14f3c0 100644
--- a/src/libxcwm/xcwm_internal.h
+++ b/src/libxcwm/xcwm_internal.h
@@ -143,9 +143,8 @@ 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
+ * Initializes the damage extension.
+ * @param contxt The context containing.
*/
void
_xcwm_init_damage(xcwm_context_t *contxt);
@@ -202,38 +201,38 @@ _xcwm_stop_event_loop (void);
* A structure (doubly linked list) to hold
* pointers to the contexts
*/
-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 */
-} _xcwm_context_node;
+typedef struct _xcwm_window_node {
+ struct xcwm_window_t *window; /**< Pointer to a window */
+ struct _xcwm_window_node * next; /**< Pointer to the next window node */
+ struct _xcwm_window_node * prev; /**< Pointer to the previous window node */
+} _xcwm_window_node;
/* this is the head pointer */
-extern _xcwm_context_node *_xcwm_window_list_head;
+extern _xcwm_window_node *_xcwm_window_list_head;
/**
- * Add a newly created context to the context_list.
- * @param context The context to be added to the linked list
- * @return Pointer to context added to the list.
+ * Add a newly created window to the context_list.
+ * @param window The window to be added to the linked list
+ * @return Pointer to window added to the list.
*/
-xcwm_context_t *
-_xcwm_add_context_t(struct xcwm_context_t *context);
+xcwm_window_t *
+_xcwm_add_window(xcwm_window_t *window);
/**
* Remove a context to the context_list using the window's id.
- * @param window_id The window_id of the context which should
+ * @param window_id The window_id of the window which should
* be removed from the context_list
*/
void
-_xcwm_remove_context_node(xcb_window_t window_id);
+_xcwm_remove_window_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.
+ * @return Pointer to window (if found), NULL if not found.
*/
-xcwm_context_t *
-_xcwm_get_context_node_by_window_id (xcb_window_t window_id);
+xcwm_window_t *
+_xcwm_get_window_node_by_window_id (xcb_window_t window_id);
/****************
* window.c
@@ -243,21 +242,23 @@ _xcwm_get_context_node_by_window_id (xcb_window_t window_id);
* Create a new context for the window specified in the event.
* @param conn The connection to xserver
* @param evt The map event for the window
- * @return Pointer to new context. NULL if window already exists.
+ * @return Pointer to new window. NULL if window already exists.
*/
-xcwm_context_t *
+xcwm_window_t *
_xcwm_window_created(xcb_connection_t * conn,
- xcb_map_request_event_t *evt);
+ xcb_map_request_event_t *evt);
+
/**
* Destroy the damage object associated with the window.
* Call the remove function in context_list.c
* @param conn The connection to xserver
* @param event The destroy notify event for the window
- * @return Pointer to the context that was removed from the list, NULL if
- * window isn't being managed by context_list
+ * @return Pointer to the window that was removed from the list, NULL if
+ * window isn't being managed
*/
-xcwm_context_t *
-_xcwm_destroy_window(xcb_destroy_notify_event_t *event);
+xcwm_window_t *
+_xcwm_destroy_window(xcb_connection_t *conn,
+ xcb_destroy_notify_event_t *event);
/**
* Resize the window to given width and height.
@@ -272,9 +273,10 @@ _xcwm_resize_window (xcb_connection_t *conn, xcb_window_t window,
/**
* Map the given window.
- * @param context The context of the window to map
+ * @param conn The connection to xserver
+ * @param window The window to map
*/
void
-_xcwm_map_window (xcwm_context_t *context);
+_xcwm_map_window (xcb_connection_t *conn, xcwm_window_t *window);
#endif /* _XTOQ_INTERNAL_H_ */
diff --git a/src/xtoq/XtoqController.h b/src/xtoq/XtoqController.h
index 628601e..73b8561 100644
--- a/src/xtoq/XtoqController.h
+++ b/src/xtoq/XtoqController.h
@@ -182,24 +182,24 @@ id referenceToSelf;
-(void) runXman: (id) sender;
/**
- * Put a new image in the window / view
- * Send an image to the view after being notified of a damage event from
- * the event handler.
- * @param an xtoq_context_t sent from eventHandler
+ * Put a new image in the window / view. Send an image to the view
+ * after being notified of a damage event from the event handler.
+ * @param window The xcwm_window_t sent from eventHandler
*/
-- (void) updateImage: (xcwm_context_t *) windowContext;
+- (void) updateImage: (xcwm_window_t *) window;
/**
* Creates a new window
- * @param an xtoq_context_t sent from eventHandler
+ * @param window The xcwm_window_t sent from eventHandler
+ *
*/
-- (void) createNewWindow: (xcwm_context_t *) windowContext;
+- (void) createNewWindow: (xcwm_window_t *) window;
/**
* Closes the window
- * @param an xtoq_context_t sent from eventHandler
+ * @param window The window to destroy, sent from eventHandler
*/
-- (void) destroyWindow: (xcwm_context_t *) windowContext;
+- (void) destroyWindow: (xcwm_window_t *) window;
/**
* Send request to close
diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m
index 6c34030..5a80841 100644
--- a/src/xtoq/XtoqController.m
+++ b/src/xtoq/XtoqController.m
@@ -70,8 +70,10 @@
setImageInterpolation:NSImageInterpolationHigh];
xcwmWindow = [[XtoqWindow alloc]
- initWithContentRect: NSMakeRect(rootContext->x, rootContext->y,
- rootContext->width, rootContext->height)
+ initWithContentRect: NSMakeRect(rootContext->root_window->x,
+ rootContext->root_window->y,
+ rootContext->root_window->width,
+ rootContext->root_window->height)
styleMask: (NSTitledWindowMask |
NSClosableWindowMask |
NSMiniaturizableWindowMask |
@@ -79,18 +81,20 @@
backing: NSBackingStoreBuffered
defer: YES];
- [xcwmWindow setContext: rootContext];
- rootContext->local_data = xcwmWindow;
+ [xcwmWindow setXcwmWindow: rootContext->root_window
+ andXcwmContext: rootContext];
+ rootContext->root_window->local_data = xcwmWindow;
// Make the menu
[self makeMenu];
// FIXME: Since this is the root window, should be getting width
// and height from the size of the root window, not hard-coded
// values.
- imageRec = NSMakeRect(0, 0, 1028,768);//[image getWidth], [image getHeight]);
+ imageRec = NSMakeRect(0, 0, 1028,768);
// create a view, init'ing it with our rect
ourView = [[XtoqView alloc] initWithFrame:imageRec];
- [ourView setContext: rootContext];
+ [ourView setXcwmWindow: rootContext->root_window
+ andXcwmContext: rootContext];
// add view to its window
[xcwmWindow setContentView: ourView];
@@ -122,7 +126,6 @@
selector: @selector(mouseMovedInApp:)
name: @"MouseMovedEvent"
object: nil];
-
// register for destroy event
[nc addObserver: self
selector: @selector(destroy:)
@@ -148,7 +151,7 @@
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
- xcwm_close();
+ xcwm_close(rootContext);
const char *spawn[4];
pid_t child;
@@ -226,6 +229,7 @@
NSDictionary *mouseDownInfo = [aNotification userInfo];
// NSLog(@"Controller Got a XTOQmouseButtonDownEvent");
NSEvent * event = [mouseDownInfo objectForKey: @"1"];
+ xcwm_window_t *window = [(XtoqWindow *)[event window] getXcwmWindow];
NSNumber * heightAsNumber = [NSNumber alloc];
heightAsNumber = [mouseDownInfo objectForKey: @"2"];
@@ -237,6 +241,7 @@
dispatch_async(xcwmDispatchQueue,
^{ xcwm_input_mouse_button_event (rootContext,
+ window,
0,
0,
buttonInt,
@@ -250,6 +255,8 @@
CGFloat heightFloat;
NSDictionary *mouseReleaseInfo = [aNotification userInfo];
NSEvent * event = [mouseReleaseInfo objectForKey: @"1"];
+ xcwm_window_t *window = [(XtoqWindow *)[event window] getXcwmWindow];
+
NSNumber * heightAsNumber = [NSNumber alloc];
heightAsNumber = [mouseReleaseInfo objectForKey: @"2"];
heightFloat = [heightAsNumber floatValue];
@@ -260,6 +267,7 @@
dispatch_async(xcwmDispatchQueue,
^{ xcwm_input_mouse_button_event (rootContext,
+ window,
0,
0,
buttonInt,
@@ -416,18 +424,19 @@
}
// create a new window
-- (void) createNewWindow: (xcwm_context_t *) windowContext {
+- (void) createNewWindow: (xcwm_window_t *) window {
XtoqWindow *newWindow;
XtoqView *newView;
xcwm_image_t *xcbImage;
XtoqImageRep *imageRep;
- int y = [self xserverToOSX:windowContext->y windowHeight:windowContext->height];
+ int y = [self xserverToOSX: window->y windowHeight:window->height];
newWindow = [[XtoqWindow alloc]
- initWithContentRect: NSMakeRect(windowContext->x, y,
- windowContext->width, windowContext->height)
+ initWithContentRect: NSMakeRect(window->x, y,
+ window->width,
+ window->height)
styleMask: (NSTitledWindowMask |
NSClosableWindowMask |
NSMiniaturizableWindowMask |
@@ -435,39 +444,42 @@
backing: NSBackingStoreBuffered
defer: YES];
- // save context in window
- [newWindow setContext:windowContext];
+ // save xcwm_window_t in the XtoqWindow
+ [newWindow setXcwmWindow: window
+ andXcwmContext: rootContext];
// save the newWindow pointer into the context
- windowContext->local_data = (id)newWindow;
+ window->local_data = (id)newWindow;
// get image to darw
- xcbImage = xcwm_get_image(windowContext);
- imageRep = [[XtoqImageRep alloc] initWithData:xcbImage x: 0 y: 0];
+ xcbImage = test_xcwm_get_image(rootContext, window);
+ imageRep = [[XtoqImageRep alloc] initWithData: xcbImage x: 0 y: 0];
// draw the image into a rect
NSRect imgRec = NSMakeRect(0, 0, [imageRep getWidth], [imageRep getHeight]);
// create a view, init'ing it with our rect
newView = [[XtoqView alloc] initWithFrame:imgRec];
- [newView setContext:windowContext];
+ [newView setXcwmWindow: window
+ andXcwmContext: rootContext];
// add view to its window
[newWindow setContentView: newView ];
// set title
NSString *winTitle;
- winTitle = [NSString stringWithCString:windowContext->name encoding:NSUTF8StringEncoding];
- [newWindow setTitle:winTitle];
+ winTitle = [NSString stringWithCString: window->name
+ encoding: NSUTF8StringEncoding];
+ [newWindow setTitle: winTitle];
//shows the window
- [newWindow makeKeyAndOrderFront:self];
+ [newWindow makeKeyAndOrderFront: self];
}
-- (void) destroyWindow:(xcwm_context_t *) windowContext {
+- (void) destroyWindow:(xcwm_window_t *) window {
// set the window to be closed
- XtoqWindow *destWindow = windowContext->local_data;
+ XtoqWindow *destWindow = window->local_data;
//close window
[destWindow close];
}
@@ -476,27 +488,27 @@
NSDictionary *contextInfo = [aNotification userInfo];
XtoqWindow *aWindow = [contextInfo objectForKey: @"1"];
- xcwm_context_t *theContext = [aWindow getContext];
//use dispatch_async() to handle the actual close
- dispatch_async(xcwmDispatchQueue, ^{
- NSLog(@"Call xcwm_request_close(theContext)");
- xcwm_request_close(theContext);
+ dispatch_async(xcwmDispatchQueue, ^{
+ NSLog(@"Call xcwm_request_close(theContext)");
+ xcwm_request_close(rootContext, [aWindow getXcwmWindow]);
});
}
-- (void) updateImage:(xcwm_context_t *) windowContext
-{
+- (void) updateImage:(xcwm_window_t *) window {
float y_transformed;
NSRect newDamageRect;
- y_transformed =( windowContext->height - windowContext->damaged_y - windowContext->damaged_height)/1.0;
- newDamageRect = NSMakeRect(windowContext->damaged_x,
+ y_transformed =( window->height - window->damaged_y
+ - window->damaged_height)/1.0;
+ newDamageRect = NSMakeRect(window->damaged_x,
y_transformed,
- windowContext->damaged_width,
- windowContext->damaged_height);
- XtoqView *localView = (XtoqView *)[(XtoqWindow *)windowContext->local_data contentView];
- [ localView setPartialImage:newDamageRect];
+ window->damaged_width,
+ window->damaged_height);
+ XtoqView *localView =
+ (XtoqView *)[(XtoqWindow *)window->local_data contentView];
+ [localView setPartialImage:newDamageRect];
}
- (void) windowDidMove:(NSNotification*)notification {
@@ -512,15 +524,16 @@
XtoqWindow *moveWindow = (XtoqWindow *)[NSApp mainWindow];
if (moveWindow != nil) {
- xcwm_context_t *moveContext = [moveWindow getContext];
+ xcwm_window_t *window = [moveWindow getXcwmWindow];
NSRect moveFrame = [moveWindow frame];
int x = (int)moveFrame.origin.x;
- int y = [self osxToXserver:(int)moveFrame.origin.y
- windowHeight:moveContext->height] - WINDOWBAR;
+ int y = [self osxToXserver: (int)moveFrame.origin.y
+ windowHeight: window->height] - WINDOWBAR;
int width = (int)moveFrame.size.width;
int height = (int)moveFrame.size.height - WINDOWBAR;
- xcwm_configure_window(moveContext, x, y - height, height, width);
+ xcwm_configure_window(rootContext, window,
+ x, y - height, height, width);
[[moveWindow contentView] setNeedsDisplay: YES];
}
}
@@ -529,17 +542,17 @@
void eventHandler (xcwm_event_t *event)
{
- xcwm_context_t *context = xcwm_event_get_context(event);
+ xcwm_window_t *window = xcwm_event_get_window(event);
if (xcwm_event_get_type(event) == XTOQ_DAMAGE) {
- [referenceToSelf updateImage: context];
+ [referenceToSelf updateImage: window];
} else if (xcwm_event_get_type(event) == XTOQ_CREATE) {
NSLog(@"Window was created");
- [referenceToSelf createNewWindow: context];
+ [referenceToSelf createNewWindow: window];
} else if (xcwm_event_get_type(event) == XTOQ_DESTROY) {
NSLog(@"Window was destroyed");
- [referenceToSelf destroyWindow: context];
+ [referenceToSelf destroyWindow: window];
} else {
- NSLog(@"Hey I'm Not damage!");
+ NSLog(@"Unknown event type received.");
}
free(event);
}
diff --git a/src/xtoq/XtoqView.h b/src/xtoq/XtoqView.h
index 0f2bfba..1001c60 100644
--- a/src/xtoq/XtoqView.h
+++ b/src/xtoq/XtoqView.h
@@ -32,8 +32,8 @@ SOFTWARE.
#import <xcwm/xcwm.h>
@interface XtoqView : NSView {
- xcwm_context_t *viewContext;
-
+ xcwm_window_t *viewXcwmWindow;
+ xcwm_context_t *viewXcwmContext;
//mouse event
NSPoint downPoint;
NSPoint currentPoint;
@@ -48,10 +48,12 @@ SOFTWARE.
- (id)initWithFrame: (NSRect)frame;
/**
- * Set the context associated with this view.
- * @param context The context
+ * Set the xcwm_window_t and xcwm_context_t associated with this view.
+ * @param xcwmWindow The xcwm_window_t for this view.
+ * @param xcwmContext The xcwm_context_t for this view.
*/
--(void)setContext: (xcwm_context_t *)context;
+-(void)setXcwmWindow: (xcwm_window_t *) xcwmWindow
+ andXcwmContext: (xcwm_context_t *) xcwmContext;
/**
* The OS X magic loop which is responsible for drawing content to the screen
diff --git a/src/xtoq/XtoqView.m b/src/xtoq/XtoqView.m
index a02d5a2..0c20c24 100644
--- a/src/xtoq/XtoqView.m
+++ b/src/xtoq/XtoqView.m
@@ -44,8 +44,10 @@ initWithFrame: (NSRect)frame {
return self;
}
--(void) setContext: (xcwm_context_t *)context {
- viewContext = context;
+-(void) setXcwmWindow: (xcwm_window_t *) xcwmWindow
+ andXcwmContext: (xcwm_context_t *) xcwmContext{
+ viewXcwmWindow = xcwmWindow;
+ viewXcwmContext = xcwmContext;
}
// Overridden by subclasses to draw the receiver’s image within the
@@ -57,20 +59,20 @@ drawRect: (NSRect)dirtyRect {
XtoqImageRep *imageNew;
xcwm_get_event_thread_lock();
- imageT = test_xcwm_get_image(viewContext);
+ imageT = test_xcwm_get_image(viewXcwmContext, viewXcwmWindow);
if (imageT->image) {
- y_transformed =( viewContext->height
- - viewContext->damaged_y
- - viewContext->damaged_height)/1.0;
+ y_transformed =( viewXcwmWindow->height
+ - viewXcwmWindow->damaged_y
+ - viewXcwmWindow->damaged_height)/1.0;
imageNew = [[XtoqImageRep alloc]
initWithData:imageT
- x:((viewContext->damaged_x))
+ x:((viewXcwmWindow->damaged_x))
y:y_transformed];
[imageNew draw];
[imageNew destroy];
// Remove the damage
- xcwm_remove_context_damage(viewContext);
+ xcwm_remove_window_damage(viewXcwmContext, viewXcwmWindow);
}
xcwm_release_event_thread_lock();
}
diff --git a/src/xtoq/XtoqWindow.h b/src/xtoq/XtoqWindow.h
index 5b57f90..ae56200 100644
--- a/src/xtoq/XtoqWindow.h
+++ b/src/xtoq/XtoqWindow.h
@@ -26,7 +26,8 @@
#import "XtoqView.h"
@interface XtoqWindow : NSWindow {
- xcwm_context_t *winContext; // The context of the window.
+ xcwm_context_t *xcwmContext; // The context of the window.
+ xcwm_window_t *xcwmWindow; // The xcwm window assoicated with this one
NSNotificationCenter * notificationCenter;
}
@@ -42,14 +43,19 @@
-(void) makeKeyAndOrderFront:(id)sender;
/**
- * Used for setting member variables context and id.
+ * Set xcwm_window_t associated with this window and the
+ * xcwm_context_t context.
+ * @param aWindow The xcwm_window_t for this window.
+ * @param aContext The xcwm_context_t for this window.
*/
--(void) setContext: (xcwm_context_t *) aContext;
+-(void) setXcwmWindow: (xcwm_window_t *) aWindow
+ andXcwmContext: (xcwm_context_t *) aContext;;
/**
- * Function for getting context of window from list.
+ * Function for getting the xcwm_window_t associated with this window.
+ * @return The xcwm_window_t for this window.
*/
--(xcwm_context_t *) getContext;
+-(xcwm_window_t *) getXcwmWindow;
/**
* Catches the close event from clicking the red button or from preformClose.
diff --git a/src/xtoq/XtoqWindow.m b/src/xtoq/XtoqWindow.m
index 6f8053d..b8ca7b4 100644
--- a/src/xtoq/XtoqWindow.m
+++ b/src/xtoq/XtoqWindow.m
@@ -55,12 +55,14 @@
[super makeKeyAndOrderFront: sender];
}
--(void) setContext: (xcwm_context_t *)aContext {
- winContext = aContext;
+-(void) setXcwmWindow: (xcwm_window_t *) aWindow
+ andXcwmContext: (xcwm_context_t *) aContext {
+ xcwmWindow = aWindow;
+ xcwmContext = aContext;
}
--(xcwm_context_t *) getContext {
- return winContext;
+-(xcwm_window_t *) getXcwmWindow {
+ return xcwmWindow;
}
- (BOOL) windowShouldClose: (id)sender {
@@ -78,8 +80,8 @@
-(void)windowDidBecomeKey: (NSNotification *)note {
- xcwm_set_input_focus(winContext);
- xcwm_set_window_to_top(winContext);
+ xcwm_set_input_focus(xcwmContext, xcwmWindow);
+ xcwm_set_window_to_top(xcwmContext, xcwmWindow);
}