]>
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
7 // RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Kevin Ollivier
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #if wxUSE_UIACTIONSIMULATOR
16 #include "wx/uiaction.h"
19 #include <X11/Xutil.h>
20 #include <X11/extensions/XTest.h>
22 void SendButtonEvent(int button
, bool isDown
)
27 case wxMOUSE_BTN_LEFT
:
30 case wxMOUSE_BTN_RIGHT
:
33 case wxMOUSE_BTN_MIDDLE
:
37 wxFAIL_MSG("Unsupported button passed in.");
42 Display
*display
= XOpenDisplay(0);
43 wxASSERT_MSG(display
, "No display available!");
45 memset(&event
, 0x00, sizeof(event
));
48 event
.type
= ButtonPress
;
50 event
.type
= ButtonRelease
;
52 event
.xbutton
.button
= xbutton
;
53 event
.xbutton
.same_screen
= True
;
55 XQueryPointer(display
, RootWindow(display
, DefaultScreen(display
)), &event
.xbutton
.root
, &event
.xbutton
.window
, &event
.xbutton
.x_root
, &event
.xbutton
.y_root
, &event
.xbutton
.x
, &event
.xbutton
.y
, &event
.xbutton
.state
);
56 event
.xbutton
.subwindow
= event
.xbutton
.window
;
58 while (event
.xbutton
.subwindow
)
60 event
.xbutton
.window
= event
.xbutton
.subwindow
;
61 XQueryPointer(display
, event
.xbutton
.window
, &event
.xbutton
.root
, &event
.xbutton
.subwindow
, &event
.xbutton
.x_root
, &event
.xbutton
.y_root
, &event
.xbutton
.x
, &event
.xbutton
.y
, &event
.xbutton
.state
);
64 XSendEvent(display
, PointerWindow
, True
, 0xfff, &event
);
66 XCloseDisplay(display
);
69 bool wxUIActionSimulator::MouseDown(int button
)
71 SendButtonEvent(button
, true);
75 bool wxUIActionSimulator::MouseMove(long x
, long y
)
77 Display
*display
= XOpenDisplay(0);
78 wxASSERT_MSG(display
, "No display available!");
79 Window root
= DefaultRootWindow(display
);
80 XWarpPointer(display
, None
, root
, 0, 0, 0, 0, x
, y
);
82 XCloseDisplay(display
);
86 bool wxUIActionSimulator::MouseUp(int button
)
88 SendButtonEvent(button
, false);
92 bool wxUIActionSimulator::Key(int keycode
, bool isDown
, bool WXUNUSED(shiftDown
), bool WXUNUSED(cmdDown
), bool WXUNUSED(altDown
))
94 Display
*display
= XOpenDisplay(0);
95 wxASSERT_MSG(display
, "No display available!");
99 memset(&event
, 0x00, sizeof(event
));
102 event
.type
= KeyPress
;
106 event
.type
= KeyRelease
;
107 mask
= KeyReleaseMask
;
109 event
.same_screen
= True
;
111 XQueryPointer(display
, RootWindow(display
, DefaultScreen(display
)), &event
.root
, &event
.window
, &event
.x_root
, &event
.y_root
, &event
.x
, &event
.y
, &event
.state
);
112 event
.subwindow
= event
.window
;
114 while (event
.subwindow
)
116 event
.window
= event
.subwindow
;
117 XQueryPointer(display
, event
.window
, &event
.root
, &event
.subwindow
, &event
.x_root
, &event
.y_root
, &event
.x
, &event
.y
, &event
.state
);
120 XSendEvent(display
, PointerWindow
, True
, mask
, (XEvent
*) &event
);
122 XCloseDisplay(display
);
127 #endif // wxUSE_UIACTIONSIMULATOR