Ejemplo n.º 1
0
void
R_gtk_setEventHandler()
{
#ifndef WIN32
  static InputHandler *h = NULL;
  if(!h)
    {
      if (!GDK_DISPLAY())
        error("GDK display not found - please make sure X11 is running");
      h = addInputHandler(R_InputHandlers, ConnectionNumber(GDK_DISPLAY()),
                          R_gtk_eventHandler, -1);
    }
#else
  /* Create a dummy window for receiving messages */
  LPCTSTR class = "cairoDevice";
  HINSTANCE instance = GetModuleHandle(NULL);
  WNDCLASS wndclass = { 0, DefWindowProc, 0, 0, instance, NULL, 0, 0, NULL,
                        class };
  RegisterClass(&wndclass);
  HWND win = CreateWindow(class, NULL, 0, 1, 1, 1, 1, HWND_MESSAGE,
                          NULL, instance, NULL);

  SetTimer(win, CD_TIMER_ID, CD_TIMER_DELAY, (TIMERPROC)R_gtk_timer_proc);
#endif
}
Ejemplo n.º 2
0
/**
 * XPending() actually performs a blocking read 
 *  if no events available. From Fakk2, by way of
 *  Heretic2, by way of SDL, original idea GGI project.
 * The benefit of this approach over the quite
 *  badly behaved XAutoRepeatOn/Off is that you get
 *  focus handling for free, which is a major win
 *  with debug and windowed mode. It rests on the
 *  assumption that the X server will use the
 *  same timestamp on press/release event pairs 
 *  for key repeats. 
 */
static qboolean X11_PendingInput(void) {

  assert(dpy != NULL);

  // Flush the display connection
  //  and look to see if events are queued
  XFlush( dpy );
  if ( XEventsQueued( dpy, QueuedAlready) ) {
    return qtrue;
  }

  // More drastic measures are required -- see if X is ready to talk
  {
    static struct timeval zero_time;
    int x11_fd;
    fd_set fdset;

    x11_fd = ConnectionNumber( dpy );
    FD_ZERO(&fdset);
    FD_SET(x11_fd, &fdset);
    if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) {
      return(XPending(dpy));
    }
  }
  
  // Oh well, nothing is ready ..
  return qfalse;
}
Ejemplo n.º 3
0
GSource *
_clutter_x11_event_source_new (ClutterBackendX11 *backend_x11)
{
  ClutterEventSource *event_source;
  int connection_number;
  GSource *source;
  gchar *name;

  connection_number = ConnectionNumber (backend_x11->xdpy);
  CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number);

  source = g_source_new (&event_funcs, sizeof (ClutterEventSource));
  event_source = (ClutterEventSource *) source;

  name = g_strdup_printf ("Clutter X11 Event (connection: %d)",
                          connection_number);
  g_source_set_name (source, name);
  g_free (name);

  event_source->backend = backend_x11;
  event_source->event_poll_fd.fd = connection_number;
  event_source->event_poll_fd.events = G_IO_IN;

  g_source_add_poll (source, &event_source->event_poll_fd);
  g_source_set_can_recurse (source, TRUE);

  return source;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{

  if(argc == 2)
    text = argv[1];
  else {
    printf("give an argument.\n");
    exit(1);
  }

  LOG_MESSAGE("starting xnotify\n");

  initX();

  signal(SIGHUP, sighup_handler);
  signal(SIGINT, sigint_handler);
  
  display_window();

  init_and_start_ev_loop(ConnectionNumber(X.display));

  cleanup();

  return 0;
}
Ejemplo n.º 5
0
static int spnav_fd(void)
{
    if(dpy) {
        return ConnectionNumber(dpy);
    }
    return -1;
}
Ejemplo n.º 6
0
// Ping X in @pingInterval miliseconds.
XServerPinger::XServerPinger(int pingInterval)
{
    Display *dpy;
    sigset_t sigs;

    // Open a separate connection to X.
    dpy = XOpenDisplay(NULL);
    xcb = XGetXCBConnection(dpy);
    connect(new QSocketNotifier(ConnectionNumber(dpy), QSocketNotifier::Read),
            SIGNAL(activated(int)), SLOT(xInput(int)));

    // XGetInputFocus() is our ping request.
    request = xcb_get_input_focus(xcb);
    xcb_flush(xcb);

    timer = new QTimer();
    connect(timer, SIGNAL(timeout()), SLOT(tick()));
    timer->start(pingInterval);

    // die() if we get SIGINT or SIGTERM.
    sigemptyset(&sigs);
    sigaddset(&sigs, SIGINT);
    sigaddset(&sigs, SIGTERM);
    connect(new QSocketNotifier(signalfd(-1, &sigs, 0),
                                QSocketNotifier::Read),
            SIGNAL(activated(int)), SLOT(die(int)));
    sigprocmask(SIG_BLOCK, &sigs, NULL);
}
Ejemplo n.º 7
0
/** Execute an external program. */
void RunCommand(const char *command) {

   const char *displayString;
   char *str;

   if(JUNLIKELY(!command)) {
      return;
   }

   displayString = DisplayString(display);

   if(!fork()) {
      close(ConnectionNumber(display));
      if(displayString && displayString[0]) {
         str = malloc(strlen(displayString) + 9);
         sprintf(str, "DISPLAY=%s", displayString);
         putenv(str);
      }
      setsid();
      execl(SHELL_NAME, SHELL_NAME, "-c", command, NULL);
      Warning(_("exec failed: (%s) %s"), SHELL_NAME, command);
      exit(EXIT_SUCCESS);
   }

}
Ejemplo n.º 8
0
Archivo: events.c Proyecto: jannek/glwt
int glwtEventHandle(int wait)
{
    int handled = 0;
    do
    {
        XFlush(glwt.x11.display);

        handled = xlib_handle_event();
        if(handled < 0)
            return -1;

        if(wait && handled == 0)
        {
            int fd;
            fd_set fds;

            fd = ConnectionNumber(glwt.x11.display);

            FD_ZERO(&fds);
            FD_SET(fd, &fds);

            int val = select(fd + 1, &fds, NULL, NULL, NULL);
            if(val == -1)
            {
                glwtErrorPrintf("select failed: %s", strerror(errno));
                return -1;
            } else if(val == 0)
                return 0;
        }
    } while(handled == 0 && wait);

    return 0;
}
Ejemplo n.º 9
0
FtkSource* ftk_source_x11_create(FtkDisplay* display, FtkOnEvent on_event, void* ctx)
{
	FtkSource* thiz = NULL;
	
	return_val_if_fail(display != NULL && on_event != NULL, NULL);

	thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo));

	if(thiz != NULL)
	{
		DECL_PRIV(thiz, priv);
		thiz->get_fd   = ftk_source_x11_get_fd;
		thiz->check	   = ftk_source_x11_check;
		thiz->dispatch = ftk_source_x11_dispatch;
		thiz->destroy  = ftk_source_x11_destroy;

		thiz->ref = 1;
		priv->ctx = ctx;
		priv->on_event = on_event;
		priv->display = display;
		priv->fd  = ConnectionNumber(ftk_display_x11_get_xdisplay(display));
		priv->win = (Window)ftk_display_x11_get_xwindow(display);

		XSetErrorHandler(on_x11_error);
	}

	return thiz;
}
Ejemplo n.º 10
0
static void getEvent(XEvent * ev) {
    int fd;
    fd_set readfds;
    struct timeval tv;
    
    /* Is there a message waiting? */
    if (QLength(dpy) > 0) {
        XNextEvent(dpy, ev);
        return;
    }
    
    /* Beg... */
    XFlush(dpy);
    
    /* Wait one second to see if a message arrives. */
    fd = ConnectionNumber(dpy);
    FD_ZERO(&readfds);
    FD_SET(fd, &readfds);
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    if (select(fd + 1, &readfds, 0, 0, &tv) == 1) {
        XNextEvent(dpy, ev);
        return;
    }
    
    /* No message, so we have a null event. */
    ev->type = NullEvent;
}
Ejemplo n.º 11
0
int main(){
        Display *display_name;
        int depth,screen,connection;


        /*Opening display and setting defaults*/
        display_name = XOpenDisplay(NULL);
        screen = DefaultScreen(display_name);
        depth = DefaultDepth(display_name,screen);
        connection = ConnectionNumber(display_name);


        /*Displaying the info gathered*/
        printf("The display is::%s\n",XDisplayName((char*)display_name));
        printf("Width::%d\tHeight::%d\n",
                                DisplayWidth(display_name,screen),
                                DisplayHeight(display_name,screen));
        printf("Connection number is %d\n",connection);


        if(depth == 1)
                printf("You live in prehistoric times\n");
        else
                printf("You've got a coloured monitor with depth of %d\n",
                        depth);


        /*Closing the display*/
        XCloseDisplay(display_name);
}
Ejemplo n.º 12
0
gboolean
_cogl_xlib_renderer_connect (CoglRenderer *renderer, GError **error)
{
  CoglXlibRenderer *xlib_renderer =
    _cogl_xlib_renderer_get_data (renderer);
  CoglX11Renderer *x11_renderer =
    (CoglX11Renderer *) xlib_renderer;
  int damage_error;

  if (!assert_xlib_display (renderer, error))
    return FALSE;

  if (getenv ("COGL_X11_SYNC"))
    XSynchronize (xlib_renderer->xdpy, TRUE);

  /* Check whether damage events are supported on this display */
  if (!XDamageQueryExtension (xlib_renderer->xdpy,
                              &x11_renderer->damage_base,
                              &damage_error))
    x11_renderer->damage_base = -1;

  xlib_renderer->trap_state = NULL;

  xlib_renderer->poll_fd.fd = ConnectionNumber (xlib_renderer->xdpy);
  xlib_renderer->poll_fd.events = COGL_POLL_FD_EVENT_IN;

  register_xlib_renderer (renderer);

  return TRUE;
}
Ejemplo n.º 13
0
/*ARGSUSED*/
extern void
shell(ScreenInfo * screen, int button, int x, int y) {
    char * command = NULL;
    char * sh;

    /* Get the command we're to execute. Give up if there isn't one. */
    if (button == Button1)
        command = btn1_command;
    if (button == Button2)
        command = btn2_command;
    if (command == NULL)
        return;

    sh = getenv("SHELL");
    if (sh == 0)
        sh = "/bin/sh";

    switch (fork()) {
    case 0:		/* Child. */
        close(ConnectionNumber(dpy));
        if (screen && screen->display_spec != 0)
            putenv(screen->display_spec);
        execl(sh, sh, "-c", command, NULL);
        fprintf(stderr, "%s: can't exec \"%s -c %s\"\n", argv0, sh,
                command);
        execlp("xterm", "xterm", NULL);
        exit(EXIT_FAILURE);
    case -1:	/* Error. */
        fprintf(stderr, "%s: couldn't fork\n", argv0);
        break;
    }
}
Ejemplo n.º 14
0
/*
 * Open up the mouse device.
 * Returns the fd if successful, or negative if unsuccessful.
 */
static int X11_Open(MOUSEDEVICE *pmd)
{
    if (x11_setup_display() < 0)
	return -1;
    /* return the x11 file descriptor for select */
    return ConnectionNumber(x11_dpy);  
}
Ejemplo n.º 15
0
Archivo: main.c Proyecto: xiaq/hlwm
// spawn() heavily inspired by dwm.c
int spawn(int argc, char** argv) {
    if (argc < 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    if (fork() == 0) {
        // only look in child
        if (g_display) {
            close(ConnectionNumber(g_display));
        }
        // shift all args in argv by 1 to the front
        // so that we have space for a NULL entry at the end for execvp
        char** execargs = argv_duplicate(argc, argv);
        free(execargs[0]);
        int i;
        for (i = 0; i < argc-1; i++) {
            execargs[i] = execargs[i+1];
        }
        execargs[i] = NULL;
        // do actual exec
        setsid();
        execvp(execargs[0], execargs);
        fprintf(stderr, "herbstluftwm: execvp \"%s\"", argv[1]);
        perror(" failed");
        exit(0);
    }
    return 0;
}
Ejemplo n.º 16
0
static bool MyXNextEventWithDelay(Display* dsp, XEvent* evt) {
    // Check for pending events before entering the select loop. There might
    // be events in the in-memory queue but not processed yet.
    if (XPending(dsp)) {
        XNextEvent(dsp, evt);
        return true;
    }

    SkMSec ms = gTimerDelay;
    if (ms > 0) {
        int x11_fd = ConnectionNumber(dsp);
        fd_set input_fds;
        FD_ZERO(&input_fds);
        FD_SET(x11_fd, &input_fds);

        timeval tv;
        tv.tv_sec = ms / 1000;              // seconds
        tv.tv_usec = (ms % 1000) * 1000;    // microseconds

        if (!select(x11_fd + 1, &input_fds, NULL, NULL, &tv)) {
            if (!XPending(dsp)) {
                return false;
            }
        }
    }
    XNextEvent(dsp, evt);
    return true;
}
Ejemplo n.º 17
0
int exec(char *type, char *device, char *status, char *name)
{
	pid_t pid;

	syslog(LOG_DEBUG, "Calling %s %s %s %s %s", cmd, type, device, status, name ? name : "");

	pid = fork();
	if (!pid) {
		char *args[] = {
			cmd,
			type,
			device,
			status,
			name ? name : "",
			NULL
		};

		setsid();
		if (display)
			close(ConnectionNumber(display));

		execv(args[0], args);
		syslog(LOG_ERR, "Failed calling %s: %s", cmd, strerror(errno));
		exit(0);
	}

	syslog(LOG_DEBUG, "Started %s as PID %d", cmd, pid);

	return 0;
}
Ejemplo n.º 18
0
static int get_next_x11_event(XEvent *xev)
{
    int available = 0;

    pXFlush(display);
    if (pXEventsQueued(display, QueuedAlready))
        available = 1;
    else
    {
        /* XPending() blocks if there's no data, so select() first. */
        struct timeval nowait;
        const int fd = ConnectionNumber(display);
        fd_set fdset;
        FD_ZERO(&fdset);
        FD_SET(fd, &fdset);
        memset(&nowait, '\0', sizeof (nowait));
        if (select(fd+1, &fdset, NULL, NULL, &nowait) == 1)
            available = pXPending(display);
    } /* else */

    if (available)
    {
        memset(xev, '\0', sizeof (*xev));
        pXNextEvent(display, xev);
        return 1;
    } /* if */

    return 0;
} /* get_next_x11_event */
Ejemplo n.º 19
0
int x11_shadow_subsystem_base_init(x11ShadowSubsystem* subsystem)
{
	if (subsystem->display)
		return 1; /* initialize once */

	if (!getenv("DISPLAY"))
		setenv("DISPLAY", ":0", 1);

	if (!XInitThreads())
		return -1;

	subsystem->display = XOpenDisplay(NULL);

	if (!subsystem->display)
	{
		WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL));
		return -1;
	}

	subsystem->xfds = ConnectionNumber(subsystem->display);
	subsystem->number = DefaultScreen(subsystem->display);
	subsystem->screen = ScreenOfDisplay(subsystem->display, subsystem->number);
	subsystem->depth = DefaultDepthOfScreen(subsystem->screen);
	subsystem->width = WidthOfScreen(subsystem->screen);
	subsystem->height = HeightOfScreen(subsystem->screen);
	subsystem->root_window = RootWindow(subsystem->display, subsystem->number);

	return 1;
}
Ejemplo n.º 20
0
void
_clutter_backend_x11_events_init (ClutterBackend *backend)
{
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
  GSource *source;
  ClutterEventSource *event_source;
  int connection_number;
  gchar *name;

  connection_number = ConnectionNumber (backend_x11->xdpy);
  CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number);

  source = backend_x11->event_source = clutter_event_source_new (backend);
  event_source = (ClutterEventSource *) source;
  g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS);

  name = g_strdup_printf ("Clutter X11 Event (connection: %d)",
                          connection_number);
  g_source_set_name (source, name);
  g_free (name);

  event_source->event_poll_fd.fd = connection_number;
  event_source->event_poll_fd.events = G_IO_IN;

  event_sources = g_list_prepend (event_sources, event_source);

  g_source_add_poll (source, &event_source->event_poll_fd);
  g_source_set_can_recurse (source, TRUE);
  g_source_attach (source, NULL);
}
Ejemplo n.º 21
0
//----------------------------------------------------------------------------------------------------------------------
// X11_Pending - from SDL
//----------------------------------------------------------------------------------------------------------------------
static int X11_Pending(Display *display)
{
   VOGL_FUNC_TRACER

   /* Flush the display connection and look to see if events are queued */
   XFlush(display);
   if (XEventsQueued(display, QueuedAlready))
   {
      return(1);
   }

   /* More drastic measures are required -- see if X is ready to talk */
   {
      static struct timeval zero_time;	/* static == 0 */
      int x11_fd;
      fd_set fdset;

      x11_fd = ConnectionNumber(display);
      FD_ZERO(&fdset);
      FD_SET(x11_fd, &fdset);
      if (select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1)
      {
         return(XPending(display));
      }
   }

   /* Oh well, nothing is ready .. */
   return(0);
}
Ejemplo n.º 22
0
bool xorg::testing::XServer::WaitForEvent(::Display *display, time_t timeout)
{
    fd_set fds;
    FD_ZERO(&fds);

    int display_fd = ConnectionNumber(display);

    XSync(display, False);

    if (XPending(display))
        return true;
    else {
        FD_SET(display_fd, &fds);

        struct timeval timeval = {
            static_cast<time_t>(timeout / 1000),
            static_cast<time_t>(timeout % 1000) * 1000,
        };

        int ret;
        if (timeout)
            ret = select(display_fd + 1, &fds, NULL, NULL, &timeval);
        else
            ret = select(display_fd + 1, &fds, NULL, NULL, NULL);

        if (ret < 0)
            throw std::runtime_error("Failed to select on X fd");

        if (ret == 0)
            return false;

        return XPending(display);
    }
}
Ejemplo n.º 23
0
void Delay (int DTime)
{
   fd_set f;
   struct timeval timeout;
   int cn;
   XEvent xe;

   if (key>=0) return;
   if (XCheckMaskEvent(dpy,KeyPressMask,&xe)) {
      process_event(&xe);
      if (key>=0) return;
   }

   if (drawcounter>0) {
      XClearWindow(dpy,w);
      XFlush(dpy);
      drawcounter=0;
   }

   timeout.tv_sec=DTime/1000;
   timeout.tv_usec=1000*(DTime%1000);
   FD_ZERO(&f);
   cn=ConnectionNumber(dpy);
   FD_SET(cn, &f);
   select(cn+1, &f, 0, 0, &timeout);
   
   /* note: the above implements a delay that is interrupted as
      soon as an X event occurs, a keypress/release in all practical
      cases. Interrupting the waiting upon keypress/release gives
      much smoother behaviour with puff.
   */
}
Ejemplo n.º 24
0
extern "C" void signalHandler(int signal)
{
#ifdef Q_WS_X11
    // Kill window since it's frozen anyway.
    if (QX11Info::display())
        close(ConnectionNumber(QX11Info::display()));
#endif
    pid_t pid = fork();
    switch (pid) {
    case -1: // error
        break;
    case 0: // child
        if (disableRestartOptionC) {
            execl(crashHandlerPathC, crashHandlerPathC, strsignal(signal), appNameC,
                  disableRestartOptionC, (char *) 0);
        } else {
            execl(crashHandlerPathC, crashHandlerPathC, strsignal(signal), appNameC, (char *) 0);
        }
        _exit(EXIT_FAILURE);
    default: // parent
        prctl(PR_SET_PTRACER, pid, 0, 0, 0);
        waitpid(pid, 0, 0);
        _exit(EXIT_FAILURE);
        break;
    }
}
Ejemplo n.º 25
0
void spawn(Display * disp, const char** com)
{
    if (fork()) return;
    if (disp) close(ConnectionNumber(disp));
    setsid();
    execvp((char*)com[0], (char**)com);
}
Ejemplo n.º 26
0
/*
 * Enter a loop processing X events & polling chars until we see a result
 */
static void serverWait(VimRemotingClient *client, Window w, VimRemotingClient_EndCond endCond, void *endData, int seconds)
{
    time_t            start;
    time_t            now;
    time_t            lastChk = 0;
    XEvent            event;
    XPropertyEvent *e = (XPropertyEvent *)&event;
    int fd = ConnectionNumber(client->dpy);

    time(&start);
    while (!endCond(endData)) {
        time(&now);
        /* Just look out for the answer without calling back into Vim */
        pollFor(fd, ((start + seconds) - now) * 1000);
        if (!isWindowValid(client, w))
            break;
        while (XEventsQueued(client->dpy, QueuedAfterReading) > 0) {
            XNextEvent(client->dpy, &event);
            if (event.type == PropertyNotify &&
                    e->window == client->window) {
                serverEventProc(client, &event);
            }
        }
    }
}
Ejemplo n.º 27
0
LOCAL_SYMBOL MetaEventQueue*
meta_event_queue_new (Display *display, MetaEventQueueFunc func, gpointer data)
{
  GSource *source;
  MetaEventQueue *eq;

  source = g_source_new (&eq_funcs, sizeof (MetaEventQueue));
  eq = (MetaEventQueue*) source;
  
  eq->connection_fd = ConnectionNumber (display);
  eq->poll_fd.fd = eq->connection_fd;
  eq->poll_fd.events = G_IO_IN;

  eq->events = g_queue_new ();

  eq->display = display;
  
  g_source_set_priority (source, G_PRIORITY_DEFAULT);
  g_source_add_poll (source, &eq->poll_fd);
  g_source_set_can_recurse (source, TRUE);

  g_source_set_callback (source, (GSourceFunc) func, data, NULL);
  
  g_source_attach (source, NULL);
  g_source_unref (source);

  return eq;
}
	bool DisplayMessageQueue_X11::process(int timeout_ms)
	{
		auto end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout_ms);

		while (true)
		{
			process_message();
			process_queued_events(); // What is this? If its related to Event then it should be removed
			process_window_sockets(); // Same for this thing

			if (end_time <= std::chrono::steady_clock::now())
				break;

			int x11_handle = ConnectionNumber(display);

			struct timeval tv;
			if (timeout_ms > 0)
			{
				tv.tv_sec = timeout_ms / 1000;
				tv.tv_usec = (timeout_ms % 1000) * 1000;
			}
			else if (timeout_ms == 0)
			{
				tv.tv_sec = 0;
				tv.tv_usec = 0;
			}
			else
			{
				tv.tv_sec = 0x7FFFFFFF;
				tv.tv_usec = 0;
			}

			fd_set rfds;
			FD_ZERO(&rfds);

			FD_SET(x11_handle, &rfds);
			FD_SET(async_work_event.read_fd(), &rfds);
			FD_SET(exit_event.read_fd(), &rfds);

			int result = select(std::max(std::max(async_work_event.read_fd(), x11_handle), exit_event.read_fd()) + 1, &rfds, nullptr, nullptr, &tv);
			if (result > 0)
			{
				if (FD_ISSET(async_work_event.read_fd(), &rfds))
				{
					async_work_event.reset();
					process_async_work();
				}
				if (FD_ISSET(exit_event.read_fd(), &rfds))
				{
					exit_event.reset();
					return false;
				}
			}
			else
			{
				break;
			}
		}
		return true;
	}
Ejemplo n.º 29
0
void
spawn(ScreenInfo *s, void (*fn)())
{
    /*
     * ugly dance to cause sweeping for terminals.
     * the very next window created will require sweeping.
     * hope it's created by the program we're about to
     * exec!
     */
    isNew = 1;
    /*
     * ugly dance to avoid leaving zombies. Could use SIGCHLD,
     * but it's not very portable.
     */
    if(fork() == 0) {
        if(fork() == 0) {
            close(ConnectionNumber(dpy));
            if(s->display[0] != '\0')
                putenv(s->display);
            signal(SIGINT, SIG_DFL);
            signal(SIGTERM, SIG_DFL);
            signal(SIGHUP, SIG_DFL);
            fn();
            exit(1);
        }
        exit(0);
    }
    wait((int *) 0);
}
Ejemplo n.º 30
0
    void Application::run(int argc, char *argv[])
    {
      DOUT("Application::run()");

      ApplicationEventPtr applicationEvent = ApplicationEvent::create(ApplicationEvent::RUN());
      eventDispatcher->dispatchEvent(applicationEvent);

      XEvent event;      
      int fd = ConnectionNumber(hiddenMembers->display);

      while(running) {

        XFlush(hiddenMembers->display);

        struct timeval tv;
        fd_set rfds;
        FD_ZERO(&rfds);
        FD_SET(fd,&rfds);
        memset(&tv,0,sizeof(tv));
        tv.tv_usec = 100000; /* delay in microseconds = 100 milliseconds */

        if (select(fd+1,&rfds,0,0,&tv) > 0) {

          XSync(hiddenMembers->display, False);        

          while(XEventsQueued(hiddenMembers->display, QueuedAlready) > 0) {

            XNextEvent(hiddenMembers->display, &event);

            switch (event.type) {
              
              case ClientMessage:
                if (event.xclient.data.l[0] == hiddenMembers->WM_WAKEUP) {
                  DOUT("wakeup!");
                  break;
                }
                
              default:
                if (event.xclient.window) {
                  linux_::WindowHandler* windowHandler = NULL;
                  if (xWindows.find(event.xclient.window) != xWindows.end()) {
                    windowHandler = xWindows[event.xclient.window];
                  }
                  
                  if (windowHandler != NULL) {
                    windowHandler->handleEvent(event);
                  }
                }
                break;
                
            }

            XFlush(hiddenMembers->display);

          }
        }
        eventDispatcher->processEvents();
      }
    }