[Xcb] problem with xcb_image

Vincent Torri vtorri at univ-evry.fr
Thu Jul 3 12:48:14 PDT 2008


Hey,

as it seems that some xcb devs are answering the mails today, i'm trying 
to send again that mail.

First there was a little bug in the test i sent. So here is another one. 
It should fill an image with 0 and put it in the window. Nothing is done. 
See the prog in attach

Does someone see the problem ?

thank you

Vincent

On Fri, 27 Jun 2008, Vincent Torri wrote:

>
> Hey
>
> that mail is more for Bart than anyone else. I still have a lot of problems 
> with xcb_image, as the api is far from being easy to use (imho).
>
> I've attached a test that creates a window and writes stuff in it.
>
> Right now it displays nothing. Where is (are) my bug(s) ? I need it to fix 
> xcb engine of evas
>
> thanks
>
> Vincent
-------------- next part --------------
/* gcc -g -Wall -o xcb_image_test xcb_image_test.c `pkg-config --cflags --libs xcb xcb-image xcb-keysyms` */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_keysyms.h>

int win_w = 320;
int win_h = 200;

void
draw_image(xcb_connection_t *conn, xcb_screen_t *screen, xcb_window_t win, xcb_gcontext_t gc)
{
  int *data;
  xcb_image_t *image;

  image = xcb_image_create_native(conn, win_w, win_h,
                                  XCB_IMAGE_FORMAT_Z_PIXMAP,
                                  screen->root_depth, NULL, ~0, NULL);

  printf ("depth : %d\n", screen->root_depth);
  printf ("size   : %d %d %d\n", image->size, win_w * win_h * 3, win_w * win_h * 4);
  printf ("stride : %d %d\n", image->stride, win_w * 4);
  data = malloc(image->size);
  memset(data, 0, image->size);
  image->data = data;
  xcb_image_put(conn, win, gc,
                image,
                0, 0,
                0);

/*   xcb_image_destroy(image); */
}

int main()
{
  uint32_t                       value_list[6];
  xcb_screen_iterator_t          iter;
  uint32_t                       value_mask;
  xcb_connection_t *conn = NULL;
  xcb_screen_t     *screen = NULL;
  xcb_window_t      win = 0;
  xcb_gcontext_t gc;
  xcb_drawable_t      rect;
  int                            s;

  conn = xcb_connect(NULL, &s);
  if (!conn) return 0;

  iter = xcb_setup_roots_iterator(xcb_get_setup(conn));
  for (; iter.rem; --s, xcb_screen_next (&iter))
    if (s == 0)
      {
        screen = iter.data;
        break;
      }

  gc = xcb_generate_id(conn);
  xcb_create_gc(conn, gc, win, 0, NULL);

  value_mask =
    XCB_CW_BACK_PIXMAP   | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY       |
    XCB_CW_BACKING_STORE | XCB_CW_EVENT_MASK   | XCB_CW_COLORMAP;

  value_list[0]  = XCB_NONE;
  value_list[1]  = 0;
  value_list[2]  = XCB_GRAVITY_BIT_FORGET;
  value_list[3]  = XCB_BACKING_STORE_NOT_USEFUL;
  value_list[4]  =
    XCB_EVENT_MASK_KEY_PRESS       | XCB_EVENT_MASK_KEY_RELEASE      |
    XCB_EVENT_MASK_BUTTON_PRESS    | XCB_EVENT_MASK_BUTTON_RELEASE   |
    XCB_EVENT_MASK_ENTER_WINDOW    | XCB_EVENT_MASK_LEAVE_WINDOW     |
    XCB_EVENT_MASK_POINTER_MOTION  | XCB_EVENT_MASK_EXPOSURE         |
    XCB_EVENT_MASK_STRUCTURE_NOTIFY;
  value_list[5]  = screen->default_colormap;

  win = xcb_generate_id(conn);
  xcb_create_window(conn,
                    screen->root_depth,
                    win, screen->root, 0, 0, win_w, win_h, 0,
                    XCB_WINDOW_CLASS_INPUT_OUTPUT,
                    screen->root_visual,
                    value_mask,
                    value_list);

  xcb_rectangle_t rect_coord = { 0, 0, win_w, win_h};
  rect = xcb_generate_id (conn);
  xcb_create_pixmap(conn, screen->root_depth, rect, win, win_w, win_h);
  xcb_poly_fill_rectangle(conn, rect, gc, 1, &rect_coord);

  xcb_map_window(conn, win);

  free(xcb_get_input_focus_reply(conn, xcb_get_input_focus_unchecked(conn), NULL));

  while (1) {
   xcb_generic_event_t *ev;

   ev = xcb_poll_for_event(conn);
   if (!ev) continue;

    switch (ev->response_type)
      {
      case XCB_BUTTON_PRESS:
        {
          xcb_button_press_event_t *e;

          e = (xcb_button_press_event_t *)ev;
          printf ("XCB_BUTTON_PRESS\n");
          free(ev);
          goto gogo;
        }
      case XCB_BUTTON_RELEASE:
        {
          xcb_button_release_event_t *e;

          e = (xcb_button_release_event_t *)ev;
          printf ("XCB_BUTTON_RELEASE\n");
          break;
        }
      case XCB_MOTION_NOTIFY:
        {
          xcb_motion_notify_event_t *e;

          e = (xcb_motion_notify_event_t *)ev;
          printf ("XCB_MOTION_NOTIFY\n");
          break;
        }
      case XCB_EXPOSE:
        {
          xcb_expose_event_t *e;

          e = (xcb_expose_event_t *)ev;
          printf ("XCB_EXPOSE\n");

          xcb_copy_area(conn, rect, win, gc,
			0, 0, 0, 0, win_w, win_h);
          draw_image(conn, screen, rect, gc);
          free(xcb_get_input_focus_reply(conn, xcb_get_input_focus_unchecked(conn), NULL));
/*           xcb_flush (conn); */
          break;
        }
      case XCB_CONFIGURE_NOTIFY:
        {
          xcb_configure_notify_event_t *e;

          e = (xcb_configure_notify_event_t *)ev;
          printf ("XCB_CONFIGURE_NOTIFY\n");
          break;
        }
      case XCB_ENTER_NOTIFY:
        printf ("XCB_ENTER_NOTIFY\n");
        break;
      case XCB_LEAVE_NOTIFY:
        printf ("XCB_LEAVE_NOTIFY\n");
        break;
      case XCB_KEY_PRESS:
        {
          xcb_key_press_event_t *e;
          xcb_key_symbols_t *kss;
          xcb_keysym_t       ks;

          e = (xcb_key_press_event_t *)ev;
          printf ("XCB_KEY_PRESS\n");

          kss = xcb_key_symbols_alloc(conn);

          ks = xcb_key_symbols_get_keysym(kss, e->detail, 0);
          xcb_key_symbols_free(kss);
          break;
        }
      case XCB_KEY_RELEASE:
        {
          xcb_key_release_event_t *e;
          xcb_key_symbols_t       *kss;
          xcb_keysym_t             ks;
          xcb_keycode_t            kc;

          e = (xcb_key_release_event_t *)ev;
          printf ("XCB_KEY_RELEASE\n");

          kss = xcb_key_symbols_alloc(conn);

          ks = xcb_key_symbols_get_keysym(kss, e->detail, 0);
          kc = xcb_key_symbols_get_keycode(kss, ks);
          printf ("%d\n", kc);
          xcb_key_symbols_free(kss);
          break;
        }
      default:
        break;
      }
    free(ev);
  }

 gogo:
  xcb_disconnect(conn);

  return 0;
}


More information about the Xcb mailing list