Example #1
0
static void *Run (void *data)
{
    services_discovery_t *sd = data;
    services_discovery_sys_t *p_sys = sd->p_sys;
    xcb_connection_t *conn = p_sys->conn;
    int fd = xcb_get_file_descriptor (conn);
    if (fd == -1)
        return NULL;

    while (!xcb_connection_has_error (conn))
    {
        xcb_generic_event_t *ev;
        struct pollfd ufd = { .fd = fd, .events = POLLIN, };

        poll (&ufd, 1, -1);

        int canc = vlc_savecancel ();
        while ((ev = xcb_poll_for_event (conn)) != NULL)
        {
            if ((ev->response_type & 0x7F) == XCB_PROPERTY_NOTIFY)
            {
                 const xcb_property_notify_event_t *pn =
                     (xcb_property_notify_event_t *)ev;
                 if (pn->atom == p_sys->net_client_list)
                     UpdateApps (sd);
            }
            free (ev);
        }
        vlc_restorecancel (canc);
    }
    return NULL;
}
Example #2
0
void v_window::_updateOSWindow() {
    xcb_generic_event_t* event = xcb_poll_for_event(_xcb_connection);   //非阻塞的方式接收事件 xcb_wait_for_event为阻塞式
    if(!event){
        return;
    }
    switch(event->response_type & ~0x80){
        case XCB_CLIENT_MESSAGE:
            if( ( (xcb_client_message_event_t*)event )->data.data32[ 0 ] == _xcb_atom_window_reply->atom ) {
                close();
            }
            break;
        case XCB_CONFIGURE_NOTIFY:
            if(xcb_configure_notify_event_t* cfg = (xcb_configure_notify_event_t*)event){
                if(_width != cfg->width || _height != cfg->height) {
                    _width = cfg->width;
                    _height = cfg->height;
                    vkDeviceWaitIdle(_renderer->getDevice());
                    _initSwapchain();
                    _initSwapchainImageViews();
                    if (onResize != nullptr) {
                        onResize(_width, _height);
                    }
                }
            }
            break;
        default:
            break;
    }

    free(event);
}
Example #3
0
/** Background thread for X11 events handling */
static void *Thread (void *data)
{
    vout_window_t *wnd = data;
    vout_window_sys_t *p_sys = wnd->sys;
    xcb_connection_t *conn = p_sys->conn;

    int fd = xcb_get_file_descriptor (conn);
    if (fd == -1)
        return NULL;

    for (;;)
    {
        xcb_generic_event_t *ev;
        struct pollfd ufd = { .fd = fd, .events = POLLIN, };

        poll (&ufd, 1, -1);

        int canc = vlc_savecancel ();
        while ((ev = xcb_poll_for_event (conn)) != NULL)
        {
            if (ProcessKeyEvent (p_sys->keys, ev) == 0)
                continue;
            msg_Dbg (wnd, "unhandled event: %"PRIu8, ev->response_type);
            free (ev);
        }
        vlc_restorecancel (canc);

        if (xcb_connection_has_error (conn))
        {
            msg_Err (wnd, "X server failure");
            break;
        }
    }
    return NULL;
}
Example #4
0
File: leaf.c Project: shaoner/leaf
static leaf_error_t leaf_run()
{
	xcb_generic_event_t *event = NULL;
	int etype;
	leaf_error_t status = ERR_NONE;

	/* Start main loop */
	gconf.running = true;
	do {
		event = xcb_poll_for_event(gconf.conn);
		if (!event) {
            if (xcb_connection_has_error(gconf.conn))
	            return ERR_CONN;
			continue;
		}
		etype = XCB_EVENT_RESPONSE_TYPE(event);

		/* Only for debug prupose */
		print_event(etype);

		/* Execute specific event handler */
		if (geventhandlers[etype])
			if (geventhandlers[etype](event) != EVENT_ERR_NONE)
				status = ERR_EVENT;
		free(event);
	} while (gconf.running && status == ERR_NONE);

	return status;
}
static cairo_status_t
_cairo_boilerplate_xcb_finish_surface (cairo_surface_t		*surface)
{
    xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface,
							     &xcb_closure_key);
    xcb_generic_event_t *ev;

    cairo_surface_flush (surface);

    if (cairo_surface_status (surface))
	return cairo_surface_status (surface);

    while ((ev = xcb_poll_for_event (xtc->c)) != NULL) {
	if (ev->response_type == 0 /* trust me! */) {
	    xcb_generic_error_t *error = (xcb_generic_error_t *) ev;

	    fprintf (stderr, "Detected error during xcb run: %d major=%d, minor=%d\n",
		     error->error_code, error->major_code, error->minor_code);

	    return CAIRO_STATUS_WRITE_ERROR;
	}
    }

    if (xcb_connection_has_error (xtc->c))
	return CAIRO_STATUS_WRITE_ERROR;

    return CAIRO_STATUS_SUCCESS;
}
gboolean
gst_gl_display_x11_handle_event (GstGLDisplayX11 * display_x11)
{
  xcb_connection_t *connection = display_x11->xcb_connection;
  xcb_generic_event_t *event;
  gboolean ret = TRUE;

  while ((event = xcb_poll_for_event (connection))) {
    GstGLWindowX11 *window_x11 = _window_from_event (display_x11, event);

    GST_TRACE_OBJECT (display_x11, "got event %p to window %" GST_PTR_FORMAT,
        event, window_x11);

    if (window_x11) {
      ret = gst_gl_window_x11_handle_event (window_x11, event);
    } else {
      /* unknown window, ignore */
      ret = TRUE;
    }

    if (window_x11)
      gst_object_unref (window_x11);
    g_free (event);
  }

  return ret;
}
Example #7
0
/*
 * Instead of polling the X connection socket we leave this to
 * xcb_poll_for_event() which knows better than we can ever know.
 *
 */
static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
    xcb_generic_event_t *event;

    while ((event = xcb_poll_for_event(conn)) != NULL) {
        if (event->response_type == 0) {
            xcb_generic_error_t *error = (xcb_generic_error_t*)event;
            if (debug_mode)
                fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n",
                        error->sequence, error->error_code);
            free(event);
            continue;
        }

        /* Strip off the highest bit (set if the event is generated) */
        int type = (event->response_type & 0x7F);
        switch (type) {
            case XCB_KEY_PRESS:
                handle_key_press((xcb_key_press_event_t*)event);
                break;

            case XCB_KEY_RELEASE:
                handle_key_release((xcb_key_release_event_t*)event);

                /* If this was the backspace or escape key we are back at an
                 * empty input, so turn off the screen if DPMS is enabled */
                if (dpms && input_position == 0)
                    dpms_turn_off_screen(conn);

                break;

            case XCB_VISIBILITY_NOTIFY:
                handle_visibility_notify((xcb_visibility_notify_event_t*)event);
                break;

            case XCB_MAP_NOTIFY:
                if (!dont_fork) {
                    /* After the first MapNotify, we never fork again. We don’t
                     * expect to get another MapNotify, but better be sure… */
                    dont_fork = true;

                    /* In the parent process, we exit */
                    if (fork() != 0)
                        exit(0);

                    ev_loop_fork(EV_DEFAULT);
                }
                break;

            case XCB_MAPPING_NOTIFY:
                handle_mapping_notify((xcb_mapping_notify_event_t*)event);
                break;

            case XCB_CONFIGURE_NOTIFY:
                handle_screen_resize();
                break;
        }

        free(event);
    }
}
Example #8
0
/*
 * Instead of polling the X connection socket we leave this to
 * xcb_poll_for_event() which knows better than we can ever know.
 *
 */
static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
    xcb_generic_event_t *event;

    while ((event = xcb_poll_for_event(conn)) != NULL) {
        if (event->response_type == 0) {
            xcb_generic_error_t *error = (xcb_generic_error_t*)event;
            if (debug_mode)
                fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n",
                        error->sequence, error->error_code);
            free(event);
            continue;
        }

        /* Strip off the highest bit (set if the event is generated) */
        int type = (event->response_type & 0x7F);

        switch (type) {
            case XCB_KEY_PRESS:
                handle_key_press((xcb_key_press_event_t*)event);
                break;

            case XCB_KEY_RELEASE:
                /* If this was the backspace or escape key we are back at an
                 * empty input, so turn off the screen if DPMS is enabled, but
                 * only do that after some timeout: maybe user mistyped and
                 * will type again right away */
                START_TIMER(dpms_timeout, TSTAMP_N_SECS(inactivity_timeout),
                            turn_off_monitors_cb);
                break;

            case XCB_VISIBILITY_NOTIFY:
                handle_visibility_notify(conn, (xcb_visibility_notify_event_t*)event);
                break;

            case XCB_MAP_NOTIFY:
                if (!dont_fork) {
                    /* After the first MapNotify, we never fork again. We don’t
                     * expect to get another MapNotify, but better be sure… */
                    dont_fork = true;

                    /* In the parent process, we exit */
                    if (fork() != 0)
                        exit(0);

                    ev_loop_fork(EV_DEFAULT);
                }
                break;

            case XCB_CONFIGURE_NOTIFY:
                handle_screen_resize();
                break;

            default:
                if (type == xkb_base_event)
                    process_xkb_event(event);
        }

        free(event);
    }
}
Example #9
0
static void
a_xcb_check_cb(EV_P_ ev_check *w, int revents)
{
    xcb_generic_event_t *mouse = NULL, *event;

    while((event = xcb_poll_for_event(globalconf.connection)))
    {
        /* We will treat mouse events later.
         * We cannot afford to treat all mouse motion events,
         * because that would be too much CPU intensive, so we just
         * take the last we get after a bunch of events. */
        if(XCB_EVENT_RESPONSE_TYPE(event) == XCB_MOTION_NOTIFY)
        {
            p_delete(&mouse);
            mouse = event;
        }
        else
        {
            event_handle(event);
            p_delete(&event);
        }
    }

    if(mouse)
    {
        event_handle(mouse);
        p_delete(&mouse);
    }
}
Example #10
0
int main(void)
{

  xcb_connection_t    *conn;
  xcb_screen_t        *screen;
  xcb_window_t         win;
  xcb_gcontext_t       gcontext;
  xcb_generic_event_t *event;
  uint32_t             mask;
  uint32_t             values[2];
  
                        /* open connection with the server */
  conn = xcb_connect(NULL,NULL);
  if (xcb_connection_has_error(conn)) {
    printf("Cannot open display\n");
    exit(1);
  }
                        /* get the first screen */
  screen = xcb_setup_roots_iterator( xcb_get_setup(conn) ).data;
 
                       /* create black graphics gcontext */
  gcontext = xcb_generate_id(conn);
  win = screen->root;
  mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
  values[0] = screen->black_pixel;
  values[1] = 0;
  xcb_create_gc(conn, gcontext, win, mask, values);
 
                       /* create window */
  win = xcb_generate_id(conn);
  mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
  values[0] = screen->white_pixel;
  values[1] = XCB_EVENT_MASK_EXPOSURE 
              | XCB_EVENT_MASK_KEY_PRESS
              | XCB_EVENT_MASK_KEY_RELEASE;
  xcb_create_window(conn, screen->root_depth, win, screen->root,
                    10, 10, 100, 100, 1,
                    XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
                    mask, values);
 
                        /* map (show) the window */
  xcb_map_window(conn, win);
 
  xcb_flush(conn);

  cterm_add_event_listener(XCB_KEY_PRESS, output_string);
  cterm_add_event_listener(XCB_KEY_PRESS, close_window);
 
                        /* event loop */
  while (!done) {
    event = xcb_poll_for_event(conn);
    if(event == NULL) continue;
    cterm_handle_event(event);
    free(event);
  }
                        /* close connection to server */
  xcb_disconnect(conn);
  cterm_free_event_handlers();
  return 0;
}
Example #11
0
static void
ephyrXcbNotify(int fd, int ready, void *data)
{
    xcb_connection_t *conn = hostx_get_xcbconn();

    while (TRUE) {
        xcb_generic_event_t *xev = xcb_poll_for_event(conn);
        if (!xev) {
            /* If our XCB connection has died (for example, our window was
             * closed), exit now.
             */
            if (xcb_connection_has_error(conn)) {
                CloseWellKnownConnections();
                OsCleanup(1);
                exit(1);
            }

            break;
        }

        switch (xev->response_type & 0x7f) {
        case 0:
            ephyrProcessErrorEvent(xev);
            break;

        case XCB_EXPOSE:
            ephyrProcessExpose(xev);
            break;

        case XCB_MOTION_NOTIFY:
            ephyrProcessMouseMotion(xev);
            break;

        case XCB_KEY_PRESS:
            ephyrProcessKeyPress(xev);
            break;

        case XCB_KEY_RELEASE:
            ephyrProcessKeyRelease(xev);
            break;

        case XCB_BUTTON_PRESS:
            ephyrProcessButtonPress(xev);
            break;

        case XCB_BUTTON_RELEASE:
            ephyrProcessButtonRelease(xev);
            break;

        case XCB_CONFIGURE_NOTIFY:
            ephyrProcessConfigureNotify(xev);
            break;
        }

        if (ephyr_glamor)
            ephyr_glamor_process_event(xev);

        free(xev);
    }
}
Example #12
0
/*
 * Instead of polling the X connection socket we leave this to
 * xcb_poll_for_event() which knows better than we can ever know.
 *
 */
static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
    xcb_generic_event_t *event;

    if (xcb_connection_has_error(conn))
        errx(EXIT_FAILURE, "X11 connection broke, did your server terminate?\n");

    while ((event = xcb_poll_for_event(conn)) != NULL) {
        if (event->response_type == 0) {

            xcb_generic_error_t *error = (xcb_generic_error_t *)event;
            if (debug_mode)
                fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n",
                        error->sequence, error->error_code);
            free(event);
            continue;
        }
        /* Strip off the highest bit (set if the event is generated) */
        int type = (event->response_type & 0x7F);

        switch (type) {
        case XCB_BUTTON_PRESS:
            handle_button_press((xcb_button_press_event_t *)event);
            break;

        case XCB_KEY_PRESS:
            handle_key_press((xcb_key_press_event_t *)event);
            break;

        case XCB_VISIBILITY_NOTIFY:
            handle_visibility_notify(conn, (xcb_visibility_notify_event_t *)event);
            break;

        case XCB_MAP_NOTIFY:
            if (!dont_fork) {
                /* After the first MapNotify, we never fork again. We don’t
                 * expect to get another MapNotify, but better be sure… */
                dont_fork = true;

                /* In the parent process, we exit */
                if (fork() != 0)
                    exit(0);

                ev_loop_fork(EV_DEFAULT);
            }
            break;

        case XCB_CONFIGURE_NOTIFY:
            handle_screen_resize();
            break;

        default:
            if (type == xkb_base_event)
                process_xkb_event(event);
        }

        free(event);
    }
}
Example #13
0
static void *Thread( void *p_data )
{
    intf_thread_t *p_intf = p_data;
    intf_sys_t *p_sys = p_intf->p_sys;
    xcb_connection_t *p_connection = p_sys->p_connection;

    int canc = vlc_savecancel();

    /* */
    xcb_flush( p_connection );

    /* */
    int fd = xcb_get_file_descriptor( p_connection );
    for( ;; )
    {
        /* Wait for x11 event */
        vlc_restorecancel( canc );
        struct pollfd fds = { .fd = fd, .events = POLLIN, };
        if( poll( &fds, 1, -1 ) < 0 )
        {
            if( errno != EINTR )
                break;
            canc = vlc_savecancel();
            continue;
        }
        canc = vlc_savecancel();

        xcb_generic_event_t *p_event;
        while( ( p_event = xcb_poll_for_event( p_connection ) ) )
        {
            if( ( p_event->response_type & 0x7f ) != XCB_KEY_PRESS )
            {
                free( p_event );
                continue;
            }

            xcb_key_press_event_t *e = (xcb_key_press_event_t *)p_event;

            for( int i = 0; i < p_sys->i_map; i++ )
            {
                hotkey_mapping_t *p_map = &p_sys->p_map[i];

                for( int j = 0; p_map->p_keys[j] != XCB_NO_SYMBOL; j++ )
                    if( p_map->p_keys[j] == e->detail &&
                        p_map->i_modifier == e->state )
                    {
                        var_SetInteger( p_intf->p_libvlc, "global-key-pressed",
                                        p_map->i_vlc );
                        goto done;
                    }
            }
        done:
            free( p_event );
        }
    }

    return NULL;
}
Example #14
0
void XSync(Display *display, Bool discard) {
	xcb_generic_event_t *event;

	if (!discard)
		fatal("XSync called for unimplemented functionality\n");
	xcb_flush(display);
	while ((event = xcb_poll_for_event(display)) != NULL)
		free(event);
}
Example #15
0
File: event.c Project: aosm/X11libs
void
xcb_event_poll_for_event_loop(xcb_event_handlers_t *evenths)
{
    xcb_generic_event_t *event;
    while ((event = xcb_poll_for_event(evenths->c)))
    {
        xcb_event_handle(evenths, event);
        free(event);
    }
}
Example #16
0
static gboolean xconn_dispatch (GSource *source,GSourceFunc callback,gpointer user_data)
{
	xconn_t c=user_data;
	xcb_generic_event_t *event;
	while((event=xcb_poll_for_event(c->c))!=NULL)
	{
		((XConnFunc)callback)(user_data,event);
		free(event);
	}
	return TRUE;
}
Example #17
0
/* This implements something like an Xlib.
 * do{
 *   threat_event(e);
 * } while (!Qlength);
 * It is a good way to optimize compositing performance.
 */
static int _handle_until_empty_queue(void *data, xcb_connection_t *conn, xcb_generic_event_t *e) {
    do {
        _handle(e);
        e = xcb_poll_for_event(gd.conn);
    } while (e != NULL);
    /* To be something hookable.. */
    fwm_composite_finalize();
    /* stop */
    xcb_flush(gd.conn);
    return 1;
}
Example #18
0
static cairo_status_t
_cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface)
{
    xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface,
							     &xcb_closure_key);
    xcb_generic_event_t *ev;

    if (xtc->surface != NULL) {
	cairo_t *cr;

	cr = cairo_create (xtc->surface);
	cairo_surface_set_device_offset (surface, 0, 0);
	cairo_set_source_surface (cr, surface, 0, 0);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint (cr);
	cairo_destroy (cr);

	surface = xtc->surface;
    }

    cairo_surface_flush (surface);
    if (cairo_surface_status (surface))
	return cairo_surface_status (surface);

    while ((ev = xcb_poll_for_event (xtc->c)) != NULL) {
	cairo_status_t status = CAIRO_STATUS_SUCCESS;

	if (ev->response_type == 0 /* trust me! */) {
	    xcb_generic_error_t *error = (xcb_generic_error_t *) ev;

#if XCB_GENERIC_ERROR_HAS_MAJOR_MINOR_CODES
	    fprintf (stderr,
		     "Detected error during xcb run: %d major=%d, minor=%d\n",
		     error->error_code, error->major_code, error->minor_code);
#else
	    fprintf (stderr,
		     "Detected error during xcb run: %d\n",
		     error->error_code);
#endif
	    free (error);

	    status = CAIRO_STATUS_WRITE_ERROR;
	}

	if (status)
	    return status;
    }

    if (xcb_connection_has_error (xtc->c))
	return CAIRO_STATUS_WRITE_ERROR;

    return CAIRO_STATUS_SUCCESS;
}
Example #19
0
static void event_task_x_events(void)
{
    xcb_generic_event_t *event;
    /* Handle all pending events */
    while ((event = xcb_poll_for_event(wm_conf.connection))) {
        if (wm_conf.trace_x_events)
            print_x_event(event);
        xcb_event_handle(&wm_conf.event_handlers, event);
        free(event);
        xcb_flush(wm_conf.connection);
    }
}
Example #20
0
bool X11AppContext::dispatchEvents()
{
	if(!checkErrorWarn()) return false;

	xcb_flush(&xConnection());
	while(auto event = xcb_poll_for_event(xConnection_))
	{
		processEvent(static_cast<const x11::GenericEvent&>(*event));
		free(event);
		xcb_flush(&xConnection());
	}

	return checkErrorWarn();
}
Example #21
0
void X11WindowedBackend::startEventReading()
{
    QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this);
    auto processXcbEvents = [this] {
        while (auto event = xcb_poll_for_event(m_connection)) {
            handleEvent(event);
            free(event);
        }
        xcb_flush(m_connection);
    };
    connect(notifier, &QSocketNotifier::activated, this, processXcbEvents);
    connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, this, processXcbEvents);
    connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::awake, this, processXcbEvents);
}
Example #22
0
static void kt_xcb_event_handler(xcb_connection_t *c)
{
        xcb_generic_event_t *event = NULL;

        while((event = xcb_poll_for_event(c))) {
                guint8 response_type;

                response_type = XCB_EVENT_RESPONSE_TYPE(event);
                if (response_type != 0) {
                        handle_x_event(response_type, event);
                }
        }

        xcb_flush(c);
}
Example #23
0
/**
 * Process incoming X events.
 */
int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, xcb_window_t window)
{
    xcb_generic_event_t *ev;

    while ((ev = xcb_poll_for_event (conn)) != NULL)
        ProcessEvent (vd, window, ev);

    if (xcb_connection_has_error (conn))
    {
        msg_Err (vd, "X server failure");
        return VLC_EGENERIC;
    }

    return VLC_SUCCESS;
}
static cairo_status_t
_cairo_boilerplate_xcb_handle_errors (xcb_target_closure_t *xtc)
{
    xcb_generic_event_t *ev = NULL;

    /* Ignore all MappingNotify events; those might happen without us causing them */
    do {
	free(ev);
	ev = xcb_poll_for_event(xtc->c);
    } while (ev != NULL && ev->response_type == XCB_MAPPING_NOTIFY);

    if (ev != NULL) {
	if (ev->response_type == CAIRO_XCB_ERROR) {
	    xcb_generic_error_t *error = (xcb_generic_error_t *) ev;

	    fprintf (stderr,
		     "Detected error during xcb run: error=%d, "
		     "seqno=0x%02x, major=%d, minor=%d\n",
		     error->error_code, error->sequence,
		     error->major_code, error->minor_code);
	} else {
	    fprintf (stderr,
		     "Detected unexpected event during xcb run: type=%d, seqno=0x%02x\n",
		     ev->response_type, ev->sequence);
	}
	free (ev);

	/* Silently discard all following errors */
	while ((ev = xcb_poll_for_event (xtc->c)) != NULL)
	    free (ev);

	return CAIRO_STATUS_WRITE_ERROR;
    }

    return CAIRO_STATUS_SUCCESS;
}
Example #25
0
void XCBWindow::pumpEvents(std::vector<Window::Event>& eventOutput)
{
    xcb_generic_event_t* event = nullptr;

    do
    {
        Assert(xcb_connection_has_error(m_connection) == 0);

        event = xcb_poll_for_event(m_connection);

        if (event != nullptr)
        {
            eventOutput.emplace_back(convertXcbEvent(event));
            free(event);
        }
    } while (event);
}
Example #26
0
static void cleanup(void) {
    xcb_generic_event_t *ev;

    xcb_aux_sync(conn);
    while ((ev = xcb_poll_for_event(conn))) {
        if (ev->response_type == 0) {
            puts("X11 error occurred");
            exit(EXIT_FAILURE);
        }
        free(ev);
    }
    if (xcb_connection_has_error(conn)) {
        fprintf(stderr, "The X11 connection broke at runtime.\n");
        exit(EXIT_FAILURE);
    }
    xcb_disconnect(conn);
}
Example #27
0
void ShellXcb::loop_poll()
{
    PosixTimer timer;

    double current_time = timer.get();
    double profile_start_time = current_time;
    int profile_present_count = 0;

    while (true) {
        // handle pending events
        while (true) {
            xcb_generic_event_t *ev = xcb_poll_for_event(c_);
            if (!ev)
                break;

            handle_event(ev);
            free(ev);
        }

        if (quit_)
            break;

        acquire_back_buffer();

        double t = timer.get();
        add_game_time(static_cast<float>(t - current_time));

        present_back_buffer();

        current_time = t;

        profile_present_count++;
        if (current_time - profile_start_time >= 5.0) {
            const double fps = profile_present_count / (current_time - profile_start_time);
            std::stringstream ss;
            ss << profile_present_count << " presents in " <<
                  current_time - profile_start_time << " seconds " <<
                  "(FPS: " << fps << ")";
            log(LOG_INFO, ss.str().c_str());

            profile_start_time = current_time;
            profile_present_count = 0;
        }
    }
}
void XRecordKeyboardMonitor::processNextReply()
{
    xcb_generic_event_t *event;
    while ((event = xcb_poll_for_event(m_connection))) {
        std::free(event);
    }

    void *reply = 0;
    while (xcb_poll_for_reply(m_connection, m_cookie.sequence, &reply, 0)) {
        if (!reply) {
            continue;
        }

        QScopedPointer<xcb_record_enable_context_reply_t, QScopedPointerPodDeleter>
        data(reinterpret_cast<xcb_record_enable_context_reply_t*>(reply));
        process(data.data());
    }
}
void Window::_UpdateOSWindow()
{
	auto event = xcb_poll_for_event( _xcb_connection );

	// if there is no event, event will be NULL
	// need to check for event == NULL to prevent segfault
	if( !event )
		return;

	switch( event->response_type & ~0x80 ) {
	case XCB_CLIENT_MESSAGE:
		if( ( (xcb_client_message_event_t*)event )->data.data32[ 0 ] == _xcb_atom_window_reply->atom ) {
			Close();
		}
		break;
	default:
		break;
	}
	free( event );
}
Example #30
0
void XServerPinger::xInput(int)
{
    void *reply;
    xcb_generic_error_t *error;
    xcb_generic_event_t *event;

    // X has sent us something, read it.
    if ((event = xcb_poll_for_event(xcb)) != NULL)
        // Some event, ignore it
        free(event);

    if (request.sequence
        && xcb_poll_for_reply(xcb, request.sequence, &reply, &error)) {
        if (reply) {
            free(reply);
            request.sequence = 0;
        } else if (error)
            // Ignore
            free(error);
    }
}