eoin is awesome http://blog.eoinisawesome.com Most recent posts at eoin is awesome posterous.com Wed, 19 Jan 2011 21:56:12 -0800 NeverSleep Again http://blog.eoinisawesome.com/neversleep-again http://blog.eoinisawesome.com/neversleep-again

Recently I’ve been continuing my adventures in the wonderful land of Cocoa development.

Tonights adventure:

NeverSleep

The other night I was sitting on The Couch (it’s such a big piece of furniture that it has to be a proper noun), trying to decide whether I should watch Conan or read some of this awesome book. But wait! There was a horrible catch! I was also waiting for someone near and dear to IM me. But if I set my laptop on the table to watch the hilarious stylings of the adorable red headed giant the display would go to sleep and I would never see those important messages.

Now I could do what a normal person would do and go into System Preferences, tell it not to sleep the display, and then just remember to turn display sleeping back lest I forget.

But I am a Nerd so of course the easy course was out. I was going to take the “easy” course by solving this general problem. So off goes Conan, down goes my book and I start on NeverSleep.

The Goal

Here were the goals I set out for the app:

  • A small, unobtrusive status bar icon
  • A simple menu to toggle Display Sleeping
  • Not letting the display sleeping be disabled if we’re running on battery power
  • “Remember” what state we should be in

The Code

The code is currently living here on github : https://github.com/ecoffey/NeverSleep.

Cocoa makes this pretty easy actually.

We use the IO Power Management API to set Assertions on the display. We set two. One to control Display Sleep, and another to control Idle Sleep.

We then use the IO Power Sources API to tie into power changes. I liked this code because it’s all event driven:

CFRunLoopSourceRef loopSource = IOPSNotificationCreateRunLoopSource(updatePowerStatus, delegate);

if (loopSource)
{
    CFRunLoopAddSource(CFRunLoopGetCurrent(), loopSource, kCFRunLoopDefaultMode);
}

That’s all the code you need to register power status change notifications. The updatePowerStatus function is a little wonky since it mainly deals with Core Foundation classes, which includes some Refs and Releases.

The code layout is pretty simple. MenuletController handles the awakeFromNib: event, and coordinates the other two objects PowerMonitor and DisplayControl. Guessing what they do is left as an exercise for the reader.

DisplayControl handles our “remember” magic. Basically we track if we should disable display sleep, and if we can disable display sleep.

The first one is controlled by the status bar menu. The second variable is controlled by PowerMonitor, proxied through MenuletController.

Future features

For some reason disable the menu items still lets you click and interact with them. Would like to figure that out, so when you can’t toggle the display sleeping, the UI won’t just let you uselessly click on things.

Also would be really nice to have some way to force display sleeping off while on battery. And some growl notification to let you know when the state switches through no direct NeverSleep UI interaction.

Also I’d like the status bar icon to change depending on what state we’re in, but I have fail worthy graphic skills. Although the github repo does contain the pings I’d like to combine to represent the two different states. Hint hint.

Ok so maybe I’ll sleep again

All in all, this was a quick little app to get a first draft of. The rest is polish. Cocoa makes it pretty easy to put these kind of things together.

If you want to actually use this, check it out from github and run it from there. I’ll post an actual app bundle at some point.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1908795/eoin_gravatar.png http://posterous.com/users/4SOiCMLus8Zr Eoin Coffey eoinisawesome Eoin Coffey
Wed, 29 Dec 2010 11:11:35 -0800 Exploring Nested Views In Cocoa Part 1 http://blog.eoinisawesome.com/exploring-nested-views-in-cocoa-part-1 http://blog.eoinisawesome.com/exploring-nested-views-in-cocoa-part-1

I've been playing with Cocoa development, and I've been having a hard time figuring out the One True Way to handle Nested Views and Controllers and cleanly compose them all together.

The below image is what we're attempting to create.

Nested View is defined in a separate xib file, and backed by NVNestedViewOneView : NSView.

The xib file also includes a reference to NVNestedViewOneController with the controller referencing the view and vice versa.

Objectlayout

You'd think that this would all work, but sadly our nested view doesn't actually *render*.

Stay tuned as you get to follow along with my idiocy!  Woo!

You can get the code at : https://github.com/ecoffey/NestedView

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1908795/eoin_gravatar.png http://posterous.com/users/4SOiCMLus8Zr Eoin Coffey eoinisawesome Eoin Coffey
Wed, 01 Dec 2010 18:20:00 -0800 How I Think http://blog.eoinisawesome.com/how-i-think http://blog.eoinisawesome.com/how-i-think

I plan on ranting here a bit more, so I figure I might try and lay out how I think about software design and development.

A good friend of mine introduced me to these terms: Mechanics vs Intent.

Mechanics are the how of your software.  It's the OS, Language, Framework, Patterns, etc that you use to write your code.  You have to have mechanics, since at some point you have to give the computer something to execute.

Intent is the why of your software.  Intent is why your particular piece of software exists.  The itch it scratches if you will.  To me this is also where the Domain concerns live.

So really I like to think as Software Development as a constant struggle between Mechanics and Intent.  The Intent is the reason for being, but you need the Mechanics to get your work done, and sometimes one can muddle the other: "How do I even express this in code!" vs "How confusing could you have made division!"

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1908795/eoin_gravatar.png http://posterous.com/users/4SOiCMLus8Zr Eoin Coffey eoinisawesome Eoin Coffey
Wed, 13 Oct 2010 14:26:00 -0700 Objectivity can be so subjective http://blog.eoinisawesome.com/objectivity-can-be-so-subjective http://blog.eoinisawesome.com/objectivity-can-be-so-subjective

I went to the optometrist today, since lately my eyes have been bugging me, and as a nerd I am constantly craving some form of objectivity in whatever "problem space" I currently sit.

At some point the doctor looks up from her notepad and asks:

"Is your night vision different?"

I somewhat froze, since I have no good answer for that.  What does that even mean?  I always assumed I was seeing the night, but how do I know that even though I think I'm seeing just Night, I'm actually seeing the Night, but *wrong*.

This frustrates me, because I'm used to solving problems in computer land.  I can reset, pause, adjust, and dissect a problem.  If I had it my way I would be able to start flipping out my eyes for someone else's carefully taking notes, reseting day / night cycles so I could quickly test night vision, or distance, or different computer screens.

Solving problems like this is what makes programming so amazing, and realizing you are able to is a Transformative moment in your career.

But I can't.  I'm stuck with this murky subjectivity that I have to pretend is objectivity, and limp to a solution.

How do other people deal with this?

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1908795/eoin_gravatar.png http://posterous.com/users/4SOiCMLus8Zr Eoin Coffey eoinisawesome Eoin Coffey