[Openmcl-devel] NSApplication run method does not seem to work quite right

Gary Byers gb at clozure.com
Sun Mar 9 00:21:31 UTC 2014


In order to communicate with the window system, Cocoa GUI code needs to run
on the initial thread.

You seem to think that this is only true of some code (the event loop) and
not other code (the code that creaetes a window).  You'll often find that
code that tries to do GUI things on some other thread sort-of-kind-of works
(it's as if the thread that created the window couldn't properly communicate
with the window system.)


Something like:

(process-interrupt ccl::*initial-process* (lambda ()
                                             (make-window)
                                             (start-run-loop)))


is a little closer to being "equivalent" to the ObjC code, unless you
change the ObjC code to create the window in a different thread ...


On Sat, 8 Mar 2014, Willem Rein Oudshoorn wrote:

> I am trying to use the objc bridge to create a GUI using the cocoa
> framework.  However the way I try it does not seem to work quite right.
>
> In Objective C I can do the following:
>
>
> #import <Cocoa/Cocoa.h>
>
> int
> main (int argn, char *argv[])
> {
>  NSApplication* app = [NSApplication sharedApplication];
>  NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect (100, 100, 300, 300)
> 						 styleMask: NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask
> 						   backing: NSBackingStoreBuffered
> 						     defer: YES];
>  [window makeKeyAndOrderFront:nil];
>  [app run];
>  return 1;
> }
>
>
> When running this I get a resiable window which does work, I can resize
> it etc.
>
>
> If I do the equivalent in CCL with the objc bridge:
>
> (require :objc-support)
>
> (defparameter *app* nil)
> (defun make-app ()
>  (setf *app*
> 	(#/sharedApplication ns:ns-application)))
>
> (defparameter *window* nil)
> (defun make-window ()
>  (setf *window*
> 	(ns:with-ns-rect (frame 0 600 300 300)
> 	  (make-instance 'ns:ns-window
> 			 :with-content-rect frame
> 			 :style-mask  (logior #$NSTitledWindowMask
> 					      #$NSClosableWindowMask
> 					      #$NSMiniaturizableWindowMask
> 					      #$NSResizableWindowMask)
> 			 :backing #$NSBackingStoreBuffered
> 			 :defer t))))
>
>
> (defun start-run-loop ()
>  (#/run *app*))
>
>
> (defun test ()
>  (make-app)
>  (make-window)
>  (#/makeKeyAndOrderFront: *window* nil)
>  (process-interrupt ccl::*initial-process* #'start-run-loop))
>
> (test)
>
>
> It seems to work at first glance, however, I cannot resize the window
> and I get the beach ball.
> So it seems that something goes wrong with handling events.   But I
> cannot figure out what.
>
> If someone has any hints where I can look, that is appreciated.
>
> Note, I can get it to work by using (require :COCOA) and use the
> infrastructure setup by the IDE.  (Not suprisingly :-)).
>
> However I slightly prefer playing with cocoa without the CCL IDE.
>
> Wim Oudshoorn.
>
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list