summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess VanDerwalker <washu@sonic.net>2012-03-10 20:05:22 -0800
committerJess VanDerwalker <washu@sonic.net>2012-03-10 20:05:22 -0800
commit726f43b9937c5289ef15e4a96ae6773c5c2802a8 (patch)
treeda3256ae85aa25379db620ee13622d847199ebb6
parentf8120a21c2f4497e0a2b5e6a8c2ac3f5aaafaa3b (diff)
parentee32a864410e1ba126f7b9739f7117b419f62b82 (diff)
Merge with milestone4-input.
-rw-r--r--src/libcompositewm/Makefile.am3
-rw-r--r--src/libcompositewm/event_loop.c40
-rw-r--r--src/libcompositewm/input.c96
-rw-r--r--src/libcompositewm/xtoq.c48
-rw-r--r--src/libcompositewm/xtoq.h86
-rw-r--r--src/libcompositewm/xtoq_internal.h5
-rw-r--r--src/xtoq/XtoqApplication.h9
-rw-r--r--src/xtoq/XtoqApplication.m33
-rw-r--r--src/xtoq/XtoqController.h29
-rw-r--r--src/xtoq/XtoqController.m138
-rw-r--r--src/xtoq/XtoqImageRep.h3
-rw-r--r--src/xtoq/XtoqImageRep.m9
-rw-r--r--src/xtoq/XtoqView.h29
-rw-r--r--src/xtoq/XtoqView.m93
-rw-r--r--src/xtoq/main.m4
-rw-r--r--xtoq-xcode/xtoq-xcode.xcodeproj/project.pbxproj2
16 files changed, 439 insertions, 188 deletions
diff --git a/src/libcompositewm/Makefile.am b/src/libcompositewm/Makefile.am
index aa0862e..b233cad 100644
--- a/src/libcompositewm/Makefile.am
+++ b/src/libcompositewm/Makefile.am
@@ -13,4 +13,5 @@ libcompositewm_la_SOURCES = \
event_loop.c \
init.c \
util.c \
- xtoq.c
+ xtoq.c \
+ input.c
diff --git a/src/libcompositewm/event_loop.c b/src/libcompositewm/event_loop.c
index a37e9cb..632aa55 100644
--- a/src/libcompositewm/event_loop.c
+++ b/src/libcompositewm/event_loop.c
@@ -37,10 +37,28 @@ typedef struct _connection_data {
/* The thread that is running the event loop */
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
*run_event_loop(void *thread_arg_struct);
+/* Functions included in xtoq.h */
+int
+xtoq_get_event_thread_lock (void)
+{
+ return pthread_mutex_lock(&_event_thread_lock);
+}
+
+int
+xtoq_release_event_thread_lock(void)
+{
+ return pthread_mutex_unlock(&_event_thread_lock);
+}
+
/* Functions included in xtoq_internal.h */
int
@@ -57,6 +75,8 @@ _xtoq_start_event_loop (xcb_connection_t *conn,
conn_data->conn = conn;
conn_data->callback = event_callback;
+ pthread_mutex_init(&_event_thread_lock, NULL);
+
ret_val = pthread_create(&_event_thread,
NULL,
run_event_loop,
@@ -213,6 +233,9 @@ void *run_event_loop (void *thread_arg_struct)
callback_ptr(return_evt);
break;
}
+ case XCB_CONFIGURE_NOTIFY: {
+ break;
+ }
case XCB_CONFIGURE_REQUEST: {
xcb_configure_request_event_t *request =
(xcb_configure_request_event_t *)evt;
@@ -228,23 +251,30 @@ void *run_event_loop (void *thread_arg_struct)
case XCB_KEY_PRESS: {
printf("X Key press from xserver-");
xcb_button_press_event_t *kp = (xcb_button_press_event_t *)evt;
- printf ("Key pressed in window %ld detail %ld\n",
+ printf ("Key pressed in window %u detail %c\n",
kp->event, kp->detail);
break;
}
case XCB_BUTTON_PRESS: {
printf("X Button press from xserver ");
xcb_button_press_event_t *bp = (xcb_button_press_event_t *)evt;
- printf ("in window %ld, at coordinates (%d,%d)\n",
+ printf ("in window %u, at coordinates (%d,%d)\n",
bp->event, bp->event_x, bp->event_y );
break;
}
- case XCB_MOTION_NOTIFY: {
- printf("X mouse motion from from xserver-");
+ case XCB_BUTTON_RELEASE: {
+ printf("X Button release from xserver ");
xcb_button_press_event_t *bp = (xcb_button_press_event_t *)evt;
- printf ("mouse motion in window %ld, at coordinates (%d,%d)\n",
+ printf ("in window %u, at coordinates (%d,%d)\n",
bp->event, bp->event_x, bp->event_y );
break;
+ }
+ case XCB_MOTION_NOTIFY: {
+ //printf("X mouse motion from from xserver-");
+ xcb_button_press_event_t *bp = (xcb_button_press_event_t *)evt;
+ // printf ("mouse motion in window %ld, at coordinates (%d,%d)\n",
+ // bp->event, bp->event_x, bp->event_y );
+ break;
}
default: {
printf("UNKNOWN EVENT: %i\n", (evt->response_type & ~0x80));
diff --git a/src/libcompositewm/input.c b/src/libcompositewm/input.c
new file mode 100644
index 0000000..a7b4d8b
--- /dev/null
+++ b/src/libcompositewm/input.c
@@ -0,0 +1,96 @@
+/*Copyright (C) 2012 Aaron Skomra
+
+ 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.
+ */
+
+//
+// input.c
+// xtoq-xcode
+
+#include <stdio.h>
+#include "xtoq.h"
+
+void
+xtoq_key_press (xtoq_context_t *context, int window, uint8_t code)
+{
+ xcb_generic_error_t *err;
+ xcb_void_cookie_t cookie;
+ xcb_window_t none = { XCB_NONE };
+
+ cookie = xcb_test_fake_input( context->conn, XCB_KEY_PRESS, code,
+ XCB_CURRENT_TIME, none, 0, 0, 1 );
+
+ err = xcb_request_check(context->conn, cookie);
+ if (err)
+ {
+ printf("err ");
+ free(err);
+ }
+ xcb_flush(context->conn);
+ printf("xtoq.c received key down - uint8_t '%i', from Mac window #%i to context.window %u\n", code, window, context->window);
+}
+
+void
+xtoq_key_release (xtoq_context_t *context, int window, uint8_t code)
+{
+ xcb_generic_error_t *err;
+ xcb_void_cookie_t cookie;
+ xcb_window_t none = { XCB_NONE };
+
+ xcb_test_fake_input( context->conn, XCB_KEY_RELEASE, code,
+ XCB_CURRENT_TIME, none,0 ,0 , 1 );
+
+ err = xcb_request_check(context->conn, cookie);
+ if (err)
+ {
+ printf("err ");
+ free(err);
+ }
+ xcb_flush(context->conn);
+ printf("xtoq.c received key release- uint8_t '%i', from Mac window #%i to context.window %u\n", code, window, context->window);
+}
+
+void
+xtoq_button_press (xtoq_context_t *context, long x, long y, int window, int button)
+{
+ //xcb_window_t none = { XCB_NONE };
+ xcb_test_fake_input (context->conn, XCB_BUTTON_PRESS, 1, XCB_CURRENT_TIME,
+ context->window, 0, 0, 0);
+ xcb_flush(context->conn);
+ printf("button down received by xtoq.c - (%ld,%ld) in Mac window #%i\n", x, y, window);
+}
+
+void
+xtoq_button_release (xtoq_context_t *context, long x, long y, int window, int button)
+{
+ xcb_test_fake_input (context->conn, XCB_BUTTON_RELEASE, 1, XCB_CURRENT_TIME,
+ context->window, 0, 0, 0);
+ xcb_flush(context->conn);
+ printf("button release received by xtoq.c - (%ld,%ld) in Mac window #%i\n", x, y, window);
+}
+
+void
+xtoq_mouse_motion (xtoq_context_t *context, long x, long y, int window, int button)
+{
+ xcb_test_fake_input (context->conn, XCB_MOTION_NOTIFY, 0, XCB_CURRENT_TIME,
+ root_context->window//root_context->window//none//context->parent
+ ,x, y, 0);
+ xcb_flush(context->conn);
+ //printf("mouse motion received by xtoq.c - (%ld,%ld) in Mac window #%i\n", x, y, window);
+}
diff --git a/src/libcompositewm/xtoq.c b/src/libcompositewm/xtoq.c
index fc22211..f634f7f 100644
--- a/src/libcompositewm/xtoq.c
+++ b/src/libcompositewm/xtoq.c
@@ -58,9 +58,14 @@ xtoq_init(char *display) {
// are created on the root. This is where we add masks for the events
// we care about catching on the root window.
mask_values[0] = XCB_EVENT_MASK_KEY_PRESS |
+ XCB_EVENT_MASK_KEY_RELEASE |
XCB_EVENT_MASK_BUTTON_PRESS |
+ XCB_EVENT_MASK_BUTTON_RELEASE |
+ XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
+ XCB_EVENT_MASK_ENTER_WINDOW |
+ XCB_EVENT_MASK_LEAVE_WINDOW |
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
cookie = xcb_change_window_attributes_checked(conn, root_window,
XCB_CW_EVENT_MASK,
@@ -196,50 +201,7 @@ xtoq_image_destroy(xtoq_image_t * xtoq_image){
free(xtoq_image);
}
-void
-dummy_xtoq_key_press (xtoq_context_t *context, int window, uint8_t code)
-{
- xcb_generic_error_t *err;
- xcb_void_cookie_t cookie;
- xcb_window_t none = { XCB_NONE };
-
- cookie = xcb_test_fake_input( context->conn, XCB_KEY_PRESS, code,
- XCB_CURRENT_TIME, none, 0, 0, 1 );
- xcb_test_fake_input( context->conn, XCB_KEY_RELEASE, code,
- XCB_CURRENT_TIME, none,0 ,0 , 1 );
-
- err = xcb_request_check(context->conn, cookie);
- if (err)
- {
- printf("err ");
- free(err);
- }
- xcb_flush(context->conn);
- printf("xtoq.c received key - uint8_t '%i', from Mac window #%i to context.window %ld\n", code, window, context->window);
-}
-
-void
-dummy_xtoq_button_down (xtoq_context_t *context, long x, long y, int window, int button)
-{
- //xcb_window_t none = { XCB_NONE };
- xcb_test_fake_input (context->conn, XCB_BUTTON_PRESS, 1, XCB_CURRENT_TIME,
- context->parent, x, y, 0);
- // x has to be translated (?in the view)
- xcb_test_fake_input (context->conn, XCB_BUTTON_RELEASE, 1, XCB_CURRENT_TIME,
- context->parent, x, y, 0);
- xcb_flush(context->conn);
- printf("button down received by xtoq.c - (%ld,%ld) in Mac window #%i\n", x, y, window);
-}
-void
-dummy_xtoq_mouse_motion (xtoq_context_t *context, long x, long y, int window, int button)
-{
- xcb_window_t none = { XCB_NONE };
- xcb_test_fake_input (context->conn, XCB_MOTION_NOTIFY, 0, 0,
- context->window//root_context->window//none//context->parent
- ,x, y, 0);
- xcb_flush(context->conn);
-}
/* Close all windows, the connection, as well as the event loop */
diff --git a/src/libcompositewm/xtoq.h b/src/libcompositewm/xtoq.h
index 36e9d65..aa550f1 100644
--- a/src/libcompositewm/xtoq.h
+++ b/src/libcompositewm/xtoq.h
@@ -41,12 +41,11 @@
#include <xcb/xcb_keysyms.h> //aaron
#include "xtoq_internal.h"
-// TODO: Remove this once we get the context_list in place. Right
-// now this is here for testing purposes to give an easy way to get the
-// root window's context in any function
+/**
+ * Context which contains the display's root window.
+ */
extern xtoq_context_t *root_context;
-
/**
* Sets up the connection and grabs the root window from the specified screen
* @param display The display to connect to
@@ -54,10 +53,26 @@ extern xtoq_context_t *root_context;
xtoq_context_t *
xtoq_init(char *display);
+/**
+ * Returns a window's entire image
+ * @param an xtoq_context_t
+ * FIXME: this might be for the root window
+ * @return an xtoq_image_t with an the image of a window
+ */
xtoq_image_t *
xtoq_get_image(xtoq_context_t *context);
/**
+ * Intended for servicing to a client's reaction to a damage notification
+ * this window returns the modified subrectangle of a window
+ * @param an xtoq_context_t of the damaged window
+ * @return an xtoq_image_t with partial image window contents
+ */
+xtoq_image_t *
+test_xtoq_get_image(xtoq_context_t * context);
+
+
+/**
* free the memory used by an xtoq_image_t created
* during a call to test_xtoq_image_create
*/
@@ -109,33 +124,81 @@ xtoq_set_window_to_top(xtoq_context_t *context);
int
xtoq_start_event_loop (xtoq_context_t *context, xtoq_event_cb_t callback);
-/* Closes the windows open on the X Server, the connection, and the event
+/**
+ * Request a lock on the mutex for the event loop thread. Blocks
+ * until lock is aquired, or error occurs.
+ * @return 0 if successful, otherwise non-zero
+ */
+int
+xtoq_get_event_thread_lock (void);
+
+/**
+ * Release the lock on the mutex for the event loop thread.
+ * @return 0 if successsful, otherwise non-zero
+ */
+int
+xtoq_release_event_thread_lock(void);
+
+/**
+ * Closes the windows open on the X Server, the connection, and the event
* loop.
*/
void
xtoq_close(void);
/**
- * Testing function
+ * function
* @param context xtoq_context_t
* @param window The window that the key press was made in.
* @param keyCode The key pressed.
*/
void
-dummy_xtoq_key_press (xtoq_context_t *context, int window, uint8_t code);
+xtoq_key_press (xtoq_context_t *context, int window, uint8_t code);
/**
- * Testing function
+ * function
+ * @param context xtoq_context_t
+ * @param window The window that the key press was made in.
+ * @param keyCode The key released.
+ */
+void
+xtoq_key_release (xtoq_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 xtoq_context_t
* @param x - x coordinate
* @param y - y coordinate
* @param window The window that the key press was made in.
*/
void
-dummy_xtoq_button_down (xtoq_context_t *context, long x, long y, int window, int button);
+xtoq_button_press (xtoq_context_t *context, long x, long y, int window, int button);
+
+/**
+ * Uses the XTEST protocol to send input events to the X Server (The X Server
+ * 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 xtoq_context_t
+ * @param x - x coordinate
+ * @param y - y coordinate
+ * @param window The window that the key release was made in.
+ */
+void
+xtoq_button_release (xtoq_context_t *context, long x, long y, int window, int button);
+/**
+ * function
+ * @param context xtoq_context_t
+ * @param x - x coordinate
+ * @param y - y coordinate
+ * @param window The window that the key release was made in.
+ */
void
-dummy_xtoq_mouse_motion (xtoq_context_t *context, long x, long y, int window, int button);
+xtoq_mouse_motion (xtoq_context_t *context, long x, long y, int window, int button);
/****************
* window.c
@@ -160,7 +223,4 @@ xtoq_request_close(xtoq_context_t *context);
void
xtoq_configure_window(xtoq_context_t *context, int x, int y, int height, int width);
-
-xtoq_image_t *
-test_xtoq_get_image(xtoq_context_t * context);
#endif // _XTOQ_H_
diff --git a/src/libcompositewm/xtoq_internal.h b/src/libcompositewm/xtoq_internal.h
index 375199b..2f2c002 100644
--- a/src/libcompositewm/xtoq_internal.h
+++ b/src/libcompositewm/xtoq_internal.h
@@ -61,6 +61,11 @@ typedef struct xtoq_wm_atoms {
*/
extern xtoq_wm_atoms *_wm_atoms;
+/**
+ * Mutex lock supplied to client to lock event loop thread
+ */
+extern pthread_mutex_t event_thread_lock;
+
/* util.c */
/**
diff --git a/src/xtoq/XtoqApplication.h b/src/xtoq/XtoqApplication.h
index dc0f086..625549e 100644
--- a/src/xtoq/XtoqApplication.h
+++ b/src/xtoq/XtoqApplication.h
@@ -31,8 +31,9 @@
#define environ (*_NSGetEnviron())
#endif
-@interface XtoqApplication : NSApplication
+@interface XtoqApplication : NSApplication {
+}
/**
* The main of our Application.
*
@@ -47,4 +48,10 @@
*/
int XtoqApplicationMain(int argc, char** argv);
+- (void) sendEvent:(NSEvent *)e;
+
@end
+
+int
+XtoqApplicationMain(int argc, char** argv);
+
diff --git a/src/xtoq/XtoqApplication.m b/src/xtoq/XtoqApplication.m
index d337dd7..f742e79 100644
--- a/src/xtoq/XtoqApplication.m
+++ b/src/xtoq/XtoqApplication.m
@@ -21,6 +21,8 @@
#import "XtoqApplication.h"
+#define FILEBAR 23
+
@implementation XtoqApplication
int XtoqApplicationMain(int argc, char** argv){
@@ -92,9 +94,40 @@ int XtoqApplicationMain(int argc, char** argv){
controller = [[XtoqController alloc] init];
[controller setScreen:scrn];
[NSApp setDelegate: controller];
+
[NSApp run];
return 1;
}
+- (void) sendEvent:(NSEvent *)e {
+ CGFloat x, y;
+ NSNumber *xObject, *yObject;
+ NSMutableDictionary *threeInfoDict;
+ switch ([e type]) {
+ case NSMouseMoved:
+ // height = [[NSScreen mainScreen] frame].size.height;
+ // you can't call mouseLocation on "e"
+ x = [NSEvent mouseLocation].x;
+ y = [NSEvent mouseLocation].y;
+
+ //NSLog(@"Mouse Moved y=%f", y);
+
+ xObject = [[NSNumber alloc] initWithFloat:x];
+ yObject = [[NSNumber alloc] initWithFloat:y];
+ threeInfoDict = [[NSMutableDictionary alloc] initWithCapacity:3];
+ [threeInfoDict setObject:e forKey:@"1"];
+ [threeInfoDict setObject:xObject forKey:@"2"];
+ [threeInfoDict setObject:yObject forKey:@"3"];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:@"MouseMovedEvent"
+ object:self
+ userInfo:threeInfoDict];
+ break;
+
+ default: [super sendEvent:e];
+ break;
+ }
+}
+
@end
diff --git a/src/xtoq/XtoqController.h b/src/xtoq/XtoqController.h
index 490ad61..cfc8386 100644
--- a/src/xtoq/XtoqController.h
+++ b/src/xtoq/XtoqController.h
@@ -67,8 +67,7 @@ id referenceToSelf;
XtoqImageRep *image;
XtoqImageRep *imageNew;
XtoqView *view;
- NSString *file;
- NSImage *image2;
+
int originalHeight;
int originalWidth;
NSRect imageRec;
@@ -79,15 +78,26 @@ id referenceToSelf;
- (void) applicationWillFinishLaunching:(NSNotification *) aNotification;
- (void) applicationDidFinishLaunching: (NSNotification *) aNotification;
+/**
+ * Receive notification of a key down event from the view.
+ * @param an NSNotification containing an NSEvent
+ */
- (void) keyDownInView: (NSNotification *) aNotification;
+/**
+ * Receive notification of a mouse button press from the view.
+ * @param an NSNotification containing an NSEvent
+ */
- (void) mouseButtonDownInView: (NSNotification *) aNotification;
/**
- * Makemenu sets the menu for the application.
- *
- * Sets main menu for the XtoQ.app. Also enables an 'applications' menu
- * in which xeyes, xclock, xterm, and xlogo can be launched.
+ * Receive notification of a mouse button release from the view.
+ * @param an NSNotification containing an NSEvent
+ */
+- (void) mouseButtonReleaseInView: (NSNotification *) aNotification;
+
+/**
+ * Makemenu and related selector functions for launching X applications.
*/
- (void) makeMenu;
@@ -132,6 +142,8 @@ id referenceToSelf;
*/
- (void) runXlogo: (id) sender;
+- (void) mouseMovedInApp: (NSNotification *) aNotification;
+
/**
* Runs xterm.
*
@@ -144,8 +156,11 @@ id referenceToSelf;
/**
* Put a new image in the window / view
+ * Send an image to the view after being notified of a damage event from
+ * the event handler.
+ * @param an xtoq_context_t sent from eventHandler
*/
-- (void) updateImageNew: (xtoq_context_t *) windowContext;
+- (void) updateImage: (xtoq_context_t *) windowContext;
- (void) createNewWindow: (xtoq_context_t *) windowContext;
- (void) destroyWindow: (xtoq_context_t *) windowContext;
diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m
index c06cbfb..d9edbe3 100644
--- a/src/xtoq/XtoqController.m
+++ b/src/xtoq/XtoqController.m
@@ -64,7 +64,7 @@
rootContext = xtoq_init(screen);
[[NSGraphicsContext currentContext]
- setImageInterpolation:NSImageInterpolationHigh];
+ setImageInterpolation:NSImageInterpolationHigh];
xtoqWindow = [[XtoqWindow alloc]
initWithContentRect: NSMakeRect(rootContext->x, rootContext->y,
@@ -110,16 +110,23 @@
selector: @selector(mouseButtonDownInView:)
name: @"XTOQmouseButtonDownEvent"
object: nil];
+
+ [nc addObserver: self
+ selector: @selector(mouseButtonReleaseInView:)
+ name: @"XTOQmouseButtonReleaseEvent"
+ object: nil];
+
+ [nc addObserver: self
+ selector: @selector(mouseMovedInApp:)
+ name: @"MouseMovedEvent"
+ object: nil];
+
// register for destroy event
[nc addObserver: self
selector: @selector(destroy:)
name: @"XTOQdestroyTheWindow"
object: nil];
- [nc addObserver: self
- selector: @selector(mouseMovedInView:)
- name: @"XTOQviewMouseMovedEvent"
- object: nil];
// regester for window will/did movement notification
[nc addObserver:self
selector:@selector(windowWillMove:)
@@ -173,29 +180,51 @@
xtoq_start_event_loop(rootContext, (void *) eventHandler);
}
+- (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;
+
+ int yInt = height - FILEBAR - [yVal intValue];
+ yVal = [[NSNumber alloc] initWithInt:yInt];
+
+ NSLog(@"Mouse x = %i, y = %i", [xVal intValue], [yVal intValue]);
+
+ dispatch_async(xtoqDispatchQueue,
+ ^{ xtoq_mouse_motion (rootContext,
+ [xVal intValue],
+ [yVal intValue],
+ (int)[event windowNumber],
+ 0);;});
+
+
+}
+
- (void) keyDownInView: (NSNotification *) aNotification
{
- int i = 0;
NSDictionary *keyInfo = [aNotification userInfo];
// note this keyInfo is the key in <key, value> not the key pressed
NSEvent * event = [keyInfo objectForKey: @"1"];
- //NSLog(@"Controller Got a XTOQviewKeyDownEvent key %@", [event characters]);
unsigned short aChar = [event keyCode];
NSString* charNSString = [event characters];
const char* charcharstar = [charNSString UTF8String];
- //printf( "\n--------------------------------------------\n" );
- // translate key here code = translate(charcharstar);
+
NSLog(@"%s pressed", charcharstar);
- //uint8_t code = (unsigned char)0x10;
- //uint8_t code =
-
- // for(i = 8; i < 256; i++){
- // aChar++;
- dispatch_async(xtoqDispatchQueue,
- ^{ dummy_xtoq_key_press(rootContext,
+ dispatch_async(xtoqDispatchQueue,
+ ^{ xtoq_key_press(rootContext,
+ (int)[event windowNumber],
+ aChar + 8) ;});
+ dispatch_async(xtoqDispatchQueue,
+ ^{ xtoq_key_release(rootContext,
(int)[event windowNumber],
aChar + 8) ;});
- // }
}
@@ -207,47 +236,49 @@
NSDictionary *mouseDownInfo = [aNotification userInfo];
// NSLog(@"Controller Got a XTOQmouseButtonDownEvent");
NSEvent * event = [mouseDownInfo objectForKey: @"1"];
- //NSRect bnd = NSMakeRect(0,0,512,386);
+
NSNumber * heightAsNumber = [NSNumber alloc];
heightAsNumber = [mouseDownInfo objectForKey: @"2"];
heightFloat = [heightAsNumber floatValue];
//NSLog(@"Mouse Info: %@", [mouseDownInfo objectForKey: @"2"]);
+
+ float height = [[NSScreen mainScreen] frame].size.height;
+
dispatch_async(xtoqDispatchQueue,
- ^{ dummy_xtoq_button_down (rootContext,
- [NSEvent mouseLocation].x,
- heightFloat - [NSEvent mouseLocation].y,
- (int)[event windowNumber],
- 0);;});
+ ^{ xtoq_button_press (rootContext,
+ 0,
+ 0,
+ (int)[event windowNumber],
+ 0);;});
}
-- (void) setScreen:(char *)scrn {
- free(screen);
- screen = strdup(scrn);
- if (screen == NULL) {
- perror(strerror(errno));
- }
- else {
- setenv("DISPLAY", screen, 1);
- }
-}
-- (void) mouseMovedInView: (NSNotification *) aNotification
+// on this side all I have is a xtoq_context , on the library side I need
+// to turn that into a real context
+- (void) mouseButtonReleaseInView: (NSNotification *) aNotification
{
CGFloat heightFloat;
- NSDictionary *mouseDownInfo = [aNotification userInfo];
- NSEvent * event = [mouseDownInfo objectForKey: @"1"];
+ NSDictionary *mouseReleaseInfo = [aNotification userInfo];
+ // NSLog(@"Controller Got a XTOQmouseButtonDownEvent");
+ NSEvent * event = [mouseReleaseInfo objectForKey: @"1"];
+ //NSRect bnd = NSMakeRect(0,0,512,386);
NSNumber * heightAsNumber = [NSNumber alloc];
- heightAsNumber = [mouseDownInfo objectForKey: @"2"];
+ heightAsNumber = [mouseReleaseInfo objectForKey: @"2"];
heightFloat = [heightAsNumber floatValue];
//NSLog(@"Mouse Info: %@", [mouseDownInfo objectForKey: @"2"]);
- //NSLog(@"Mouse x = %i, y = %i", (int)[NSEvent mouseLocation].x,
- // (int)[[NSScreen mainScreen] frame].size.height - FILEBAR - (int)[NSEvent mouseLocation].y);
+
+ float height = [[NSScreen mainScreen] frame].size.height;
dispatch_async(xtoqDispatchQueue,
- ^{ dummy_xtoq_mouse_motion (rootContext,
- [NSEvent mouseLocation].x,
- [[NSScreen mainScreen] frame].size.height - FILEBAR - [NSEvent mouseLocation].y,
- (int)[event windowNumber],
- 0);;});
+ ^{ xtoq_button_release (rootContext,
+ 0,
+ 0,
+ (int)[event windowNumber],
+ 0);;});
+}
+
+
+- (void) setScreen:(char *)scrn {
+ screen = scrn;
}
- (void) makeMenu {
@@ -436,14 +467,11 @@
- (void) windowWillMove:(NSNotification*)notification {
//NSLog(@"window will move");
}
-- (void) updateImageNew : (xtoq_context_t *) windowContext
+- (void) updateImage:(xtoq_context_t *) windowContext
{
-
float y_transformed;
-
+ //FIXME : rename test_xtoq_get_image to remove "test"
libImageT = test_xtoq_get_image(windowContext);
- // libImageT = xtoq_get_image(windowContext);
-
//NSLog(@"update image new values in - %i, %i, %i, %i", windowContext->damaged_x, windowContext->damaged_y, windowContext->damaged_width, windowContext->damaged_height);
y_transformed =( windowContext->height - windowContext->damaged_y - windowContext->damaged_height)/1.0;
@@ -459,7 +487,7 @@
}
- (void) windowDidResize:(NSNotification*)notification {
- // [self reshape];
+ [self reshape];
}
- (void) reshape {
@@ -469,15 +497,13 @@
if (moveWindow != nil) {
xtoq_context_t *moveContext = [moveWindow getContext];
NSRect moveFrame = [moveWindow frame];
-
int x = (int)moveFrame.origin.x;
int y = [self osxToXserver:(int)moveFrame.origin.y
windowHeight:moveContext->height] - WINDOWBAR;
int width = (int)moveFrame.size.width;
int height = (int)moveFrame.size.height - WINDOWBAR;
- NSLog(@"x = %i, y = %i, width = %i, height = %i,", x, y, width, height);
- NSLog(@"Call xtoq_configure_window(moveContext, x, y, height, width)");
- xtoq_configure_window(moveContext, x, y, height, width);
+ NSLog(@"Call xtoq_configure_window(moveContext, x = %i, y = %i, height = %i, width = %i)", x, y, height, width);
+ xtoq_configure_window(moveContext, x, y - height, height, width);
}
}
@@ -487,9 +513,7 @@ void eventHandler (xtoq_event_t *event)
{
xtoq_context_t *context = event->context;
if (event->event_type == XTOQ_DAMAGE) {
- // This message generates a lot of console spam - only uncomment when testing
- //NSLog(@"Got damage event");
- [referenceToSelf updateImageNew: context];
+ [referenceToSelf updateImage: context];
} else if (event->event_type == XTOQ_CREATE) {
NSLog(@"Window was created");
[referenceToSelf createNewWindow: context];
diff --git a/src/xtoq/XtoqImageRep.h b/src/xtoq/XtoqImageRep.h
index 7b915f4..e8cafd9 100644
--- a/src/xtoq/XtoqImageRep.h
+++ b/src/xtoq/XtoqImageRep.h
@@ -30,7 +30,7 @@
@interface XtoqImageRep : NSImageRep {
- struct CGImage *cgImage;
+ CGImageRef cgImage;
xcb_image_t *imageT;
xtoq_image_t * imageParent;
NSSize size;
@@ -87,4 +87,5 @@
- (BOOL)drawInRect:(NSRect)rect;
- (void)destroy;
+
@end
diff --git a/src/xtoq/XtoqImageRep.m b/src/xtoq/XtoqImageRep.m
index ca2b5f5..c08759d 100644
--- a/src/xtoq/XtoqImageRep.m
+++ b/src/xtoq/XtoqImageRep.m
@@ -43,7 +43,6 @@
- (id)initWithData:(xtoq_image_t *)imageData x:(int)x y:(int)y{
imageParent = imageData;
imageT = imageData->image;
- // windowSize = NSMakeSize(imageT->width, imageT->height);
self = [super init];
if (!self) {
return nil;
@@ -56,14 +55,14 @@
);
CGColorSpaceRef csp = CGColorSpaceCreateDeviceRGB();
-
+ CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
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,
csp, //CGColorSpaceRef colorspace,
- kCGBitmapByteOrderDefault,//CGBitmapInfo bitmapInfo,
+ bitmapInfo,
cgdat,//CGDataProviderRef provider,
NULL, //const CGFloat decode[],
YES, //bool shouldInterpolate,
@@ -74,6 +73,7 @@
size = NSMakeSize (width, height);
imageX =x;
imageY =y;
+
return self;
}
@@ -128,4 +128,7 @@
xtoq_image_destroy(imageParent);
}
}
+
+
+
@end
diff --git a/src/xtoq/XtoqView.h b/src/xtoq/XtoqView.h
index 3d5e4e1..61ab384 100644
--- a/src/xtoq/XtoqView.h
+++ b/src/xtoq/XtoqView.h
@@ -28,7 +28,6 @@ SOFTWARE.
*/
#import <Cocoa/Cocoa.h>
-#import "xtoq_internal.h"
#import "XtoqImageRep.h"
#import "xtoq.h"
@@ -52,10 +51,32 @@ SOFTWARE.
int bufferIndexTwo;
}
+/**
+ * Intialize the view given its bounds
+ * @param an NSRect with the bounds (size) of the view
+ */
+- (id)initWithFrame:(NSRect)frame;
+
+/**
+ * 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;
+
+/**
+ * Set the entire image contents in the view
+ * @param an XtoqImageRep
+ */
- (void)setImage:(XtoqImageRep *)newImage;
+
+/**
+ * Set the partial image contents in the view
+ * @param an XtoqImageRep
+ */
- (void)setPartialImage:(XtoqImageRep *)newImage;
-- (id)initWithFrame:(NSRect)frame;
+
+
//- (void)getRectsBeingDrawn:(const NSRect **)rects count:(NSInteger *)count;
-- (void)ourDisp;
+
@end
-
diff --git a/src/xtoq/XtoqView.m b/src/xtoq/XtoqView.m
index 38d60bd..6397fa3 100644
--- a/src/xtoq/XtoqView.m
+++ b/src/xtoq/XtoqView.m
@@ -20,7 +20,9 @@
*/
#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
/**
@@ -38,37 +40,33 @@ initWithFrame:(NSRect)frame {
bufferIndexTwo = 0;
trackingArea = [[NSTrackingArea alloc] initWithRect:frame
-
- options: (NSTrackingMouseEnteredAndExited |
- NSTrackingMouseMoved
- | NSTrackingActiveInKeyWindow
- )
-
+ options: (NSTrackingMouseEnteredAndExited |
+ NSTrackingMouseMoved
+ | NSTrackingActiveInKeyWindow)
owner:self userInfo:nil];
-
[self addTrackingArea:trackingArea];
}
return self;
}
-/**
- * Overridden by subclasses to draw the receiver’s image within the passed-in rectangle.
- */
+
+// Overridden by subclasses to draw the receiver’s image within the passed-in rectangle.
-(void)
drawRect:(NSRect)dirtyRect {
-
- while (bufferIndexTwo < bufferIndex) {
- int i = bufferIndexTwo++;
- [image[i] draw];//InRect:dirtyRect];
- [image[i] destroy];
- }
- bufferIndex = bufferIndexTwo = 0;
+ xtoq_get_event_thread_lock();
+ while (bufferIndexTwo < bufferIndex) {
+ int i = bufferIndexTwo++;
+ [image[i] draw];//InRect:dirtyRect];
+ [image[i] destroy];
+ }
+ bufferIndex = bufferIndexTwo = 0;
+ xtoq_release_event_thread_lock();
}
-/**
- * This is necessary for accepting input.
- */
+
+
+//This is necessary for accepting input.
- (BOOL)
acceptsFirstResponder {
return YES;
@@ -78,27 +76,16 @@ acceptsFirstResponder {
return YES;
}
-- (void)mouseMoved:(NSEvent *)mouseMovedEvent
-{
- CGFloat f = [self bounds].size.height;
- NSNumber *n = [[NSNumber alloc] initWithFloat:f];
- NSMutableDictionary *twoInfoDict = [[NSMutableDictionary alloc] initWithCapacity:2];
- [twoInfoDict setObject:mouseMovedEvent forKey:@"1"];
- [twoInfoDict setObject:n forKey:@"2"];
-
- //NSLog(@"bound %f location %f", CGRectGetHeight(bnd), [mouseMovedEvent locationInWindow].y );
- [notificationCenter postNotificationName:@"XTOQviewMouseMovedEvent"
- object:self
- userInfo:twoInfoDict];
+/*- (void)mouseEntered:(NSEvent *)theEvent {
+
}
+- (void)mouseExited:(NSEvent *)theEvent {
-/*- (void)mouseEntered:(NSEvent *)theEvent {
-
}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
-- (void)mouseExited:(NSEvent *)theEvent {
-
}*/
/**
@@ -108,7 +95,6 @@ acceptsFirstResponder {
keyDown:(NSEvent *)theEvent {
NSDictionary * dictionary = [NSDictionary dictionaryWithObject:theEvent
forKey:@"1"];
-
[notificationCenter postNotificationName:@"XTOQviewKeyDownEvent"
object:self
userInfo:dictionary];
@@ -116,8 +102,10 @@ keyDown:(NSEvent *)theEvent {
-(void)
mouseDown:(NSEvent *)mouseEvent {
- CGFloat f = [self bounds].size.height;
+ 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"];
@@ -128,16 +116,29 @@ mouseDown:(NSEvent *)mouseEvent {
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)setImage:(XtoqImageRep *)newImage {
+ xtoq_get_event_thread_lock();
image[bufferIndex++] = newImage;
+ xtoq_release_event_thread_lock();
}
- (void)setPartialImage:(XtoqImageRep *)newImage{
-
- image[bufferIndex++] = newImage;
-
+ xtoq_get_event_thread_lock(); {
+ image[bufferIndex++] = newImage;
+ } xtoq_release_event_thread_lock();
+
NSRect imageRec = NSMakeRect([newImage imageX], [newImage imageY], [newImage getWidth] , [newImage getHeight]);
-
[self setNeedsDisplayInRect:imageRec];
//[[self window] flushWindow];
}
@@ -146,12 +147,4 @@ mouseDown:(NSEvent *)mouseEvent {
return YES;
}
-- (void)ourDisp{
- CGContextRef destCtx = (CGContextRef)[[NSGraphicsContext currentContext]
- graphicsPort];
- while (bufferIndexTwo < bufferIndex) {
- [image[bufferIndexTwo++] draw];
- }
-}
-
@end
diff --git a/src/xtoq/main.m b/src/xtoq/main.m
index 9ef3887..a6caedb 100644
--- a/src/xtoq/main.m
+++ b/src/xtoq/main.m
@@ -31,7 +31,5 @@
int main(int argc, char *argv[])
{
// Xcode provided code
- //return NSApplicationMain(argc, (const char **)argv);
-
- return XtoqApplicationMain(argc, (const char **)argv);
+ return XtoqApplicationMain(argc, argv);
}
diff --git a/xtoq-xcode/xtoq-xcode.xcodeproj/project.pbxproj b/xtoq-xcode/xtoq-xcode.xcodeproj/project.pbxproj
index c0597c1..ce012be 100644
--- a/xtoq-xcode/xtoq-xcode.xcodeproj/project.pbxproj
+++ b/xtoq-xcode/xtoq-xcode.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXFileReference section */
+ 48D40DB41508870C00DD5428 /* input.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = input.c; sourceTree = "<group>"; };
52BF61D114F5607E00CA8AA0 /* xinitrc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = xinitrc; sourceTree = "<group>"; };
E1D4D05614EE5011000AB51B /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
E1D4D05814EE5011000AB51B /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Makefile.am; path = ../Makefile.am; sourceTree = "<group>"; };
@@ -139,6 +140,7 @@
E1D4D08714EE5011000AB51B /* xtoq.c */,
E1D4D08814EE5011000AB51B /* xtoq.h */,
E1D4D08B14EE5011000AB51B /* xtoq_internal.h */,
+ 48D40DB41508870C00DD5428 /* input.c */,
);
path = libcompositewm;
sourceTree = "<group>";