]> git.saurik.com Git - wxWidgets.git/blob - src/unix/uiactionx11.cpp
adding more infos, links
[wxWidgets.git] / src / unix / uiactionx11.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/uiactionx11.cpp
3 // Purpose: wxUIActionSimulator implementation
4 // Author: Kevin Ollivier
5 // Modified by:
6 // Created: 2010-03-06
7 // RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Kevin Ollivier
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/defs.h"
13
14 #if wxUSE_UIACTIONSIMULATOR
15
16 #include "wx/uiaction.h"
17
18 #include <X11/Xlib.h>
19 #include <X11/Xutil.h>
20 #include <X11/extensions/XTest.h>
21
22 void SendButtonEvent(int button, bool isDown)
23 {
24 int xbutton = 0;
25 switch (button)
26 {
27 case wxMOUSE_BTN_LEFT:
28 xbutton = 1;
29 break;
30 case wxMOUSE_BTN_RIGHT:
31 xbutton = 2;
32 break;
33 case wxMOUSE_BTN_MIDDLE:
34 xbutton = 3;
35 break;
36 default:
37 wxFAIL_MSG("Unsupported button passed in.");
38 }
39
40 XEvent event;
41
42 Display *display = XOpenDisplay(0);
43 wxASSERT_MSG(display, "No display available!");
44
45 memset(&event, 0x00, sizeof(event));
46
47 if (isDown)
48 event.type = ButtonPress;
49 else
50 event.type = ButtonRelease;
51
52 event.xbutton.button = xbutton;
53 event.xbutton.same_screen = True;
54
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;
57
58 while (event.xbutton.subwindow)
59 {
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);
62 }
63
64 XSendEvent(display, PointerWindow, True, 0xfff, &event);
65 XFlush(display);
66 XCloseDisplay(display);
67 }
68
69 bool wxUIActionSimulator::MouseDown(int button)
70 {
71 SendButtonEvent(button, true);
72 return true;
73 }
74
75 bool wxUIActionSimulator::MouseMove(long x, long y)
76 {
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);
81 XFlush(display);
82 XCloseDisplay(display);
83 return true;
84 }
85
86 bool wxUIActionSimulator::MouseUp(int button)
87 {
88 SendButtonEvent(button, false);
89 return true;
90 }
91
92 bool wxUIActionSimulator::Key(int keycode, bool isDown, bool WXUNUSED(shiftDown), bool WXUNUSED(cmdDown), bool WXUNUSED(altDown))
93 {
94 Display *display = XOpenDisplay(0);
95 wxASSERT_MSG(display, "No display available!");
96
97 XKeyEvent event;
98 int mask = 0xfff;
99 memset(&event, 0x00, sizeof(event));
100
101 if (isDown) {
102 event.type = KeyPress;
103 mask = KeyPressMask;
104 }
105 else {
106 event.type = KeyRelease;
107 mask = KeyReleaseMask;
108 }
109 event.same_screen = True;
110
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;
113
114 while (event.subwindow)
115 {
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);
118 }
119
120 XSendEvent(display, PointerWindow, True, mask, (XEvent*) &event);
121 XFlush(display);
122 XCloseDisplay(display);
123
124 return true;
125 }
126
127 #endif // wxUSE_UIACTIONSIMULATOR