]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/uiactionx11.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/uiactionx11.cpp
3 // Purpose: wxUIActionSimulator implementation
4 // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
7 // RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Kevin Ollivier
9 // (c) 2010 Steven Lamerton
10 // (c) 2010 Vadim Zeitlin
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
16 #if wxUSE_UIACTIONSIMULATOR
18 #include "wx/uiaction.h"
20 #include <X11/Xutil.h>
22 #include "wx/unix/utilsx11.h"
27 void SendButtonEvent(int button
, bool isDown
)
32 case wxMOUSE_BTN_LEFT
:
35 case wxMOUSE_BTN_MIDDLE
:
38 case wxMOUSE_BTN_RIGHT
:
42 wxFAIL_MSG("Unsupported button passed in.");
47 wxCHECK_RET(display
, "No display available!");
50 memset(&event
, 0x00, sizeof(event
));
52 event
.type
= isDown
? ButtonPress
: ButtonRelease
;
53 event
.xbutton
.button
= xbutton
;
54 event
.xbutton
.same_screen
= True
;
56 XQueryPointer(display
, display
.DefaultRoot(),
57 &event
.xbutton
.root
, &event
.xbutton
.window
,
58 &event
.xbutton
.x_root
, &event
.xbutton
.y_root
,
59 &event
.xbutton
.x
, &event
.xbutton
.y
, &event
.xbutton
.state
);
60 event
.xbutton
.subwindow
= event
.xbutton
.window
;
62 while (event
.xbutton
.subwindow
)
64 event
.xbutton
.window
= event
.xbutton
.subwindow
;
65 XQueryPointer(display
, event
.xbutton
.window
,
66 &event
.xbutton
.root
, &event
.xbutton
.subwindow
,
67 &event
.xbutton
.x_root
, &event
.xbutton
.y_root
,
68 &event
.xbutton
.x
, &event
.xbutton
.y
, &event
.xbutton
.state
);
71 XSendEvent(display
, PointerWindow
, True
, 0xfff, &event
);
74 } // anonymous namespace
76 bool wxUIActionSimulator::MouseDown(int button
)
78 SendButtonEvent(button
, true);
82 bool wxUIActionSimulator::MouseMove(long x
, long y
)
85 wxASSERT_MSG(display
, "No display available!");
87 Window root
= display
.DefaultRoot();
88 XWarpPointer(display
, None
, root
, 0, 0, 0, 0, x
, y
);
93 bool wxUIActionSimulator::MouseUp(int button
)
95 SendButtonEvent(button
, false);
99 bool wxUIActionSimulator::DoKey(int keycode
, int modifiers
, bool isDown
)
101 wxX11Display display
;
102 wxCHECK_MSG(display
, false, "No display available!");
114 mask
= KeyReleaseMask
;
117 WXKeySym xkeysym
= wxCharCodeWXToX(keycode
);
118 KeyCode xkeycode
= XKeysymToKeycode(display
, xkeysym
);
119 if ( xkeycode
== NoSymbol
)
124 XGetInputFocus(display
, &focus
, &revert
);
130 if (modifiers
& wxMOD_SHIFT
)
132 //Mod1 is alt in the vast majority of cases
133 if (modifiers
& wxMOD_ALT
)
135 if (modifiers
& wxMOD_CMD
)
139 event
.display
= display
;
140 event
.window
= focus
;
141 event
.root
= DefaultRootWindow(event
.display
);
142 event
.subwindow
= None
;
143 event
.time
= CurrentTime
;
148 event
.same_screen
= True
;
151 event
.keycode
= xkeycode
;
153 XSendEvent(event
.display
, event
.window
, True
, mask
, (XEvent
*) &event
);
158 #endif // wxUSE_UIACTIONSIMULATOR