Thursday, August 24, 2006

Notes on porting Vim Mac to Carbon Events

Vim for Mac still uses the seriously deprecated WaitNextEvent() api. Using Carbon Events (especially the standard event handlers) should make the code shorter.

Before porting to Carbon events, gui_mac.c is about 6500 lines (with gui tab pages).

Plan: Replace WaintForNextEvent() with RunApplicationEventLoop() (and use CreateNewWindow() instead of NewCWindow() in gui_mch_init()), use standard event handler. Check what codes needs to be changed. We need callbacks for
  • Keyboard events (seems to be already in place)
  • Mouse events
  • Menu events
  • Control events
(wow. what a superfluous list.)

Stuff that's influenced by a change to Carbon Events and the standard event handler:
  • proxy icon handling is done automatically (as soon as proxy icons are supported)
  • toolbar config stuff is done automatically (as soon as there's a toolbar)
  • window movement, app activation, menu handling...
  • window resizing becomes life (can prolly be prevented if this turns out to be annoying, though)
  • drawing is automatically double buffered (it's prolly buffered atm as well, so this is no real change) -- think about drawing code
  • gui_mch_wait_for_chars() (or whatever it's called) has to work with the event stuff -- see gui_win48 how they do it
  • Control handling code should get easier (at least once controls are used in the osx way)

Important functions to convert:

  • gui_mch_wait_for_chars() (calls WaitNextEvent())
  • gui_mac_handle_event()

Stuff to take care off:

  • redraw only up to N (˜ 25) times per second (measure fps? prolly overkill)
  • scrolling must not be allowed under certain cirumstances (allow_scrollbar)

General Notes
  • Standard App Handler is called automatically by RunApplicationEventLoop(), Standard Window Handler has to be specified with the kWindowStandardHandlerAttribute (in CreateNewWindow() or ChangeWindowAttributes(), preferably the first)


Post a Comment

<< Home