Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made window-specific event stacks. Handled key event conversion. Refa…

…ctoring event handling to allow for escape and tab keys.
  • Loading branch information...
commit 1dd93e55a07073e01862bc9f8f2739cb66ebd292 1 parent 22d7827
@jtza8 jtza8 authored committed
View
1  AUTHORS
@@ -5,3 +5,4 @@ Morgan Veyret <patzy at oxyde org>
Michael Compton <michael compton at littleedge co uk>
Josh March�n <sykopomp at sykosomatic org>
Benjamin Saunders < ??? >
+Jens Thiede <jensthiede at gmail com>
View
139 src/osx/appkit.lisp
@@ -64,6 +64,138 @@
(defun ns-event-type (event)
(foreign-enum-keyword 'ns-event-type (%ns-event-type event)))
+(defcenum ns-key-code
+ :A
+ :S
+ :D
+ :F
+ :H
+ :G
+ :Z
+ :X
+ :C
+ :V
+ (:B 11)
+ :Q
+ :W
+ :E
+ :R
+ :Y
+ :T
+ :1
+ :2
+ :3
+ :4
+ :6
+ :5
+ :|=|
+ :9
+ :7
+ :|-|
+ :8
+ :0
+ :|]|
+ :O
+ :U
+ :|[|
+ :I
+ :P
+ :enter
+ :L
+ :J
+ :|'|
+ :K
+ (:|;| 41)
+ :|\\|
+ :|,|
+ :|/|
+ :N
+ :M
+ :|.|
+ :tab
+ :space
+ :|`|
+ (:backspace 51)
+ :esc
+ (:rsuper 54)
+ :lsuper
+ :lshift
+ :caps-lock
+ :lalt
+ :lctrl
+ :rshift
+ :ralt
+ :rctrl
+ (:f17 64)
+ :kp-decimal
+ (:kp-multiply 67)
+ (:kp-add 69)
+ (:kp-divide 75)
+ :kp-enter
+ (:kp-subtract 78)
+ :f18
+ :f19
+ :kp-equal
+ :kp-0
+ :kp-1
+ :kp-2
+ :kp-3
+ :kp-4
+ :kp-5
+ :kp-6
+ :kp-7
+ :f20
+ :kp-8
+ :kp-9
+ (:f5 96)
+ :f6
+ :f7
+ :f3
+ :f8
+ :f9
+ (:f11 103)
+ (:f13 105)
+ :f16
+ :f14
+ (:f10 109)
+ (:f12 111)
+ (:f15 113)
+ :insert
+ :home
+ :pageup
+ :del
+ :f4
+ :end
+ :f2
+ :pagedown
+ :f1
+ :left
+ :right
+ :down
+ :up)
+
+(defcfun ("NSEventKeyCode" %ns-event-key-code) :uint16
+ (event :pointer))
+
+(defun ns-event-key-code (event)
+ (let* ((code (%ns-event-key-code event))
+ (key (foreign-enum-keyword 'ns-key-code code :errorp nil)))
+ (if key key :unknown)))
+
+(defbitfield ns-modifier-flags
+ (:caps-lock #x10000)
+ (:shift #x20000)
+ (:control #x40000)
+ (:alt #x80000)
+ (:special #x100000)
+ (:num-lock #x110000)
+ (:help #x120000)
+ (:function #x140000)
+ (:device-independant #xffff0000))
+
+(defcfun ("NSEventModifierFlags" ns-event-modifier-flags) ns-modifier-flags
+ (event :pointer))
+
(defcfun ("NSEventWindow" ns-event-window) :pointer
(event :pointer))
@@ -156,6 +288,10 @@
(window :pointer)
(accept-events :boolean))
+(defcfun ("NSWindowDiscardRemainingEvents" ns-window-discard-remaining-events)
+ :void
+ (window :pointer))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; NSMenu ;;;
@@ -273,4 +409,7 @@
(defcfun ("NSOpenGLContextClearDrawable" ns-opengl-context-clear-drawable) :void
+ (context :pointer))
+
+(defcfun ("NSOpneGLContextFlushBuffer" ns-opengl-context-flush-buffer) :void
(context :pointer))
View
5 src/osx/bridge/GlopWindowResponder.m
@@ -58,6 +58,11 @@ - (void)scrollWheel:(NSEvent *)event
eventCallback(event);
}
+- (void)flagsChanged:(NSEvent *)event
+{
+ eventCallback(event);
+}
+
/*
- (void)mouseDragged:(NSEvent *)event
{
View
2  src/osx/bridge/Makefile
@@ -4,7 +4,7 @@ OBJ=foundation.o appkit.o GlopApp.o GlopWindowResponder.o GlopGLView.o
all: glop-bridge.dylib
glop-bridge.dylib: ${OBJ}
- ld -dylib -o glop-bridge.dylib ${OBJ} -lc -framework AppKit,Carbon,OpenGL
+ ld -dylib -o glop-bridge.dylib ${OBJ} -lc -framework AppKit,Carbon
clean:
rm -f *.dylib *.o
View
21 src/osx/bridge/appkit.m
@@ -32,6 +32,16 @@ NSUInteger NSEventGetType (NSEvent *event)
return [event type];
}
+unsigned short NSEventKeyCode (NSEvent *event)
+{
+ return [event keyCode];
+}
+
+NSUInteger NSEventModifierFlags (NSEvent *event)
+{
+ return [event modifierFlags];
+}
+
NSWindow *NSEventWindow (NSEvent *event)
{
return [event window];
@@ -140,6 +150,12 @@ void NSWindowSetAcceptsMouseMovedEvents (NSWindow *window, BOOL acceptEvents)
[window setAcceptsMouseMovedEvents:acceptEvents];
}
+void NSWindowDiscardRemainingEvents (NSWindow *window)
+{
+ [window discardEventsMatchingMask:NSAnyEventMask
+ beforeEvent:nil];
+}
+
/******************************************************************************/
/*** NSMenu ***/
/******************************************************************************/
@@ -198,3 +214,8 @@ void NSOpenGLContextClearDrawable (NSOpenGLContext *context)
{
[context clearDrawable];
}
+
+void NSOpenGLContextFlushBuffer (NSOpenGLContext *context)
+{
+ [context flushBuffer];
+}
View
BIN  src/osx/bridge/glop-bridge.dylib
Binary file not shown
View
2  src/osx/glop-gl-view.lisp
@@ -19,4 +19,4 @@
(defcfun ("GlopGLViewSetNextResponder" glop-gl-view-set-next-responder) :void
(view :pointer)
- (responder :pointer))
+ (responder :pointer))
View
93 src/osx/glop-osx.lisp
@@ -3,7 +3,15 @@
(defparameter *autorelease-pool* nil)
(defparameter *opengl-bundle* nil)
(defparameter *main-menu* nil)
-(defparameter *event-stack* '())
+(defparameter *event-stacks* (make-hash-table))
+(defparameter *active-modifiers* '())
+
+(defun event-stack (ns-window)
+ (gethash (cffi:pointer-address ns-window) *event-stacks*))
+
+(defsetf event-stack (ns-window) (value)
+ `(setf (gethash (cffi:pointer-address ,ns-window) *event-stacks*)
+ ,value))
(defun release-global-autorelease-pool ()
(when *autorelease-pool*
@@ -58,36 +66,48 @@
(let ((display-modes (glop-bridge:copy-all-display-modes
(glop-bridge:main-display-id) (cffi:null-pointer))))
(loop for i below (glop-bridge:ns-array-count display-modes)
- collect (display-to-video-modepress-event
+ collect (display-to-video-mode
(glop-bridge:ns-array-object-at-index
display-modes i)))))
(cffi:defcallback push-event-to-stack :void ((ns-event :pointer))
- (let ((event
- (case (glop-bridge:ns-event-type ns-event)
- (:key-down
- (make-instance 'key-press-event
- :pressed t
- :keysym :foo
- :keycode 0))
- (:mouse-moved
- (destructuring-bind (x y)
- (glop-bridge:ns-event-location-in-window ns-event)
- (make-instance 'mouse-motion-event
- :x x
- :y y
- :dx (glop-bridge:ns-event-delta-x ns-event)
- :dy (glop-bridge:ns-event-delta-y ns-event))))
- ((:left-mouse-down :right-mouse-down :other-mouse-down)
- (make-instance 'button-press-event
- :button (glop-bridge:ns-event-button-number ns-event)
- :pressed t))
- ((:left-mouse-up :right-mouse-up :other-mouse-up)
- (make-instance 'button-release-event
- :button (glop-bridge:ns-event-button-number ns-event)
- :pressed nil)))))
+ (let* ((event-type (glop-bridge:ns-event-type ns-event))
+ (event
+ (case event-type
+ ((:key-down :key-up)
+ (let ((pressed (eq event-type :key-down)))
+ (make-instance (if pressed 'key-press-event 'key-release-event)
+ :pressed pressed
+ :keysym (glop-bridge:ns-event-key-code ns-event)
+ :keycode 0)))
+ (:flags-changed
+ (let* ((keysym (glop-bridge:ns-event-key-code ns-event))
+ (pressed (null (find keysym *active-modifiers*))))
+ (if pressed
+ (push keysym *active-modifiers*)
+ (setf *active-modifiers* (delete keysym *active-modifiers*)))
+ (make-instance (if pressed 'key-press-event 'key-release-event)
+ :pressed pressed
+ :keysym keysym
+ :keycode 0)))
+ (:mouse-moved
+ (destructuring-bind (x y)
+ (glop-bridge:ns-event-location-in-window ns-event)
+ (make-instance 'mouse-motion-event
+ :x x
+ :y y
+ :dx (glop-bridge:ns-event-delta-x ns-event)
+ :dy (glop-bridge:ns-event-delta-y ns-event))))
+ ((:left-mouse-down :right-mouse-down :other-mouse-down)
+ (make-instance 'button-press-event
+ :button (glop-bridge:ns-event-button-number ns-event)
+ :pressed t))
+ ((:left-mouse-up :right-mouse-up :other-mouse-up)
+ (make-instance 'button-release-event
+ :button (glop-bridge:ns-event-button-number ns-event)
+ :pressed nil)))))
(when event
- (push event *event-stack*))))
+ (push event (event-stack (glop-bridge:ns-event-window ns-event))))))
(defmethod open-window ((window osx-window) title width height
&key (x 0) (y 0) (rgba t) (double-buffer t) stereo
@@ -117,7 +137,9 @@
(setf ns-window
(glop-bridge:ns-window-alloc-init
x (- (+ (video-mode-height (current-video-mode)) height) y)
- width height))
+ width height)
+ (event-stack ns-window) '())
+ (glop-bridge:ns-window-discard-remaining-events ns-window)
(glop-bridge:ns-window-set-delegate ns-window responder)
(glop-bridge:ns-window-set-accepts-mouse-moved-events ns-window t)
(glop-bridge:ns-window-set-next-responder ns-window responder)
@@ -134,7 +156,9 @@
(glop-bridge:ns-window-order-out (ns-window window) glop-bridge:*ns-app*))
(defmethod close-window ((window osx-window))
- (glop-bridge:ns-window-close (ns-window window)))
+ (with-accessors ((ns-window ns-window)) window
+ (remhash (cffi:pointer-address (ns-window window)) *event-stacks*)
+ (glop-bridge:ns-window-close ns-window)))
(defmethod create-gl-context ((window osx-window)
&key make-current major minor forward-compat
@@ -157,19 +181,22 @@
(glop-bridge:ns-opengl-context-clear-drawable context)
(glop-bridge:ns-release context))
+(defmethod swap-buffers ((window osx-window))
+ (glop-bridge:ns-opengl-context-flush-buffer (gl-context window)))
+
(defmethod set-fullscreen ((window osx-window) &optional state)
(declare (ignorable window state)))
(defun %next-event (win &key blocking)
(loop
+ for ns-window = (ns-window win)
for event = (glop-bridge:glop-app-next-event glop-bridge:*ns-app* blocking)
- for found = (cffi:pointer-eq (ns-window win)
- (glop-bridge:ns-event-window event))
+ for found = (cffi:pointer-eq ns-window (glop-bridge:ns-event-window event))
do (progn (glop-bridge:glop-app-send-event glop-bridge:*ns-app* event)
(glop-bridge:glop-app-update-windows))
- while (and blocking (not found))
- finally (when (and *event-stack* found)
- (return (pop *event-stack*)))))
+ while (and blocking (or (not found) (null (event-stack ns-window))))
+ finally (when found
+ (return (pop (event-stack ns-window))))))
(defun gl-get-proc-address (proc-name)
(init-opengl-bundle)
View
6 src/osx/package.lisp
@@ -78,4 +78,8 @@
#:ns-event-location-in-window
#:ns-event-delta-x
#:ns-event-delta-y
- #:ns-event-button-number))
+ #:ns-event-button-number
+ #:ns-opengl-context-flush-buffer
+ #:ns-event-key-code
+ #:ns-event-modifier-flags
+ #:ns-window-discard-remaining-events))
Please sign in to comment.
Something went wrong with that request. Please try again.