I develop Qt application with C++ code without mixing with Objective-C. Need to implement native window moving (to resolve flickering problems). Now I can move window with
struct NSPoint
{
double x;
double y;
} point;
point.x = (pos() + (mouseEvent->pos() - m_prevMousePos)).x();
point.y = (pos() + (mouseEvent->pos() - m_prevMousePos)).y();
id nsView = reinterpret_cast<id>(winId());
objc_msgSend(objc_msgSend((id)nsView, sel_registerName("window")), sel_registerName("setFrameTopLeftPoint:"), point);
This code works and allow me to avoid flickering problems. But Mac OS X and Qt coordinate systems are differnt. I want to get coordinate of top left window corner. For this I tried to use this code:
struct NSPoint
{
double x;
double y;
};
struct NSSize
{
double width;
double height;
};
struct NSRect
{
NSPoint origin;
NSSize size;
} rect;
id nsView = reinterpret_cast<id>(winId());
rect = *(NSRect*)objc_msgSend_stret)(objc_msgSend((id)nsView, sel_registerName("window")), sel_registerName("frame"));
But it leads to crush. Comments in objc/message.h
say:
/* Struct-returning Messaging Primitives
*
* Use these functions to call methods that return structs on the stack.
* On some architectures, some structures are returned in registers.
* Consult your local function call ABI documentation for details.
*
* These functions must be cast to an appropriate function pointer type
* before being called.
*/
So here I stucked. My final question how to get NSWindow::frame property with Pure C?