-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdisplays.c
41 lines (37 loc) · 1.09 KB
/
xdisplays.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Simple Xdisplay program to use x11
* Requires compiling with -lX11
*
* On AlmaLinux this requires install libX11-devel Library
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main(int argc, char** argv)
{
Display *dpy = XOpenDisplay(None);
int screen = DefaultScreen(dpy);
int blackColor = BlackPixel(dpy, screen);
int whiteColor = WhitePixel(dpy, screen);
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 200, 600, 500, 500, 0 , blackColor, blackColor);
XSelectInput(dpy, w, StructureNotifyMask);
XMapWindow(dpy, w);
XFlush(dpy);
for (;;){
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify) break;
}
sleep(1);
GC gc = XCreateGC(dpy, w, 0, 0);
XSetForeground(dpy, gc, whiteColor);
XDrawLine(dpy, w, gc, 10, 10, 200, 20);
XDrawRectangle(dpy, w, gc, 30, 200, 100, 200);
XDrawRectangle(dpy, w, gc, 200, 200, 100, 200);
XDrawString(dpy, w, gc, 35, 300, "Hello X world", 13);
XFlush(dpy);
sleep(10);
return (EXIT_SUCCESS);
}