g4tools  5.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::X11::session Class Reference
Inheritance diagram for tools::X11::session:
Inheritance graph
[legend]
Collaboration diagram for tools::X11::session:
Collaboration graph
[legend]

Public Member Functions

 session (std::ostream &a_out, unsigned int a_monitor=0)
 
virtual ~session ()
 
GLXContext context () const
 
Window create_window (const char *a_title, int a_x, int a_y, unsigned int a_width, unsigned int a_height)
 
- Public Member Functions inherited from tools::X11::base_session
 base_session (std::ostream &a_out, unsigned int a_monitor=0)
 
virtual ~base_session ()
 
std::ostream & out () const
 
Atom WM_DELETE_WINDOW_atom () const
 
Atom SESSION_EXIT_STEER_atom () const
 
bool is_valid () const
 
Display * display () const
 
bool steer ()
 
bool sync ()
 
bool event_pending (bool &a_is)
 
bool next_event (bool &a_to_exit)
 
bool flush ()
 
Window create_window (const char *a_title, int a_x, int a_y, unsigned int a_width, unsigned int a_height)
 
void map_raise_window (Window a_window) const
 
void show_window (Window a_window) const
 
void hide_window (Window a_window) const
 
void resize_window (Window a_window, unsigned int a_width, unsigned int a_height) const
 
bool window_size (Window a_window, int &a_width, int &a_height) const
 
void delete_window (Window a_window) const
 
void set_override_redirect (Window a_window) const
 
void set_wm_no_decorations (Window a_window) const
 
bool post (Window a_win, long a_0=0, long a_1=0, long a_2=0, long a_3=0, long a_4=0) const
 
bool post_EXIT_STEER (Window a_win)
 
void add_dispatcher (dispatcher *a_dispatcher)
 
void invalidate_dispatchers_with_window (Window a_win)
 
void remove_dispatchers_with_window (Window a_win)
 
bool dispatch (XEvent &a_event)
 

Protected Member Functions

 session (const session &a_from)
 
sessionoperator= (const session &a_from)
 
- Protected Member Functions inherited from tools::X11::base_session
 base_session (const base_session &a_from)
 
base_sessionoperator= (const base_session &a_from)
 
void clear_dispatchers ()
 

Protected Attributes

XVisualInfo * m_vinfo
 
GLXContext m_ctx
 
Colormap m_colormap
 
- Protected Attributes inherited from tools::X11::base_session
std::ostream & m_out
 
unsigned int m_monitor
 
Display * m_display
 
Atom m_WM_DELETE_WINDOW_atom
 
Atom m_SESSION_EXIT_STEER_atom
 
std::vector< dispatcher * > m_dispatchers
 

Additional Inherited Members

- Static Protected Member Functions inherited from tools::X11::base_session
static Bool wait_map_notify (Display *, XEvent *a_event, char *a_arg)
 
static Bool wait_unmap_notify (Display *, XEvent *a_event, char *a_arg)
 

Detailed Description

Definition at line 14 of file session.

Constructor & Destructor Documentation

◆ session() [1/2]

tools::X11::session::session ( std::ostream &  a_out,
unsigned int  a_monitor = 0 
)
inline

Definition at line 31 of file session.

32  :parent(a_out,a_monitor)
33  ,m_vinfo(0)
34  ,m_ctx(0)
35  ,m_colormap(0)
36  {
37  if(!m_display) return;
38 
39  {int glxMajor, glxMinor;
40  ::glXQueryVersion(m_display,&glxMajor,&glxMinor);
41  if(glxMajor<=0) {
42  m_out << "tools::X11::session::session : bad GLX-Version " << glxMajor << "." << glxMinor << std::endl;
43  ::XCloseDisplay(m_display);
44  m_display = 0;
45  m_vinfo = 0;
46  m_ctx = 0;
47  return;
48  }}
49 
50  static const int atbs_alpha[] = {
51  GLX_RGBA,
52  GLX_RED_SIZE, 1,
53  GLX_GREEN_SIZE, 1,
54  GLX_BLUE_SIZE, 1,
55  GLX_ALPHA_SIZE, 1,
56  GLX_DEPTH_SIZE, 1,
57  GLX_DOUBLEBUFFER,
58  None};
59 
60  //NOTE : macOS : glXChooseVisual leaks 640 bytes.
61  m_vinfo = ::glXChooseVisual(m_display,m_monitor,(int*)atbs_alpha);
62  if(!m_vinfo) {
63  //m_out << "tools::X11::session::initialize :"
64  // << " can't get a visual with alpha on screen " << m_monitor << ". Try without alpha..."
65  // << std::endl;
66  //m_out << "tools::X11::session::initialize :"
67  // << " DefaultScreen(m_display): " << DefaultScreen(m_display) << "."
68  // << std::endl;
69 
70  static const int atbs[] = {
71  GLX_RGBA,
72  GLX_RED_SIZE, 1,
73  GLX_GREEN_SIZE, 1,
74  GLX_BLUE_SIZE, 1,
75  GLX_DEPTH_SIZE, 1,
76  GLX_DOUBLEBUFFER,
77  None};
78 
79  m_vinfo = ::glXChooseVisual(m_display,m_monitor,(int*)atbs);
80  if(!m_vinfo) {
81  m_out << "tools::X11::session::session :"
82  << " can't choose a visual on screen " << m_monitor << "."
83  << std::endl;
84  ::XCloseDisplay(m_display);
85  m_display = 0;
86  m_vinfo = 0;
87  m_ctx = 0;
88  return;
89  }
90  }
91 
92  m_ctx = ::glXCreateContext(m_display,m_vinfo,NULL,GL_TRUE);
93  if(!m_ctx) {
94  m_out << "tools::X11::session::session :"
95  << " can't create a glX context with direct rendering."
96  << std::endl;
97  m_ctx = ::glXCreateContext(m_display,m_vinfo,NULL,GL_FALSE);
98  if(!m_ctx) {
99  m_out << "tools::X11::session::session :"
100  << " can't create a glX context."
101  << std::endl;
102  ::XCloseDisplay(m_display);
103  m_display = 0;
104  m_vinfo = 0;
105  m_ctx = 0;
106  return;
107  }
108  //} else {
109  //m_out << "tools::X11::session::session :"
110  // << " glX context with direct rendering created."
111  // << std::endl;
112  }
113 
114  // It is better to create a colormap adapted to the visual.
115  m_colormap = ::XCreateColormap(m_display,::XRootWindow(m_display,m_monitor),m_vinfo->visual,AllocNone);
116  //m_colormap = ::XDefaultColormap(m_display,m_monitor);
117  if(m_colormap==0L) {
118  m_out << "tools::X11::session::session : XCreateColormap failed." << std::endl;
119  ::XCloseDisplay(m_display);
120  m_display = 0;
121  m_vinfo = 0;
122  m_ctx = 0;
123  return;
124  }
125  }

◆ ~session()

virtual tools::X11::session::~session ( )
inlinevirtual

Definition at line 126 of file session.

126  {
127  if(m_display) {
128  if(m_ctx) {
129  ::glXDestroyContext(m_display,m_ctx);
130  m_ctx = 0;
131  }
132  if(m_colormap) {
133  ::XFreeColormap(m_display,m_colormap);
134  m_colormap = 0;
135  }
136  ::XCloseDisplay(m_display);
137  m_display = 0;
138  }
139  if(m_vinfo) {
140  ::XFree(m_vinfo);
141  m_vinfo = 0;
142  }
143  //std::cout << "debug : ~session" << std::endl;
144  }

◆ session() [2/2]

tools::X11::session::session ( const session a_from)
inlineprotected

Definition at line 146 of file session.

147  :parent(a_from)
148  ,m_vinfo(0)
149  ,m_ctx(0)
150  ,m_colormap(0)
151  {}

Member Function Documentation

◆ context()

GLXContext tools::X11::session::context ( ) const
inline

Definition at line 158 of file session.

158 {return m_ctx;}

◆ create_window()

Window tools::X11::session::create_window ( const char *  a_title,
int  a_x,
int  a_y,
unsigned int  a_width,
unsigned int  a_height 
)
inline

Definition at line 160 of file session.

160  {
161  if(!m_display) return 0L;
162 
163  XSetWindowAttributes swa;
164  swa.event_mask = StructureNotifyMask | ExposureMask
165  | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
166  | PointerMotionMask
167  | KeyPressMask;
168 
169  swa.colormap = m_colormap;
170  swa.border_pixel = 0L;
171 
172  Window window = ::XCreateWindow(m_display,
173  ::XRootWindow(m_display,m_monitor),
174  a_x,a_y,a_width,a_height,
175  0,
176  m_vinfo->depth,
177  InputOutput,
178  m_vinfo->visual,
179  CWBorderPixel|CWColormap|CWEventMask,&swa);
180 
181  if(window==0L) {
182  m_out << "tools::X11::session::create_window :"
183  << " can't create a X11 window."
184  << std::endl;
185  return 0L;
186  }
187 
188  XTextProperty tp;
189  ::XStringListToTextProperty((char**)&a_title,1,&tp);
190  XSizeHints sh;
191  sh.flags = USPosition | USSize;
192  ::XSetWMProperties(m_display,window,&tp,&tp,0,0,&sh,0,0);
193  ::XFree(tp.value);
194 
195  ::XSetWMProtocols(m_display,window,&m_WM_DELETE_WINDOW_atom,1);
196  return window;
197  }

◆ operator=()

session& tools::X11::session::operator= ( const session a_from)
inlineprotected

Definition at line 152 of file session.

152  {
153  if(&a_from==this) return *this;
154  parent::operator=(a_from);
155  return *this;
156  }

Member Data Documentation

◆ m_colormap

Colormap tools::X11::session::m_colormap
protected

Definition at line 201 of file session.

◆ m_ctx

GLXContext tools::X11::session::m_ctx
protected

Definition at line 200 of file session.

◆ m_vinfo

XVisualInfo* tools::X11::session::m_vinfo
protected

Definition at line 199 of file session.


The documentation for this class was generated from the following file:
tools::X11::session::m_ctx
GLXContext m_ctx
Definition: session:200
tools::X11::base_session::m_out
std::ostream & m_out
Definition: base_session:392
tools::X11::session::m_vinfo
XVisualInfo * m_vinfo
Definition: session:199
tools::X11::base_session::m_WM_DELETE_WINDOW_atom
Atom m_WM_DELETE_WINDOW_atom
Definition: base_session:395
tools::X11::base_session::operator=
base_session & operator=(const base_session &a_from)
Definition: base_session:87
tools::X11::base_session::m_monitor
unsigned int m_monitor
Definition: base_session:393
tools::X11::base_session::m_display
Display * m_display
Definition: base_session:394
tools::X11::session::m_colormap
Colormap m_colormap
Definition: session:201