Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/toolx/X11/base_session

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/toolx/X11/base_session (Version 11.3.0) and /externals/g4tools/include/toolx/X11/base_session (Version 11.1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef toolx_X11_base_session                      4 #ifndef toolx_X11_base_session
  5 #define toolx_X11_base_session                      5 #define toolx_X11_base_session
  6                                                     6 
  7 // pure X11 code, no GL.                            7 // pure X11 code, no GL.
  8                                                     8 
  9 #include <ostream>                                  9 #include <ostream>
 10 #include <vector>                                  10 #include <vector>
 11                                                    11 
 12 #include "dispatcher"                              12 #include "dispatcher"
 13 #include <tools/forit>                             13 #include <tools/forit>
 14                                                    14 
 15 #include <X11/Xatom.h>     //XA_INTEGER        <<  15 #include <X11/Xatom.h>      //XA_INTEGER
 16                                                    16 
 17 #include <X11/Xutil.h>     //XVisualInfo       <<  17 #include <X11/Xutil.h>      //XVisualInfo
 18                                                    18 
 19 namespace toolx {                                  19 namespace toolx {
 20 namespace X11 {                                    20 namespace X11 {
 21                                                    21 
 22 class base_session {                               22 class base_session {
 23 public:                                            23 public:
 24   //virtual bool make_current(Window) const {      24   //virtual bool make_current(Window) const {
 25   //  if(!m_display) return false;                 25   //  if(!m_display) return false;
 26   //  return true;                                 26   //  return true;
 27   //}                                              27   //}
 28   //virtual bool swap_buffers(Window) const {      28   //virtual bool swap_buffers(Window) const {
 29   //  if(!m_display) return false;                 29   //  if(!m_display) return false;
 30   //  return true;                                 30   //  return true;
 31   //}                                              31   //}
 32 public:                                            32 public:
 33   base_session(std::ostream& a_out,unsigned in     33   base_session(std::ostream& a_out,unsigned int a_monitor = 0)
 34   :m_out(a_out)                                    34   :m_out(a_out)
 35   ,m_monitor(a_monitor)                            35   ,m_monitor(a_monitor)
 36   ,m_display(0)                                    36   ,m_display(0)
 37   ,m_WM_DELETE_WINDOW_atom(None)                   37   ,m_WM_DELETE_WINDOW_atom(None)
 38   ,m_SESSION_EXIT_STEER_atom(None)                 38   ,m_SESSION_EXIT_STEER_atom(None)
 39   {                                                39   {
 40     //NOTE : macOS : XOpenDisplay leaks 128 by     40     //NOTE : macOS : XOpenDisplay leaks 128 bytes.
 41     m_display = ::XOpenDisplay(NULL);              41     m_display = ::XOpenDisplay(NULL);
 42     if(!m_display) {                               42     if(!m_display) {
 43       m_out << "toolx::X11::base_session::base     43       m_out << "toolx::X11::base_session::base_session : can't open display." << std::endl;
 44       return;                                      44       return;
 45     }                                              45     }
 46                                                    46 
 47     int monitors = ::XScreenCount(m_display);      47     int monitors = ::XScreenCount(m_display);
 48     if(int(m_monitor)>=monitors) {                 48     if(int(m_monitor)>=monitors) {
 49       m_out << "toolx::X11::base_session::base     49       m_out << "toolx::X11::base_session::base_session : bad monitor index "
 50             << m_monitor << ". (#monitors " <<     50             << m_monitor << ". (#monitors " << monitors << ")." << std::endl;
 51       ::XCloseDisplay(m_display);                  51       ::XCloseDisplay(m_display);
 52       m_display = 0;                               52       m_display = 0;
 53       return;                                      53       return;
 54     }                                              54     }
 55                                                    55 
 56     m_WM_DELETE_WINDOW_atom = ::XInternAtom(m_     56     m_WM_DELETE_WINDOW_atom = ::XInternAtom(m_display,"WM_DELETE_WINDOW",False);
 57     if(m_WM_DELETE_WINDOW_atom==None) {            57     if(m_WM_DELETE_WINDOW_atom==None) {
 58       m_out << "toolx::X11::base_session::base     58       m_out << "toolx::X11::base_session::base_session : can't create WM_DELETE_WINDOW Atom." << std::endl;
 59       ::XCloseDisplay(m_display);                  59       ::XCloseDisplay(m_display);
 60       m_display = 0;                               60       m_display = 0;
 61       return;                                      61       return;
 62     }                                              62     }
 63                                                    63 
 64     m_SESSION_EXIT_STEER_atom = ::XInternAtom(     64     m_SESSION_EXIT_STEER_atom = ::XInternAtom(m_display,"TOOLX_X11_SESSION_EXIT_STEER",False);
 65     if(m_SESSION_EXIT_STEER_atom==None) {          65     if(m_SESSION_EXIT_STEER_atom==None) {
 66       m_out << "toolx::X11::base_session::base     66       m_out << "toolx::X11::base_session::base_session :"
 67             << " can't create TOOLX_X11_SESSIO     67             << " can't create TOOLX_X11_SESSION_EXIT_STEER Atom." << std::endl;
 68       ::XCloseDisplay(m_display);                  68       ::XCloseDisplay(m_display);
 69       m_display = 0;                               69       m_display = 0;
 70       return;                                      70       return;
 71     }                                              71     }
 72   }                                                72   }
 73   virtual ~base_session() {                        73   virtual ~base_session() {
 74     clear_dispatchers();                           74     clear_dispatchers();
 75     if(m_display) ::XCloseDisplay(m_display);      75     if(m_display) ::XCloseDisplay(m_display);
 76     m_display = 0;                                 76     m_display = 0;
 77     //std::cout << "debug : ~base_session" <<      77     //std::cout << "debug : ~base_session" << std::endl;
 78   }                                                78   }
 79 protected:                                         79 protected:
 80   base_session(const base_session& a_from)         80   base_session(const base_session& a_from)
 81   :m_out(a_from.m_out)                             81   :m_out(a_from.m_out)
 82   ,m_monitor(a_from.m_monitor)                     82   ,m_monitor(a_from.m_monitor)
 83   ,m_display(0)                                    83   ,m_display(0)
 84   ,m_WM_DELETE_WINDOW_atom(None)                   84   ,m_WM_DELETE_WINDOW_atom(None)
 85   ,m_SESSION_EXIT_STEER_atom(None)                 85   ,m_SESSION_EXIT_STEER_atom(None)
 86   {}                                               86   {}
 87   base_session& operator=(const base_session&      87   base_session& operator=(const base_session& a_from){
 88     if(&a_from==this) return *this;                88     if(&a_from==this) return *this;
 89     return *this;                                  89     return *this;
 90   }                                                90   }
 91 public:                                            91 public:
 92   std::ostream& out() const {return m_out;}        92   std::ostream& out() const {return m_out;}
 93                                                    93 
 94   Atom WM_DELETE_WINDOW_atom() const {return m     94   Atom WM_DELETE_WINDOW_atom() const {return m_WM_DELETE_WINDOW_atom;}
 95   Atom SESSION_EXIT_STEER_atom() const {return     95   Atom SESSION_EXIT_STEER_atom() const {return m_SESSION_EXIT_STEER_atom;}
 96                                                    96 
 97   bool is_valid() const {return m_display?true     97   bool is_valid() const {return m_display?true:false;}
 98                                                    98 
 99   unsigned int monitor() const {return m_monit << 
100   Display* display() const {return m_display;}     99   Display* display() const {return m_display;}
101                                                   100 
102   bool steer() {                                  101   bool steer() {
103     if(!m_display) return false;                  102     if(!m_display) return false;
104                                                   103 
105     while(true) {                                 104     while(true) {
106       XEvent xevent;                              105       XEvent xevent;
107       ::XNextEvent(m_display,&xevent);            106       ::XNextEvent(m_display,&xevent);
108       if(xevent.type==ClientMessage) {            107       if(xevent.type==ClientMessage) {
109         if(xevent.xclient.data.l[0]==(long)m_S    108         if(xevent.xclient.data.l[0]==(long)m_SESSION_EXIT_STEER_atom) break;
110       }                                           109       }
111       dispatch(xevent);                           110       dispatch(xevent);
112     }                                             111     }
113                                                   112 
114     return true;                                  113     return true;
115   }                                               114   }
116                                                   115 
117   bool sync() {                                   116   bool sync() {
118     if(!m_display) return false;                  117     if(!m_display) return false;
119   //::glXWaitX();                                 118   //::glXWaitX();
120     ::XSync(m_display,False);                     119     ::XSync(m_display,False);
121     while(true) {                                 120     while(true) {
122       XEvent xevent;                              121       XEvent xevent;
123       if(::XPending(m_display)) {                 122       if(::XPending(m_display)) {
124         ::XNextEvent(m_display,&xevent);          123         ::XNextEvent(m_display,&xevent);
125         if(xevent.type==ClientMessage) {          124         if(xevent.type==ClientMessage) {
126           if(xevent.xclient.data.l[0]==(long)m    125           if(xevent.xclient.data.l[0]==(long)m_SESSION_EXIT_STEER_atom) return false;
127         }                                         126         }
128         dispatch(xevent);                         127         dispatch(xevent);
129       } else {                                    128       } else {
130         break;                                    129         break;
131       }                                           130       }
132     }                                             131     }
133     return true;                                  132     return true;
134   }                                               133   }
135                                                   134 
136   bool event_pending(bool& a_is) {                135   bool event_pending(bool& a_is) {
137     if(!m_display) {a_is = false;return false;    136     if(!m_display) {a_is = false;return false;}
138     a_is = ::XPending(m_display)?true:false;      137     a_is = ::XPending(m_display)?true:false;
139     return true;                                  138     return true;
140   }                                               139   }
141                                                   140 
142   bool next_event(bool& a_to_exit) {              141   bool next_event(bool& a_to_exit) {
143     if(!m_display) {a_to_exit = false;return f    142     if(!m_display) {a_to_exit = false;return false;}
144     XEvent xevent;                                143     XEvent xevent;
145     ::XNextEvent(m_display,&xevent);              144     ::XNextEvent(m_display,&xevent);
146     if(xevent.type==ClientMessage) {              145     if(xevent.type==ClientMessage) {
147       if(xevent.xclient.data.l[0]==(long)m_SES    146       if(xevent.xclient.data.l[0]==(long)m_SESSION_EXIT_STEER_atom) {
148         a_to_exit = true;                         147         a_to_exit = true;
149         return true;                              148         return true;
150       }                                           149       }
151     }                                             150     }
152     dispatch(xevent);                             151     dispatch(xevent);
153     a_to_exit = false;                            152     a_to_exit = false;
154     return true;                                  153     return true;
155   }                                               154   }
156                                                   155 
157   bool flush() {                                  156   bool flush() {
158     if(!m_display) return false;                  157     if(!m_display) return false;
159     ::XFlush(m_display);                          158     ::XFlush(m_display);
160     return true;                                  159     return true;
161   }                                               160   }
162                                                   161 
163                                                   162 
164   ////////////////////////////////////////////    163   //////////////////////////////////////////////////
165   ////////////////////////////////////////////    164   //////////////////////////////////////////////////
166   ////////////////////////////////////////////    165   //////////////////////////////////////////////////
167   Window create_window(const char* a_title,int    166   Window create_window(const char* a_title,int a_x,int a_y,unsigned int a_width,unsigned int a_height) {
168     if(!m_display) return 0L;                     167     if(!m_display) return 0L;
169                                                   168 
170     XSetWindowAttributes swa;                     169     XSetWindowAttributes swa;
171     swa.event_mask = StructureNotifyMask | Exp    170     swa.event_mask = StructureNotifyMask | ExposureMask
172        | ButtonPressMask | ButtonReleaseMask |    171        | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
173        | PointerMotionMask                        172        | PointerMotionMask
174        | KeyPressMask;                            173        | KeyPressMask;
175                                                   174 
176     swa.background_pixel = ::XWhitePixel(m_dis    175     swa.background_pixel = ::XWhitePixel(m_display,m_monitor);
177                                                   176 
178     Window window = ::XCreateWindow(m_display,    177     Window window = ::XCreateWindow(m_display,
179                                     ::XRootWin    178                                     ::XRootWindow(m_display,m_monitor),
180                                     a_x,a_y,a_    179                                     a_x,a_y,a_width,a_height,
181             0,                                    180             0,
182                                     (int)CopyF    181                                     (int)CopyFromParent,
183                                     InputOutpu    182                                     InputOutput,
184                                     (Visual*)C    183                                     (Visual*)CopyFromParent,
185             CWEventMask|CWBackPixel,&swa);        184             CWEventMask|CWBackPixel,&swa);
186     if(window==0L) {                              185     if(window==0L) {
187       m_out << "toolx::X11::base_session::crea    186       m_out << "toolx::X11::base_session::create_window : can't create a X11 window." << std::endl;
188       return 0L;                                  187       return 0L;
189     }                                             188     }
190                                                   189 
191     XTextProperty tp;                             190     XTextProperty tp;
192     ::XStringListToTextProperty((char**)&a_tit    191     ::XStringListToTextProperty((char**)&a_title,1,&tp);
193     XSizeHints sh;                                192     XSizeHints sh;
194     sh.flags = USPosition | USSize;               193     sh.flags = USPosition | USSize;
195     ::XSetWMProperties(m_display,window,&tp,&t    194     ::XSetWMProperties(m_display,window,&tp,&tp,0,0,&sh,0,0);
196     ::XFree(tp.value);                            195     ::XFree(tp.value);
197                                                   196 
198     ::XSetWMProtocols(m_display,window,&m_WM_D    197     ::XSetWMProtocols(m_display,window,&m_WM_DELETE_WINDOW_atom,1);
199     return window;                                198     return window;
200   }                                               199   }
201                                                   200 
202   void map_raise_window(Window a_window) const    201   void map_raise_window(Window a_window) const {
203     if(!m_display) return;                        202     if(!m_display) return;
204     ::XMapWindow(m_display,a_window);             203     ::XMapWindow(m_display,a_window);
205     ::XRaiseWindow(m_display,a_window);           204     ::XRaiseWindow(m_display,a_window);
206   }                                               205   }
207                                                   206 
208   void show_window(Window a_window) const {       207   void show_window(Window a_window) const {
209     if(!m_display) return;                        208     if(!m_display) return;
210                                                   209 
211     XWindowAttributes watbs;                      210     XWindowAttributes watbs;
212     ::XGetWindowAttributes(m_display,a_window,    211     ::XGetWindowAttributes(m_display,a_window,&watbs);
213     if(watbs.map_state!=IsUnmapped) return;       212     if(watbs.map_state!=IsUnmapped) return;
214                                                   213 
215     ::XMapWindow(m_display,a_window);             214     ::XMapWindow(m_display,a_window);
216     ::XRaiseWindow(m_display,a_window);           215     ::XRaiseWindow(m_display,a_window);
217                                                   216 
218    {XEvent event;                                 217    {XEvent event;
219     ::XIfEvent(m_display,&event,wait_map_notif    218     ::XIfEvent(m_display,&event,wait_map_notify,(char*)a_window);}
220   }                                               219   }
221                                                   220 
222   void hide_window(Window a_window) const {       221   void hide_window(Window a_window) const {
223     if(!m_display) return;                        222     if(!m_display) return;
224                                                   223 
225     XWindowAttributes watbs;                      224     XWindowAttributes watbs;
226     ::XGetWindowAttributes(m_display,a_window,    225     ::XGetWindowAttributes(m_display,a_window,&watbs);
227     if(watbs.map_state==IsUnmapped) return;       226     if(watbs.map_state==IsUnmapped) return;
228                                                   227 
229     ::XUnmapWindow(m_display,a_window);           228     ::XUnmapWindow(m_display,a_window);
230                                                   229 
231    {XEvent event;                                 230    {XEvent event;
232     ::XIfEvent(m_display,&event,wait_unmap_not    231     ::XIfEvent(m_display,&event,wait_unmap_notify,(char*)a_window);}
233   }                                               232   }
234                                                   233 
235   void resize_window(Window a_window,unsigned     234   void resize_window(Window a_window,unsigned int a_width,unsigned int a_height) const {
236     if(!m_display) return;                        235     if(!m_display) return;
237     unsigned int mask = CWWidth | CWHeight | C    236     unsigned int mask = CWWidth | CWHeight | CWBorderWidth;
238     XWindowChanges changes;                       237     XWindowChanges changes;
239     changes.border_width = 0;                     238     changes.border_width = 0;
240     changes.width = a_width;                      239     changes.width = a_width;
241     changes.height = a_height;                    240     changes.height = a_height;
242     ::XConfigureWindow(m_display,a_window,mask    241     ::XConfigureWindow(m_display,a_window,mask,&changes);
243   }                                               242   }
244                                                   243 
245   bool window_size(Window a_window,int& a_widt    244   bool window_size(Window a_window,int& a_width,int& a_height) const {
246     if(!m_display) {a_width = 0;a_height = 0;r    245     if(!m_display) {a_width = 0;a_height = 0;return false;}
247     XWindowAttributes watbs;                      246     XWindowAttributes watbs;
248     if(!XGetWindowAttributes(m_display,a_windo    247     if(!XGetWindowAttributes(m_display,a_window,&watbs)) {a_width = 0;a_height = 0;return false;}
249     a_width  = watbs.width;                       248     a_width  = watbs.width;
250     a_height = watbs.height;                      249     a_height = watbs.height;
251     return true;                                  250     return true;
252   }                                               251   }
253                                                   252 
254   void delete_window(Window a_window) const {     253   void delete_window(Window a_window) const {
255     if(!m_display) return;                        254     if(!m_display) return;
256     ::XDestroyWindow(m_display,a_window);         255     ::XDestroyWindow(m_display,a_window);
257   }                                               256   }
258                                                   257 
259   void set_override_redirect(Window a_window)     258   void set_override_redirect(Window a_window) const {
260     //must be executed before window is mapped    259     //must be executed before window is mapped.
261     if(!m_display) return;                        260     if(!m_display) return;
262     XSetWindowAttributes swa;                     261     XSetWindowAttributes swa;
263     swa.override_redirect = True;                 262     swa.override_redirect = True;
264     ::XChangeWindowAttributes(m_display,a_wind    263     ::XChangeWindowAttributes(m_display,a_window,CWOverrideRedirect,&swa);
265   }                                               264   }
266                                                   265 
267   void set_wm_no_decorations(Window a_window)     266   void set_wm_no_decorations(Window a_window) const {
268     //must be executed before window is mapped    267     //must be executed before window is mapped.
269     if(!m_display) return;                        268     if(!m_display) return;
270                                                   269 
271     // struct, mwm_hints_decorations taken fro    270     // struct, mwm_hints_decorations taken from OpenMotif MwmUtils.h.
272     struct{                                       271     struct{
273       unsigned long flags;                        272       unsigned long flags;
274       unsigned long functions;                    273       unsigned long functions;
275       unsigned long decorations;                  274       unsigned long decorations;
276       long          inputMode;                    275       long          inputMode;
277       unsigned long status;                       276       unsigned long status;
278     } prop;                                       277     } prop;
279                                                   278 
280     //unsigned long mwm_hints_functions = 1L <    279     //unsigned long mwm_hints_functions = 1L << 0;
281     unsigned long mwm_hints_decorations  = 1L     280     unsigned long mwm_hints_decorations  = 1L << 1;
282                                                   281 
283     Atom atom = ::XInternAtom(m_display,"_MOTI    282     Atom atom = ::XInternAtom(m_display,"_MOTIF_WM_HINTS",False);
284     if(atom==None) {                              283     if(atom==None) {
285       m_out << "toolx::X11::base_session::set_    284       m_out << "toolx::X11::base_session::set_wm_no_decorations : can't create/get _MOTIF_WM_HINTS Atom." << std::endl;
286       return;                                     285       return;
287     }                                             286     }
288     prop.flags = mwm_hints_decorations;           287     prop.flags = mwm_hints_decorations;
289     prop.functions = 0;                           288     prop.functions = 0;
290     prop.decorations = 0;                         289     prop.decorations = 0;
291                                                   290 
292     ::XChangeProperty(m_display,a_window,atom,    291     ::XChangeProperty(m_display,a_window,atom,atom,32,PropModeReplace,(unsigned char*)&prop,5);
293   }                                               292   }
294                                                   293 
295   bool post(Window a_win,                         294   bool post(Window a_win,
296             long a_0 = 0,long a_1 = 0,            295             long a_0 = 0,long a_1 = 0,
297             long a_2 = 0,long a_3 = 0,            296             long a_2 = 0,long a_3 = 0,
298             long a_4 = 0) const {                 297             long a_4 = 0) const {
299     if(!m_display) return false;                  298     if(!m_display) return false;
300     XEvent event;                                 299     XEvent event;
301     event.type = ClientMessage;                   300     event.type = ClientMessage;
302     event.xclient.display = m_display;            301     event.xclient.display = m_display;
303     event.xclient.window = a_win;                 302     event.xclient.window = a_win;
304     event.xclient.message_type = XA_INTEGER;      303     event.xclient.message_type = XA_INTEGER;
305     event.xclient.format = 8;    /* put 8 beca    304     event.xclient.format = 8;    /* put 8 because bug with 32 on VMCMS */
306     event.xclient.data.l[0] = a_0;                305     event.xclient.data.l[0] = a_0;
307     event.xclient.data.l[1] = a_1;                306     event.xclient.data.l[1] = a_1;
308     event.xclient.data.l[2] = a_2;                307     event.xclient.data.l[2] = a_2;
309     event.xclient.data.l[3] = a_3;                308     event.xclient.data.l[3] = a_3;
310     event.xclient.data.l[4] = a_4;                309     event.xclient.data.l[4] = a_4;
311     //lock();                                     310     //lock();
312     Status stat = ::XSendEvent(m_display,a_win    311     Status stat = ::XSendEvent(m_display,a_win,False,0L,&event);
313     ::XFlush(m_display);                          312     ::XFlush(m_display);
314     //unlock();                                   313     //unlock();
315     return (stat==0?false:true);                  314     return (stat==0?false:true);
316   }                                               315   }
317                                                   316 
318   bool post_EXIT_STEER(Window a_win) {            317   bool post_EXIT_STEER(Window a_win) {
319     return post(a_win,SESSION_EXIT_STEER_atom(    318     return post(a_win,SESSION_EXIT_STEER_atom());
320   }                                               319   }
321                                                   320 
322   ////////////////////////////////////////////    321   //////////////////////////////////////////////////
323   ////////////////////////////////////////////    322   //////////////////////////////////////////////////
324   ////////////////////////////////////////////    323   //////////////////////////////////////////////////
325   void add_dispatcher(dispatcher* a_dispatcher    324   void add_dispatcher(dispatcher* a_dispatcher) {
326     m_dispatchers.push_back(a_dispatcher); //t    325     m_dispatchers.push_back(a_dispatcher); //take ownership.
327   }                                               326   }
328                                                   327 
329   void invalidate_dispatchers_with_window(Wind    328   void invalidate_dispatchers_with_window(Window a_win){
330     tools_vforit(dispatcher*,m_dispatchers,it)    329     tools_vforit(dispatcher*,m_dispatchers,it) {
331       if((*it)->window()==a_win) (*it)->invali    330       if((*it)->window()==a_win) (*it)->invalidate();
332     }                                             331     }
333   }                                               332   }
334                                                   333 
335   void remove_dispatchers_with_window(Window a    334   void remove_dispatchers_with_window(Window a_win){
336     tools_vforit_npp(dispatcher*,m_dispatchers    335     tools_vforit_npp(dispatcher*,m_dispatchers,it) {
337       if((*it)->window()==a_win) {                336       if((*it)->window()==a_win) {
338         dispatcher* obj = *it;                    337         dispatcher* obj = *it;
339         it = m_dispatchers.erase(it);             338         it = m_dispatchers.erase(it);
340         delete obj;                               339         delete obj;
341       } else {                                    340       } else {
342         it++;                                     341         it++;
343       }                                           342       }
344     }                                             343     }
345   }                                               344   }
346                                                   345 
347   bool dispatch(XEvent& a_event) {                346   bool dispatch(XEvent& a_event) {
348    {tools_vforit_npp(dispatcher*,m_dispatchers    347    {tools_vforit_npp(dispatcher*,m_dispatchers,it) {
349       if(!(*it)->is_valid()) {                    348       if(!(*it)->is_valid()) {
350         dispatcher* obj = *it;                    349         dispatcher* obj = *it;
351         it = m_dispatchers.erase(it);             350         it = m_dispatchers.erase(it);
352         delete obj;                               351         delete obj;
353       } else {                                    352       } else {
354         it++;                                     353         it++;
355       }                                           354       }
356     }}                                            355     }}
357     tools_vforit(dispatcher*,m_dispatchers,it)    356     tools_vforit(dispatcher*,m_dispatchers,it) {
358       if((*it)->is_valid()) {                     357       if((*it)->is_valid()) {
359         if((*it)->dispatch(a_event)) return tr    358         if((*it)->dispatch(a_event)) return true;
360       }                                           359       }
361     }                                             360     }
362     return false;                                 361     return false;
363   }                                               362   }
364 protected:                                        363 protected:
365   static Bool wait_map_notify(Display*,XEvent*    364   static Bool wait_map_notify(Display*,XEvent* a_event,char* a_arg){
366     return (a_event->type == MapNotify) && (a_    365     return (a_event->type == MapNotify) && (a_event->xmap.window == (Window)a_arg);
367   }                                               366   }
368   static Bool wait_unmap_notify(Display*,XEven    367   static Bool wait_unmap_notify(Display*,XEvent* a_event,char* a_arg){
369     return (a_event->type == UnmapNotify) && (    368     return (a_event->type == UnmapNotify) && (a_event->xmap.window == (Window)a_arg);
370   }                                               369   }
371                                                << 370   
372 /*                                             << 
373   void wait_xxx(Window a_window) {             << 
374     if(!m_display) return;                     << 
375    {wait_what arg;                             << 
376     arg.m_event_type = ConfigureNotify;        << 
377     arg.m_window = a_window;                   << 
378     XEvent event;                              << 
379     ::XIfEvent(m_display,&event,wait_for,(char << 
380     dispatch(event);}                          << 
381   }                                            << 
382                                                << 
383   struct wait_what {                           << 
384     int m_event_type;                          << 
385     Window m_window;                           << 
386   };                                           << 
387   static Bool wait_for(Display*,XEvent* a_even << 
388     wait_what* arg = (wait_what*)a_arg;        << 
389     return (a_event->type == arg->m_event_type << 
390            (a_event->xmap.window == arg->m_win << 
391   }                                            << 
392 */                                             << 
393                                                << 
394   void clear_dispatchers() {                      371   void clear_dispatchers() {
395     tools_vforit_npp(dispatcher*,m_dispatchers    372     tools_vforit_npp(dispatcher*,m_dispatchers,it) {
396       dispatcher* obj = *it;                      373       dispatcher* obj = *it;
397       it = m_dispatchers.erase(it);               374       it = m_dispatchers.erase(it);
398       delete obj;                                 375       delete obj;
399     }                                             376     }
400     m_dispatchers.clear();                        377     m_dispatchers.clear();
401   }                                               378   }
402                                                   379 
403 protected:                                        380 protected:
404   std::ostream& m_out;                            381   std::ostream& m_out;
405   unsigned int  m_monitor;                        382   unsigned int  m_monitor;
406   Display*      m_display;                        383   Display*      m_display;
407   Atom          m_WM_DELETE_WINDOW_atom;          384   Atom          m_WM_DELETE_WINDOW_atom;
408   Atom          m_SESSION_EXIT_STEER_atom;        385   Atom          m_SESSION_EXIT_STEER_atom;
409   std::vector<dispatcher*> m_dispatchers;         386   std::vector<dispatcher*> m_dispatchers;
410 };                                                387 };
411                                                   388 
412 }}                                                389 }}
413                                                << 
414                                                   390 
415 #endif                                            391 #endif
416                                                   392