36 unsigned long value_mask = 0UL ;
40 XSetWindowAttributes values ;
41 values.background_pixmap = None ;
42 values.border_pixmap = None ;
43 create( display , dx , dy , value_mask , values ) ;
52 unsigned long value_mask = CWBackPixel ;
54 XSetWindowAttributes values ;
55 values.background_pixel =
static_cast<unsigned int>(background) ;
56 values.background_pixmap = None ;
57 values.border_pixmap = None ;
58 create( display , dx , dy , value_mask , values ) ;
63 char * list[1] = {
const_cast<char*
>(title.c_str()) } ;
64 XStringListToTextProperty( list , 1 , &text ) ;
65 XSetWMName( display.
x() ,
x() , &text ) ;
72 void GX::Window::create(
GX::Display & display ,
int dx ,
int dy ,
73 unsigned long value_mask ,
const XSetWindowAttributes & values )
75 ::Window parent = DefaultRootWindow( display.
x() ) ;
76 unsigned int border_width = 0U ;
77 int depth = CopyFromParent ;
78 unsigned int class_ = CopyFromParent ;
80 XSetWindowAttributes * values_p =
const_cast<XSetWindowAttributes*
>(&values) ;
82 G_ASSERT( dx >= 0 && dy >= 0 ) ;
83 m_window = XCreateWindow( display.
x() , parent , 0 , 0 ,
84 static_cast<unsigned int>(
dx) , static_cast<unsigned int>(dy) ,
85 border_width , depth , class_ , visual , value_mask , values_p ) ;
94 char buffer[10] = {
'\0' } ;
95 int rc = XLookupString( &e , buffer ,
sizeof(buffer) , &keysym ,
nullptr ) ;
96 if( rc == 1 && ( buffer[0] ==
'\t' || ( buffer[0] >= 0x20 && buffer[0] < 0x7f ) ) )
97 m_key = std::string(1U,buffer[0]) ;
101 m_key = keysymToString( XLookupKeysym(&e,0) , e.state & ShiftMask ) ;
105 if( m_key.length() == 1U )
134 XMapWindow( m_display.
x() , m_window ) ;
142 XDestroyWindow( m_display.
x() , m_window ) ;
161 XSelectInput( m_display.
x() , m_window , mask ) ;
167 (with_mouse_moves?PointerMotionMask:0L) |
169 StructureNotifyMask |
178 XClearWindow( m_display.
x() , m_window ) ;
183 XSetWindowColormap( m_display.
x() , m_window , map.
x() ) ;
198 static XClientMessageEvent z ;
199 XClientMessageEvent
event = z ;
200 event.type = ClientMessage ;
201 event.display = m_display.
x() ;
202 event.window = m_window ;
203 event.message_type = 0 ;
205 event.data.s[0] = 123 ;
206 XSendEvent( m_display.
x() , m_window , False , 0 ,
reinterpret_cast<XEvent*
>(&event) ) ;
211 static XExposeEvent z ;
212 XExposeEvent
event = z ;
213 event.type = Expose ;
214 event.display = m_display.
x() ;
215 event.window = m_window ;
219 event.height =
dy() ;
221 XSendEvent( m_display.
x() , m_window , False , 0 ,
reinterpret_cast<XEvent*
>(&event) ) ;
229 std::string GX::Window::keysymToString( ::KeySym keysym ,
bool shifted )
231 const char * p =
"" ;
234 case XK_BackSpace: p =
"BackSpace" ; break ;
235 case XK_Tab: p =
"Tab" ; break ;
236 case XK_Linefeed: p =
"Linefeed" ; break ;
237 case XK_Clear: p =
"Clear" ; break ;
238 case XK_Return: p =
"Return" ; break ;
239 case XK_Pause: p =
"Pause" ; break ;
240 case XK_Scroll_Lock: p =
"Scroll_Lock" ; break ;
241 case XK_Sys_Req: p =
"Sys_Req" ; break ;
242 case XK_Escape: p =
"Escape" ; break ;
243 case XK_Delete: p =
"Delete" ; break ;
244 case XK_Home: p =
"Home" ; break ;
245 case XK_Left: p =
"Left" ; break ;
246 case XK_Up: p =
"Up" ; break ;
247 case XK_Right: p =
"Right" ; break ;
248 case XK_Down: p =
"Down" ; break ;
249 case XK_Page_Up: p =
"Page_Up" ; break ;
250 case XK_Page_Down: p =
"Page_Down" ; break ;
251 case XK_End: p =
"End" ; break ;
252 case XK_Begin: p =
"Begin" ; break ;
253 case XK_Select: p =
"Select" ; break ;
254 case XK_Print: p =
"Print" ; break ;
255 case XK_Execute: p =
"Execute" ; break ;
256 case XK_Insert: p =
"Insert" ; break ;
257 case XK_Undo: p =
"Undo" ; break ;
258 case XK_Redo: p =
"Redo" ; break ;
259 case XK_Menu: p =
"Menu" ; break ;
260 case XK_Find: p =
"Find" ; break ;
261 case XK_Cancel: p =
"Cancel" ; break ;
262 case XK_Help: p =
"Help" ; break ;
263 case XK_Break: p =
"Break" ; break ;
264 case XK_Mode_switch: p =
"Mode_switch" ; break ;
265 case XK_Num_Lock: p =
"Num_Lock" ; break ;
266 case XK_KP_Space: p =
"KP_Space" ; break ;
267 case XK_KP_Tab: p =
"KP_Tab" ; break ;
268 case XK_KP_Enter: p =
"KP_Enter" ; break ;
269 case XK_KP_F1: p =
"KP_F1" ; break ;
270 case XK_KP_F2: p =
"KP_F2" ; break ;
271 case XK_KP_F3: p =
"KP_F3" ; break ;
272 case XK_KP_F4: p =
"KP_F4" ; break ;
273 case XK_KP_Home: p =
"KP_Home" ; break ;
274 case XK_KP_Left: p =
"KP_Left" ; break ;
275 case XK_KP_Up: p =
"KP_Up" ; break ;
276 case XK_KP_Right: p =
"KP_Right" ; break ;
277 case XK_KP_Down: p =
"KP_Down" ; break ;
278 case XK_KP_Page_Up: p =
"KP_Page_Up" ; break ;
279 case XK_KP_Page_Down: p =
"KP_Page_Down" ; break ;
280 case XK_KP_End: p =
"KP_End" ; break ;
281 case XK_KP_Begin: p =
"KP_Begin" ; break ;
282 case XK_KP_Insert: p =
"KP_Insert" ; break ;
283 case XK_KP_Delete: p =
"KP_Delete" ; break ;
284 case XK_KP_Equal: p =
"KP_Equal" ; break ;
285 case XK_KP_Multiply: p =
"KP_Multiply" ; break ;
286 case XK_KP_Add: p =
"KP_Add" ; break ;
287 case XK_KP_Separator: p =
"KP_Separator" ; break ;
288 case XK_KP_Subtract: p =
"KP_Subtract" ; break ;
289 case XK_KP_Decimal: p =
"KP_Decimal" ; break ;
290 case XK_KP_Divide: p =
"KP_Divide" ; break ;
291 case XK_KP_0: p =
"KP_0" ; break ;
292 case XK_KP_1: p =
"KP_1" ; break ;
293 case XK_KP_2: p =
"KP_2" ; break ;
294 case XK_KP_3: p =
"KP_3" ; break ;
295 case XK_KP_4: p =
"KP_4" ; break ;
296 case XK_KP_5: p =
"KP_5" ; break ;
297 case XK_KP_6: p =
"KP_6" ; break ;
298 case XK_KP_7: p =
"KP_7" ; break ;
299 case XK_KP_8: p =
"KP_8" ; break ;
300 case XK_KP_9: p =
"KP_9" ; break ;
301 case XK_F1: p =
"F1" ; break ;
302 case XK_F2: p =
"F2" ; break ;
303 case XK_F3: p =
"F3" ; break ;
304 case XK_F4: p =
"F4" ; break ;
305 case XK_F5: p =
"F5" ; break ;
306 case XK_F6: p =
"F6" ; break ;
307 case XK_F7: p =
"F7" ; break ;
308 case XK_F8: p =
"F8" ; break ;
309 case XK_F9: p =
"F9" ; break ;
310 case XK_F10: p =
"F10" ; break ;
311 case XK_F11: p =
"F11" ; break ;
312 case XK_F12: p =
"F12" ; break ;
313 case XK_Shift_L: p =
"Shift_L" ; break ;
314 case XK_Shift_R: p =
"Shift_R" ; break ;
315 case XK_Control_L: p =
"Control_L" ; break ;
316 case XK_Control_R: p =
"Control_R" ; break ;
317 case XK_Caps_Lock: p =
"Caps_Lock" ; break ;
318 case XK_Shift_Lock: p =
"Shift_Lock" ; break ;
319 case XK_Meta_L: p =
"Meta_L" ; break ;
320 case XK_Meta_R: p =
"Meta_R" ; break ;
321 case XK_Alt_L: p =
"Alt_L" ; break ;
322 case XK_Alt_R: p =
"Alt_R" ; break ;
323 case XK_Super_L: p =
"Super_L" ; break ;
324 case XK_Super_R: p =
"Super_R" ; break ;
325 case XK_Hyper_L: p =
"Hyper_L" ; break ;
326 case XK_Hyper_R: p =
"Hyper_R" ; break ;
327 case XK_space: p =
" " ; break ;
328 case XK_exclam: p =
"!" ; break ;
329 case XK_quotedbl: p =
"\"" ; break ;
330 case XK_numbersign: p =
"#" ; break ;
331 case XK_dollar: p =
"$" ; break ;
332 case XK_percent: p =
"%" ; break ;
333 case XK_ampersand: p =
"&" ; break ;
334 case XK_apostrophe: p =
"'" ; break ;
335 case XK_parenleft: p =
"(" ; break ;
336 case XK_parenright: p =
")" ; break ;
337 case XK_asterisk: p =
"*" ; break ;
338 case XK_plus: p =
"+" ; break ;
339 case XK_comma: p = shifted ?
"<" :
"," ; break ;
340 case XK_minus: p = shifted ?
"_" :
"-" ; break ;
341 case XK_period: p = shifted ?
">" :
"." ; break ;
342 case XK_slash: p = shifted ?
"?" :
"/" ; break ;
343 case XK_0: p = shifted ?
")" :
"0" ; break ;
344 case XK_1: p = shifted ?
"!" :
"1" ; break ;
345 case XK_2: p = shifted ?
"\"" :
"2" ; break ;
346 case XK_3: p = shifted ?
"£" :
"3" ; break ;
347 case XK_4: p = shifted ?
"$" :
"4" ; break ;
348 case XK_5: p = shifted ?
"%" :
"5" ; break ;
349 case XK_6: p = shifted ?
"^" :
"6" ; break ;
350 case XK_7: p = shifted ?
"&" :
"7" ; break ;
351 case XK_8: p = shifted ?
"*" :
"8" ; break ;
352 case XK_9: p = shifted ?
"(" :
"9" ; break ;
353 case XK_colon: p =
":" ; break ;
354 case XK_semicolon: p = shifted ?
":" :
";" ; break ;
355 case XK_less: p =
"<" ; break ;
356 case XK_equal: p = shifted ?
"+" :
"=" ; break ;
357 case XK_greater: p =
">" ; break ;
358 case XK_question: p =
"?" ; break ;
359 case XK_at: p =
"@" ; break ;
360 case XK_A: p =
"A" ; break ;
361 case XK_B: p =
"B" ; break ;
362 case XK_C: p =
"C" ; break ;
363 case XK_D: p =
"D" ; break ;
364 case XK_E: p =
"E" ; break ;
365 case XK_F: p =
"F" ; break ;
366 case XK_G: p =
"G" ; break ;
367 case XK_H: p =
"H" ; break ;
368 case XK_I: p =
"I" ; break ;
369 case XK_J: p =
"J" ; break ;
370 case XK_K: p =
"K" ; break ;
371 case XK_L: p =
"L" ; break ;
372 case XK_M: p =
"M" ; break ;
373 case XK_N: p =
"N" ; break ;
374 case XK_O: p =
"O" ; break ;
375 case XK_P: p =
"P" ; break ;
376 case XK_Q: p =
"Q" ; break ;
377 case XK_R: p =
"R" ; break ;
378 case XK_S: p =
"S" ; break ;
379 case XK_T: p =
"T" ; break ;
380 case XK_U: p =
"U" ; break ;
381 case XK_V: p =
"V" ; break ;
382 case XK_W: p =
"W" ; break ;
383 case XK_X: p =
"X" ; break ;
384 case XK_Y: p =
"Y" ; break ;
385 case XK_Z: p =
"Z" ; break ;
386 case XK_bracketleft: p = shifted ?
"{" :
"[" ; break ;
387 case XK_backslash: p = shifted ?
"|" :
"\\" ; break ;
388 case XK_bracketright: p = shifted ?
"}" :
"]" ; break ;
389 case XK_asciicircum: p =
"asciicircum" ; break ;
390 case XK_underscore: p =
"_" ; break ;
391 case XK_grave: p =
"`" ; break ;
392 case XK_a: p = shifted ?
"A" :
"a" ; break ;
393 case XK_b: p = shifted ?
"B" :
"b" ; break ;
394 case XK_c: p = shifted ?
"C" :
"c" ; break ;
395 case XK_d: p = shifted ?
"D" :
"d" ; break ;
396 case XK_e: p = shifted ?
"E" :
"e" ; break ;
397 case XK_f: p = shifted ?
"F" :
"f" ; break ;
398 case XK_g: p = shifted ?
"G" :
"g" ; break ;
399 case XK_h: p = shifted ?
"H" :
"h" ; break ;
400 case XK_i: p = shifted ?
"I" :
"i" ; break ;
401 case XK_j: p = shifted ?
"J" :
"j" ; break ;
402 case XK_k: p = shifted ?
"K" :
"k" ; break ;
403 case XK_l: p = shifted ?
"L" :
"l" ; break ;
404 case XK_m: p = shifted ?
"M" :
"m" ; break ;
405 case XK_n: p = shifted ?
"N" :
"n" ; break ;
406 case XK_o: p = shifted ?
"O" :
"o" ; break ;
407 case XK_p: p = shifted ?
"P" :
"p" ; break ;
408 case XK_q: p = shifted ?
"Q" :
"q" ; break ;
409 case XK_r: p = shifted ?
"R" :
"r" ; break ;
410 case XK_s: p = shifted ?
"S" :
"s" ; break ;
411 case XK_t: p = shifted ?
"T" :
"t" ; break ;
412 case XK_u: p = shifted ?
"U" :
"u" ; break ;
413 case XK_v: p = shifted ?
"V" :
"v" ; break ;
414 case XK_w: p = shifted ?
"W" :
"w" ; break ;
415 case XK_x: p = shifted ?
"X" :
"x" ; break ;
416 case XK_y: p = shifted ?
"Y" :
"y" ; break ;
417 case XK_z: p = shifted ?
"Z" :
"z" ; break ;
418 case XK_braceleft: p =
"{" ; break ;
419 case XK_bar: p =
"|" ; break ;
420 case XK_braceright: p =
"}" ; break ;
421 case XK_asciitilde: p =
"~" ; break ;
422 case XK_nobreakspace: p =
"nobreakspace" ; break ;
423 case XK_exclamdown: p =
"exclamdown" ; break ;
424 case XK_cent: p =
"cent" ; break ;
425 case XK_sterling: p =
"£" ; break ;
426 case XK_currency: p =
"currency" ; break ;
427 case XK_yen: p =
"yen" ; break ;
428 case XK_brokenbar: p =
"brokenbar" ; break ;
429 case XK_section: p =
"section" ; break ;
430 case XK_diaeresis: p =
"diaeresis" ; break ;
431 case XK_copyright: p =
"copyright" ; break ;
432 case XK_ordfeminine: p =
"ordfeminine" ; break ;
433 case XK_guillemotleft: p =
"guillemotleft" ; break ;
434 case XK_notsign: p =
"notsign" ; break ;
435 case XK_hyphen: p =
"hyphen" ; break ;
436 case XK_registered: p =
"registered" ; break ;
437 case XK_macron: p =
"macron" ; break ;
438 case XK_degree: p =
"degree" ; break ;
439 case XK_plusminus: p =
"plusminus" ; break ;
440 case XK_twosuperior: p =
"twosuperior" ; break ;
441 case XK_threesuperior: p =
"threesuperior" ; break ;
442 case XK_acute: p =
"acute" ; break ;
443 case XK_mu: p =
"mu" ; break ;
444 case XK_paragraph: p =
"paragraph" ; break ;
445 case XK_periodcentered: p =
"periodcentered" ; break ;
446 case XK_cedilla: p =
"cedilla" ; break ;
447 case XK_onesuperior: p =
"onesuperior" ; break ;
448 case XK_masculine: p =
"masculine" ; break ;
449 case XK_guillemotright: p =
"guillemotright" ; break ;
450 case XK_onequarter: p =
"onequarter" ; break ;
451 case XK_onehalf: p =
"onehalf" ; break ;
452 case XK_threequarters: p =
"threequarters" ; break ;
453 case XK_questiondown: p =
"questiondown" ; break ;
454 case XK_Agrave: p =
"Agrave" ; break ;
455 case XK_Aacute: p =
"Aacute" ; break ;
456 case XK_Acircumflex: p =
"Acircumflex" ; break ;
457 case XK_Atilde: p =
"Atilde" ; break ;
458 case XK_Adiaeresis: p =
"Adiaeresis" ; break ;
459 case XK_Aring: p =
"Aring" ; break ;
460 case XK_AE: p =
"AE" ; break ;
461 case XK_Ccedilla: p =
"Ccedilla" ; break ;
462 case XK_Egrave: p =
"Egrave" ; break ;
463 case XK_Eacute: p =
"Eacute" ; break ;
464 case XK_Ecircumflex: p =
"Ecircumflex" ; break ;
465 case XK_Ediaeresis: p =
"Ediaeresis" ; break ;
466 case XK_Igrave: p =
"Igrave" ; break ;
467 case XK_Iacute: p =
"Iacute" ; break ;
468 case XK_Icircumflex: p =
"Icircumflex" ; break ;
469 case XK_Idiaeresis: p =
"Idiaeresis" ; break ;
470 case XK_ETH: p =
"ETH" ; break ;
471 case XK_Ntilde: p =
"Ntilde" ; break ;
472 case XK_Ograve: p =
"Ograve" ; break ;
473 case XK_Oacute: p =
"Oacute" ; break ;
474 case XK_Ocircumflex: p =
"Ocircumflex" ; break ;
475 case XK_Otilde: p =
"Otilde" ; break ;
476 case XK_Odiaeresis: p =
"Odiaeresis" ; break ;
477 case XK_multiply: p =
"multiply" ; break ;
479 case XK_Oslash: p =
"Oslash" ; break ;
480 case XK_Ugrave: p =
"Ugrave" ; break ;
481 case XK_Uacute: p =
"Uacute" ; break ;
482 case XK_Ucircumflex: p =
"Ucircumflex" ; break ;
483 case XK_Udiaeresis: p =
"Udiaeresis" ; break ;
484 case XK_Yacute: p =
"Yacute" ; break ;
485 case XK_THORN: p =
"THORN" ; break ;
486 case XK_ssharp: p =
"ssharp" ; break ;
487 case XK_agrave: p =
"agrave" ; break ;
488 case XK_aacute: p =
"aacute" ; break ;
489 case XK_acircumflex: p =
"acircumflex" ; break ;
490 case XK_atilde: p =
"atilde" ; break ;
491 case XK_adiaeresis: p =
"adiaeresis" ; break ;
492 case XK_aring: p =
"aring" ; break ;
493 case XK_ae: p =
"ae" ; break ;
494 case XK_ccedilla: p =
"ccedilla" ; break ;
495 case XK_egrave: p =
"egrave" ; break ;
496 case XK_eacute: p =
"eacute" ; break ;
497 case XK_ecircumflex: p =
"ecircumflex" ; break ;
498 case XK_ediaeresis: p =
"ediaeresis" ; break ;
499 case XK_igrave: p =
"igrave" ; break ;
500 case XK_iacute: p =
"iacute" ; break ;
501 case XK_icircumflex: p =
"icircumflex" ; break ;
502 case XK_idiaeresis: p =
"idiaeresis" ; break ;
503 case XK_eth: p =
"eth" ; break ;
504 case XK_ntilde: p =
"ntilde" ; break ;
505 case XK_ograve: p =
"ograve" ; break ;
506 case XK_oacute: p =
"oacute" ; break ;
507 case XK_ocircumflex: p =
"ocircumflex" ; break ;
508 case XK_otilde: p =
"otilde" ; break ;
509 case XK_odiaeresis: p =
"odiaeresis" ; break ;
510 case XK_division: p =
"division" ; break ;
511 case XK_oslash: p =
"oslash" ; break ;
513 case XK_ugrave: p =
"ugrave" ; break ;
514 case XK_uacute: p =
"uacute" ; break ;
515 case XK_ucircumflex: p =
"ucircumflex" ; break ;
516 case XK_udiaeresis: p =
"udiaeresis" ; break ;
517 case XK_yacute: p =
"yacute" ; break ;
518 case XK_thorn: p =
"thorn" ; break ;
519 case XK_ydiaeresis: p =
"ydiaeresis" ; break ;
521 return std::string(p) ;
A window class that is-a GX::Drawable and a GX::EventHandler.
void invalidate()
Invalidates the window by posting an expose event (see GX::EventHandler::onExpose()).
::Display * x()
Returns the X object.
void install(GX::ColourMap &)
Installs a colourmap.
virtual ::Drawable xd()
From Drawable.
GX::Capture * capture()
Starts capturing the mouse.
int dx() const
Returns the current width.
virtual void onChar(char c)
Called from this class's override of EventHandler::onKeyPress() in the case of simple character keys...
A colourmap class that provides pixel values for a set of mapped colours.
void clear()
Clears the window.
GX::Display & windowDisplay()
Returns a reference to the display as passed in to the ctor.
Window(GX::Display &, int dx, int dy)
Constructor. The display reference is kept.
::Window x()
Returns the X object.
virtual void onKeyPress(::XKeyEvent &) override
An override from EventHandler that calls onKey() doing the translation from opaque keycode to meaning...
void add(GX::Window &w)
Adds a window.
int dy() const
Returns the current hieght.
std::string key() const
Returns the last onKey() string.
virtual void onKey(const std::string &key)
Called from this class's override of EventHandler::onKeyPress().
void enableEvents(long mask)
Enables the specified event types.
virtual ~Window()
Destructor.
void show()
Shows ("maps") the window.
RAII class to capture Xlib mouse events.
void remove(GX::Window &w)
Removes a window.
static long events(bool with_mouse_moves)
Returns a default event mask for enableEvents().
static WindowMap * instance()
Singleton access. Returns nullptr if none.
void sendUserEvent()
Posts a message back to itself so that onUser() gets called.
An abstract base class for xserver-side drawables (windows, pixmaps, etc) with methods for drawing po...
::Colormap x()
Returns the X colourmap id. See XCreateColormap(3).