コード例 #1
0
ファイル: window.c プロジェクト: CSRedRat/vlc
/**
 * Wrap an existing X11 window to embed the video.
 */
static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg)
{
    xcb_window_t window = var_InheritInteger (wnd, "drawable-xid");
    if (window == 0)
        return VLC_EGENERIC;

    if (AcquireDrawable (VLC_OBJECT(wnd), window))
        return VLC_EGENERIC;

    vout_window_sys_t *p_sys = malloc (sizeof (*p_sys));
    xcb_connection_t *conn = xcb_connect (NULL, NULL);
    if (p_sys == NULL || xcb_connection_has_error (conn))
        goto error;

    p_sys->embedded = true;
    p_sys->keys = NULL;
    wnd->handle.xid = window;
    wnd->control = Control;
    wnd->sys = p_sys;

    p_sys->conn = conn;

    xcb_get_geometry_reply_t *geo =
        xcb_get_geometry_reply (conn, xcb_get_geometry (conn, window), NULL);
    if (geo == NULL)
    {
        msg_Err (wnd, "bad X11 window 0x%08"PRIx8, window);
        goto error;
    }
    p_sys->root = geo->root;
    free (geo);

    if (var_InheritBool (wnd, "keyboard-events"))
    {
        p_sys->keys = CreateKeyHandler (VLC_OBJECT(wnd), conn);
        if (p_sys->keys != NULL)
        {
            const uint32_t mask = XCB_CW_EVENT_MASK;
            const uint32_t values[1] = {
                XCB_EVENT_MASK_KEY_PRESS,
            };
            xcb_change_window_attributes (conn, window, mask, values);
        }
    }

    CacheAtoms (p_sys);
    if ((p_sys->keys != NULL)
     && vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
        DestroyKeyHandler (p_sys->keys);

    xcb_flush (conn);
    (void) cfg;
    return VLC_SUCCESS;

error:
    xcb_disconnect (conn);
    free (p_sys);
    ReleaseDrawable (VLC_OBJECT(wnd), window);
    return VLC_EGENERIC;
}
コード例 #2
0
ファイル: swm.c プロジェクト: Uladox/.sxhkd.d
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;
}
コード例 #3
0
ファイル: application.cpp プロジェクト: durandj/simplicity
	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;
	}
コード例 #4
0
ファイル: nilwm.c プロジェクト: nqv/nilwm
int main(int argc, char **argv) {
    (void)argc;
    (void)argv;

    /* open connection with the server */
    nil_.con = xcb_connect(0, 0);
    if (xcb_connection_has_error(nil_.con)) {
        NIL_ERR("xcb_connect %p", (void *)nil_.con);
        exit(1);
    }
    /* 1st stage */
    if ((init_screen() != 0) || (init_key() != 0) || (init_mouse() != 0)) {
        xcb_disconnect(nil_.con);
        exit(1);
    }
    /* 2nd stage */
    if ((init_cursor() != 0) || (init_color() != 0) != (init_font() != 0)
        || (init_bar() != 0) || (init_wm() != 0))  {
        cleanup();
        exit(1);
    }
    xcb_flush(nil_.con);
    recv_events();
    cleanup();
    return 0;
}
コード例 #5
0
ファイル: NGBaseLib.c プロジェクト: moemoechu/NyanGraph2
void NGBInit()
{
	event = NULL;
	mask = 0;
	con = xcb_connect(":0.0", NULL); //打开连接
	if(xcb_connection_has_error(con))
	{
		printf("Cannot open display\n");
		exit(1);
	}
	screen = xcb_setup_roots_iterator(xcb_get_setup(con)).data;

	win = screen->root;
	foreground = xcb_generate_id(con);
	mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
	values[0] = screen->black_pixel;
	values[1] = 0;

	xcb_create_gc(con, foreground, win, mask, values);

	win = xcb_generate_id(con);

	mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
	values[0] = screen->white_pixel;
	values[1] = XCB_EVENT_MASK_EXPOSURE;

}
コード例 #6
0
int
main ()
{
  xcb_connection_t     *c;
  xcb_screen_t         *screen;
  int                   screen_nbr;
  xcb_screen_iterator_t iter;

  /* Open the connection to the X server. Use the DISPLAY environment variable */
  c = xcb_connect (NULL, &screen_nbr);

  /* Get the screen #screen_nbr */
  iter = xcb_setup_roots_iterator (xcb_get_setup (c));
  for (; iter.rem; --screen_nbr, xcb_screen_next (&iter))
    if (screen_nbr == 0) {
      screen = iter.data;
      break;
    }

  printf ("\n");
  printf ("Informations of screen %ld:\n", screen->root);
  printf ("  width.........: %d\n", screen->width_in_pixels);
  printf ("  height........: %d\n", screen->height_in_pixels);
  printf ("  white pixel...: %ld\n", screen->white_pixel);
  printf ("  black pixel...: %ld\n", screen->black_pixel);
  printf ("\n");

  return 0;
}
コード例 #7
0
ファイル: main.c プロジェクト: TheNeikos/cterm
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;
}
コード例 #8
0
ファイル: hidden.c プロジェクト: satran/mcwm
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);
    }
}
コード例 #9
0
int main() {
  /* Open the connection to the server. Use de DISPLAY enviroment variable */
  int i, screenNum;
  xcb_connection_t *connection = xcb_connect(NULL, &screenNum);

  // Get the screen whose number is screenNum
  const xcb_setup_t *setup = xcb_get_setup(connection);
  xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);

  // We want the screen at index screenNum of the iterator
  for (i = 0; i < screenNum; i++) {
    xcb_screen_next(&iter);
  }

  xcb_screen_t *screen = iter.data;

  // report
  printf("\n");
  printf("Informations of screen %" PRIu32 "\n", screen->root);
  printf("  width.........: %" PRIu16 "\n", screen->width_in_pixels);
  printf("  height........: %" PRIu16 "\n", screen->height_in_pixels);
  printf("  white_pixel...: %" PRIu32 "\n", screen->white_pixel);
  printf("  black pixel...: %" PRIu32 "\n", screen->black_pixel);
  printf("\n");

  return 0;
}
コード例 #10
0
xcb_window_t LinuxWindowCapture::FindWindow( const QString& instanceName, const QString& windowClass ) {

  xcb_window_t window = static_cast< xcb_window_t > ( 0 );
  xcb_connection_t* dpy = xcb_connect( NULL, NULL );
  if ( xcb_connection_has_error( dpy ) ) { qDebug() << "Can't open display"; }

  xcb_screen_t* screen = xcb_setup_roots_iterator( xcb_get_setup( dpy ) ).data;
  if( !screen ) { qDebug() << "Can't acquire screen"; }

  xcb_window_t root = screen->root;
  QList< xcb_window_t > windows = listWindowsRecursive( dpy, root );

  foreach( const xcb_window_t& win, windows ) {

    xcb_icccm_get_wm_class_reply_t wmNameR;
    xcb_get_property_cookie_t wmClassC = xcb_icccm_get_wm_class( dpy, win );
    if ( xcb_icccm_get_wm_class_reply( dpy, wmClassC, &wmNameR, NULL ) ) {

      if( !qstrcmp( wmNameR.class_name, windowClass.toStdString().c_str() ) ||
          !qstrcmp( wmNameR.instance_name, instanceName.toStdString().c_str() ) ) {
          qDebug() << wmNameR.instance_name;
          qDebug() << wmNameR.class_name;
          window = win;
          break;
      }
    }

  }
コード例 #11
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;
}
コード例 #12
0
ファイル: xcb_image_viewer.c プロジェクト: technosaurus/stb
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;
コード例 #13
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;
}
コード例 #14
0
ファイル: X11IdleDetector.cpp プロジェクト: KDAB/Charm
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;
}
コード例 #15
0
xcb_connection_t *X11Info::xcbConnection()
{
    if (!_xcb) {
        _xcb = xcb_connect(NULL, &_xcbPreferredScreen);
        Q_ASSERT(_xcb);
    }
    return _xcb;
}
コード例 #16
0
int main(int argc, char **argv) {
    uint32_t width = test_width - 2 * INSET_X;
    uint32_t height = test_height - 2 * INSET_Y;
    int snum;
    xcb_void_cookie_t check_cookie;
    xcb_window_t w;
    xcb_gcontext_t gc;
    xcb_pixmap_t pix;
    xcb_connection_t *c = xcb_connect(0, &snum);
    xcb_screen_t *s = xcb_aux_get_screen(c, snum);
    xcb_alloc_named_color_cookie_t bg_cookie =
	xcb_alloc_named_color(c, s->default_colormap,
			      strlen("white"), "white");
    xcb_alloc_named_color_cookie_t fg_cookie =
	xcb_alloc_named_color(c, s->default_colormap,
			      strlen("black"), "black");
    xcb_alloc_named_color_reply_t *bg_reply =
	xcb_alloc_named_color_reply(c, bg_cookie, 0);
    xcb_alloc_named_color_reply_t *fg_reply =
	xcb_alloc_named_color_reply(c, fg_cookie, 0);
    uint32_t fg, bg;
    xcb_image_t *image, *native_image, *subimage;
    uint32_t mask = 0;
    xcb_params_gc_t gcv;

    assert(bg_reply && fg_reply);
    bg = bg_reply->pixel;
    fg = fg_reply->pixel;
    free(bg_reply);
    free(fg_reply);
    w = make_window(c, s, bg, fg, width, height);
    gc = xcb_generate_id(c);
    check_cookie = xcb_create_gc_checked(c, gc, w, 0, 0);
    assert(!xcb_request_check(c, check_cookie));
    image = xcb_image_create_from_bitmap_data((uint8_t *)test_bits,
					      test_width, test_height);
    native_image = xcb_image_native(c, image, 1);
    assert(native_image);
    if (native_image != image)
	xcb_image_destroy(image);
    subimage = xcb_image_subimage(native_image, INSET_X, INSET_Y,
				  width, height,
				  0, 0, 0);
    assert(subimage);
    xcb_image_destroy(native_image);
    subimage->format = XCB_IMAGE_FORMAT_XY_BITMAP;
    pix = xcb_generate_id(c);
    xcb_create_pixmap(c, s->root_depth, pix, w,
		      subimage->width, subimage->height);
    gc = xcb_generate_id(c);
    XCB_AUX_ADD_PARAM(&mask, &gcv, foreground, fg);
    XCB_AUX_ADD_PARAM(&mask, &gcv, background, bg);
    xcb_aux_create_gc(c, gc, pix, mask, &gcv);
    xcb_image_put(c, pix, gc, subimage, 0, 0, 0);
    process_events(c, gc, w, pix, width, height);
    xcb_disconnect(c);
    return 1;
}
コード例 #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);
}
コード例 #18
0
ファイル: iterate_screens.cpp プロジェクト: amezin/xcb-cpp
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;
}
コード例 #19
0
ファイル: xcb.c プロジェクト: 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;
}
コード例 #20
0
ファイル: DisplayVkXcb.cpp プロジェクト: luke-chang/gecko-1
egl::Error DisplayVkXcb::initialize(egl::Display *display)
{
    mXcbConnection = xcb_connect(nullptr, nullptr);
    if (mXcbConnection == nullptr)
    {
        return egl::EglNotInitialized();
    }
    return DisplayVk::initialize(display);
}
コード例 #21
0
ファイル: leaf.c プロジェクト: 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;
}
コード例 #22
0
ファイル: grabkeys.c プロジェクト: OpenInkpot-archive/uk
int run(config_t* config, key_handler_t key_handler)
{
    int default_screen;
    xcb_connection_t* c = xcb_connect(NULL, &default_screen);

    if(xcb_connection_has_error(c))
    {
		fprintf(stderr, "Cannot open display %s\n",
                getenv("DISPLAY") ? getenv("DISPLAY") : "<NULL>");
        return -1;
    }
    xcb_screen_t* screen;
    if(!(screen = xcb_aux_get_screen(c, default_screen)))
    {
        fprintf(stderr, "Cannot obtain default screen.\n");
        return -1;
    }

    context_t context = { config, key_handler };

    xcb_event_handlers_t eh;
    memset(&eh, 0, sizeof(xcb_event_handlers_t));
    xcb_event_handlers_init(c, &eh);
    xcb_event_set_key_press_handler(&eh, handle_keypress, &context);

    xcb_void_cookie_t* cookies = alloca(sizeof(xcb_void_cookie_t)
                                             * config->count);
    if(!cookies)
        return -1;

    int i;
    for(i = 0; i < config->count; ++i)
        cookies[i] = xcb_grab_key(c, true, screen->root,
                                  config->keys[i].is_alt ? XCB_MOD_MASK_1 : 0,
                                  config->keys[i].keysym, XCB_GRAB_MODE_ASYNC,
                                  XCB_GRAB_MODE_ASYNC);

    for(i = 0; i < config->count; ++i)
    {
        xcb_generic_error_t* e = xcb_request_check(c, cookies[i]);
        if(e)
        {
            fprintf(stderr, "WARNING: unable to grab key: %d\n", e->error_code);
            free(e);
        }
    }

    xcb_generic_event_t* e;
    while((e = xcb_wait_for_event(c)))
    {
        xcb_event_handle(&eh, e);
        free(e);
    }

    return 0;
}
コード例 #23
0
static void setup(void) {
    int screennr;
    conn = xcb_connect(NULL, &screennr);
    if (xcb_connection_has_error(conn)) {
        fprintf(stderr, "Failed to connect to X11 server.\n");
        exit(EXIT_FAILURE);
    }

    screen = xcb_aux_get_screen(conn, 0);
}
コード例 #24
0
ファイル: watcher.cpp プロジェクト: gpocentek/qslsaver
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();
}
コード例 #25
0
ファイル: towel.c プロジェクト: kanru/towel
int
main(int argc, char *argv[])
{
  /* TODO: Accept DISPLAY environment or --display arguments */
  xcb_connection_t *conn = xcb_connect(NULL, NULL);
  towel_window_t *win = NULL;

  for (;;) {
    if (win == NULL) {
      win = towel_create_window(conn);
      towel_window_hide_cursor(win);
    }
    sleep(CHECK_PERIOD);
    towel_window_update_working_time(win, CHECK_PERIOD);
    if (win->idle_time > REST_TIME)
      win->working_time = 0;

    /* TODO: option processing */
    if (win->working_time > WORKING_TIME) {
      time_t prev = time(NULL);
      towel_window_map(win);
      xcb_flush(conn);
      for (;;) {
        xcb_generic_event_t *event = xcb_wait_for_event(conn);
        if ((event->response_type & ~0x80) == XCB_EXPOSE) {
#if !DEBUG
          towel_window_grab_input(win);
#endif
          towel_window_render_time(win, REST_TIME);
          xcb_flush(conn);
          break;
        }
        free(event);
      }
      for (;;) {
        int delta = time(NULL) - prev;
        towel_window_render_time(win, REST_TIME - delta);
        xcb_flush(conn);
        if (delta >= REST_TIME) {
          towel_window_unmap(win);
          towel_window_destroy(win);
          win = NULL;
          xcb_flush(conn);
          break;
        }
        sleep(1);
      }
    }
  }

  if (win)
    towel_window_destroy(win);
  xcb_disconnect(conn);
  return EXIT_SUCCESS;
}
コード例 #26
0
ファイル: pixmap.c プロジェクト: tossu/xcb-fun
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;
}
コード例 #27
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();
}
コード例 #28
0
ファイル: pipe_loader_drm.c プロジェクト: Gnurou/mesa
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
}
コード例 #29
0
ファイル: cawc.c プロジェクト: Roger/caw
static PyObject * _xcb_connect(PyObject *self, PyObject *args)
{
    xcb_connection_t *connection;
    /*
    if (!PyArg_ParseTuple(args, "ls", &panel, &font))
        return NULL;
        */
    connection = xcb_connect(0, 0);
    _init_atoms(connection);
    return Py_BuildValue("l", connection);
}
コード例 #30
0
ファイル: main.c プロジェクト: imwally/tabover
int
init_xcb(xcb_connection_t **con)
{
    *con = xcb_connect(NULL, NULL);
    
    if (xcb_connection_has_error(*con)) {
	perror("unable to connect to the X server");
	return -1;
    }

    return 0;
}