]> git.saurik.com Git - wxWidgets.git/blame - src/unix/uiactionx11.cpp
Large image-loading speedup and small attribute-loading speedup
[wxWidgets.git] / src / unix / uiactionx11.cpp
CommitLineData
a02a5cfc
KO
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
9b7e0226
VZ
12#include "wx/defs.h"
13
14#if wxUSE_UIACTIONSIMULATOR
15
16#include "wx/uiaction.h"
a02a5cfc
KO
17
18#include <X11/Xlib.h>
19#include <X11/Xutil.h>
20#include <X11/extensions/XTest.h>
21
22void 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;
9b7e0226 41
a02a5cfc
KO
42 Display *display = XOpenDisplay(0);
43 wxASSERT_MSG(display, "No display available!");
9b7e0226 44
a02a5cfc 45 memset(&event, 0x00, sizeof(event));
9b7e0226 46
a02a5cfc
KO
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;
9b7e0226 54
a02a5cfc
KO
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;
9b7e0226 57
a02a5cfc
KO
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 }
9b7e0226 63
a02a5cfc
KO
64 XSendEvent(display, PointerWindow, True, 0xfff, &event);
65 XFlush(display);
66 XCloseDisplay(display);
67}
68
69bool wxUIActionSimulator::MouseDown(int button)
70{
71 SendButtonEvent(button, true);
72 return true;
73}
74
75bool wxUIActionSimulator::MouseMove(long x, long y)
9b7e0226 76{
a02a5cfc
KO
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
86bool wxUIActionSimulator::MouseUp(int button)
87{
88 SendButtonEvent(button, false);
89 return true;
90}
91
92bool 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!");
9b7e0226 96
a02a5cfc
KO
97 XKeyEvent event;
98 int mask = 0xfff;
99 memset(&event, 0x00, sizeof(event));
9b7e0226 100
a02a5cfc
KO
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;
9b7e0226 110
a02a5cfc
KO
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;
9b7e0226 113
a02a5cfc
KO
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 }
9b7e0226 119
a02a5cfc
KO
120 XSendEvent(display, PointerWindow, True, mask, (XEvent*) &event);
121 XFlush(display);
122 XCloseDisplay(display);
123
124 return true;
125}
126
9b7e0226 127#endif // wxUSE_UIACTIONSIMULATOR