views:

19

answers:

1

Hi everybody, I'm trying to register for CGScreenRefreshCallback and CGScreenUpdateMoveCallback ( here's what apple's saying about http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/doc/uid/TP30001070-CH1g-F16970 ) using C++ only.

I wrote this simple tester for the refresh callback in order to retrieve the changing rectangles:

#include "ApplicationServices/ApplicationServices.h"
#include <iostream>

using namespace std;

/////////////HEADER
static void DHRefreshCallback (CGRectCount count,const CGRect * rectArray,void * userParameter);
///////////////////

int main (int argc, char * const argv[]) {

CGRegisterScreenRefreshCallback(DHRefreshCallback, NULL);

while (true) {
    // just hanging
}
return 0;
}


static void DHRefreshCallback (CGRectCount count,const CGRect * rectArray,void * userParameter){
cout << "something changed" << endl;
return;
}

...but didn't work.

I know I need a connection with WindowServer (Quartz Compositor \ Quartz Extreme \ Quartz Extreme 2D...still can't figure out the difference) and a running thread in order to get these callbacks, but I really don't know how to do this in C++ only (no Objective-C at all).

any direction?

thx in advance, pigiuz

+1  A: 

It's not about using/not using Objective-C. It's about the event loop in OS X apps in general, which is done by CFRunloop, which is a C API. See Run Loop management and CFRunLoop reference. You also need a connection to the window server, which can be established by calling

Instead of

while (true) {
    // just hanging
}

just do

extern "C" void NSApplicationLoad(void);
NSApplicationLoad();  // establish a connection to the window server. In <Cocoa/Cocoa.h>
CFRunLoopRun();       // run the event loop

Don't forget to link against Cocoa.framework; just add -framework Cocoa in the command line of the compiler. You can #import <Cocoa/Cocoa.h> but then you need to use Objective-C++ because of the Objective-C classes declared in it.

You could use

 RunApplicationEventLoop(); //establish a connection to the window server 
                            //and runs the event loop. In <Carbon/Carbon.h>

in an 32 bit app, instead of NSApplicationLoad + CFRunLoopRun, but it's not available in an 64 bit app.

Yuji
wonderful! you opened my eyes! :)thank you!do you know any resource (or book) i can read in order to get this kind of knowledge? i mean, something like "c++ for mac" (possibly 64 bits)...
pigiuz
You just need to read Apple's own document one by one. As for "C++ for mac," I just wrote one here for another SO question: http://stackoverflow.com/questions/3203763/is-there-a-library-framework-that-allows-to-program-a-carbon-application-using/3206761#3206761
Yuji