Inside SWT

Saturday, March 28, 2009

Lots of good stuff at EclipseCon

There was a ton of interesting stuff this year at EclipseCon but my favourite was Kevin McGuire and Tim Wagner's key note, "Darwin Among the IDEs". We are often so mired in our day to day work that we fail to step back, evaluate where we are, where we have come from and where we might be going. Keynotes are supposed to make you think and this one took my mind off throbbing default buttons and Mac toolbars that didn't make M6.

During the "e4 in Review" talk, people were asking about backward compatibility with 3.x and Martin Oberhuber stressed that Eclipse was a platform and then innocently asked, "What would happen if Windows suddenly stopped running our old programs?"

It took a second for the room to get it and then explode.


Monday, March 02, 2009

Fighting the Cocoa default button!

On Mac Cocoa OS X 10.5, the throbbing default button animation is implemented as a separate thread that calls drawing methods directly from that thread. You would think that this wouldn't be a big deal but threads in a GUI toolkit are always a big deal.

It's an amazing GUI toolkit 101 blooper!

Who cares if the default button is painted from another thread? First off, SWT checks thread accesses to avoid operating system crashes. First attempts at a fix removed this check, causing operating system crashes.

How about hacking so that drawing requests from the throbbing thread are serviced, but don't run any SWT listeners? No good. The Mac user-interface is composited so parents of the button are asked to a paint all the way up to the shell and the button paints last on top of them.

Can't paint ... but must.

It seems that there are only two fixes:
  1. Lock and allow the throbbing thread to run as the Cocoa Gods intended
  2. Throb somehow safely in the UI-thread

Since introducing locking everywhere in SWT at Eclipse 3.5 M6 and hoping that it works at this point is insane, all we can do for now is attempt to throb safely. This fix involves remembering that you were asked to throb, telling the operating system that it has throbbed already and then later throbbing with impunity from the user-interface thread.