I'm doing this in an X11 application in order to send a timer event every 100 milliseconds to the main event queue.

class Application
{
  shared private bool s_tick;

void clock_task (shared X11.Display* disp, X11.Atom atom, X11.Window win)
  {
    for (;;)
    {
      try
      {
        receiveTimeout (100.msecs);

        if (disp && atomicLoad(s_tick))
        {
// disable ticking until it is allowed again at the end of the event loop
          atomicStore(s_tick, false);

          X11.XClientMessageEvent event;
          event.type         = X11.ClientMessage;
          event.window       = win;
          event.message_type = atom;
          event.format       = 32;
          event.data.l       = [0, 0, 0, 0, 0];

X11.XSendEvent (cast (X11.Display*) disp, win, 0, 0, cast(X11.XEvent*)&event);
          X11.XFlush (cast (X11.Display*) disp);
        }
      }
      catch (Throwable)
      {
        return;
      }
    }
  }

  this ()
  {
...
spawn (&clock_task, cast(shared)x11Display, x11SigClockAtom, _x11_proxyWindow);
  }

  run ()
  {
    while (true)
    {
...
// event processing starts here: read in X11 event and convert it to a wit Event
      X11.XEvent x11_event;
      X11.XNextEvent (_x11.display, &x11_event);
...
      atomicStore(s_tick, true);
    }
  }
}

Reply via email to