OGLplus  (0.59.0) a C++ wrapper for rendering APIs

window.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_INTEROP_X11_WINDOW_HPP
10 #define EAGINE_INTEROP_X11_WINDOW_HPP
11 
12 #include "color_map.hpp"
13 #include "display.hpp"
14 #include "visual_info.hpp"
15 
16 #include <X11/Xlib.h>
17 #include <cassert>
18 #include <stdexcept>
19 
20 namespace eagine::x11 {
21 
22 class window : public display_object<::Window> {
23 private:
24  static auto make_window(
25  const display& dpy,
26  const visual_info& vi,
27  const colormap& cmap,
28  int pos_x,
29  int pos_y,
30  unsigned width,
31  unsigned height) -> ::Window {
32  ::XSetWindowAttributes swa;
33  swa.colormap = cmap.handle();
34  swa.background_pixmap = None;
35  swa.border_pixel = 0;
36  // NOLINTNEXTLINE(hicpp-signed-bitwise)
37  swa.event_mask = StructureNotifyMask;
38 
39  return ::XCreateWindow(
40  dpy,
41  RootWindow(dpy.get(), vi->screen),
42  pos_x,
43  pos_y,
44  width,
45  height,
46  0,
47  vi->depth,
48  InputOutput,
49  vi->visual,
50  // NOLINTNEXTLINE(hicpp-signed-bitwise)
51  CWBorderPixel | CWColormap | CWEventMask,
52  &swa);
53  }
54 
55 public:
56  window(
57  const display& dpy,
58  const visual_info& vi,
59  const colormap& cmap,
60  const char* title,
61  int pos_x,
62  int pos_y,
63  unsigned width,
64  unsigned height)
65  : display_object<::Window>(
66  dpy,
67  make_window(dpy, vi, cmap, pos_x, pos_y, width, height),
68  ::XDestroyWindow,
69  "Error creating X Window") {
70  ::XSizeHints size_hints;
71  size_hints.width = int(width);
72  size_hints.height = int(height);
73  // NOLINTNEXTLINE(hicpp-signed-bitwise)
74  size_hints.flags = USSize;
75  ::XSetNormalHints(dpy, this->handle(), &size_hints);
76 
77  ::Atom wmDelete = ::XInternAtom(dpy, "WM_DELETE_WINDOW", True);
78  ::XSetWMProtocols(dpy, this->handle(), &wmDelete, 1);
79 
80  ::XStoreName(dpy, this->handle(), title);
81  ::XMapWindow(dpy, this->handle());
82  }
83 
84  void select_input(long event_mask) const {
85  ::XSelectInput(this->display_ref(), this->handle(), event_mask);
86  }
87 };
88 
89 } // namespace eagine::x11
90 
91 #endif
X11 wrapper code is placed in this namespace.
Definition: x11.hpp:11
Definition: color_map.hpp:20

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).