tonyarnold.com

Aug 10

Fixing an annoying Exposé bug with NSWindows

Picture 3 Uploaded with plasq’s Skitch!

You’ve seen it before - Exposé’s F-10 mode stops working for no apparent reason. F-9 is still good to go, but F-10 just looks busted.

Why?

Your application has set one of it’s NSWindow instances to the desktop level or lower (kCGDesktopIconWindowLevel or kCGDesktopWindowLevelKey are where it all seems to start).

Can I fix it?

Yes - fixing this problem is simple - either stop using windows at or below the desktop icon level, or add the following code to a window category or subclass in your project and execute the “clearExposeTags” method upon an active instance of your troublesome NSWindow. If you’re using CGSPrivate.h, you can just include the method without all the typedefs and externs.

typedef int CGSConnection;
typedef int CGSWindow;
typedef enum {
    CGSTagNone          = 0,        // No tags
    CGSTagExposeFade    = 0x0002,    // Fade out when Expose activates.
    CGSTagNoShadow      = 0x0008,    // No window shadow.
    CGSTagTransparent   = 0x0200,   // Transparent to mouse clicks.
    CGSTagSticky        = 0x0800,    // Appears on all workspaces.
} CGSWindowTag;
extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSClearWindowTags(const CGSConnection cid, const CGSWindow wid, CGSWindowTag *tags, int thirtyTwo);

- (OSStatus)clearExposeTags
{
    CGSConnection cid;
    CGSWindow wid;
    CGSWindowTag tags[2];
    
    wid = [self windowNumber];
    cid = _CGSDefaultConnection();
    tags[0] = 0x02;
    tags[1] = 0;
    return CGSClearWindowTags(cid, wid, tags, 32);
}

Come and join the discussion.

Jul 14

Internet Explorer does not support modern web standards

Apple - MobileMe - Migrating

Found here: http://www.apple.com/mobileme/migrating/

Finally, someone has the balls to out and out say it in a professional context. IE 7 does not support modern web standards.

Nice.

Come and join the discussion.

Jul 5

Convenience #DEFINEs

Update: Lazy programmer, indeed! After doing some research myself this afternoon (at the prompting of Karsten), I’d recommend not using anything but the ZNCGAutoRelease() method below - the others aren’t dangerous, but they’re really not necessary and just obscure your ability to properly debug your code. As for using macros, well, I guess that’s a matter of personal preference - what I’ve seen so far is that it does make debugging harder - you’re probably better off implementing proper methods for repeatable tasks. But it works if you want to use it.

When I first started working on VirtueDesktops (all those years ago), I was still new to Objective-C and very new to the concept of (mostly) manual memory management. Thankfully Thomas had the foresight to do what all good, lazy programmers should do and write himself a few small convenience methods into his codebase.

They’ve had a couple of minor additions and changes since then, but line-for-line, they’ve stood the test of time and I find them an invaluable way to reduce some of the fuss involved in manually managing your object assignments, copies and releases.

#define ZNCGAutoRelease(x) (__typeof(x))[NSMakeCollectable(x) autorelease]

#define ZNAssign(aTarget, aSource)  \
if (aTarget != nil) {               \
    [aTarget autorelease];          \
}                                   \
aTarget = [aSource retain];

#define ZNAssignCopy(aTarget, aSource)  \
if (aTarget != nil) {                   \
    [aTarget autorelease];              \
}                                       \
aTarget = [aSource copy];

#define ZNRelease(aTarget)          \
if (aTarget != nil) {               \
    id oldObject = aTarget;     \
    aTarget = nil;                  \
    [oldObject release];            \
}

I use these everywhere in my code, but just the other day I discovered the absolutely incredibly wonderful CLANG Static Analysis tools (more on this shortly!), and based on some feedback it gave around these calls (nothing bad!) it made me wonder - should I be #DEFINEing convenience methods? Is this best practice? Should I go back to doing this all by hand?

I’m hoping some of my CocoaPeers™ will be able to provide me with some advice here, but if you think the code’s good for your needs - go for your life and use it.

Oh, and happy 4th of July to our friends in the states. We’re waiting for you here on the 5th :)

Come and join the discussion.

Tumblelog

5 Jun 08

Neil’s white whale of a blog: A seriously impressive rebuild with a focus on speed and accessibility of information. Everyone can learn something from Neil.

28 Apr 08

Scalability really does have a lot to do with arse: http://teddziuba.com/2008/04/im-going-to-scale-my-foot-up-y.html

Linky Linky