C Make a desktop screenshot with only libx11-dev ?

Hello,

Wanted to test Ubuntu for hardware testing reason. On my Ubuntu Live testing pendrive, I face the issue that scrot is not available on the repository.


Luckily in Wayland, there is still libx11-dev. I want to use the simple C programme to be free, totally free, using libx11-dev.

Would you have a small programme in C that would simply use libx11-dev to make a screenshot of the desktop?

thank you very much
 
Indicated LibX11.

Libx11 is a library for FreeBSD, LInux, Unix,...
https://www.freebsd.org/cgi/ports.cgi?query=libx11&stype=all

This library allows to compile for instance C or C++ programmes.

Herewith a nice example of applications, which might run well on FreeBSD:

I could give an example of running hello world using libX11 on FreeBSD.
This example allows to popup a message on the graphical environment, which is made available by the fantastic library X11.

Code:
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/types.h>
#include <unistd.h>  
#include <time.h>  
int main( int argc, char *argv[])
{

    ////////////////////////////////////////////////////////
    if ( argc == 2)
      if ( strcmp( argv[1] , "" ) !=  0 ) 
      {

   Display *d;
   Window w;
   XEvent e;
   char *msg = "";
   char cmdi[ PATH_MAX ]; 
   int s;

      strncpy( cmdi , "" , PATH_MAX);
      strncat( cmdi , strtimenow() , PATH_MAX - strlen( cmdi ) - 1);
      strncat( cmdi , " " , PATH_MAX - strlen( cmdi ) - 1);
      strncat( cmdi , argv[ 1 ], PATH_MAX - strlen( cmdi ) - 1);
      strncat( cmdi , " " , PATH_MAX - strlen( cmdi ) - 1);

   int WINWIDTH = strlen( cmdi ) * 9;

   d = XOpenDisplay(NULL);
   if (d == NULL) {
      fprintf(stderr, "Cannot open display\n");
      exit(1);
   }

   s = DefaultScreen(d);
   w = XCreateSimpleWindow(d, RootWindow(d, s), 0, 0, WINWIDTH , 20, 1, BlackPixel(d, s), WhitePixel(d, s));
   XStoreName( d , w , "nxmessage");
   XSelectInput(d, w, ExposureMask | KeyPressMask);
   XMapWindow(d, w);
   XMoveResizeWindow(d, w , 2 , 2 ,  WINWIDTH  , 20 );
   XRaiseWindow(d , w );
   {
      XNextEvent(d, &e);
      if (e.type == Expose) 
      {
    {
           XClearWindow(d, w);
           XDrawString(d, w, DefaultGC(d, s), 5, 10, cmdi , strlen( cmdi ));
           XFlush( d );
      usleep( 10000e2 );
    }
      }
   }
         XCloseDisplay(d);
         return 0;
      }
   return 0;
}

X11 is great.

X11 has been there on Unix platforms since a very long time. X11 was firstly designed at MIT.
Cool thing since it replaced the earliest W graphical environment which originated from Bell Labs.

X11 has been there since a long time.

In US, where earliest version of UNIX took developments, research allowed to make huge progresses.
LibX11 found a name, place and can allow many things.

One of them is to make a screenshot using it. LibX11.

One of them - One of thousand possibilitiies with X11, including Screenshots.

Fantastic Possibilities, no?
 
Back
Top