1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/utilsx11.cpp
3 // Purpose: Miscellaneous X11 functions (for wxCore)
4 // Author: Mattia Barbon, Vaclav Slavik, Robert Roebling
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__WXX11__) || defined(__WXGTK__) || defined(__WXMOTIF__)
14 // for compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
17 #include "wx/unix/utilsx11.h"
26 #include "wx/iconbndl.h"
27 #include "wx/apptrait.h"
30 #pragma message disable nosimpint
33 #include <X11/Xatom.h>
34 #include <X11/Xutil.h>
36 #pragma message enable nosimpint
44 // Various X11 Atoms used in this file:
45 static Atom _NET_WM_STATE
= 0;
46 static Atom _NET_WM_STATE_FULLSCREEN
= 0;
47 static Atom _NET_WM_STATE_STAYS_ON_TOP
= 0;
48 static Atom _NET_WM_WINDOW_TYPE
= 0;
49 static Atom _NET_WM_WINDOW_TYPE_NORMAL
= 0;
50 static Atom _KDE_NET_WM_WINDOW_TYPE_OVERRIDE
= 0;
51 static Atom _WIN_LAYER
= 0;
52 static Atom KWIN_RUNNING
= 0;
54 static Atom _NET_SUPPORTING_WM_CHECK
= 0;
55 static Atom _NET_SUPPORTED
= 0;
58 #define wxMAKE_ATOM(name, display) \
59 if (name == 0) name = XInternAtom((display), #name, False)
62 // X11 Window is an int type, so use the macro to suppress warnings when
64 #define WindowCast(w) (Window)(wxPtrToUInt(w))
66 // Is the window mapped?
67 static bool IsMapped(Display
*display
, Window window
)
69 XWindowAttributes attr
;
70 XGetWindowAttributes(display
, window
, &attr
);
71 return (attr
.map_state
!= IsUnmapped
);
76 // Suspends X11 errors. Used when we expect errors but they are not fatal
80 typedef int (*wxX11ErrorHandler
)(Display
*, XErrorEvent
*);
82 static int wxX11ErrorsSuspender_handler(Display
*, XErrorEvent
*) { return 0; }
85 class wxX11ErrorsSuspender
88 wxX11ErrorsSuspender(Display
*d
) : m_display(d
)
90 m_old
= XSetErrorHandler(wxX11ErrorsSuspender_handler
);
92 ~wxX11ErrorsSuspender()
95 XSetErrorHandler(m_old
);
100 wxX11ErrorHandler m_old
;
105 // ----------------------------------------------------------------------------
106 // Setting icons for window manager:
107 // ----------------------------------------------------------------------------
109 #if wxUSE_IMAGE && !wxUSE_NANOX
111 static Atom _NET_WM_ICON
= 0;
114 wxSetIconsX11(WXDisplay
* display
, WXWindow window
, const wxIconBundle
& ib
)
118 const size_t numIcons
= ib
.GetIconCount();
119 for ( size_t i
= 0; i
< numIcons
; ++i
)
121 const wxIcon icon
= ib
.GetIconByIndex(i
);
123 size
+= 2 + icon
.GetWidth() * icon
.GetHeight();
126 wxMAKE_ATOM(_NET_WM_ICON
, (Display
*)display
);
130 unsigned long* data
= new unsigned long[size
];
131 unsigned long* ptr
= data
;
133 for ( size_t i
= 0; i
< numIcons
; ++i
)
135 const wxImage image
= ib
.GetIconByIndex(i
).ConvertToImage();
136 int width
= image
.GetWidth(),
137 height
= image
.GetHeight();
138 unsigned char* imageData
= image
.GetData();
139 unsigned char* imageDataEnd
= imageData
+ ( width
* height
* 3 );
140 bool hasMask
= image
.HasMask();
141 unsigned char rMask
, gMask
, bMask
;
142 unsigned char r
, g
, b
, a
;
146 rMask
= image
.GetMaskRed();
147 gMask
= image
.GetMaskGreen();
148 bMask
= image
.GetMaskBlue();
150 else // no mask, but still init the variables to avoid warnings
160 while ( imageData
< imageDataEnd
)
165 if( hasMask
&& r
== rMask
&& g
== gMask
&& b
== bMask
)
170 *ptr
++ = ( a
<< 24 ) | ( r
<< 16 ) | ( g
<< 8 ) | b
;
176 XChangeProperty( (Display
*)display
,
181 (unsigned char*)data
, size
);
186 XDeleteProperty( (Display
*)display
,
192 #endif // wxUSE_IMAGE && !wxUSE_NANOX
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 // NB: Setting fullscreen mode under X11 is a complicated matter. There was
199 // no standard way of doing it until recently. ICCCM doesn't know the
200 // concept of fullscreen windows and the only way to make a window
201 // fullscreen is to remove decorations, resize it to cover entire screen
202 // and set WIN_LAYER_ABOVE_DOCK.
204 // This doesn't always work, though. Specifically, at least kwin from
205 // KDE 3 ignores the hint. The only way to make kwin accept our request
206 // is to emulate the way Qt does it. That is, unmap the window, set
207 // _NET_WM_WINDOW_TYPE to _KDE_NET_WM_WINDOW_TYPE_OVERRIDE (KDE extension),
208 // add _NET_WM_STATE_STAYS_ON_TOP (ditto) to _NET_WM_STATE and map
211 // Version 1.2 of Window Manager Specification (aka wm-spec aka
212 // Extended Window Manager Hints) introduced _NET_WM_STATE_FULLSCREEN
213 // window state which provides cleanest and simplest possible way of
214 // making a window fullscreen. WM-spec is a de-facto standard adopted
215 // by GNOME and KDE folks, but _NET_WM_STATE_FULLSCREEN isn't yet widely
216 // supported. As of January 2003, only GNOME 2's default WM Metacity
217 // implements, KDE will support it from version 3.2. At toolkits level,
218 // GTK+ >= 2.1.2 uses it as the only method of making windows fullscreen
219 // (that's why wxGTK will *not* switch to using gtk_window_fullscreen
220 // unless it has better compatibility with older WMs).
223 // This is what wxWidgets does in wxSetFullScreenStateX11:
224 // 1) if _NET_WM_STATE_FULLSCREEN is supported, use it
225 // 2) otherwise try WM-specific hacks (KDE, IceWM)
226 // 3) use _WIN_LAYER and hope that the WM will recognize it
227 // The code was tested with:
228 // twm, IceWM, WindowMaker, Metacity, kwin, sawfish, lesstif-mwm
231 #define WIN_LAYER_NORMAL 4
232 #define WIN_LAYER_ABOVE_DOCK 10
234 static void wxWinHintsSetLayer(Display
*display
, Window rootWnd
,
235 Window window
, int layer
)
237 wxX11ErrorsSuspender
noerrors(display
);
241 wxMAKE_ATOM( _WIN_LAYER
, display
);
243 if (IsMapped(display
, window
))
245 xev
.type
= ClientMessage
;
246 xev
.xclient
.type
= ClientMessage
;
247 xev
.xclient
.window
= window
;
248 xev
.xclient
.message_type
= _WIN_LAYER
;
249 xev
.xclient
.format
= 32;
250 xev
.xclient
.data
.l
[0] = (long)layer
;
251 xev
.xclient
.data
.l
[1] = CurrentTime
;
253 XSendEvent(display
, rootWnd
, False
,
254 SubstructureNotifyMask
, (XEvent
*) &xev
);
261 XChangeProperty(display
, window
,
262 _WIN_LAYER
, XA_CARDINAL
, 32,
263 PropModeReplace
, (unsigned char *)data
, 1);
270 static bool wxQueryWMspecSupport(Display
* WXUNUSED(display
),
271 Window
WXUNUSED(rootWnd
),
274 GdkAtom gatom
= gdk_x11_xatom_to_atom(feature
);
275 return gdk_net_wm_supports(gatom
);
278 static bool wxQueryWMspecSupport(Display
*display
, Window rootWnd
, Atom feature
)
280 wxMAKE_ATOM(_NET_SUPPORTING_WM_CHECK
, display
);
281 wxMAKE_ATOM(_NET_SUPPORTED
, display
);
283 // FIXME: We may want to cache these checks. Note that we can't simply
284 // remember the results in global variable because the WM may go
285 // away and be replaced by another one! One possible approach
286 // would be invalidate the case every 15 seconds or so. Since this
287 // code is currently only used by wxTopLevelWindow::ShowFullScreen,
288 // it is not important that it is not optimized.
290 // If the WM supports ICCCM (i.e. the root window has
291 // _NET_SUPPORTING_WM_CHECK property that points to a WM-owned
292 // window), we could watch for DestroyNotify event on the window
293 // and invalidate our cache when the windows goes away (= WM
294 // is replaced by another one). This is what GTK+ 2 does.
295 // Let's do it only if it is needed, it requires changes to
303 unsigned long nwins
, natoms
;
305 // Is the WM ICCCM supporting?
306 XGetWindowProperty(display
, rootWnd
,
307 _NET_SUPPORTING_WM_CHECK
, 0, LONG_MAX
,
308 False
, XA_WINDOW
, &type
, &format
, &nwins
,
309 &after
, (unsigned char **)&wins
);
310 if ( type
!= XA_WINDOW
|| nwins
<= 0 || wins
[0] == None
)
314 // Query for supported features:
315 XGetWindowProperty(display
, rootWnd
,
316 _NET_SUPPORTED
, 0, LONG_MAX
,
317 False
, XA_ATOM
, &type
, &format
, &natoms
,
318 &after
, (unsigned char **)&atoms
);
319 if ( type
!= XA_ATOM
|| atoms
== NULL
)
322 // Lookup the feature we want:
323 for (unsigned i
= 0; i
< natoms
; i
++)
325 if ( atoms
[i
] == feature
)
337 #define _NET_WM_STATE_REMOVE 0
338 #define _NET_WM_STATE_ADD 1
340 static void wxWMspecSetState(Display
*display
, Window rootWnd
,
341 Window window
, int operation
, Atom state
)
343 wxMAKE_ATOM(_NET_WM_STATE
, display
);
345 if ( IsMapped(display
, window
) )
348 xev
.type
= ClientMessage
;
349 xev
.xclient
.type
= ClientMessage
;
350 xev
.xclient
.serial
= 0;
351 xev
.xclient
.send_event
= True
;
352 xev
.xclient
.display
= display
;
353 xev
.xclient
.window
= window
;
354 xev
.xclient
.message_type
= _NET_WM_STATE
;
355 xev
.xclient
.format
= 32;
356 xev
.xclient
.data
.l
[0] = operation
;
357 xev
.xclient
.data
.l
[1] = state
;
358 xev
.xclient
.data
.l
[2] = None
;
360 XSendEvent(display
, rootWnd
,
362 SubstructureRedirectMask
| SubstructureNotifyMask
,
365 // FIXME - must modify _NET_WM_STATE property list if the window
369 static void wxWMspecSetFullscreen(Display
*display
, Window rootWnd
,
370 Window window
, bool fullscreen
)
372 wxMAKE_ATOM(_NET_WM_STATE_FULLSCREEN
, display
);
373 wxWMspecSetState(display
, rootWnd
,
375 fullscreen
? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
,
376 _NET_WM_STATE_FULLSCREEN
);
380 // Is the user running KDE's kwin window manager? At least kwin from KDE 3
381 // sets KWIN_RUNNING property on the root window.
382 static bool wxKwinRunning(Display
*display
, Window rootWnd
)
384 wxMAKE_ATOM(KWIN_RUNNING
, display
);
389 unsigned long nitems
, after
;
390 if (XGetWindowProperty(display
, rootWnd
,
391 KWIN_RUNNING
, 0, 1, False
, KWIN_RUNNING
,
392 &type
, &format
, &nitems
, &after
,
398 bool retval
= (type
== KWIN_RUNNING
&&
399 nitems
== 1 && data
&& ((long*)data
)[0] == 1);
404 // KDE's kwin is Qt-centric so much than no normal method of fullscreen
405 // mode will work with it. We have to carefully emulate the Qt way.
406 static void wxSetKDEFullscreen(Display
*display
, Window rootWnd
,
407 Window w
, bool fullscreen
, wxRect
*origRect
)
412 wxMAKE_ATOM(_NET_WM_WINDOW_TYPE
, display
);
413 wxMAKE_ATOM(_NET_WM_WINDOW_TYPE_NORMAL
, display
);
414 wxMAKE_ATOM(_KDE_NET_WM_WINDOW_TYPE_OVERRIDE
, display
);
415 wxMAKE_ATOM(_NET_WM_STATE_STAYS_ON_TOP
, display
);
419 data
[0] = _KDE_NET_WM_WINDOW_TYPE_OVERRIDE
;
420 data
[1] = _NET_WM_WINDOW_TYPE_NORMAL
;
425 data
[0] = _NET_WM_WINDOW_TYPE_NORMAL
;
430 // it is necessary to unmap the window, otherwise kwin will ignore us:
431 XSync(display
, False
);
433 bool wasMapped
= IsMapped(display
, w
);
436 XUnmapWindow(display
, w
);
437 XSync(display
, False
);
440 XChangeProperty(display
, w
, _NET_WM_WINDOW_TYPE
, XA_ATOM
, 32,
441 PropModeReplace
, (unsigned char *) &data
[0], lng
);
442 XSync(display
, False
);
446 XMapRaised(display
, w
);
447 XSync(display
, False
);
450 wxWMspecSetState(display
, rootWnd
, w
,
451 fullscreen
? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
,
452 _NET_WM_STATE_STAYS_ON_TOP
);
453 XSync(display
, False
);
457 // NB: like many other WMs, kwin ignores the first request for a window
458 // position change after the window was mapped. This additional
459 // move+resize event will ensure that the window is restored in
460 // exactly the same position as before it was made fullscreen
461 // (because wxTopLevelWindow::ShowFullScreen will call SetSize, thus
462 // setting the position for the second time).
463 XMoveResizeWindow(display
, w
,
464 origRect
->x
, origRect
->y
,
465 origRect
->width
, origRect
->height
);
466 XSync(display
, False
);
471 wxX11FullScreenMethod
wxGetFullScreenMethodX11(WXDisplay
* display
,
474 Window root
= WindowCast(rootWindow
);
475 Display
*disp
= (Display
*)display
;
477 // if WM supports _NET_WM_STATE_FULLSCREEN from wm-spec 1.2, use it:
478 wxMAKE_ATOM(_NET_WM_STATE_FULLSCREEN
, disp
);
479 if (wxQueryWMspecSupport(disp
, root
, _NET_WM_STATE_FULLSCREEN
))
481 wxLogTrace(wxT("fullscreen"),
482 wxT("detected _NET_WM_STATE_FULLSCREEN support"));
483 return wxX11_FS_WMSPEC
;
486 // if the user is running KDE's kwin WM, use a legacy hack because
487 // kwin doesn't understand any other method:
488 if (wxKwinRunning(disp
, root
))
490 wxLogTrace(wxT("fullscreen"), wxT("detected kwin"));
494 // finally, fall back to ICCCM heuristic method:
495 wxLogTrace(wxT("fullscreen"), wxT("unknown WM, using _WIN_LAYER"));
496 return wxX11_FS_GENERIC
;
500 void wxSetFullScreenStateX11(WXDisplay
* display
, WXWindow rootWindow
,
501 WXWindow window
, bool show
,
503 wxX11FullScreenMethod method
)
505 // NB: please see the comment under "Fullscreen mode:" title above
506 // for implications of changing this code.
508 Window wnd
= WindowCast(window
);
509 Window root
= WindowCast(rootWindow
);
510 Display
*disp
= (Display
*)display
;
512 if (method
== wxX11_FS_AUTODETECT
)
513 method
= wxGetFullScreenMethodX11(display
, rootWindow
);
517 case wxX11_FS_WMSPEC
:
518 wxWMspecSetFullscreen(disp
, root
, wnd
, show
);
521 wxSetKDEFullscreen(disp
, root
, wnd
, show
, origRect
);
524 wxWinHintsSetLayer(disp
, root
, wnd
,
525 show
? WIN_LAYER_ABOVE_DOCK
: WIN_LAYER_NORMAL
);
532 // ----------------------------------------------------------------------------
533 // keycode translations
534 // ----------------------------------------------------------------------------
536 #include <X11/keysym.h>
538 // FIXME what about tables??
540 int wxCharCodeXToWX(WXKeySym keySym
)
547 id
= WXK_SHIFT
; break;
550 id
= WXK_CONTROL
; break;
555 id
= WXK_CAPITAL
; break;
557 id
= WXK_BACK
; break;
559 id
= WXK_DELETE
; break;
561 id
= WXK_CLEAR
; break;
567 id
= WXK_RETURN
; break;
569 id
= WXK_ESCAPE
; break;
572 id
= WXK_PAUSE
; break;
574 id
= WXK_NUMLOCK
; break;
576 id
= WXK_SCROLL
; break;
579 id
= WXK_HOME
; break;
583 id
= WXK_LEFT
; break;
585 id
= WXK_RIGHT
; break;
589 id
= WXK_DOWN
; break;
591 id
= WXK_PAGEDOWN
; break;
593 id
= WXK_PAGEUP
; break;
595 id
= WXK_MENU
; break;
597 id
= WXK_SELECT
; break;
599 id
= WXK_CANCEL
; break;
601 id
= WXK_PRINT
; break;
603 id
= WXK_EXECUTE
; break;
605 id
= WXK_INSERT
; break;
607 id
= WXK_HELP
; break;
610 id
= WXK_NUMPAD_MULTIPLY
; break;
612 id
= WXK_NUMPAD_ADD
; break;
614 id
= WXK_NUMPAD_SUBTRACT
; break;
616 id
= WXK_NUMPAD_DIVIDE
; break;
618 id
= WXK_NUMPAD_DECIMAL
; break;
620 id
= WXK_NUMPAD_EQUAL
; break;
622 id
= WXK_NUMPAD_SPACE
; break;
624 id
= WXK_NUMPAD_TAB
; break;
626 id
= WXK_NUMPAD_ENTER
; break;
628 id
= WXK_NUMPAD0
; break;
630 id
= WXK_NUMPAD1
; break;
632 id
= WXK_NUMPAD2
; break;
634 id
= WXK_NUMPAD3
; break;
636 id
= WXK_NUMPAD4
; break;
638 id
= WXK_NUMPAD5
; break;
640 id
= WXK_NUMPAD6
; break;
642 id
= WXK_NUMPAD7
; break;
644 id
= WXK_NUMPAD8
; break;
646 id
= WXK_NUMPAD9
; break;
648 id
= WXK_NUMPAD_INSERT
; break;
650 id
= WXK_NUMPAD_END
; break;
652 id
= WXK_NUMPAD_DOWN
; break;
653 case XK_KP_Page_Down
:
654 id
= WXK_NUMPAD_PAGEDOWN
; break;
656 id
= WXK_NUMPAD_LEFT
; break;
658 id
= WXK_NUMPAD_RIGHT
; break;
660 id
= WXK_NUMPAD_HOME
; break;
662 id
= WXK_NUMPAD_UP
; break;
664 id
= WXK_NUMPAD_PAGEUP
; break;
714 id
= (keySym
<= 255) ? (int)keySym
: -1;
720 WXKeySym
wxCharCodeWXToX(int id
)
726 case WXK_CANCEL
: keySym
= XK_Cancel
; break;
727 case WXK_BACK
: keySym
= XK_BackSpace
; break;
728 case WXK_TAB
: keySym
= XK_Tab
; break;
729 case WXK_CLEAR
: keySym
= XK_Clear
; break;
730 case WXK_RETURN
: keySym
= XK_Return
; break;
731 case WXK_SHIFT
: keySym
= XK_Shift_L
; break;
732 case WXK_CONTROL
: keySym
= XK_Control_L
; break;
733 case WXK_ALT
: keySym
= XK_Meta_L
; break;
734 case WXK_CAPITAL
: keySym
= XK_Caps_Lock
; break;
735 case WXK_MENU
: keySym
= XK_Menu
; break;
736 case WXK_PAUSE
: keySym
= XK_Pause
; break;
737 case WXK_ESCAPE
: keySym
= XK_Escape
; break;
738 case WXK_SPACE
: keySym
= ' '; break;
739 case WXK_PAGEUP
: keySym
= XK_Prior
; break;
740 case WXK_PAGEDOWN
: keySym
= XK_Next
; break;
741 case WXK_END
: keySym
= XK_End
; break;
742 case WXK_HOME
: keySym
= XK_Home
; break;
743 case WXK_LEFT
: keySym
= XK_Left
; break;
744 case WXK_UP
: keySym
= XK_Up
; break;
745 case WXK_RIGHT
: keySym
= XK_Right
; break;
746 case WXK_DOWN
: keySym
= XK_Down
; break;
747 case WXK_SELECT
: keySym
= XK_Select
; break;
748 case WXK_PRINT
: keySym
= XK_Print
; break;
749 case WXK_EXECUTE
: keySym
= XK_Execute
; break;
750 case WXK_INSERT
: keySym
= XK_Insert
; break;
751 case WXK_DELETE
: keySym
= XK_Delete
; break;
752 case WXK_HELP
: keySym
= XK_Help
; break;
753 case WXK_NUMPAD0
: keySym
= XK_KP_0
; break; case WXK_NUMPAD_INSERT
: keySym
= XK_KP_Insert
; break;
754 case WXK_NUMPAD1
: keySym
= XK_KP_1
; break; case WXK_NUMPAD_END
: keySym
= XK_KP_End
; break;
755 case WXK_NUMPAD2
: keySym
= XK_KP_2
; break; case WXK_NUMPAD_DOWN
: keySym
= XK_KP_Down
; break;
756 case WXK_NUMPAD3
: keySym
= XK_KP_3
; break; case WXK_NUMPAD_PAGEDOWN
: keySym
= XK_KP_Page_Down
; break;
757 case WXK_NUMPAD4
: keySym
= XK_KP_4
; break; case WXK_NUMPAD_LEFT
: keySym
= XK_KP_Left
; break;
758 case WXK_NUMPAD5
: keySym
= XK_KP_5
; break;
759 case WXK_NUMPAD6
: keySym
= XK_KP_6
; break; case WXK_NUMPAD_RIGHT
: keySym
= XK_KP_Right
; break;
760 case WXK_NUMPAD7
: keySym
= XK_KP_7
; break; case WXK_NUMPAD_HOME
: keySym
= XK_KP_Home
; break;
761 case WXK_NUMPAD8
: keySym
= XK_KP_8
; break; case WXK_NUMPAD_UP
: keySym
= XK_KP_Up
; break;
762 case WXK_NUMPAD9
: keySym
= XK_KP_9
; break; case WXK_NUMPAD_PAGEUP
: keySym
= XK_KP_Page_Up
; break;
763 case WXK_NUMPAD_DECIMAL
: keySym
= XK_KP_Decimal
; break; case WXK_NUMPAD_DELETE
: keySym
= XK_KP_Delete
; break;
764 case WXK_NUMPAD_MULTIPLY
: keySym
= XK_KP_Multiply
; break;
765 case WXK_NUMPAD_ADD
: keySym
= XK_KP_Add
; break;
766 case WXK_NUMPAD_SUBTRACT
: keySym
= XK_KP_Subtract
; break;
767 case WXK_NUMPAD_DIVIDE
: keySym
= XK_KP_Divide
; break;
768 case WXK_NUMPAD_ENTER
: keySym
= XK_KP_Enter
; break;
769 case WXK_NUMPAD_SEPARATOR
: keySym
= XK_KP_Separator
; break;
770 case WXK_F1
: keySym
= XK_F1
; break;
771 case WXK_F2
: keySym
= XK_F2
; break;
772 case WXK_F3
: keySym
= XK_F3
; break;
773 case WXK_F4
: keySym
= XK_F4
; break;
774 case WXK_F5
: keySym
= XK_F5
; break;
775 case WXK_F6
: keySym
= XK_F6
; break;
776 case WXK_F7
: keySym
= XK_F7
; break;
777 case WXK_F8
: keySym
= XK_F8
; break;
778 case WXK_F9
: keySym
= XK_F9
; break;
779 case WXK_F10
: keySym
= XK_F10
; break;
780 case WXK_F11
: keySym
= XK_F11
; break;
781 case WXK_F12
: keySym
= XK_F12
; break;
782 case WXK_F13
: keySym
= XK_F13
; break;
783 case WXK_F14
: keySym
= XK_F14
; break;
784 case WXK_F15
: keySym
= XK_F15
; break;
785 case WXK_F16
: keySym
= XK_F16
; break;
786 case WXK_F17
: keySym
= XK_F17
; break;
787 case WXK_F18
: keySym
= XK_F18
; break;
788 case WXK_F19
: keySym
= XK_F19
; break;
789 case WXK_F20
: keySym
= XK_F20
; break;
790 case WXK_F21
: keySym
= XK_F21
; break;
791 case WXK_F22
: keySym
= XK_F22
; break;
792 case WXK_F23
: keySym
= XK_F23
; break;
793 case WXK_F24
: keySym
= XK_F24
; break;
794 case WXK_NUMLOCK
: keySym
= XK_Num_Lock
; break;
795 case WXK_SCROLL
: keySym
= XK_Scroll_Lock
; break;
796 default: keySym
= id
<= 255 ? (KeySym
)id
: 0;
803 // ----------------------------------------------------------------------------
804 // check current state of a key
805 // ----------------------------------------------------------------------------
807 bool wxGetKeyState(wxKeyCode key
)
809 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
810 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
812 Display
*pDisplay
= (Display
*) wxGetDisplay();
814 int iKey
= wxCharCodeWXToX(key
);
816 Window wDummy1
, wDummy2
;
817 int iDummy3
, iDummy4
, iDummy5
, iDummy6
;
819 KeyCode keyCode
= XKeysymToKeycode(pDisplay
,iKey
);
820 if (keyCode
== NoSymbol
)
823 if ( IsModifierKey(iKey
) ) // If iKey is a modifier key, use a different method
825 XModifierKeymap
*map
= XGetModifierMapping(pDisplay
);
826 wxCHECK_MSG( map
, false, wxT("failed to get X11 modifiers map") );
828 for (int i
= 0; i
< 8; ++i
)
830 if ( map
->modifiermap
[map
->max_keypermod
* i
] == keyCode
)
836 XQueryPointer(pDisplay
, DefaultRootWindow(pDisplay
), &wDummy1
, &wDummy2
,
837 &iDummy3
, &iDummy4
, &iDummy5
, &iDummy6
, &iMask
);
838 XFreeModifiermap(map
);
839 return (iMask
& iKeyMask
) != 0;
842 // From the XLib manual:
843 // The XQueryKeymap() function returns a bit vector for the logical state of the keyboard,
844 // where each bit set to 1 indicates that the corresponding key is currently pressed down.
845 // The vector is represented as 32 bytes. Byte N (from 0) contains the bits for keys 8N to 8N + 7
846 // with the least-significant bit in the byte representing key 8N.
848 XQueryKeymap(pDisplay
, key_vector
);
849 return key_vector
[keyCode
>> 3] & (1 << (keyCode
& 7));
852 // ----------------------------------------------------------------------------
853 // Launch document with default app
854 // ----------------------------------------------------------------------------
856 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
860 // Our best best is to use xdg-open from freedesktop.org cross-desktop
861 // compatibility suite xdg-utils
862 // (see http://portland.freedesktop.org/wiki/) -- this is installed on
863 // most modern distributions and may be tweaked by them to handle
864 // distribution specifics.
865 wxString path
, xdg_open
;
866 if ( wxGetEnv("PATH", &path
) &&
867 wxFindFileInPath(&xdg_open
, path
, "xdg-open") )
869 if ( wxExecute(xdg_open
+ " " + document
) )
876 // ----------------------------------------------------------------------------
877 // Launch default browser
878 // ----------------------------------------------------------------------------
880 bool wxDoLaunchDefaultBrowser(const wxString
& url
, int flags
)
884 // Our best best is to use xdg-open from freedesktop.org cross-desktop
885 // compatibility suite xdg-utils
886 // (see http://portland.freedesktop.org/wiki/) -- this is installed on
887 // most modern distributions and may be tweaked by them to handle
888 // distribution specifics. Only if that fails, try to find the right
889 // browser ourselves.
890 wxString path
, xdg_open
;
891 if ( wxGetEnv("PATH", &path
) &&
892 wxFindFileInPath(&xdg_open
, path
, "xdg-open") )
894 if ( wxExecute(xdg_open
+ " " + url
) )
898 wxString desktop
= wxTheApp
->GetTraits()->GetDesktopEnvironment();
900 // GNOME and KDE desktops have some applications which should be always installed
901 // together with their main parts, which give us the
902 if (desktop
== wxT("GNOME"))
904 wxArrayString errors
;
905 wxArrayString output
;
907 // gconf will tell us the path of the application to use as browser
908 long res
= wxExecute( wxT("gconftool-2 --get /desktop/gnome/applications/browser/exec"),
909 output
, errors
, wxEXEC_NODISABLE
);
910 if (res
>= 0 && errors
.GetCount() == 0)
912 wxString cmd
= output
[0];
913 cmd
<< wxT(' ') << url
;
918 else if (desktop
== wxT("KDE"))
920 // kfmclient directly opens the given URL
921 if (wxExecute(wxT("kfmclient openURL ") + url
))
928 #endif // __WXX11__ || __WXGTK__ || __WXMOTIF__