summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess VanDerwalker <washu@sonic.net>2012-04-05 22:58:14 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2012-04-06 00:50:57 -0700
commit0edf2f2ac21bcc91b4fc18decaa5ccb69cf3b451 (patch)
treef16914f5290dea893fa0f10254fb9ebb3e2284fe
parentf69b898f1a640e89dd85a434a30dca598fb758f6 (diff)
xcwm_context_t added to xcwm_window_t struct.
The xcwm_window_t now holds the xcwm_context_t that its associated with. Changed functions that required a window and a context to only take a window. Signed-off-by: Jess VanDerwalker <washu@sonic.net>
-rw-r--r--include/xcwm/xtoq.h41
-rw-r--r--src/libxcwm/event_loop.c15
-rw-r--r--src/libxcwm/input.c7
-rw-r--r--src/libxcwm/window.c28
-rw-r--r--src/libxcwm/xcwm.c18
-rw-r--r--src/libxcwm/xcwm_internal.h10
-rw-r--r--src/xtoq/XtoqController.m23
-rw-r--r--src/xtoq/XtoqView.h6
-rw-r--r--src/xtoq/XtoqView.m6
-rw-r--r--src/xtoq/XtoqWindow.h5
-rw-r--r--src/xtoq/XtoqWindow.m6
11 files changed, 74 insertions, 91 deletions
diff --git a/include/xcwm/xtoq.h b/include/xcwm/xtoq.h
index 70a42aa..a053df8 100644
--- a/include/xcwm/xtoq.h
+++ b/include/xcwm/xtoq.h
@@ -45,9 +45,18 @@
#include <xcb/xcb_keysyms.h>
/* Abstract types for xcwm data types */
+struct xcwm_window_t;
+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 xcwm_window_t {
xcb_drawable_t window_id;
+ xcwm_context_t *context;
struct xcwm_window_t *parent;
xcb_damage_damage_t damage;
int x;
@@ -62,13 +71,6 @@ struct xcwm_window_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 {
uint8_t *data;
@@ -105,12 +107,11 @@ 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 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, xcwm_window_t *window);
+test_xcwm_get_image(xcwm_window_t *window);
/**
* free the memory used by an xcwm_image_t created
@@ -122,35 +123,30 @@ 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_window_t *window);
+xcwm_set_input_focus(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_window_t *window);
-
+xcwm_set_window_to_bottom(xcwm_window_t *window);
/**
* Set a window to the top of the window stack.
- * @param context The context containing the window.
* @param window The window to move.
*/
void
-xcwm_set_window_to_top(xcwm_context_t *context, xcwm_window_t *window);
+xcwm_set_window_to_top(xcwm_window_t *window);
/**
* 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_window_damage(xcwm_context_t *context, xcwm_window_t *window);
+xcwm_remove_window_damage(xcwm_window_t *window);
/**
* Closes the windows open on the X Server, the connection, and the event
@@ -162,8 +158,8 @@ xcwm_close(xcwm_context_t *context);
/**
* Send key event to the X server.
- * @param context xcwm_context_t
- * @param window The window that the key press was made in.
+ * @param context The context the event occured in.
+ * @param code The keycode of event.
* @param state 1 if key has been pressed, 0 if key released.
*/
void
@@ -174,7 +170,6 @@ xcwm_input_key_event(xcwm_context_t *context, uint8_t code, int state);
* is usually in the position of sending input events to a client). The client
* 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
@@ -182,12 +177,12 @@ xcwm_input_key_event(xcwm_context_t *context, uint8_t code, int state);
* @param state 1 if the mouse button is pressed down, 0 if released.
*/
void
-xcwm_input_mouse_button_event(xcwm_context_t *context, xcwm_window_t *window,
+xcwm_input_mouse_button_event(xcwm_window_t *window,
long x, long y, int button,
int state);
/**
- * function
+ * Handler for mouse motion event.
* @param context xcwm_context_t
* @param x - x coordinate
* @param y - y coordinate
diff --git a/src/libxcwm/event_loop.c b/src/libxcwm/event_loop.c
index f14dafe..9cf1bd9 100644
--- a/src/libxcwm/event_loop.c
+++ b/src/libxcwm/event_loop.c
@@ -33,7 +33,7 @@
#include "xcwm_internal.h"
typedef struct _connection_data {
- xcb_connection_t *conn;
+ xcwm_context_t *context;
xcwm_event_cb_t callback;
} _connection_data;
@@ -43,8 +43,7 @@ pthread_t _event_thread = 0;
pthread_mutex_t _event_thread_lock;
/* Functions only called within event_loop.c */
-void
-*
+void *
run_event_loop(void *thread_arg_struct);
/* Functions included in xcwm.h */
@@ -63,7 +62,7 @@ xcwm_release_event_thread_lock(void)
/* Functions included in xcwm_internal.h */
int
-_xcwm_start_event_loop(xcb_connection_t *conn,
+_xcwm_start_event_loop(xcwm_context_t *context,
xcwm_event_cb_t event_callback)
{
_connection_data *conn_data;
@@ -73,7 +72,7 @@ _xcwm_start_event_loop(xcb_connection_t *conn,
conn_data = malloc(sizeof(_connection_data));
assert(conn_data);
- conn_data->conn = conn;
+ conn_data->context = context;
conn_data->callback = event_callback;
pthread_mutex_init(&_event_thread_lock, NULL);
@@ -102,13 +101,15 @@ void *
run_event_loop(void *thread_arg_struct)
{
_connection_data *conn_data;
+ xcwm_context_t *context;
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;
+ context = conn_data->context;
+ event_conn = context->conn;
callback_ptr = conn_data->callback;
free(thread_arg_struct);
@@ -255,7 +256,7 @@ run_event_loop(void *thread_arg_struct)
xcb_map_request_event_t *request =
(xcb_map_request_event_t *)evt;
return_evt = malloc(sizeof(xcwm_event_t));
- return_evt->window = _xcwm_window_created(event_conn, request);
+ return_evt->window = _xcwm_window_created(context, request);
if (!return_evt->window) {
free(return_evt);
break;
diff --git a/src/libxcwm/input.c b/src/libxcwm/input.c
index f03780d..6397b31 100644
--- a/src/libxcwm/input.c
+++ b/src/libxcwm/input.c
@@ -49,7 +49,7 @@ xcwm_input_key_event(xcwm_context_t *context, uint8_t code, int state)
}
void
-xcwm_input_mouse_button_event(xcwm_context_t *context, xcwm_window_t *window,
+xcwm_input_mouse_button_event(xcwm_window_t *window,
long x, long y,
int button, int state)
{
@@ -63,9 +63,10 @@ xcwm_input_mouse_button_event(xcwm_context_t *context, xcwm_window_t *window,
}
/* 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,
+ xcb_test_fake_input(window->context->conn, button_state, button,
+ XCB_CURRENT_TIME,
window->window_id, 0, 0, 0);
- xcb_flush(context->conn);
+ xcb_flush(window->context->conn);
printf("Mouse event received by xtoq.c - (%ld,%ld), state: %d\n",
x, y, state);
}
diff --git a/src/libxcwm/window.c b/src/libxcwm/window.c
index 6cd920f..db6b8ce 100644
--- a/src/libxcwm/window.c
+++ b/src/libxcwm/window.c
@@ -50,50 +50,51 @@ 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_window_t *window)
+xcwm_set_window_to_top(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, window->window_id,
+ xcb_configure_window(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_window_t *window)
+xcwm_set_window_to_bottom(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, window->window_id,
+ xcb_configure_window(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_window_t *window)
+xcwm_set_input_focus(xcwm_window_t *window)
{
// Test -- David
- xcb_get_input_focus_cookie_t cookie = xcb_get_input_focus(context->conn);
+ xcb_get_input_focus_cookie_t cookie =
+ xcb_get_input_focus(window->context->conn);
xcb_get_input_focus_reply_t *reply =
- xcb_get_input_focus_reply(context->conn, cookie, NULL);
+ xcb_get_input_focus_reply(window->context->conn, cookie, NULL);
printf("Focus was in window #%d, now in #%d (window.c)\n",
reply->focus, window->window_id);
free(reply);
// End test -- David
- xcb_set_input_focus(context->conn, XCB_INPUT_FOCUS_PARENT,
+ xcb_set_input_focus(window->context->conn, XCB_INPUT_FOCUS_PARENT,
window->window_id, XCB_CURRENT_TIME);
- xcb_flush(context->conn);
+ xcb_flush(window->context->conn);
}
xcwm_window_t *
-_xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t *event)
+_xcwm_window_created(xcwm_context_t *context, xcb_map_request_event_t *event)
{
/* Check to see if the window is already created */
@@ -105,10 +106,11 @@ _xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t *event)
xcwm_window_t *window = malloc(sizeof(xcwm_window_t));
xcb_get_geometry_reply_t *geom;
- geom = _xcwm_get_window_geometry(conn, event->window);
+ geom = _xcwm_get_window_geometry(context->conn, event->window);
/* set any available values from xcb_create_notify_event_t object pointer
and geom pointer */
+ window->context = context;
window->window_id = event->window;
window->x = geom->x;
window->y = geom->y;
@@ -121,10 +123,10 @@ _xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t *event)
free(geom);
/* Set the ICCCM properties we care about */
- set_icccm_properties(conn, window);
+ set_icccm_properties(context->conn, window);
/* register for damage */
- init_damage_on_window(conn, window);
+ init_damage_on_window(context->conn, window);
/* add context to context_list */
window = _xcwm_add_window(window);
diff --git a/src/libxcwm/xcwm.c b/src/libxcwm/xcwm.c
index f8f8adf..f12867a 100644
--- a/src/libxcwm/xcwm.c
+++ b/src/libxcwm/xcwm.c
@@ -155,18 +155,18 @@ 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);
+ return _xcwm_start_event_loop(context, callback);
}
xcwm_image_t *
-test_xcwm_get_image(xcwm_context_t *context, xcwm_window_t *window)
+test_xcwm_get_image(xcwm_window_t *window)
{
xcb_image_t *image;
- xcb_flush(context->conn);
+ xcb_flush(window->context->conn);
/* Get the image of the root window */
- image = xcb_image_get(context->conn,
+ image = xcb_image_get(window->context->conn,
window->window_id,
window->damaged_x,
window->damaged_y,
@@ -197,9 +197,9 @@ xcwm_image_destroy(xcwm_image_t * xcwm_image)
}
void
-xcwm_remove_window_damage(xcwm_context_t *context, xcwm_window_t *window)
+xcwm_remove_window_damage(xcwm_window_t *window)
{
- xcb_xfixes_region_t region = xcb_generate_id(context->conn);
+ xcb_xfixes_region_t region = xcb_generate_id(window->context->conn);
xcb_rectangle_t rect;
xcb_void_cookie_t cookie;
@@ -212,17 +212,17 @@ xcwm_remove_window_damage(xcwm_context_t *context, xcwm_window_t *window)
rect.width = window->damaged_width;
rect.height = window->damaged_height;
- xcb_xfixes_create_region(context->conn,
+ xcb_xfixes_create_region(window->context->conn,
region,
1,
&rect);
- cookie = xcb_damage_subtract_checked(context->conn,
+ cookie = xcb_damage_subtract_checked(window->context->conn,
window->damage,
region,
0);
- if (!(_xcwm_request_check(context->conn, cookie,
+ if (!(_xcwm_request_check(window->context->conn, cookie,
"Failed to subtract damage"))) {
window->damaged_x = 0;
window->damaged_y = 0;
diff --git a/src/libxcwm/xcwm_internal.h b/src/libxcwm/xcwm_internal.h
index f5dd16c..f582239 100644
--- a/src/libxcwm/xcwm_internal.h
+++ b/src/libxcwm/xcwm_internal.h
@@ -178,12 +178,12 @@ _xcwm_get_wm_atoms(xcwm_context_t *contxt);
/**
* Starts the event loop thread which listens on the given connection and
* calls event_callback if an event is caught.
- * @param *conn The connection to listen for X events on
+ * @param context The context to listen for X events on
* @param event_callback The callback function to call when a event is caught.
* @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(xcwm_context_t *context, xcwm_event_cb_t event_callback);
/**
* Stops the thread running the event loop.
@@ -239,12 +239,12 @@ _xcwm_get_window_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
+ * @param context The context window was created in.
+ * @param evt The map event for the window.
* @return Pointer to new window. NULL if window already exists.
*/
xcwm_window_t *
-_xcwm_window_created(xcb_connection_t * conn, xcb_map_request_event_t *evt);
+_xcwm_window_created(xcwm_context_t *context, xcb_map_request_event_t *evt);
/**
* Destroy the damage object associated with the window.
diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m
index 51de5b6..d40ccc1 100644
--- a/src/xtoq/XtoqController.m
+++ b/src/xtoq/XtoqController.m
@@ -86,8 +86,7 @@
backing: NSBackingStoreBuffered
defer: YES];
- [xcwmWindow setXcwmWindow: rootContext->root_window
- andXcwmContext: rootContext];
+ [xcwmWindow setXcwmWindow: rootContext->root_window];
rootContext->root_window->local_data = xcwmWindow;
// Make the menu
[self makeMenu];
@@ -98,9 +97,8 @@
imageRec = NSMakeRect(0, 0, 1028, 768);
// create a view, init'ing it with our rect
ourView = [[XtoqView alloc] initWithFrame:imageRec];
- [ourView setXcwmWindow: rootContext->root_window
- andXcwmContext: rootContext];
-
+ [ourView setXcwmWindow: rootContext->root_window];
+
// add view to its window
[xcwmWindow setContentView: ourView];
@@ -247,8 +245,7 @@
int buttonInt = [mouseButton intValue];
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_input_mouse_button_event (rootContext,
- window,
+ ^{ xcwm_input_mouse_button_event (window,
0,
0,
buttonInt,
@@ -275,13 +272,11 @@
int buttonInt = [mouseButton intValue];
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_input_mouse_button_event (rootContext,
- window,
+ ^{ xcwm_input_mouse_button_event (window,
0,
0,
buttonInt,
0);
- ;
});
}
@@ -465,14 +460,13 @@
defer: YES];
// save xcwm_window_t in the XtoqWindow
- [newWindow setXcwmWindow: window
- andXcwmContext: rootContext];
+ [newWindow setXcwmWindow: window];
// save the newWindow pointer into the context
window->local_data = (id)newWindow;
// get image to darw
- xcbImage = test_xcwm_get_image(rootContext, window);
+ xcbImage = test_xcwm_get_image(window);
imageRep = [[XtoqImageRep alloc] initWithData: xcbImage x: 0 y: 0];
// draw the image into a rect
@@ -481,8 +475,7 @@
// create a view, init'ing it with our rect
newView = [[XtoqView alloc] initWithFrame:imgRec];
- [newView setXcwmWindow: window
- andXcwmContext: rootContext];
+ [newView setXcwmWindow: window];
// add view to its window
[newWindow setContentView: newView];
diff --git a/src/xtoq/XtoqView.h b/src/xtoq/XtoqView.h
index 0fe51c3..e7f3b04 100644
--- a/src/xtoq/XtoqView.h
+++ b/src/xtoq/XtoqView.h
@@ -33,7 +33,7 @@
@interface XtoqView : NSView {
xcwm_window_t *viewXcwmWindow;
- xcwm_context_t *viewXcwmContext;
+
//mouse event
NSPoint downPoint;
NSPoint currentPoint;
@@ -50,10 +50,8 @@
/**
* 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)setXcwmWindow: (xcwm_window_t *)xcwmWindow
- andXcwmContext: (xcwm_context_t *)xcwmContext;
+-(void)setXcwmWindow: (xcwm_window_t *)xcwmWindow;
/**
* 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 4b1710c..3f12c35 100644
--- a/src/xtoq/XtoqView.m
+++ b/src/xtoq/XtoqView.m
@@ -48,10 +48,8 @@
}
-(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
@@ -64,7 +62,7 @@
XtoqImageRep *imageNew;
xcwm_get_event_thread_lock();
- imageT = test_xcwm_get_image(viewXcwmContext, viewXcwmWindow);
+ imageT = test_xcwm_get_image(viewXcwmWindow);
if (imageT->image) {
y_transformed = (viewXcwmWindow->height
- viewXcwmWindow->damaged_y
@@ -77,7 +75,7 @@
[imageNew destroy];
// Remove the damage
- xcwm_remove_window_damage(viewXcwmContext, viewXcwmWindow);
+ xcwm_remove_window_damage(viewXcwmWindow);
}
xcwm_release_event_thread_lock();
}
diff --git a/src/xtoq/XtoqWindow.h b/src/xtoq/XtoqWindow.h
index c8c7f61..89094a5 100644
--- a/src/xtoq/XtoqWindow.h
+++ b/src/xtoq/XtoqWindow.h
@@ -26,7 +26,6 @@
#import "XtoqView.h"
@interface XtoqWindow : NSWindow {
- xcwm_context_t *xcwmContext; // The context of the window.
xcwm_window_t *xcwmWindow; // The xcwm window assoicated with this one
NSNotificationCenter * notificationCenter;
}
@@ -49,9 +48,7 @@
* @param aWindow The xcwm_window_t for this window.
* @param aContext The xcwm_context_t for this window.
*/
--(void)setXcwmWindow: (xcwm_window_t *)aWindow
- andXcwmContext: (xcwm_context_t *)aContext;
-;
+-(void)setXcwmWindow: (xcwm_window_t *)aWindow;
/**
* Function for getting the xcwm_window_t associated with this window.
diff --git a/src/xtoq/XtoqWindow.m b/src/xtoq/XtoqWindow.m
index 9a11499..ba47476 100644
--- a/src/xtoq/XtoqWindow.m
+++ b/src/xtoq/XtoqWindow.m
@@ -58,10 +58,8 @@
}
-(void) setXcwmWindow: (xcwm_window_t *) aWindow
- andXcwmContext: (xcwm_context_t *) aContext
{
xcwmWindow = aWindow;
- xcwmContext = aContext;
}
-(xcwm_window_t *) getXcwmWindow
@@ -86,8 +84,8 @@
-(void)windowDidBecomeKey: (NSNotification *)note
{
- xcwm_set_input_focus(xcwmContext, xcwmWindow);
- xcwm_set_window_to_top(xcwmContext, xcwmWindow);
+ xcwm_set_input_focus(xcwmWindow);
+ xcwm_set_window_to_top(xcwmWindow);
}
-(void) mouseMoved: (NSEvent *) event