state = 
{
  ...
};

>> ()
{
  msg_queue = create_queue ();

  layer = create_layer (&mp),
  {
    mp = {
           layer_proc : vio_msg_proc,
           placement : PRIMARY_LAYER,
           wm_mode : ALLOW_READ_WRITE
         }
  };

  msg_in (msg_queue, (pstruct -w reply, p_msg message) { 
                                                         dispatch (reply, &state, message);
                                                       }),
  {
    state _ = .;
  };
}
/
{
  free (&layer, &msg_queue);
}

vio_msg_proc (pstruct -w reply, p_state -&w _, p_msg _)
{
  mouse_button_down ()
  {
    ...
  }

  kbd_input ()
  {
    ...
  }

  paint ()
  {
    ...
  }
  /
  {
    free (&ps);
  }

  select (msg->message)
  {
    case WM_BUTTON_1_DOWN:
      mouse_button_down ();
    return;

    case WM_CHAR:
      kbd_input ();
    return;

    case WM_PAINT:
      paint ();
    return;
  }
  else
  {
    ;
  }
}