Evas and X11 example

440 views Asked by At

I am trying to write a little application in order to understand how evas works with X11. I haven't find a full example in the documentation only some parts that I try to use. Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <Evas.h>
#include <Evas_Engine_Software_X11.h>

/*
gcc -o evas_software_x11 evas_software_x11.c $(pkg-config --libs --cflags x11 evas)
*/

#define WIDTH 640
#define HEIGHT 480

int main(int argc, char **argv)
{
  Evas *canevas;
  Evas_Engine_Info_Software_X11 *einfo;
  Display * display;
  Window win;
  display = XOpenDisplay(NULL);
  int s;
  XEvent e;
  s = DefaultScreen(display);
  win = XCreateSimpleWindow(  display,
                              RootWindow(display, s),
                              10,10,WIDTH,HEIGHT,1,
                              BlackPixel(display, s),
                              WhitePixel(display, s));

  XSelectInput(display, win, ExposureMask | KeyPressMask);                            

  evas_init();
  /*Création et configuration du canevas*/
  canevas = evas_new();
  evas_output_method_set(canevas, evas_render_method_lookup("software_x11"));
  evas_output_size_set(canevas, WIDTH, HEIGHT);
  evas_output_viewport_set(canevas, 0, 0, WIDTH, HEIGHT);
  einfo = NULL;
  einfo = (Evas_Engine_Info_Software_X11 *) evas_engine_info_get(canevas);
  if(!einfo)
  {
    printf("einfo not valide\n");
    exit(EXIT_FAILURE);
  }
  einfo->info.display = display;
  einfo->info.visual = DefaultVisual(display, DefaultScreen(display));
  einfo->info.colormap = DefaultColormap(display, DefaultScreen(display));
  einfo->info.drawable = win;
  einfo->info.depth = DefaultDepth(display, DefaultScreen(display));
  evas_engine_info_set(canevas, (Evas_Engine_Info *) einfo);

  /*Création d'un fond et d'un rectangle pour l'exemple*/
  Evas_Object * bg, *rect;

  bg = evas_object_rectangle_add(canevas);
  evas_object_move(bg, 0, 0);
  evas_object_resize(bg, WIDTH, HEIGHT);
  evas_object_color_set(bg, 0, 128, 0, 128); // 50% opaque vert
  eavs_object_show(bg);

  rect = evas_object_rectangle_add(canevas);
  evas_object_move(rect, 20, 20);
  evas_object_resize(rect, 100, 100);
  evas_object_color_set(rect, 255, 0, 0, 255); // opaque rouge
  eavs_object_show(rect);


  evas_render(canevas);
  while(1) {
    XnextEvent(display, &e);
    if (e.type == Expose)
    {

    }
    if (e.type == KeyPress)
      break;
  }
  evas_free(canevas);
  evas_shutdown();

  XCloseDisplay(d);
  return EXIT_SUCCESS;
}

When I compile it I have this error:

gcc -o evas_software_x11 evas_software_x11.c $(pkg-config --libs --cflags evas x11) 
evas_software_x11.c: In function ‘main’:
evas_software_x11.c:45:14: erreur: ‘struct <anonymous>’ has no member named ‘display’
einfo->info.display = display;
          ^

But the part einfo->info.display = display comes from the official documentation :

https://build.enlightenment.org/job/nightly_efl_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/group__Evas__Output__Method.html#details

Any idea on where I have done an error?

1

There are 1 answers

0
cedlemo On

The documentation is not up to date.

The info structure have a member named connection instead of display ( see file Evas_Engine_Software_X11.h and http://lists.enlightenment.fr/enlightenment-devel/att-27663/expedite_merge_1.diff ).