cancel
Showing results for 
Search instead for 
Did you mean: 

Xlib: I can not connect to the X server

AShva.1
Associate II

Hi!

I'm in search of a better GUI programming path :) Now trying Xlib.

Here is a simple program from the Internet

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <errno.h>

#include <X11/Xlib.h>

extern int errno;

int main( void ) {

  Display *d;

  Window w;

  XEvent e;

  char *msg = "Hello, World!";

  int s;

  if( ( d = XOpenDisplay( getenv("DISPLAY" ) ) ) == NULL )

  { // Connect X server

     printf( "Can't connect X server: %s\n", strerror( errno ) );

     exit( 1 );

  }

  s = DefaultScreen( d );

  w = XCreateSimpleWindow( d, RootWindow( d, s ), 10, 10, 200, 200, 1, BlackPixel( d, s ), WhitePixel( d, s ) );

  XSelectInput( d, w, ExposureMask | KeyPressMask ); 

  XMapWindow( d, w );                                

  while( 1 )

  {                                       

     XNextEvent( d, &e );

     if( e.type == Expose )

     {                        

        XFillRectangle( d, w, DefaultGC( d, s ), 20, 20, 10, 10 );

        XDrawString( d, w, DefaultGC( d, s ), 50, 50, msg, strlen( msg ) );

     }

     if( e.type == KeyPress ) break;

  }

  XCloseDisplay( d );                                

  return 0;

}

If you build and run on PC Ubuntu - it works fine

On the STM32MP157C-DK2 board - not working :(

Message in terminal:

Can't connect X server: Success

What am I doing wrong?

Best regards

Alexander

1 ACCEPTED SOLUTION

Accepted Solutions
mleo
Senior II

Hi Alexander,

Do you use the default distibution?

If yes, it is based on Wayland (not X11).

If you want to create one based on X11:

https://wiki.st.com/stm32mpu/wiki/How_to_create_your_own_image

BR,

Milan

View solution in original post

2 REPLIES 2
mleo
Senior II

Hi Alexander,

Do you use the default distibution?

If yes, it is based on Wayland (not X11).

If you want to create one based on X11:

https://wiki.st.com/stm32mpu/wiki/How_to_create_your_own_image

BR,

Milan

AShva.1
Associate II

Hi Milan!

Thanks.

I understood.

I use the default distibution.

I will try to understand further :)

Best regards!