summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--include/xcwm/event.h8
-rw-r--r--include/xcwm/xtoq.h103
-rw-r--r--src/libxcwm/context_list.c33
-rw-r--r--src/libxcwm/data.h1
-rw-r--r--src/libxcwm/event_loop.c66
-rw-r--r--src/libxcwm/init.c33
-rw-r--r--src/libxcwm/input.c85
-rw-r--r--src/libxcwm/window.c207
-rw-r--r--src/libxcwm/xcwm.c102
-rw-r--r--src/libxcwm/xcwm_internal.h56
-rw-r--r--src/xtoq/XtoqApplication.h39
-rw-r--r--src/xtoq/XtoqApplication.m51
-rw-r--r--src/xtoq/XtoqController.h121
-rw-r--r--src/xtoq/XtoqController.m298
-rw-r--r--src/xtoq/XtoqImageRep.h6
-rw-r--r--src/xtoq/XtoqImageRep.m11
-rw-r--r--src/xtoq/XtoqView.h19
-rw-r--r--src/xtoq/XtoqView.m108
-rw-r--r--src/xtoq/XtoqWindow.h37
-rw-r--r--src/xtoq/XtoqWindow.m73
21 files changed, 748 insertions, 713 deletions
diff --git a/.gitignore b/.gitignore
index 5925934..07b76b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,3 +53,7 @@ autom4te.cache
config.sub
depcomp
missing
+
+# Merge and patch files to ignore
+*.orig
+*.patch \ No newline at end of file
diff --git a/include/xcwm/event.h b/include/xcwm/event.h
index f10fece..7b5b4fc 100644
--- a/include/xcwm/event.h
+++ b/include/xcwm/event.h
@@ -55,6 +55,14 @@ 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 bc0927b..70a42aa 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);
/**
* free the memory used by an xcwm_image_t created
@@ -126,69 +123,51 @@ 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);
+xcwm_close(xcwm_context_t *context);
/**
- * function
+ * Send key event to the X server.
* @param context xcwm_context_t
* @param window The window that the key press was made in.
- * @param keyCode The key pressed.
- */
-void
-xcwm_key_press(xcwm_context_t *context, int window, uint8_t code);
-
-/**
- * function
- * @param context xcwm_context_t
- * @param window The window that the key press was made in.
- * @param keyCode The key released.
- */
-void
-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
- * 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 x - x coordinate
- * @param y - y coordinate
- * @param window The window that the key press was made in.
+ * @param state 1 if key has been pressed, 0 if key released.
*/
void
-xcwm_button_press(xcwm_context_t *context, long x, long y, int window,
- int button);
+xcwm_input_key_event(xcwm_context_t *context, uint8_t code, int state);
/**
* Uses the XTEST protocol to send input events to the X Server (The X Server
@@ -196,24 +175,25 @@ xcwm_button_press(xcwm_context_t *context, long x, long y, int window,
* 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 window The window that the key release was made in.
+ * @param button The mouse button pressed.
+ * @param state 1 if the mouse button is pressed down, 0 if released.
*/
void
-xcwm_button_release(xcwm_context_t *context, long x, long y, int window,
- int button);
+xcwm_input_mouse_button_event(xcwm_context_t *context, xcwm_window_t *window,
+ long x, long y, int button,
+ int state);
/**
* function
* @param context xcwm_context_t
* @param x - x coordinate
* @param y - y coordinate
- * @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_input_mouse_motion(xcwm_context_t *context, long x, long y, int button);
/****************
* window.c
@@ -222,21 +202,24 @@ xcwm_mouse_motion(xcwm_context_t *context, long x, long y, int window,
/**
* 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,
+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 8a4e004..6f46577 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) {
@@ -60,18 +57,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,14 +76,14 @@ _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 3556d0b..5bd62e1 100644
--- a/src/libxcwm/data.h
+++ b/src/libxcwm/data.h
@@ -29,6 +29,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 e057fb2..f14dafe 100644
--- a/src/libxcwm/event_loop.c
+++ b/src/libxcwm/event_loop.c
@@ -42,9 +42,6 @@ pthread_t _event_thread = 0;
pthread_mutex_t _event_thread_lock;
-/* Mutex lock supplied to clients */
-/* pthread_mutex_t _event_thread_lock = 0; */
-
/* Functions only called within event_loop.c */
void
*
@@ -130,9 +127,9 @@ 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;
}
@@ -143,32 +140,31 @@ 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();
@@ -188,7 +184,9 @@ run_event_loop(void *thread_arg_struct)
{
/* Error case. Something very bad has happened. Spit
* out some hopefully useful information and then
- * die. */
+ * die.
+ * FIXME: Decide under what circumstances we should
+ * acutally kill the application. */
xcb_generic_error_t *err = (xcb_generic_error_t *)evt;
fprintf(stderr, "Error received in event loop.\n"
"Error code: %i\n",
@@ -203,9 +201,6 @@ run_event_loop(void *thread_arg_struct)
val_err->major_opcode,
val_err->minor_opcode);
}
-/* fprintf(stderr, "Exiting....\n"); */
-/* free(evt); */
- /* exit(1); */
break;
}
@@ -238,19 +233,20 @@ run_event_loop(void *thread_arg_struct)
// 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);
+ 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;
}
@@ -259,13 +255,12 @@ 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->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;
@@ -351,8 +346,15 @@ 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 4266034..b53b82c 100644
--- a/src/libxcwm/init.c
+++ b/src/libxcwm/init.c
@@ -58,8 +58,8 @@ 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,
@@ -75,32 +75,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_redirect_subwindows_checked(contxt->conn, contxt->window,
+ xcb_composite_redirect_subwindows_checked(contxt->conn,
+ contxt->root_window->window_id,
XCB_COMPOSITE_REDIRECT_MANUAL);
free(version_reply);
@@ -125,7 +129,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 064a2dd..f03780d 100644
--- a/src/libxcwm/input.c
+++ b/src/libxcwm/input.c
@@ -29,82 +29,51 @@
#include "xcwm_internal.h"
void
-xcwm_key_press(xcwm_context_t *context, int window, uint8_t code)
+xcwm_input_key_event(xcwm_context_t *context, uint8_t code, int state)
{
- xcb_generic_error_t *err;
- xcb_void_cookie_t cookie;
xcb_window_t none = { XCB_NONE };
+ int key_state;
- 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) {
- printf("err ");
- free(err);
+ if (state) {
+ key_state = XCB_KEY_PRESS;
+ }
+ else {
+ key_state = XCB_KEY_RELEASE;
}
- 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);
-}
-
-void
-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_test_fake_input(context->conn, key_state, code,
XCB_CURRENT_TIME, none, 0, 0, 1);
- err = xcb_request_check(context->conn, cookie);
- 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 event - uint8_t '%i'\n", code);
}
void
-xcwm_button_press(xcwm_context_t *context, long x, long y, int window,
- int button)
+xcwm_input_mouse_button_event(xcwm_context_t *context, xcwm_window_t *window,
+ long x, long y,
+ int button, int state)
{
- //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);
-}
+ int button_state;
-void
-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);
+ if (state) {
+ button_state = XCB_BUTTON_PRESS;
+ }
+ 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,
+ window->window_id, 0, 0, 0);
xcb_flush(context->conn);
- printf(
- "button release received by xcwm.c - (%ld,%ld) in Mac window #%i\n",
- x, y,
- window);
+ printf("Mouse event received by xtoq.c - (%ld,%ld), state: %d\n",
+ x, y, state);
}
void
-xcwm_mouse_motion(xcwm_context_t *context, long x, long y, int window,
- 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 //root_context->window//none//context->parent
- , x, y, 0);
+ context->root_window->window_id, 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/window.c b/src/libxcwm/window.c
index b80474f..6cd920f 100644
--- a/src/libxcwm/window.c
+++ b/src/libxcwm/window.c
@@ -34,182 +34,187 @@
/* 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_CONFIG_WINDOW_STACK_MODE,
- values);
+ 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_CONFIG_WINDOW_STACK_MODE,
- values);
+ 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);
+ 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, 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;
-
- 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 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,
+ window->window_id,
+ 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;
+ 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_send_event(context->conn, 0, window->window_id,
XCB_EVENT_MASK_NO_EVENT,
(char *)&event);
xcb_flush(context->conn);
@@ -235,22 +240,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;
@@ -258,30 +263,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;
@@ -291,20 +294,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);
@@ -314,43 +315,43 @@ 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 34f798f..f8f8adf 100644
--- a/src/libxcwm/xcwm.c
+++ b/src/libxcwm/xcwm.c
@@ -35,8 +35,6 @@
// 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
@@ -44,17 +42,18 @@ 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
@@ -69,7 +68,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,
@@ -82,15 +82,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);
@@ -98,7 +102,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");
@@ -110,23 +115,23 @@ 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,
@@ -154,7 +159,7 @@ 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;
@@ -162,11 +167,11 @@ test_xcwm_get_image(xcwm_context_t *context)
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);
@@ -175,10 +180,10 @@ test_xcwm_get_image(xcwm_context_t *context)
(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;
}
@@ -192,64 +197,65 @@ 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)
+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;
}
- // 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 (_xcwm_stop_event_loop() != 1) {
+ printf("Event loop failed to close\n");
+ }
+
+ // Disconnect from the display
+ xcb_disconnect(context->conn);
return;
diff --git a/src/libxcwm/xcwm_internal.h b/src/libxcwm/xcwm_internal.h
index d7c06ff..f5dd16c 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);
@@ -201,38 +200,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
@@ -242,20 +241,22 @@ _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);
+
/**
* 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.
@@ -270,9 +271,10 @@ _xcwm_resize_window(xcb_connection_t *conn, xcb_window_t window, int width,
/**
* 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/XtoqApplication.h b/src/xtoq/XtoqApplication.h
index 2285e22..08f7937 100644
--- a/src/xtoq/XtoqApplication.h
+++ b/src/xtoq/XtoqApplication.h
@@ -1,22 +1,22 @@
-/* Copyright (C) 2012 Braden Wooley, Ben Huddle
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+/*Copyright (C) 2012 Braden Wooley, Ben Huddle
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
*/
#import <AppKit/AppKit.h>
@@ -34,7 +34,6 @@
@interface XtoqApplication : NSApplication {
NSNotificationCenter *notificationCenter;
}
-
/**
* The main of our Application.
*
diff --git a/src/xtoq/XtoqApplication.m b/src/xtoq/XtoqApplication.m
index d31338e..7824968 100644
--- a/src/xtoq/XtoqApplication.m
+++ b/src/xtoq/XtoqApplication.m
@@ -1,22 +1,22 @@
-/* Copyright (C) 2012 Braden Wooley, Ben Huddle
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+/*Copyright (C) 2012 Braden Wooley, Ben Huddle
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
@@ -201,14 +201,13 @@ XtoqApplicationMain(int argc, char** argv)
xNum = [[NSNumber alloc] initWithFloat:ns_location.x];
yNum = [[NSNumber alloc] initWithFloat:ns_location.y];
- InfoDict = [[NSMutableDictionary alloc] initWithCapacity:3];
- [InfoDict setObject:e forKey:@"1"];
- [InfoDict setObject:xNum forKey:@"2"];
- [InfoDict setObject:yNum forKey:@"3"];
+ InfoDict = [[NSMutableDictionary alloc] initWithCapacity: 2];
+ [InfoDict setObject:xNum forKey: @"1"];
+ [InfoDict setObject:yNum forKey: @"2"];
- [notificationCenter postNotificationName:@"MouseMovedEvent"
- object:self
- userInfo:InfoDict];
+ [notificationCenter postNotificationName: @"MouseMovedEvent"
+ object: self
+ userInfo: InfoDict];
break;
}
diff --git a/src/xtoq/XtoqController.h b/src/xtoq/XtoqController.h
index 0eb77f8..c9bb6f2 100644
--- a/src/xtoq/XtoqController.h
+++ b/src/xtoq/XtoqController.h
@@ -70,11 +70,29 @@ id referenceToSelf;
int originalHeight;
int originalWidth;
NSRect imageRec;
- NSString *keyFirst;
}
+/**
+ * Initialize
+ */
- (id)init;
+
+/**
+ * Sent by the default notification center immediately before the
+ * application object is initialized.
+ * @param A notification named NSApplicationWillFinishLaunchingNotification.
+ * Calling the object method of this notification returns the
+ * NSApplication object itself.
+ */
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification;
+
+/**
+ * Sent by the default notification center after the application has been
+ * launched and initialized but before it has received its first event.
+ * @param A notification named NSApplicationWillFinishLaunchingNotification.
+ * Calling the object method of this notification returns the
+ * NSApplication object itself.
+ */
- (void)applicationDidFinishLaunching: (NSNotification *)aNotification;
/**
@@ -84,6 +102,12 @@ id referenceToSelf;
- (void)keyDownInView: (NSNotification *)aNotification;
/**
+ * Receive notification of a key up event from the view.
+ * @param an NSNotification containing an NSEvent
+ */
+- (void)keyUpInView: (NSNotification *)aNotification;
+
+/**
* Receive notification of a mouse button press from the view.
* @param an NSNotification containing an NSEvent
*/
@@ -96,98 +120,149 @@ id referenceToSelf;
- (void)mouseButtonReleaseInView: (NSNotification *)aNotification;
/**
- * Makemenu and related selector functions for launching X applications.
+ * Make menu and related selector functions for launching X applications.
*/
- (void)makeMenu;
/**
* Launches the application based on filename.
- *
* Launches the selected application based on the filename passed in as an
* argument. Uses posix_spawn() to launch the application after the arguments
* have been filled in.
- *
* @param filename The name of the application to be run within XtoQ.app.
*/
- (void)launch_client: (NSString *)filename;
/**
* Runs xeyes.
- *
* Sends "xeyes" argument to the launch client function to open up the
* application xeyes within XtoQ.app.
- *
* @param sender Only needed for functionality with Makemenu's menu system.
*/
- (void)runXeyes: (id)sender;
/**
* Runs xclock.
- *
* Sends "xclock" argument to the launch client function to open up the
* application xclock within XtoQ.app.
- *
* @param sender Only needed for functionality with Makemenu's menu system.
*/
- (void)runXclock: (id)sender;
/**
* Runs xlogo.
- *
* Sends "xlogo" argument to the launch client function to open up the
* application xlogo within XtoQ.app.
- *
* @param sender Only needed for functionality with Makemenu's menu system.
*/
- (void)runXlogo: (id)sender;
+/**
+ * Receive notification of mouse movement from the app
+ * @param aNotification A notification containing an NSEvent
+ */
- (void)mouseMovedInApp: (NSNotification *)aNotification;
/**
* Runs xterm.
- *
* Sends "xterm" argument to the launch client function to open up the
* application xterm within XtoQ.app.
- *
* @param sender Only needed for functionality with Makemenu's menu system.
*/
- (void)runXterm: (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 xcwm_context_t sent from eventHandler
+ * Runs xman
+ * Sends "xman" argument to the launch client function to open up the
+ * application xman within XtoQ.app.
+ * @param sender Olny needed for functionality with Makemenu's menu system.
*/
-- (void)updateImage: (xcwm_context_t *)windowContext;
+-(void)runXman: (id)sender;
-- (void)createNewWindow: (xcwm_context_t *)windowContext;
-- (void)destroyWindow: (xcwm_context_t *)windowContext;
+/**
+ * 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_window_t *)window;
/**
- * Sets the variable screen to correct display.
+ * Creates a new window
+ * @param window The xcwm_window_t sent from eventHandler
*
+ */
+- (void)createNewWindow: (xcwm_window_t *)window;
+
+/**
+ * Closes the window
+ * @param window The window to destroy, sent from eventHandler
+ */
+- (void)destroyWindow: (xcwm_window_t *)window;
+
+/**
+ * Send request to close
+ * @param an NSNotification containing an NSEvent
+ */
+- (void)destroy:(NSNotification *)aNotification;
+
+/**
+ * Sets the variable screen to correct display.
* Sets class variable screen to correct display and also sets the environment
* variable "DISPLAY" to correct value.
- *
* @param scrn This value is determined in XtoqApplication before connection
* to Xorg is established.
*/
- (void)setScreen: (char *)scrn;
-- (void)windowWillMove:(NSNotification *)notification;
+//- (void)windowWillMove:(NSNotification*)notification;
+
+/**
+ * Informs the delegate that the window has been moved.
+ * @param notification A notification named NSWindowDidMoveNotification.
+ */
- (void)windowDidMove:(NSNotification *)notification;
+
+/**
+ * Informs the delegate that the window has been resized.
+ * @param notification A notification named NSWindowDidResizeNotification.
+ */
- (void)windowDidResize:(NSNotification *)notification;
+
+/**
+ * Sent by the default notification center immediately before
+ * the application terminates.
+ * @param aNotification A notification named
+ * NSApplicationWillTerminateNotification. Calling the
+ * object method of this notification returns the
+ * NSApplication object itself.
+ */
- (void)applicationWillTerminate:(NSNotification *)aNotification;
+
+/**
+ * Reshapes the window
+ */
- (void)reshape;
+/**
+ * Converts the Xserver y value to the OSX coordinate system
+ * @param yValue an int value of the y coordinat
+ * @param windowH int value of the window eight
+ * @return an int that has been converted
+ */
- (int)xserverToOSX:(int)yValue windowHeight:(int)windowH;
+
+/**
+ * Converts the OSX y value to the Xserver coordinate system
+ * @param yValue an int value of the y coordinat
+ * @param windowH int value of the window eight
+ * @return an int that has been converted
+ */
- (int)osxToXserver:(int)yValue windowHeight:(int)windowH;
@end
/**
- * Callback function that will receive events from the xcwm event loop
+ * Callback function that will receive events from the xtoq event loop
* once it is started.
* @param event The event received.
*/
diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m
index 877f404..51de5b6 100644
--- a/src/xtoq/XtoqController.m
+++ b/src/xtoq/XtoqController.m
@@ -35,7 +35,6 @@
#import "XtoqController.h"
#define WINDOWBAR 22
-#define FILEBAR 23
@implementation XtoqController
@@ -64,7 +63,7 @@
}
-- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// setup X connection and get the initial image from the server
@@ -74,10 +73,12 @@
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 |
@@ -85,28 +86,23 @@
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];
- //create an XtoqImageRep with the information from X
- //libImageT = xcwm_get_image(rootContext);
- //image = [[XtoqImageRep alloc] initWithData:libImageT x:0 y:0];
- //draw the image into a rect
- imageRec = NSMakeRect(0, 0, 1028, 768); //[image getWidth], [image getHeight]);
+ // 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);
// 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];
- // set the initial image in the window
- //[ourView setImage:image];
-
- originalWidth = [image getWidth];
- originalHeight = [image getHeight];
- //[ourView setPartialImage:imageNew];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
@@ -117,6 +113,11 @@
object: nil];
[nc addObserver: self
+ selector: @selector(keyUpInView:)
+ name: @"XTOQviewKeyUpEvent"
+ object: nil];
+
+ [nc addObserver: self
selector: @selector(mouseButtonDownInView:)
name: @"XTOQmouseButtonDownEvent"
object: nil];
@@ -130,19 +131,12 @@
selector: @selector(mouseMovedInApp:)
name: @"MouseMovedEvent"
object: nil];
-
// register for destroy event
[nc addObserver: self
selector: @selector(destroy:)
name: @"XTOQdestroyTheWindow"
object: nil];
- // regester for window will/did movement notification
- [nc addObserver:self
- selector:@selector(windowWillMove:)
- name:NSWindowWillMoveNotification
- object:nil];
-
[nc addObserver:self
selector:@selector(windowDidMove:)
name:NSWindowDidMoveNotification
@@ -153,22 +147,22 @@
selector:@selector(windowDidResize:)
name:NSWindowDidResizeNotification
object:nil];
- /* [nc addObserver:self
- selector:@selector(applicationWillTerminate:)
- name:NSApplicationWillTerminateNotification object:nil]; */
xcwmDispatchQueue = dispatch_queue_create("xcwm.dispatch.queue", NULL);
+ // Start the event loop and set the handler function
+ xcwm_start_event_loop(rootContext, (void *)eventHandler);
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
- xcwm_close();
+ xcwm_close(rootContext);
const char *spawn[4];
pid_t child;
- int error = 0;
+ // FIXME: This clobbers all instantances of the xserver. Not what
+ // we want to do.
spawn[0] = "/usr/bin/killall";
spawn[1] = "-9";
spawn[2] = "Xorg";
@@ -177,44 +171,27 @@
posix_spawn(&child, spawn[0], NULL, NULL, (char *const *)spawn, environ);
}
-- (void) applicationDidFinishLaunching: (NSNotification *) aNotification
-{
- [xcwmWindow makeKeyAndOrderFront: self];
-
- //hide window
- [xcwmWindow orderOut:self];
-
- // Start the event loop and set the handler function
- xcwm_start_event_loop(rootContext, (void *)eventHandler);
-}
+- (void) applicationWillFinishLaunching: (NSNotification *) aNotification
+{}
- (void) mouseMovedInApp: (NSNotification *) aNotification
{
//CGFloat heightFloat;
NSDictionary *mouseMoveInfo = [aNotification userInfo];
- NSEvent * event = [mouseMoveInfo objectForKey: @"1"];
- NSNumber * xVal = [NSNumber alloc];
- NSNumber * yVal = [NSNumber alloc];
- xVal = [mouseMoveInfo objectForKey: @"2"];
- yVal = [mouseMoveInfo objectForKey: @"3"];
-
- float height = [[NSScreen mainScreen] frame].size.height;
+ NSNumber *xNum = [mouseMoveInfo objectForKey: @"1"];
+ NSNumber *yNum = [mouseMoveInfo objectForKey: @"2"];
- int yInt = height - FILEBAR - [yVal intValue];
- yVal = [[NSNumber alloc] initWithInt:yInt];
-
- NSLog(@"Mouse x = %i, y = %i", [xVal intValue], [yVal intValue]);
+ int height = [[NSScreen mainScreen] frame].size.height;
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_mouse_motion (rootContext,
- [xVal intValue],
- [yVal intValue],
- (int)[event windowNumber],
- 0);
- ;
+ ^{ xcwm_input_mouse_motion
+ (rootContext,
+ [xNum intValue],
+ //Converting OSX coordinates to X11
+ height - WINDOWBAR - [yNum intValue],
+ 0);
});
-
}
- (void) keyDownInView: (NSNotification *) aNotification
@@ -227,15 +204,27 @@
const char* charcharstar = [charNSString UTF8String];
NSLog(@"%s pressed", charcharstar);
+ // FIXME: Uses a 'magic number' for offset into keymap - should a
+ // #define or gotten programmatically.
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_key_press (rootContext,
- (int)[event windowNumber],
- aChar + 8);
+ ^{ xcwm_input_key_event (rootContext,
+ aChar + 8,
+ 1);
});
+}
+
+- (void) keyUpInView: (NSNotification *) aNotification
+{
+ NSDictionary *keyInfo = [aNotification userInfo];
+ // note this keyInfo is the key in <key, value> not the key pressed
+ NSEvent * event = [keyInfo objectForKey: @"1"];
+ unsigned short aChar = [event keyCode];
+
+ // FIXME: Uses a 'magic number' for offset.
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_key_release (rootContext,
- (int)[event windowNumber],
- aChar + 8);
+ ^{ xcwm_input_key_event (rootContext,
+ aChar + 8,
+ 0);
});
}
@@ -247,20 +236,23 @@
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"];
heightFloat = [heightAsNumber floatValue];
- //NSLog(@"Mouse Info: %@", [mouseDownInfo objectForKey: @"2"]);
- float height = [[NSScreen mainScreen] frame].size.height;
+ NSNumber * mouseButton = [NSNumber alloc];
+ mouseButton = [mouseDownInfo objectForKey:@"3"];
+ int buttonInt = [mouseButton intValue];
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_button_press (rootContext,
- 0,
- 0,
- (int)[event windowNumber],
- 0);
+ ^{ xcwm_input_mouse_button_event (rootContext,
+ window,
+ 0,
+ 0,
+ buttonInt,
+ 1);
;
});
}
@@ -271,29 +263,33 @@
{
CGFloat heightFloat;
NSDictionary *mouseReleaseInfo = [aNotification userInfo];
- // NSLog(@"Controller Got a XTOQmouseButtonDownEvent");
NSEvent * event = [mouseReleaseInfo objectForKey: @"1"];
- //NSRect bnd = NSMakeRect(0,0,512,386);
+ xcwm_window_t *window = [(XtoqWindow *)[event window] getXcwmWindow];
+
NSNumber * heightAsNumber = [NSNumber alloc];
heightAsNumber = [mouseReleaseInfo objectForKey: @"2"];
heightFloat = [heightAsNumber floatValue];
- //NSLog(@"Mouse Info: %@", [mouseDownInfo objectForKey: @"2"]);
- float height = [[NSScreen mainScreen] frame].size.height;
+ NSNumber * mouseButton = [NSNumber alloc];
+ mouseButton = [mouseReleaseInfo objectForKey:@"3"];
+ int buttonInt = [mouseButton intValue];
dispatch_async(xcwmDispatchQueue,
- ^{ xcwm_button_release (rootContext,
- 0,
- 0,
- (int)[event windowNumber],
- 0);
+ ^{ xcwm_input_mouse_button_event (rootContext,
+ window,
+ 0,
+ 0,
+ buttonInt,
+ 0);
;
});
}
- (void) setScreen:(char *)scrn
{
- screen = scrn;
+ free(screen);
+ screen = strdup(scrn);
+ setenv("DISPLAY", screen, 1);
}
- (void) makeMenu
@@ -372,6 +368,15 @@
[startXMenu addItem:xtermMenuItem];
[startXApps setSubmenu:startXMenu];
+ // Run Xman
+ NSMenuItem *xmanMenuItem;
+ xTitle = @"Run Xman";
+ xmanMenuItem = [[NSMenuItem alloc] initWithTitle:xTitle
+ action:@selector(runXman:)
+ keyEquivalent:@""];
+ [startXMenu addItem:xmanMenuItem];
+ [startXApps setSubmenu:startXMenu];
+
// Adding all the menu items to the main menu for XtoQ.
[menubar addItem:appMenuItem];
[menubar addItem:startXApps];
@@ -383,16 +388,34 @@
int status;
pid_t child;
const char *file_name = [filename UTF8String];
- const char *newargv[4];
+ const char *newargv[6];
+ char *exec_path;
+
+ // Xman Special case
+ if ([filename isEqualToString:@"xman"]) {
+ const char *manpath =
+ "/opt/local/share/man:/usr/share/man:/usr/local/share/man:/opt/X11/share/man:/usr/X11/man:/usr/local/git/share/man";
+ setenv("MANPATH", manpath, 1);
+ }
- asprintf(&newargv[0], "/usr/X11/bin/%s", file_name);
+ // FIXME: Doesn't seem like we should be relying on an absolute path,
+ // but just sending the executable name doesn't always work.
+ asprintf(&exec_path, "/usr/X11/bin/%s", file_name);
+ newargv[0] = exec_path;
newargv[1] = "-display";
newargv[2] = screen;
- newargv[3] = NULL;
- status =
- posix_spawn(&child, newargv[0], NULL, NULL, (char *const *)newargv,
- environ);
+ if ([filename isEqualToString:@"xclock"]) {
+ newargv[3] = "-update";
+ newargv[4] = "1";
+ newargv[5] = NULL;
+ }
+ else {
+ newargv[3] = NULL;
+ }
+
+ status = posix_spawnp(&child, newargv[0], NULL, NULL,
+ (char *const *)newargv, environ);
if (status) {
NSLog(@"Error spawning file for launch.");
}
@@ -414,9 +437,13 @@
{
[self launch_client:@"xterm"];
}
+-(void) runXman:(id) sender
+{
+ [self launch_client:@"xman"];
+}
// create a new window
-- (void) createNewWindow: (xcwm_context_t *) windowContext
+- (void) createNewWindow: (xcwm_window_t *) window
{
XtoqWindow *newWindow;
@@ -424,30 +451,29 @@
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)
- styleMask: (NSTitledWindowMask |
+ initWithContentRect: NSMakeRect(window->x, y,
+ window->width,
+ window->height)
+ styleMask: (NSTitledWindowMask |
NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask)
- backing: NSBackingStoreBuffered
- defer: YES];
+ 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],
@@ -455,28 +481,27 @@
// 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];
}
@@ -486,33 +511,28 @@
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);
+ xcwm_request_close (rootContext,
+ [aWindow getXcwmWindow]);
});
}
-- (void) windowWillMove:(NSNotification *)notification
-{
- //NSLog(@"window will move");
-}
-- (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);
+ window->damaged_width,
+ window->damaged_height);
XtoqView *localView =
- (XtoqView *)[(XtoqWindow *)windowContext->local_data contentView];
+ (XtoqView *)[(XtoqWindow *)window->local_data contentView];
[localView setPartialImage:newDamageRect];
}
@@ -532,17 +552,17 @@
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;
- NSLog(
- @"Call xcwm_configure_window(moveContext, x = %i, y = %i, height = %i, width = %i)",
- x, y, height, width);
- xcwm_configure_window(moveContext, x, y - height, height, width);
+
+ xcwm_configure_window(rootContext, window,
+ x, y - height, height, width);
+ [[moveWindow contentView] setNeedsDisplay: YES];
}
}
@@ -551,20 +571,20 @@
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/XtoqImageRep.h b/src/xtoq/XtoqImageRep.h
index 0669dfe..7e2ad3f 100644
--- a/src/xtoq/XtoqImageRep.h
+++ b/src/xtoq/XtoqImageRep.h
@@ -56,14 +56,14 @@
* @param imageData The image from the Xserver that you want drawn
* @return No if image from the xserver is null else Yes
*/
-- (BOOL)canInitWithData:(xcb_image_t *)imageData;
+- (BOOL)canInitWithData: (xcb_image_t *)imageData;
/**
* Return the image it has constructed from the imageData
* @param imageData The image from the Xserver that you want drawn
* @return id It returns its own id
*/
-- (id)initWithData:(xcwm_image_t *)imageData x:(int)x y:(int)y;
+- (id)initWithData: (xcwm_image_t *)imageData x:(int)x y:(int)y;
/**
* Return whether the window was drawn
@@ -81,7 +81,7 @@
- (CGFloat)getWidth;
- (CGFloat)getHeight;
-- (BOOL)drawInRect:(NSRect)rect;
+- (BOOL)drawInRect: (NSRect)rect;
- (void)destroy;
diff --git a/src/xtoq/XtoqImageRep.m b/src/xtoq/XtoqImageRep.m
index f0969b2..bad8ce9 100644
--- a/src/xtoq/XtoqImageRep.m
+++ b/src/xtoq/XtoqImageRep.m
@@ -63,11 +63,11 @@
CGColorSpaceRef csp = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipFirst |
kCGBitmapByteOrder32Host;
- cgImage = CGImageCreate(imageT->width, // size_t width,
+ cgImage = CGImageCreate(imageT->width, // size_t width,
imageT->height, //size_t height,
- 8, //size_t bitsPerComponent,
- 32, //size_t bitsPerPixel,
- imageT->stride, //size_t bytesPerRow,
+ 8, //size_t bitsPerComponent,
+ 32, //size_t bitsPerPixel,
+ imageT->stride, //size_t bytesPerRow,
csp, //CGColorSpaceRef colorspace,
bitmapInfo,
cgdat, //CGDataProviderRef provider,
@@ -94,7 +94,6 @@
NSLog(@"No image");
return NO;
}
- // CGContextDrawImage(contextMac, CGRectMake(imageX, imageY, width, height), cgImage);
CGContextDrawImage(contextMac, CGRectMake(imageX, imageY, width,
height), cgImage);
@@ -137,10 +136,12 @@
{
return imageX;
}
+
- (float)imageY
{
return imageY;
}
+
- (void)destroy
{
if (imageParent) {
diff --git a/src/xtoq/XtoqView.h b/src/xtoq/XtoqView.h
index 0b229c0..0fe51c3 100644
--- a/src/xtoq/XtoqView.h
+++ b/src/xtoq/XtoqView.h
@@ -32,39 +32,40 @@
#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;
NSNotificationCenter * notificationCenter;
- NSTrackingArea * trackingArea;
}
/**
* Intialize the view given its bounds
* @param an NSRect with the bounds (size) of the view
*/
-- (id)initWithFrame:(NSRect)frame;
+- (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
* @param a "fake" NSRect which is not actually used within the body of the
* method
*/
--(void)drawRect:(NSRect)dirtyRect;
+-(void)drawRect: (NSRect)dirtyRect;
/**
* Set the partial image contents in the view
* @param newDamageRect The area of the image that needs to be redrawn
*/
-- (void)setPartialImage:(NSRect)newDamageRect;
+- (void)setPartialImage: (NSRect)newDamageRect;
@end
diff --git a/src/xtoq/XtoqView.m b/src/xtoq/XtoqView.m
index e6d5776..4b1710c 100644
--- a/src/xtoq/XtoqView.m
+++ b/src/xtoq/XtoqView.m
@@ -25,13 +25,17 @@
#import "XtoqView.h"
+#define RECTLOG(rect) NSLog(@"" # rect @" x:%f y:%f w:%f h:%f", \
+ rect.origin.x, rect.origin.y, rect.size.width, \
+ rect.size.height)
+
@implementation XtoqView
/**
* This is the initializer.
*/
- (id)
- initWithFrame:(NSRect)frame
+ initWithFrame: (NSRect)frame
{
self = [super initWithFrame:frame];
@@ -39,124 +43,48 @@
notificationCenter = [NSNotificationCenter defaultCenter];
[[self window] flushWindow];
[self setNeedsDisplay:YES];
-
- trackingArea = [[NSTrackingArea alloc] initWithRect:frame
- options: (
- NSTrackingMouseEnteredAndExited |
- NSTrackingMouseMoved
- | NSTrackingActiveInKeyWindow)
- owner:self userInfo:nil
- ];
- [self addTrackingArea:trackingArea];
-
}
return self;
}
--(void) setContext: (xcwm_context_t *)context
+-(void) setXcwmWindow: (xcwm_window_t *) xcwmWindow
+ andXcwmContext: (xcwm_context_t *) xcwmContext
{
- viewContext = context;
+ viewXcwmWindow = xcwmWindow;
+ viewXcwmContext = xcwmContext;
}
// Overridden by subclasses to draw the receiver’s image within the
// passed-in rectangle.
-(void)
- drawRect:(NSRect)dirtyRect
+ drawRect: (NSRect)dirtyRect
{
xcwm_image_t *imageT;
float y_transformed;
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();
}
-//This is necessary for accepting input.
-- (BOOL)
- acceptsFirstResponder
-{
- return YES;
-}
-
-- (BOOL)acceptsMouseMovedEvents
-{
- return YES;
-}
-
-/*- (void)mouseEntered:(NSEvent *)theEvent {
-
- }
-
- - (void)mouseExited:(NSEvent *)theEvent {
-
- }
-
- - (void)rightMouseDown:(NSEvent *)theEvent
-
- }*/
-
-/**
- * Capture keyboard events
- */
-- (void)
- keyDown:(NSEvent *)theEvent
-{
- NSDictionary * dictionary = [NSDictionary dictionaryWithObject:theEvent
- forKey:@"1"];
- [notificationCenter postNotificationName:@"XTOQviewKeyDownEvent"
- object:self
- userInfo:dictionary];
-}
-
--(void)
- mouseDown:(NSEvent *)mouseEvent
-{
- CGFloat f = [self bounds].size.height;
- NSNumber *n = [[NSNumber alloc] initWithFloat:f];
- //NSLog(@"mouseevent %i", [mouseEvent mouseLocation]->x);
- // NSLog(@"mouse event bound %f location %f", CGRectGetHeight(bnd), [mouseEvent locationInWindow].y );
- NSMutableDictionary *twoInfoDict =
- [[NSMutableDictionary alloc] initWithCapacity:2];
- [twoInfoDict setObject:mouseEvent forKey:@"1"];
- [twoInfoDict setObject:n forKey:@"2"];
-
- //NSLog(@"bound %f location %f", CGRectGetHeight(bnd), [mouseEvent locationInWindow].y );
- [notificationCenter postNotificationName:@"XTOQmouseButtonDownEvent"
- object:self
- userInfo:twoInfoDict];
-}
-
-- (void)mouseUp:(NSEvent *)theEvent
-{
- CGFloat f = [self bounds].size.height;
- NSNumber *n = [[NSNumber alloc] initWithFloat:f];
- NSMutableDictionary *twoInfoDict =
- [[NSMutableDictionary alloc] initWithCapacity:2];
- [twoInfoDict setObject:theEvent forKey:@"1"];
- [twoInfoDict setObject:n forKey:@"2"];
- [notificationCenter postNotificationName:@"XTOQmouseButtonReleaseEvent"
- object:self
- userInfo:twoInfoDict];
-}
-
-- (void)setPartialImage:(NSRect)newDamageRect
+- (void)setPartialImage: (NSRect)newDamageRect
{
- [self setNeedsDisplayInRect:newDamageRect];
+ [self setNeedsDisplayInRect: newDamageRect];
}
- (BOOL)isOpaque
diff --git a/src/xtoq/XtoqWindow.h b/src/xtoq/XtoqWindow.h
index fbe4fd4..c8c7f61 100644
--- a/src/xtoq/XtoqWindow.h
+++ b/src/xtoq/XtoqWindow.h
@@ -26,15 +26,17 @@
#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;
}
/**
* Used for initialization of a window.
*/
--(id)initWithContentRect:(NSRect) contentRect styleMask:(NSUInteger) aStyle
- backing:(NSBackingStoreType) bufferingType defer:(BOOL)flag;
+-(id)initWithContentRect: (NSRect) contentRect styleMask: (NSUInteger) aStyle
+ backing: (NSBackingStoreType) bufferingType defer: (BOOL)
+ flag;
/*
* Orders a specific window to the front and makes it key window.
@@ -42,28 +44,35 @@
-(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;
/**
- * Sets the root window's pointer xcwmLocalData to the context's pointer.
+ * Catches the close event from clicking the red button or from preformClose.
*/
-//-(void) setRootDataPointer: (xcwm_context_t *) xqContext;
+- (BOOL)windowShouldClose: (id)sender;
/**
- * Catches the close event from clicking the red button or from preformClose.
+ * Catches the event that a window gains focus
*/
-- (BOOL)windowShouldClose:(id)sender;
+-(void)windowDidBecomeKey: (NSNotification *)note;
-/*
- * Catches the event that a window gains focus
+/**
+ * Handler for mouse movement events.
+ * @param event The mouse movement event.
*/
--(void)windowDidBecomeKey:(NSNotification *)note;
+-(void)mouseMoved: (NSEvent *)event;
@end
diff --git a/src/xtoq/XtoqWindow.m b/src/xtoq/XtoqWindow.m
index 3114bfa..9a11499 100644
--- a/src/xtoq/XtoqWindow.m
+++ b/src/xtoq/XtoqWindow.m
@@ -27,10 +27,10 @@
@implementation XtoqWindow
--(id) initWithContentRect:(NSRect)contentRect
- styleMask:(NSUInteger)aStyle
- backing:(NSBackingStoreType)bufferingType
- defer:(BOOL)flag
+-(id) initWithContentRect: (NSRect)contentRect
+ styleMask: (NSUInteger)aStyle
+ backing: (NSBackingStoreType)bufferingType
+ defer: (BOOL)flag
{
notificationCenter = [NSNotificationCenter defaultCenter];
@@ -44,47 +44,74 @@
object: self];
// End Hack job -- David
- XtoqWindow *result = [super initWithContentRect:contentRect
- styleMask:aStyle
- backing:bufferingType
- defer:flag];
+ XtoqWindow *result = [super initWithContentRect: contentRect
+ styleMask: aStyle
+ backing: bufferingType
+ defer: flag];
+ [self setAcceptsMouseMovedEvents: YES];
return result;
}
--(void) makeKeyAndOrderFront:(id)sender
+-(void) makeKeyAndOrderFront: (id)sender
{
- [super makeKeyAndOrderFront:sender];
+ [super makeKeyAndOrderFront: sender];
}
--(void) setContext:(xcwm_context_t *)aContext
+-(void) setXcwmWindow: (xcwm_window_t *) aWindow
+ andXcwmContext: (xcwm_context_t *) aContext
{
- winContext = aContext;
+ xcwmWindow = aWindow;
+ xcwmContext = aContext;
}
--(xcwm_context_t *) getContext
+-(xcwm_window_t *) getXcwmWindow
{
- return winContext;
+ return xcwmWindow;
}
-- (BOOL) windowShouldClose:(id)sender
+- (BOOL) windowShouldClose: (id)sender
{
// send notification to controller to close the window
XtoqWindow * aWindow = self;
- NSDictionary * dictionary = [NSDictionary dictionaryWithObject:aWindow
- forKey:@"1"];
- [notificationCenter postNotificationName:@"XTOQdestroyTheWindow"
- object:self
- userInfo:dictionary];
+ NSDictionary * dictionary = [NSDictionary dictionaryWithObject: aWindow
+ forKey: @"1"];
+ [notificationCenter postNotificationName: @"XTOQdestroyTheWindow"
+ object: self
+ userInfo: dictionary];
// keep window from closing till server tells it to
return NO;
}
--(void)windowDidBecomeKey:(NSNotification *)note
+-(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);
+}
+
+-(void) mouseMoved: (NSEvent *) event
+{
+ NSMutableDictionary *InfoDict;
+ NSNumber *xNum, *yNum;
+
+ NSPoint location = [event locationInWindow];
+ NSRect frame = [self frame];
+
+ location.x += frame.origin.x;
+ location.y += frame.origin.y;
+
+ xNum = [[NSNumber alloc] initWithFloat: location.x];
+ yNum = [[NSNumber alloc] initWithFloat: location.y];
+
+ InfoDict = [[NSMutableDictionary alloc] initWithCapacity: 2];
+ [InfoDict setObject: xNum forKey: @"1"];
+ [InfoDict setObject: yNum forKey: @"2"];
+
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName: @"MouseMovedEvent"
+ object: self
+ userInfo: InfoDict];
}
@end