]>
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
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"
21 #include <X11/Xutil.h>
23 #include "wx/unix/utilsx11.h"
28 void SendButtonEvent(int button
, bool isDown
)
33 case wxMOUSE_BTN_LEFT
:
36 case wxMOUSE_BTN_MIDDLE
:
39 case wxMOUSE_BTN_RIGHT
:
43 wxFAIL_MSG("Unsupported button passed in.");
48 wxCHECK_RET(display
, "No display available!");
51 memset(&event
, 0x00, sizeof(event
));
53 event
.type
= isDown
? ButtonPress
: ButtonRelease
;
54 event
.xbutton
.button
= xbutton
;
55 event
.xbutton
.same_screen
= True
;
57 XQueryPointer(display
, display
.DefaultRoot(),
58 &event
.xbutton
.root
, &event
.xbutton
.window
,
59 &event
.xbutton
.x_root
, &event
.xbutton
.y_root
,
60 &event
.xbutton
.x
, &event
.xbutton
.y
, &event
.xbutton
.state
);
61 event
.xbutton
.subwindow
= event
.xbutton
.window
;
63 while (event
.xbutton
.subwindow
)
65 event
.xbutton
.window
= event
.xbutton
.subwindow
;
66 XQueryPointer(display
, event
.xbutton
.window
,
67 &event
.xbutton
.root
, &event
.xbutton
.subwindow
,
68 &event
.xbutton
.x_root
, &event
.xbutton
.y_root
,
69 &event
.xbutton
.x
, &event
.xbutton
.y
, &event
.xbutton
.state
);
72 XSendEvent(display
, PointerWindow
, True
, 0xfff, &event
);
75 } // anonymous namespace
77 bool wxUIActionSimulator::MouseDown(int button
)
79 SendButtonEvent(button
, true);
83 bool wxUIActionSimulator::MouseMove(long x
, long y
)
86 wxASSERT_MSG(display
, "No display available!");
88 Window root
= display
.DefaultRoot();
89 XWarpPointer(display
, None
, root
, 0, 0, 0, 0, x
, y
);
94 bool wxUIActionSimulator::MouseUp(int button
)
96 SendButtonEvent(button
, false);
100 bool wxUIActionSimulator::DoKey(int keycode
, int modifiers
, bool isDown
)
102 wxX11Display display
;
103 wxCHECK_MSG(display
, false, "No display available!");
115 mask
= KeyReleaseMask
;
118 WXKeySym xkeysym
= wxCharCodeWXToX(keycode
);
119 KeyCode xkeycode
= XKeysymToKeycode(display
, xkeysym
);
120 if ( xkeycode
== NoSymbol
)
125 XGetInputFocus(display
, &focus
, &revert
);
131 if (modifiers
& wxMOD_SHIFT
)
133 //Mod1 is alt in the vast majority of cases
134 if (modifiers
& wxMOD_ALT
)
136 if (modifiers
& wxMOD_CMD
)
140 event
.display
= display
;
141 event
.window
= focus
;
142 event
.root
= DefaultRootWindow(event
.display
);
143 event
.subwindow
= None
;
144 event
.time
= CurrentTime
;
149 event
.same_screen
= True
;
152 event
.keycode
= xkeycode
;
154 XSendEvent(event
.display
, event
.window
, True
, mask
, (XEvent
*) &event
);
159 #endif // wxUSE_UIACTIONSIMULATOR