If you are asking for a way to force a window to redraw itself using a lower level API than Cocoa, then as far as I know, this is not possible. The window is redrawn when the contentRect: content method is called. It goes into CGContextRef to the window, which then uses the method to redraw the window. CoreGraphics is not responsible for redrawing the window. Cocoa uses CoreGraphics to redraw windows.
You can get the window graphic context outside of drawRect: and then draw it whenever you want (see, for example, here ), but it looks like what you really want to do is intercept the results of the usual window drawing procedure and do some of your own things from above. Perhaps you could do this by switching the presentation class of the window contents and overriding drawRect. The helper function for processing the injection will look something like this:
typedef void (^InjectedBlock)(CGContextRef, CGRect); void InjectIntoView(NSView* view, InjectedBlock aBlock) { Class viewClass = [view class]; InjectedBlock injectedBlock = [aBlock copy]; void(^drawRect)(id, SEL, NSRect) = ^(id self, SEL _cmd, NSRect rect) { struct objc_super superId = { self, viewClass }; objc_msgSendSuper(superId, @selector(drawRect:), rect); injectedBlock([[NSGraphicsContext currentContext] graphicsPort], CGRectFromNSRect(rect)); }; NSString* subclassName = [NSString stringWithFormat:"%s_injected", class_getName(viewClass)] Class subclass objc_allocateClassPair(viewClass, [subclassName UTF8String], 0); objc_registerClassPair(subclass); Method overriddenMethod = class_getInstanceMethod([NSView class], @selector(drawRect:)); IMP imp = imp_implementationWithBlock(drawRect); class_addMethod(subclass, @selector(drawRect:), imp, method_getTypeEncoding(overriddenMethod)) }
Edit:
Ahhh, you are interested in the whole window. Frame, etc. They are also instances of NSView, but they are private subclasses of NSView that you do not have direct access to. You can force them to redraw by calling display
in the window, but this will most likely overwrite everything you did with the window, since it will use the existing procedures for drawing these classes.
So, you can also consider swizzling the drawRect method: these views (calling [[NSGraphicsContext currentContext] graphicsPort] in drawRect: will give you a CGContextRef that you can use with the Quartz API). You can get frame views by calling superview
on the window's content view.
Please note that the location of window frame views is undocumented and can be changed using system updates.
It seems like an interesting project!