Ejemplo n.º 1
0
void initScreen() {
    /* Open Xlib Display */
    display = XOpenDisplay(0);
    if (!display) printf("Can't open display");

    default_screen = ((_XPrivDisplay)display)->default_screen;
    /* Get the XCB connection from the display */
    connection = XGetXCBConnection(display);
    if (!connection) printf("Can't get xcb connection from display");

    /* Acquire event queue ownership */
    XSetEventQueueOwner(display, XCBOwnsEventQueue);

    /* Find XCB screen */
    screen = 0;
    xcb_screen_iterator_t screen_iter =
            xcb_setup_roots_iterator(xcb_get_setup(connection));
    for (int screen_num = default_screen;
        screen_iter.rem && screen_num > 0;
        --screen_num, xcb_screen_next(&screen_iter));
    screen = screen_iter.data;

/*
  width = screen->width_in_pixels;
  height = screen->height_in_pixels;
*/
  width = 250;
  height = 260;

}
Ejemplo n.º 2
0
/** Handle systray message.
 * \param ev The event.
 * \return 0 on no error.
 */
int
systray_process_client_message(xcb_client_message_event_t *ev)
{
    int screen_nbr = 0, ret = 0;
    xcb_get_geometry_cookie_t geom_c;
    xcb_get_geometry_reply_t *geom_r;
    xcb_screen_iterator_t iter;

    switch(ev->data.data32[1])
    {
      case SYSTEM_TRAY_REQUEST_DOCK:
        geom_c = xcb_get_geometry_unchecked(globalconf.connection, ev->window);

        if(!(geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL)))
            return -1;

        for(iter = xcb_setup_roots_iterator(xcb_get_setup(globalconf.connection)), screen_nbr = 0;
            iter.rem && iter.data->root != geom_r->root; xcb_screen_next (&iter), ++screen_nbr);

        p_delete(&geom_r);

        ret = systray_request_handle(ev->data.data32[2], screen_nbr, NULL);
        break;
    }

    return ret;
}
Ejemplo n.º 3
0
static int
_best_depth_get(int backend, void *connection, int screen)
{
   if (!connection) return 0;

#ifdef BUILD_ENGINE_SOFTWARE_XLIB
   if (backend == EVAS_ENGINE_INFO_SOFTWARE_X11_BACKEND_XLIB)
     {
        return DefaultDepth((Display *)connection, screen);
     }
#endif

#ifdef BUILD_ENGINE_SOFTWARE_XCB
   if (backend == EVAS_ENGINE_INFO_SOFTWARE_X11_BACKEND_XCB)
     {
        xcb_screen_iterator_t iter_screen;
        xcb_screen_t          *s;

        iter_screen = xcb_setup_roots_iterator(xcb_get_setup((xcb_connection_t *)connection));
        for (; iter_screen.rem; --screen, xcb_screen_next (&iter_screen))
          if (screen == 0)
            {
               s = iter_screen.data;
               break;
            }

        return s->root_depth;
     }
#endif

   return 0;
}
Ejemplo n.º 4
0
	void SimplicityApplication::initialize_x_connection(void)
	{
		int nScreenNum = 0;
		m_pXConnection = xcb_connect(m_sDisplayName.c_str(), &nScreenNum);

		if (check_xcb_connection(m_pXConnection))
		{
			xcb_disconnect(m_pXConnection);
			m_bRunning = false;
			return;
		}

		xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(m_pXConnection));
		for (int i = 0; i != nScreenNum; i++)
			xcb_screen_next(&iter);

		m_pRootScreen = iter.data;
		if (m_pRootScreen == nullptr)
		{
			global_log_error << "Could not get the current screen. Exiting";
			xcb_disconnect(m_pXConnection);
			m_bRunning = false;
		}

		global_log_debug << "Root screen dimensions: "
						 << m_pRootScreen->width_in_pixels
						 << "x"
						 << m_pRootScreen->height_in_pixels;
		global_log_debug << "Root window: "
						 << m_pRootScreen->root;
	}
Ejemplo n.º 5
0
static int
deploy(void)
{
	/* init xcb and grab events */
	uint32_t values[2];
	int mask;

	if (xcb_connection_has_error(conn = xcb_connect(NULL, NULL)))
		return -1;

	scr = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
	focuswin = scr->root;

#ifdef ENABLE_MOUSE
	xcb_grab_button(conn, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
			XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
			XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 1, MOD);

	xcb_grab_button(conn, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
			XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
			XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 3, MOD);
#endif

	mask = XCB_CW_EVENT_MASK;
	values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
	xcb_change_window_attributes_checked(conn, scr->root, mask, values);

	xcb_flush(conn);

	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv){
	xcb_connection_t *c = xcb_connect(0, 0);
	xcb_screen_t *s = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
	int w, h, n,
		depth = s->root_depth,
		win_class = XCB_WINDOW_CLASS_INPUT_OUTPUT,
		format = XCB_IMAGE_FORMAT_Z_PIXMAP;
	xcb_colormap_t colormap = s->default_colormap;
	xcb_drawable_t win = xcb_generate_id(c);
	xcb_gcontext_t gc = xcb_generate_id(c);
	xcb_pixmap_t pixmap = xcb_generate_id(c);
	xcb_generic_event_t *ev;
	xcb_image_t *image;
	char *data = NULL;
	uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
		value_mask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS,
		values[] = { s->black_pixel, value_mask };

	if (argc<2) return -1;
	data = stbi_load(argv[1], &w, &h, &n, 4);
	if (data) {
		unsigned *dp = (unsigned *)data;
		size_t i, len = w*h;
		for(i=0;i<len;i++) //rgba to bgra
			dp[i]=dp[i]&0xff00ff00|((dp[i]>>16)&0xFF)|((dp[i]<<16)&0xFF0000);
	}else return -1;
Ejemplo n.º 7
0
void QXcbCursor::queryPointer(QXcbConnection *c, xcb_window_t *rootWin, QPoint *pos, int *keybMask)
{
    if (pos)
        *pos = QPoint();
    xcb_screen_iterator_t it = xcb_setup_roots_iterator(c->setup());
    while (it.rem) {
        xcb_window_t root = it.data->root;
        xcb_query_pointer_cookie_t cookie = xcb_query_pointer(c->xcb_connection(), root);
        xcb_generic_error_t *err = 0;
        xcb_query_pointer_reply_t *reply = xcb_query_pointer_reply(c->xcb_connection(), cookie, &err);
        if (!err && reply) {
            if (pos)
                *pos = QPoint(reply->root_x, reply->root_y);
            if (rootWin)
                *rootWin = root;
            if (keybMask)
                *keybMask = reply->mask;
            free(reply);
            return;
        }
        free(err);
        free(reply);
        xcb_screen_next(&it);
    }
}
Ejemplo n.º 8
0
int main()
{
    /* Open the connection to the X server */
    xcb_connection_t *connection = xcb_connect(NULL, NULL);

    /* Get the first screen */
    const xcb_setup_t  *setup = xcb_get_setup(connection);
    xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
    xcb_screen_t  *screen = iter.data;

    /* Create the window */
    xcb_window_t window = xcb_generate_id(connection);
    xcb_create_window(connection,                 /* Connection */
                      XCB_COPY_FROM_PARENT,      /* depth (same as root) */
                      window,                     /* window Id */
                      screen->root,               /* parent window */
                      0, 0,                       /* x, y */
                      150, 150,                   /* width, height */
                      10,                         /* border_width */
                      XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
                      screen->root_visual,        /* visual */
                      0, NULL);                   /* masks, not used yet */

    /* Map the window on the screen */
    xcb_map_window(connection, window);

    /* Make sure commands are sent before we pause so that the window gets shown */
    xcb_flush(connection);

    pause(); /* hold client until Ctrl-C */

    xcb_disconnect(connection);

    return 0;
}
Ejemplo n.º 9
0
int vkDisplay::init(const unsigned int gpu_idx)
{
    //m_gpuIdx = gpu_idx;
#if 0
    VkResult result = init_vk(gpu_idx);
    if (result != VK_SUCCESS) {
        vktrace_LogError("could not init vulkan library");
        return -1;
    } else {
        m_initedVK = true;
    }
#endif
#if defined(PLATFORM_LINUX)
    const xcb_setup_t *setup;
    xcb_screen_iterator_t iter;
    int scr;
    m_pXcbConnection = xcb_connect(NULL, &scr);
    setup = xcb_get_setup(m_pXcbConnection);
    iter = xcb_setup_roots_iterator(setup);
    while (scr-- > 0)
        xcb_screen_next(&iter);
    m_pXcbScreen = iter.data;
#endif
    return 0;
}
Ejemplo n.º 10
0
Archivo: cache.c Proyecto: aosm/X11libs
static int
has_required_depths (xcb_connection_t *c)
{
    xcb_screen_iterator_t screens;
    xcb_pixmap_t pixmap = { -1 };
    for (screens = xcb_setup_roots_iterator(xcb_get_setup(c)); screens.rem; xcb_screen_next(&screens))
    {
	xcb_depth_iterator_t depths;
	uint32_t missing = REQUIRED_DEPTHS;
	xcb_drawable_t root;

	for (depths = xcb_screen_allowed_depths_iterator(screens.data); depths.rem; xcb_depth_next(&depths))
	    missing &= ~DEPTH_MASK(depths.data->depth);
	if (!missing)
	    continue;

	/*
	 * Ok, this is ugly.  It should be sufficient at this
	 * point to just return false, but Xinerama is broken at
	 * this point and only advertises depths which have an
	 * associated visual.  Of course, the other depths still
	 * work, but the only way to find out is to try them.
	 */
	if (pixmap == -1)
	    pixmap = xcb_generate_id(c);
	root = screens.data->root;
	if (!pixmap_depths_usable (c, missing, pixmap, root))
	    return 0;
    }
    return 1;
}
Ejemplo n.º 11
0
static xcb_screen_t *
_cairo_xcb_screen_from_visual (xcb_connection_t *connection,
			       xcb_visualtype_t *visual,
			       int *depth)
{
    xcb_depth_iterator_t d;
    xcb_screen_iterator_t s;

    s = xcb_setup_roots_iterator (xcb_get_setup (connection));
    for (; s.rem; xcb_screen_next (&s)) {
	if (s.data->root_visual == visual->visual_id) {
	    *depth = s.data->root_depth;
	    return s.data;
	}

	d = xcb_screen_allowed_depths_iterator(s.data);
	for (; d.rem; xcb_depth_next (&d)) {
	    xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator (d.data);

	    for (; v.rem; xcb_visualtype_next (&v)) {
		if (v.data->visual_id == visual->visual_id) {
		    *depth = d.data->depth;
		    return s.data;
		}
	    }
	}
    }

    return NULL;
}
Ejemplo n.º 12
0
void init(void)
{
    int scrno;
    xcb_screen_iterator_t iter;
    
    conn = xcb_connect(NULL, &scrno);
    if (!conn)
    {
        fprintf(stderr, "can't connect to an X server\n");
        exit(1);
    }

    iter = xcb_setup_roots_iterator(xcb_get_setup(conn));

    for (int i = 0; i < scrno; ++i)
    {
        xcb_screen_next(&iter);
    }

    screen = iter.data;

    if (!screen)
    {
        fprintf(stderr, "can't get the current screen\n");
        xcb_disconnect(conn);
        exit(1);
    }
}
Ejemplo n.º 13
0
xcb_screen_t* IdlenessWatcher::screenOfDisplay(xcb_connection_t* conn, int screen)
{
    xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(conn));
    for (; iter.rem; --screen, xcb_screen_next(&iter))
        if (screen == 0)
            return iter.data;
    return NULL;
}
Ejemplo n.º 14
0
static xcb_window_t xconn_get_root(xconn_t c)
{
	const xcb_setup_t *setup;
	setup=xcb_get_setup(c->c);
	xcb_screen_iterator_t iter = xcb_setup_roots_iterator (setup);
	xcb_screen_t *screen = iter.data;
	return screen->root;
}
Ejemplo n.º 15
0
bool X11IdleDetector::idleCheckPossible()
{
    m_connection = xcb_connect(NULL, NULL); //krazy:exclude=null
    m_screen = xcb_setup_roots_iterator(xcb_get_setup(m_connection)).data;
    if (m_screen)
        return true;
    return false;
}
Ejemplo n.º 16
0
Archivo: xcb.c Proyecto: FLYKingdom/vlc
/*****************************************************************************
 * Open:
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
    intf_sys_t *p_sys;

    p_intf->p_sys = p_sys = calloc( 1, sizeof(*p_sys) );
    if( !p_sys )
        return VLC_ENOMEM;

    char *psz_display = var_CreateGetNonEmptyString( p_intf, "x11-display" );

    int i_screen_default;
    p_sys->p_connection = xcb_connect( psz_display, &i_screen_default );
    free( psz_display );

    if( !p_sys->p_connection )
        goto error;

    /* Get the root windows of the default screen */
    const xcb_setup_t* xcbsetup = xcb_get_setup( p_sys->p_connection );
    if( !xcbsetup )
        goto error;
    xcb_screen_iterator_t iter = xcb_setup_roots_iterator( xcbsetup );
    for( int i = 0; i < i_screen_default; i++ )
    {
        if( !iter.rem )
            break;
        xcb_screen_next( &iter );
    }
    if( !iter.rem )
        goto error;
    p_sys->root = iter.data->root;

    /* */
    p_sys->p_symbols = xcb_key_symbols_alloc( p_sys->p_connection ); // FIXME
    if( !p_sys->p_symbols )
        goto error;

    Mapping( p_intf );
    Register( p_intf );

    if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
    {
        Unregister( p_intf );
        free( p_sys->p_map );
        goto error;
    }
    return VLC_SUCCESS;

error:
    if( p_sys->p_symbols )
        xcb_key_symbols_free( p_sys->p_symbols );
    if( p_sys->p_connection )
        xcb_disconnect( p_sys->p_connection );
    free( p_sys );
    return VLC_EGENERIC;
}
Ejemplo n.º 17
0
cairo_surface_t *
_cairo_boilerplate_xcb_create_surface (const char		 *name,
				       cairo_content_t		  content,
				       int			  width,
				       int			  height,
				       int			  max_width,
				       int			  max_height,
				       cairo_boilerplate_mode_t	  mode,
				       int                        id,
				       void			**closure)
{
    xcb_screen_t *root;
    xcb_target_closure_t *xtc;
    xcb_connection_t *c;
    xcb_render_pictforminfo_t *render_format;
    xcb_pict_standard_t format;

    *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));

    if (width == 0)
	width = 1;
    if (height == 0)
	height = 1;

    xtc->c = c = xcb_connect(NULL,NULL);
    if (xcb_connection_has_error(c)) {
	fprintf (stderr, "Failed to connect to X server through XCB\n");
	return NULL;
    }

    root = xcb_setup_roots_iterator(xcb_get_setup(c)).data;

    xtc->pixmap = xcb_generate_id (c);
    xcb_create_pixmap (c, 32, xtc->pixmap, root->root,
			 width, height);

    switch (content) {
    case CAIRO_CONTENT_COLOR:
	format = XCB_PICT_STANDARD_RGB_24;
	break;
    case CAIRO_CONTENT_COLOR_ALPHA:
	format = XCB_PICT_STANDARD_ARGB_32;
	break;
    case CAIRO_CONTENT_ALPHA:  /* would be XCB_PICT_STANDARD_A_8 */
    default:
	fprintf (stderr, "Invalid content for XCB test: %d\n", content);
	return NULL;
    }

    render_format = xcb_render_util_find_standard_format (xcb_render_util_query_formats (c), format);
    if (render_format->id == 0)
	return NULL;

    return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
							 render_format,
							 width, height);
}
Ejemplo n.º 18
0
int iterate_screens(int, char **)
{
    xcb_connection_t *conn = xcb_connect(0, 0);
    xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(conn));
    std::vector<xcb_screen_t> screens;
    std::copy(i, xcb::end(i), std::back_inserter(screens));
    assert(screens.size() == xcb_setup_roots_length(xcb_get_setup(conn)));
    return EXIT_SUCCESS;
}
Ejemplo n.º 19
0
Archivo: leaf.c Proyecto: shaoner/leaf
static leaf_error_t leaf_init()
{
	int first_screen = 0;
	xcb_screen_iterator_t iter;
	struct sigaction action;
	uint32_t values;
	xcb_void_cookie_t cookie;
	xcb_generic_error_t *status = NULL;

	gconf.running = false;
	action.sa_handler = stop_signal_handler;
	action.sa_flags = 0;
	sigemptyset(&action.sa_mask);

	/* Catch signals */
	/*
	 * TODO: Catch sighup
	 */
	sigaction(SIGINT, &action, NULL);
	sigaction(SIGTERM, &action, NULL);
	/* Initialize connection to the X server */
	gconf.conn = xcb_connect(NULL, &first_screen);
	if (xcb_connection_has_error(gconf.conn)) {
		print_e("Cannot initialize connection to the X server");
		return ERR_CONN;
	}
	print_d("First screen = %i", first_screen);
	/* Get back X data */
	gconf.xsetup = xcb_get_setup(gconf.conn);
	/* Find the first screen */
	iter = xcb_setup_roots_iterator(gconf.xsetup);
	while (first_screen--)
		xcb_screen_next(&iter);
	gconf.screen = iter.data;

	/* Configure the root screen to get window's events */
	values = \
		XCB_EVENT_MASK_STRUCTURE_NOTIFY |
		XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
	cookie = xcb_change_window_attributes_checked(gconf.conn,
	                                              gconf.screen->root,
	                                              XCB_CW_EVENT_MASK,
	                                              &values);
	status = xcb_request_check(gconf.conn, cookie);
	xcb_flush(gconf.conn);

    if (status)
    {
	    print_d("X is busy, another window manager may be running (%d)",
	            status->error_code);
	    free(status);
	    return ERR_CONN;
    }

	return ERR_NONE;
}
Ejemplo n.º 20
0
xcb_screen_t *defaultScreen(xcb_connection_t *c, int screen)
{
    for (auto it = xcb_setup_roots_iterator(xcb_get_setup(c)); it.rem; --screen, xcb_screen_next(&it)) {
        if (screen == 0) {
            return it.data;
        }
    }

    return nullptr;
}
Ejemplo n.º 21
0
xcb_screen_t *
xcb_aux_get_screen (xcb_connection_t *c,
                    int               screen)
{
  xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(c));
  for (; i.rem; --screen, xcb_screen_next(&i))
    if (screen == 0)
      return i.data;
  return 0;
}
Ejemplo n.º 22
0
Watcher::Watcher() : QTimer()
{
    connection = xcb_connect (NULL, NULL);
    screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data;
    xcb_dpms_disable (connection);

    connect(this, SIGNAL(timeout()), this, SLOT(onTimeout()));
    setInterval(1000);
    start();
}
Ejemplo n.º 23
0
int
main ()
{
    xcb_connection_t*       connection;
    xcb_screen_t*           screen;
    xcb_window_t            root_window;
    xcb_alloc_color_reply_t *color_reply;
    xcb_colormap_t          colormap = { 0 };
    uint32_t                params[1];
    uint16_t                r,g,b;

    connection = xcb_connect(NULL, NULL);
    if (!connection) {
        fprintf(stderr, "ERROR: can't connect to an X server\n");
        return -1;
    }

    screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
    if (!screen)
    {
        fprintf(stderr, "ERROR: can't setup a screen\n");
        xcb_disconnect(connection);
        return -1;
    }

    root_window = screen->root;
    colormap = screen->default_colormap;

    r = 60000, g = 20000, b = 20000;
    color_reply = xcb_alloc_color_reply(connection,
            xcb_alloc_color(connection, colormap, r, g, b), NULL);

    if(!color_reply)
    {
        fprintf(stderr, "ERROR: can't alloc an color\n");
        xcb_disconnect(connection);
        return 0;
    }

    params[0] = color_reply->pixel;

    // sets the root_window back_pixel to pixel(params)
    xcb_change_window_attributes(connection, root_window, XCB_CW_BACK_PIXEL, params);

    // free color resources
    free(color_reply);

    // waits all things are send??
    xcb_flush(connection);

    // xcb_destroy_window(connection, window);
    xcb_disconnect(connection);

    return 0;
}
Ejemplo n.º 24
0
QXcbConnection::QXcbConnection(const char *displayName)
    : m_displayName(displayName ? QByteArray(displayName) : qgetenv("DISPLAY"))
#ifdef XCB_USE_DRI2
    , m_dri2_major(0)
    , m_dri2_minor(0)
    , m_dri2_support_probed(false)
    , m_has_support_for_dri2(false)
#endif
{
    int primaryScreen = 0;

#ifdef XCB_USE_XLIB
    Display *dpy = XOpenDisplay(m_displayName.constData());
    primaryScreen = DefaultScreen(dpy);
    m_connection = XGetXCBConnection(dpy);
    XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
    m_xlib_display = dpy;
#ifdef XCB_USE_EGL
    EGLDisplay eglDisplay = eglGetDisplay(dpy);
    m_egl_display = eglDisplay;
    EGLint major, minor;
    eglBindAPI(EGL_OPENGL_ES_API);
    m_has_egl = eglInitialize(eglDisplay,&major,&minor);
#endif //XCB_USE_EGL
#else
    m_connection = xcb_connect(m_displayName.constData(), &primaryScreen);

#endif //XCB_USE_XLIB
    m_setup = xcb_get_setup(xcb_connection());

    initializeAllAtoms();

    xcb_screen_iterator_t it = xcb_setup_roots_iterator(m_setup);

    int screenNumber = 0;
    while (it.rem) {
        m_screens << new QXcbScreen(this, it.data, screenNumber++);
        xcb_screen_next(&it);
    }

    m_keyboard = new QXcbKeyboard(this);

#ifdef XCB_USE_DRI2
    initializeDri2();
#endif

    QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
    connect(notifier, SIGNAL(activated(int)), this, SLOT(processXcbEvents()));

    QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(qApp->thread());
    connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processXcbEvents()));

    sync();
}
Ejemplo n.º 25
0
static void
pipe_loader_drm_x_auth(int fd)
{
#ifdef HAVE_PIPE_LOADER_XCB
   /* Try authenticate with the X server to give us access to devices that X
    * is running on. */
   xcb_connection_t *xcb_conn;
   const xcb_setup_t *xcb_setup;
   xcb_screen_iterator_t s;
   xcb_dri2_connect_cookie_t connect_cookie;
   xcb_dri2_connect_reply_t *connect;
   drm_magic_t magic;
   xcb_dri2_authenticate_cookie_t authenticate_cookie;
   xcb_dri2_authenticate_reply_t *authenticate;
   int screen;

   xcb_conn = xcb_connect(NULL, &screen);

   if(!xcb_conn)
      return;

   xcb_setup = xcb_get_setup(xcb_conn);

  if (!xcb_setup)
    goto disconnect;

   s = xcb_setup_roots_iterator(xcb_setup);
   connect_cookie = xcb_dri2_connect_unchecked(xcb_conn,
                                               get_xcb_screen(s, screen)->root,
                                               XCB_DRI2_DRIVER_TYPE_DRI);
   connect = xcb_dri2_connect_reply(xcb_conn, connect_cookie, NULL);

   if (!connect || connect->driver_name_length
                   + connect->device_name_length == 0) {

      goto disconnect;
   }

   if (drmGetMagic(fd, &magic))
      goto disconnect;

   authenticate_cookie = xcb_dri2_authenticate_unchecked(xcb_conn,
                                                         s.data->root,
                                                         magic);
   authenticate = xcb_dri2_authenticate_reply(xcb_conn,
                                              authenticate_cookie,
                                              NULL);
   FREE(authenticate);

disconnect:
   xcb_disconnect(xcb_conn);

#endif
}
Ejemplo n.º 26
0
Archivo: core.hpp Proyecto: jotrk/xpp
    xcb_screen_t *
    screen_of_display(int screen)
    {
      xcb_screen_iterator_t iter;

      iter = xcb_setup_roots_iterator(xcb_get_setup(m_c.get()));
      for (; iter.rem; --screen, xcb_screen_next(&iter))
        if (screen == 0)
          return iter.data;

      return NULL;
    }
Ejemplo n.º 27
0
int
get_screen(xcb_connection_t *con, xcb_screen_t **scr)
{
    *scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data;
    
    if (*scr == NULL) {
	perror("unable to retrieve screen information");
	return -1;
    }

    return 0;
}
Ejemplo n.º 28
0
static xcb_screen_t *
find_xcb_screen(xcb_connection_t *c, int default_screen)
{
    xcb_screen_iterator_t screen_iter;
    int screen_num;

    screen_iter = xcb_setup_roots_iterator(xcb_get_setup(c));
    for (screen_num = default_screen; screen_iter.rem && screen_num > 0;
            --screen_num, xcb_screen_next(&screen_iter));

    return screen_iter.data;
}
Ejemplo n.º 29
0
static EGLBoolean
dri2_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
			     _EGLDisplay *disp)
{
   xcb_screen_iterator_t s;
   xcb_depth_iterator_t d;
   xcb_visualtype_t *visuals;
   int i, j, id;
   EGLint surface_type;
   EGLint config_attrs[] = {
	   EGL_NATIVE_VISUAL_ID,   0,
	   EGL_NATIVE_VISUAL_TYPE, 0,
	   EGL_NONE
   };

   s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
   d = xcb_screen_allowed_depths_iterator(s.data);
   id = 1;

   surface_type =
      EGL_WINDOW_BIT |
      EGL_PIXMAP_BIT |
      EGL_PBUFFER_BIT |
      EGL_SWAP_BEHAVIOR_PRESERVED_BIT;

   while (d.rem > 0) {
      EGLBoolean class_added[6] = { 0, };

      visuals = xcb_depth_visuals(d.data);
      for (i = 0; i < xcb_depth_visuals_length(d.data); i++) {
	 if (class_added[visuals[i]._class])
	    continue;

	 class_added[visuals[i]._class] = EGL_TRUE;
	 for (j = 0; dri2_dpy->driver_configs[j]; j++) {
            config_attrs[1] = visuals[i].visual_id;
            config_attrs[3] = visuals[i]._class;

	    dri2_add_config(disp, dri2_dpy->driver_configs[j], id++,
			    d.data->depth, surface_type, config_attrs, NULL);
	 }
      }

      xcb_depth_next(&d);
   }

   if (!_eglGetArraySize(disp->Configs)) {
      _eglLog(_EGL_WARNING, "DRI2: failed to create any config");
      return EGL_FALSE;
   }

   return EGL_TRUE;
}
Ejemplo n.º 30
-1
EGLNativeWindowType QEglFSX11Hooks::createNativeWindow(QPlatformWindow *platformWindow,
                                                       const QSize &size,
                                                       const QSurfaceFormat &format)
{
    Q_UNUSED(format);

    m_platformWindow = platformWindow;

    xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(m_connection));
    m_window = xcb_generate_id(m_connection);
    xcb_create_window(m_connection, XCB_COPY_FROM_PARENT, m_window, it.data->root,
                      0, 0, size.width(), size.height(), 0,
                      XCB_WINDOW_CLASS_INPUT_OUTPUT, it.data->root_visual,
                      0, 0);

    xcb_map_window(m_connection, m_window);

    xcb_intern_atom_cookie_t cookies[Atoms::N_ATOMS];
    static const char *atomNames[Atoms::N_ATOMS] = {
        "_NET_WM_NAME",
        "UTF8_STRING",
        "WM_PROTOCOLS",
        "WM_DELETE_WINDOW",
        "_NET_WM_STATE",
        "_NET_WM_STATE_FULLSCREEN"
    };

    for (int i = 0; i < Atoms::N_ATOMS; ++i) {
        cookies[i] = xcb_intern_atom(m_connection, false, strlen(atomNames[i]), atomNames[i]);
        xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(m_connection, cookies[i], 0);
        m_atoms[i] = reply->atom;
        free(reply);
    }

    // Set window title
    xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window,
                        m_atoms[Atoms::_NET_WM_NAME], m_atoms[Atoms::UTF8_STRING], 8, 5, "EGLFS");

    // Enable WM_DELETE_WINDOW
    xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window,
                        m_atoms[Atoms::WM_PROTOCOLS], XCB_ATOM_ATOM, 32, 1, &m_atoms[Atoms::WM_DELETE_WINDOW]);

    if (qgetenv("EGLFS_X11_FULLSCREEN").toInt()) {
        // Go fullscreen. The QScreen and QWindow size is controlled by EGLFS_X11_SIZE regardless,
        // this is just the native window.
        xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window,
                            m_atoms[Atoms::_NET_WM_STATE], XCB_ATOM_ATOM, 32, 1, &m_atoms[Atoms::_NET_WM_STATE_FULLSCREEN]);
    }

    xcb_flush(m_connection);

    return m_window;
}