4 #ifndef tools_X11_base_session
5 #define tools_X11_base_session
15 #include <X11/Xatom.h>
17 #include <X11/Xutil.h>
43 m_out <<
"tools::X11::base_session::base_session : can't open display." << std::endl;
49 m_out <<
"tools::X11::base_session::base_session : bad monitor index "
50 <<
m_monitor <<
". (#monitors " << monitors <<
")." << std::endl;
58 m_out <<
"tools::X11::base_session::base_session : can't create WM_DELETE_WINDOW Atom." << std::endl;
66 m_out <<
"tools::X11::base_session::base_session :"
67 <<
" can't create TOOLS_X11_SESSION_EXIT_STEER Atom." << std::endl;
88 if(&a_from==
this)
return *
this;
107 if(xevent.type==ClientMessage) {
124 if(xevent.type==ClientMessage) {
136 if(!
m_display) {a_is =
false;
return false;}
142 if(!
m_display) {a_to_exit =
false;
return false;}
145 if(xevent.type==ClientMessage) {
166 Window
create_window(
const char* a_title,
int a_x,
int a_y,
unsigned int a_width,
unsigned int a_height) {
169 XSetWindowAttributes swa;
170 swa.event_mask = StructureNotifyMask | ExposureMask
171 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
177 Window window = ::XCreateWindow(
m_display,
179 a_x,a_y,a_width,a_height,
183 (Visual*)CopyFromParent,
184 CWEventMask|CWBackPixel,&swa);
186 m_out <<
"tools::X11::base_session::create_window : can't create a X11 window." << std::endl;
191 ::XStringListToTextProperty((
char**)&a_title,1,&tp);
193 sh.flags = USPosition | USSize;
194 ::XSetWMProperties(
m_display,window,&tp,&tp,0,0,&sh,0,0);
223 void resize_window(Window a_window,
unsigned int a_width,
unsigned int a_height)
const {
225 unsigned int mask = CWWidth | CWHeight | CWBorderWidth;
226 XWindowChanges changes;
227 changes.border_width = 0;
228 changes.width = a_width;
229 changes.height = a_height;
230 ::XConfigureWindow(
m_display,a_window,mask,&changes);
233 bool window_size(Window a_window,
int& a_width,
int& a_height)
const {
234 if(!
m_display) {a_width = 0;a_height = 0;
return false;}
235 XWindowAttributes watbs;
236 if(!XGetWindowAttributes(
m_display,a_window,&watbs)) {a_width = 0;a_height = 0;
return false;}
237 a_width = watbs.width;
238 a_height = watbs.height;
250 XSetWindowAttributes swa;
251 swa.override_redirect = True;
252 ::XChangeWindowAttributes(
m_display,a_window,CWOverrideRedirect,&swa);
262 unsigned long functions;
263 unsigned long decorations;
265 unsigned long status;
269 unsigned long mwm_hints_decorations = 1L << 1;
271 Atom atom = ::XInternAtom(
m_display,
"_MOTIF_WM_HINTS",False);
273 m_out <<
"tools::X11::base_session::set_wm_no_decorations : can't create/get _MOTIF_WM_HINTS Atom." << std::endl;
276 prop.flags = mwm_hints_decorations;
278 prop.decorations = 0;
280 ::XChangeProperty(
m_display,a_window,atom,atom,32,PropModeReplace,(
unsigned char*)&prop,5);
284 long a_0 = 0,
long a_1 = 0,
285 long a_2 = 0,
long a_3 = 0,
286 long a_4 = 0)
const {
289 event.type = ClientMessage;
291 event.xclient.window = a_win;
292 event.xclient.message_type = XA_INTEGER;
293 event.xclient.format = 8;
294 event.xclient.data.l[0] = a_0;
295 event.xclient.data.l[1] = a_1;
296 event.xclient.data.l[2] = a_2;
297 event.xclient.data.l[3] = a_3;
298 event.xclient.data.l[4] = a_4;
300 Status stat = ::XSendEvent(
m_display,a_win,False,0L,&event);
303 return (stat==0?
false:
true);
319 if((*it)->window()==a_win) (*it)->invalidate();
325 if((*it)->window()==a_win) {
337 if(!(*it)->is_valid()) {
346 if((*it)->is_valid()) {
347 if((*it)->dispatch(a_event))
return true;
354 return (a_event->type == MapNotify) && (a_event->xmap.window == (Window)a_arg);
357 return (a_event->type == UnmapNotify) && (a_event->xmap.window == (Window)a_arg);