]> git.saurik.com Git - wxWidgets.git/blame - src/unix/uiactionx11.cpp
Use _UNICODE instead of UNICODE in wx/msw/winundef.h.
[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
12#include <wx/defs.h>
13#include <wx/uiaction.h>
14
15#include <X11/Xlib.h>
16#include <X11/Xutil.h>
17#include <X11/extensions/XTest.h>
18
19void SendButtonEvent(int button, bool isDown)
20{
21 int xbutton = 0;
22 switch (button)
23 {
24 case wxMOUSE_BTN_LEFT:
25 xbutton = 1;
26 break;
27 case wxMOUSE_BTN_RIGHT:
28 xbutton = 2;
29 break;
30 case wxMOUSE_BTN_MIDDLE:
31 xbutton = 3;
32 break;
33 default:
34 wxFAIL_MSG("Unsupported button passed in.");
35 }
36
37 XEvent event;
38
39 Display *display = XOpenDisplay(0);
40 wxASSERT_MSG(display, "No display available!");
41
42 memset(&event, 0x00, sizeof(event));
43
44 if (isDown)
45 event.type = ButtonPress;
46 else
47 event.type = ButtonRelease;
48
49 event.xbutton.button = xbutton;
50 event.xbutton.same_screen = True;
51
52 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);
53 event.xbutton.subwindow = event.xbutton.window;
54
55 while (event.xbutton.subwindow)
56 {
57 event.xbutton.window = event.xbutton.subwindow;
58 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);
59 }
60
61 XSendEvent(display, PointerWindow, True, 0xfff, &event);
62 XFlush(display);
63 XCloseDisplay(display);
64}
65
66bool wxUIActionSimulator::MouseDown(int button)
67{
68 SendButtonEvent(button, true);
69 return true;
70}
71
72bool wxUIActionSimulator::MouseMove(long x, long y)
73{
74 Display *display = XOpenDisplay(0);
75 wxASSERT_MSG(display, "No display available!");
76 Window root = DefaultRootWindow(display);
77 XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);
78 XFlush(display);
79 XCloseDisplay(display);
80 return true;
81}
82
83bool wxUIActionSimulator::MouseUp(int button)
84{
85 SendButtonEvent(button, false);
86 return true;
87}
88
89bool wxUIActionSimulator::Key(int keycode, bool isDown, bool WXUNUSED(shiftDown), bool WXUNUSED(cmdDown), bool WXUNUSED(altDown))
90{
91 Display *display = XOpenDisplay(0);
92 wxASSERT_MSG(display, "No display available!");
93
94 XKeyEvent event;
95 int mask = 0xfff;
96 memset(&event, 0x00, sizeof(event));
97
98 if (isDown) {
99 event.type = KeyPress;
100 mask = KeyPressMask;
101 }
102 else {
103 event.type = KeyRelease;
104 mask = KeyReleaseMask;
105 }
106 event.same_screen = True;
107
108 XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.root, &event.window, &event.x_root, &event.y_root, &event.x, &event.y, &event.state);
109 event.subwindow = event.window;
110
111 while (event.subwindow)
112 {
113 event.window = event.subwindow;
114 XQueryPointer(display, event.window, &event.root, &event.subwindow, &event.x_root, &event.y_root, &event.x, &event.y, &event.state);
115 }
116
117 XSendEvent(display, PointerWindow, True, mask, (XEvent*) &event);
118 XFlush(display);
119 XCloseDisplay(display);
120
121 return true;
122}
123