38#include <X11/extensions/dpms.h>
40class jevois::VideoDisplayBackendX11::Impl
44 Display *itsX11display =
nullptr;
49jevois::VideoDisplayBackendX11::VideoDisplayBackendX11() :
50 jevois::VideoDisplayBackend(), pimpl(new Impl)
54jevois::VideoDisplayBackendX11::~VideoDisplayBackendX11()
61void jevois::VideoDisplayBackendX11::init(
unsigned short w,
unsigned short h,
bool fullscreen)
64 pimpl->itsX11display = XOpenDisplay(NULL);
65 if (pimpl->itsX11display ==
nullptr)
LFATAL(
"Cannot open X11 display");
68 Window win_root = DefaultRootWindow(pimpl->itsX11display);
71 XSetWindowAttributes xattr { };
72 xattr.override_redirect =
false;
75 xattr.event_mask = ExposureMask | KeyPressMask;
78 xattr.background_pixel = XWhitePixel(pimpl->itsX11display, XDefaultScreen(pimpl->itsX11display));
81 pimpl->itsWindow = XCreateWindow(pimpl->itsX11display, win_root, 0, 0, w,
h, 0,
82 CopyFromParent, InputOutput, CopyFromParent,
83 CWOverrideRedirect | CWEventMask | CWBackPixel, &xattr);
86 XSetStandardProperties(pimpl->itsX11display, pimpl->itsWindow, itsName.c_str(), itsName.c_str(), None, NULL, 0, NULL);
89 DPMSDisable(pimpl->itsX11display);
92 XClearWindow(pimpl->itsX11display, pimpl->itsWindow);
93 XMapRaised (pimpl->itsX11display, pimpl->itsWindow);
99 Atom wm_state = XInternAtom(pimpl->itsX11display,
"_NET_WM_STATE",
false);
100 Atom fs = XInternAtom(pimpl->itsX11display,
"_NET_WM_STATE_FULLSCREEN",
false);
103 fs_event.type = ClientMessage;
104 fs_event.xclient.window = pimpl->itsWindow;
105 fs_event.xclient.message_type = wm_state;
106 fs_event.xclient.format = 32;
107 fs_event.xclient.data.l[0] = 1;
108 fs_event.xclient.data.l[1] = fs;
109 fs_event.xclient.data.l[2] = 0;
111 XSendEvent(pimpl->itsX11display, win_root,
false, SubstructureRedirectMask | SubstructureNotifyMask, &fs_event);
119void jevois::VideoDisplayBackendX11::uninit()
121 if (pimpl->itsX11display)
124 DPMSEnable(pimpl->itsX11display);
127 if (pimpl->itsWindow) { XDestroyWindow(pimpl->itsX11display, pimpl->itsWindow); pimpl->itsWindow = 0; }
128 XCloseDisplay(pimpl->itsX11display); pimpl->itsX11display =
nullptr;
136bool jevois::VideoDisplayBackendX11::pollEvents(
bool & shouldclose)
139 bool gotsome =
false;
142 while (XPending(pimpl->itsX11display))
146 XNextEvent(pimpl->itsX11display, &event);
156 char text[11]; KeySym key_press;
157 int keys = XLookupString(&event.xkey, text, 10, &key_press, 0);
158 if (keys == 1 && text[0] ==
'q') shouldclose =
true;
virtual void uninit()
Un-initialize the underlying engine, close windows, etc.
virtual void init(unsigned short w, unsigned short h, bool fullscreen=false)=0
Initialize the underlying engine that will process events, create windows, etc.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Main namespace for all JeVois classes and functions.