aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/platform
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-10-05 21:10:12 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-10-05 21:10:12 -0400
commit78fb19eb26c8814cc83c649a252b7f47bdf649a0 (patch)
treee8f38f35e404b37d4683604cb2a826ff3f4d2f1d /src/lib/platform
parent226b07c35afedc28ad1a769d6bf539e6cab320d4 (diff)
parentdff8b887edf10407f22aaab9d147948cd5491f0a (diff)
Update upstream source from tag 'upstream/2.3.2+dfsg'
Update to upstream version '2.3.2+dfsg' with Debian dir da6cb58f0203c792df99a475344204697ce64812
Diffstat (limited to 'src/lib/platform')
-rw-r--r--src/lib/platform/MSWindowsDesks.cpp13
-rw-r--r--src/lib/platform/MSWindowsHook.cpp11
-rw-r--r--src/lib/platform/MSWindowsScreen.cpp11
-rw-r--r--src/lib/platform/MSWindowsScreen.h2
-rw-r--r--src/lib/platform/OSXScreen.h2
-rw-r--r--src/lib/platform/OSXScreen.mm29
-rw-r--r--src/lib/platform/XWindowsScreen.cpp138
-rw-r--r--src/lib/platform/XWindowsScreen.h10
8 files changed, 128 insertions, 88 deletions
diff --git a/src/lib/platform/MSWindowsDesks.cpp b/src/lib/platform/MSWindowsDesks.cpp
index b43a218..e47aeaa 100644
--- a/src/lib/platform/MSWindowsDesks.cpp
+++ b/src/lib/platform/MSWindowsDesks.cpp
@@ -33,6 +33,7 @@
#include "base/IEventQueue.h"
#include <malloc.h>
+#include <VersionHelpers.h>
// these are only defined when WINVER >= 0x0500
#if !defined(SPI_GETMOUSESPEED)
@@ -45,6 +46,10 @@
#define SPI_GETSCREENSAVERRUNNING 114
#endif
+#if !defined(MOUSEEVENTF_HWHEEL)
+#define MOUSEEVENTF_HWHEEL 0x1000
+#endif
+
// X button stuff
#if !defined(WM_XBUTTONDOWN)
#define WM_XBUTTONDOWN 0x020B
@@ -296,12 +301,12 @@ MSWindowsDesks::fakeMouseButton(ButtonID button, bool press)
flags = press ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
break;
- case kButtonExtra0 + 0:
+ case kButtonExtra0:
data = XBUTTON1;
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
break;
- case kButtonExtra0 + 1:
+ case kButtonExtra1:
data = XBUTTON2;
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
break;
@@ -686,10 +691,12 @@ MSWindowsDesks::deskThread(void* vdesk)
break;
case BARRIER_MSG_FAKE_WHEEL:
- // XXX -- add support for x-axis scrolling
if (msg.lParam != 0) {
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, (DWORD)msg.lParam, 0);
}
+ else if (IsWindowsVistaOrGreater() && msg.wParam != 0) {
+ mouse_event(MOUSEEVENTF_HWHEEL, 0, 0, (DWORD)msg.wParam, 0);
+ }
break;
case BARRIER_MSG_CURSOR_POS: {
diff --git a/src/lib/platform/MSWindowsHook.cpp b/src/lib/platform/MSWindowsHook.cpp
index 2d7845a..b9b9740 100644
--- a/src/lib/platform/MSWindowsHook.cpp
+++ b/src/lib/platform/MSWindowsHook.cpp
@@ -25,6 +25,10 @@
#include "common/DataDirectories.h"
#include "base/Log.h"
+#ifndef WM_MOUSEHWHEEL
+#define WM_MOUSEHWHEEL 0x020E
+#endif
+
//
// debugging compile flag. when not zero the server doesn't grab
// the keyboard when the mouse leaves the server screen. this
@@ -473,6 +477,13 @@ mouseHookHandler(WPARAM wParam, SInt32 x, SInt32 y, SInt32 data)
}
return (g_mode == kHOOK_RELAY_EVENTS);
+ case WM_MOUSEHWHEEL:
+ if (g_mode == kHOOK_RELAY_EVENTS) {
+ // relay event
+ PostThreadMessage(g_threadID, BARRIER_MSG_MOUSE_WHEEL, 0, data);
+ }
+ return (g_mode == kHOOK_RELAY_EVENTS);
+
case WM_NCMOUSEMOVE:
case WM_MOUSEMOVE:
if (g_mode == kHOOK_RELAY_EVENTS) {
diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp
index 5246f96..2717034 100644
--- a/src/lib/platform/MSWindowsScreen.cpp
+++ b/src/lib/platform/MSWindowsScreen.cpp
@@ -952,9 +952,9 @@ MSWindowsScreen::updateButtons()
m_buttons[kButtonLeft] = (GetKeyState(VK_LBUTTON) < 0);
m_buttons[kButtonRight] = (GetKeyState(VK_RBUTTON) < 0);
m_buttons[kButtonMiddle] = (GetKeyState(VK_MBUTTON) < 0);
- m_buttons[kButtonExtra0 + 0] = (numButtons >= 4) &&
+ m_buttons[kButtonExtra0] = (numButtons >= 4) &&
(GetKeyState(VK_XBUTTON1) < 0);
- m_buttons[kButtonExtra0 + 1] = (numButtons >= 5) &&
+ m_buttons[kButtonExtra1] = (numButtons >= 5) &&
(GetKeyState(VK_XBUTTON2) < 0);
}
@@ -1007,8 +1007,7 @@ MSWindowsScreen::onPreDispatchPrimary(HWND,
static_cast<SInt32>(lParam));
case BARRIER_MSG_MOUSE_WHEEL:
- // XXX -- support x-axis scrolling
- return onMouseWheel(0, static_cast<SInt32>(wParam));
+ return onMouseWheel(static_cast<SInt32>(lParam), static_cast<SInt32>(wParam));
case BARRIER_MSG_PRE_WARP:
{
@@ -1670,13 +1669,13 @@ MSWindowsScreen::mapButtonFromEvent(WPARAM msg, LPARAM button) const
switch (button) {
case XBUTTON1:
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 4) {
- return kButtonExtra0 + 0;
+ return kButtonExtra0;
}
break;
case XBUTTON2:
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 5) {
- return kButtonExtra0 + 1;
+ return kButtonExtra1;
}
break;
}
diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h
index 4245d6c..14cd505 100644
--- a/src/lib/platform/MSWindowsScreen.h
+++ b/src/lib/platform/MSWindowsScreen.h
@@ -307,7 +307,7 @@ private:
HotKeyToIDMap m_hotKeyToIDMap;
// map of button state
- bool m_buttons[1 + kButtonExtra0 + 1];
+ bool m_buttons[NumButtonIDs];
// the system shows the mouse cursor when an internal display count
// is >= 0. this count is maintained per application but there's
diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h
index 6178529..bbddfb9 100644
--- a/src/lib/platform/OSXScreen.h
+++ b/src/lib/platform/OSXScreen.h
@@ -118,7 +118,7 @@ private:
void sendClipboardEvent(Event::Type type, ClipboardID id) const;
// message handlers
- bool onMouseMove(SInt32 mx, SInt32 my);
+ bool onMouseMove(CGFloat mx, CGFloat my);
// mouse button handler. pressed is true if this is a mousedown
// event, false if it is a mouseup event. macButton is the index
// of the button pressed using the mac button mapping.
diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm
index 8c7e24c..2b4594f 100644
--- a/src/lib/platform/OSXScreen.mm
+++ b/src/lib/platform/OSXScreen.mm
@@ -422,6 +422,7 @@ OSXScreen::constructMouseButtonEventMap()
{kCGEventRightMouseUp, kCGEventRightMouseDragged, kCGEventRightMouseDown},
{kCGEventOtherMouseUp, kCGEventOtherMouseDragged, kCGEventOtherMouseDown},
{kCGEventOtherMouseUp, kCGEventOtherMouseDragged, kCGEventOtherMouseDown},
+ {kCGEventOtherMouseUp, kCGEventOtherMouseDragged, kCGEventOtherMouseDown},
{kCGEventOtherMouseUp, kCGEventOtherMouseDragged, kCGEventOtherMouseDown}
};
@@ -1076,20 +1077,20 @@ OSXScreen::handleSystemEvent(const Event& event, void*)
}
bool
-OSXScreen::onMouseMove(SInt32 mx, SInt32 my)
+OSXScreen::onMouseMove(CGFloat mx, CGFloat my)
{
- LOG((CLOG_DEBUG2 "mouse move %+d,%+d", mx, my));
+ LOG((CLOG_DEBUG2 "mouse move %+f,%+f", mx, my));
- SInt32 x = mx - m_xCursor;
- SInt32 y = my - m_yCursor;
+ CGFloat x = mx - m_xCursor;
+ CGFloat y = my - m_yCursor;
if ((x == 0 && y == 0) || (mx == m_xCenter && mx == m_yCenter)) {
return true;
}
// save position to compute delta of next motion
- m_xCursor = mx;
- m_yCursor = my;
+ m_xCursor = (SInt32)mx;
+ m_yCursor = (SInt32)my;
if (m_isOnScreen) {
// motion on primary screen
@@ -1118,7 +1119,21 @@ OSXScreen::onMouseMove(SInt32 mx, SInt32 my)
}
else {
// send motion
- sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), MotionInfo::alloc(x, y));
+ // Accumulate together the move into the running total
+ static CGFloat m_xFractionalMove = 0;
+ static CGFloat m_yFractionalMove = 0;
+
+ m_xFractionalMove += x;
+ m_yFractionalMove += y;
+
+ // Return the integer part
+ SInt32 intX = (SInt32)m_xFractionalMove;
+ SInt32 intY = (SInt32)m_yFractionalMove;
+
+ // And keep only the fractional part
+ m_xFractionalMove -= intX;
+ m_yFractionalMove -= intY;
+ sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), MotionInfo::alloc(intX, intY));
}
}
diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp
index 5f6c623..e5db1a3 100644
--- a/src/lib/platform/XWindowsScreen.cpp
+++ b/src/lib/platform/XWindowsScreen.cpp
@@ -66,7 +66,8 @@ XWindowsScreen::XWindowsScreen(
IEventQueue* events) :
m_isPrimary(isPrimary),
m_mouseScrollDelta(mouseScrollDelta),
- m_accumulatedScroll(0),
+ m_x_accumulatedScroll(0),
+ m_y_accumulatedScroll(0),
m_display(NULL),
m_root(None),
m_window(None),
@@ -829,35 +830,37 @@ XWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
}
void
-XWindowsScreen::fakeMouseWheel(SInt32, SInt32 yDelta) const
+XWindowsScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
{
- // XXX -- support x-axis scrolling
- if (yDelta == 0) {
- return;
- }
+ int numEvents;
- int numEvents = accumulateMouseScroll(yDelta);
+ if ((!xDelta && !yDelta) || (xDelta && yDelta)) {
+ // Invalid scrolling inputs
+ return;
+ }
- // choose button depending on rotation direction
- const unsigned int xButton = mapButtonToX(static_cast<ButtonID>(
- (numEvents >= 0) ? -1 : -2));
- if (xButton == 0) {
- // If we get here, then the XServer does not support the scroll
- // wheel buttons, so send PageUp/PageDown keystrokes instead.
- // Patch by Tom Chadwick.
- KeyCode keycode = 0;
- if (yDelta >= 0) {
- keycode = m_impl->XKeysymToKeycode(m_display, XK_Page_Up);
- }
- else {
- keycode = m_impl->XKeysymToKeycode(m_display, XK_Page_Down);
- }
- if (keycode != 0) {
- m_impl->XTestFakeKeyEvent(m_display, keycode, True, CurrentTime);
- m_impl->XTestFakeKeyEvent(m_display, keycode, False, CurrentTime);
- }
- return;
- }
+ // 4, 5, 6, 7
+ // up, down, left, right
+ unsigned int xButton;
+
+ if (yDelta) { // vertical scroll
+ numEvents = y_accumulateMouseScroll(yDelta);
+ if (numEvents >= 0) {
+ xButton = 4; // up
+ }
+ else {
+ xButton = 5; // down
+ }
+ }
+ else { // horizontal scroll
+ numEvents = x_accumulateMouseScroll(xDelta);
+ if (numEvents >= 0) {
+ xButton = 7; // right
+ }
+ else {
+ xButton = 6; // left
+ }
+ }
numEvents = std::abs(numEvents);
@@ -1540,7 +1543,14 @@ XWindowsScreen::onMouseRelease(const XButtonEvent& xbutton)
// wheel backward (toward user)
sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(0, -120));
}
- // XXX -- support x-axis scrolling
+ else if (xbutton.button == 6) {
+ // wheel left
+ sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(-120, 0));
+ }
+ else if (xbutton.button == 7) {
+ // wheel right
+ sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(120, 0));
+ }
}
void
@@ -1613,11 +1623,20 @@ XWindowsScreen::onMouseMove(const XMotionEvent& xmotion)
}
int
-XWindowsScreen::accumulateMouseScroll(SInt32 yDelta) const
+XWindowsScreen::x_accumulateMouseScroll(SInt32 xDelta) const
+{
+ m_x_accumulatedScroll += xDelta;
+ int numEvents = m_x_accumulatedScroll / m_mouseScrollDelta;
+ m_x_accumulatedScroll -= numEvents * m_mouseScrollDelta;
+ return numEvents;
+}
+
+int
+XWindowsScreen::y_accumulateMouseScroll(SInt32 yDelta) const
{
- m_accumulatedScroll += yDelta;
- int numEvents = m_accumulatedScroll / m_mouseScrollDelta;
- m_accumulatedScroll -= numEvents * m_mouseScrollDelta;
+ m_y_accumulatedScroll += yDelta;
+ int numEvents = m_y_accumulatedScroll / m_mouseScrollDelta;
+ m_y_accumulatedScroll -= numEvents * m_mouseScrollDelta;
return numEvents;
}
@@ -1840,19 +1859,19 @@ XWindowsScreen::mapButtonFromX(const XButtonEvent* event) const
{
unsigned int button = event->button;
- // first three buttons map to 1, 2, 3 (kButtonLeft, Middle, Right)
- if (button >= 1 && button <= 3) {
+ // http://xahlee.info/linux/linux_x11_mouse_button_number.html
+ // and the program `xev`
+ switch (button)
+ {
+ case 1: case 2: case 3: // kButtonLeft, Middle, Right
return static_cast<ButtonID>(button);
- }
-
- // buttons 4 and 5 are ignored here. they're used for the wheel.
- // buttons 6, 7, etc and up map to 4, 5, etc.
- else if (button >= 6) {
- return static_cast<ButtonID>(button - 2);
- }
-
- // unknown button
- else {
+ case 4: case 5: case 6: case 7: // scroll up, down, left, right -- ignored here
+ return kButtonNone;
+ case 8: // mouse button 4
+ return kButtonExtra0;
+ case 9: // mouse button 5
+ return kButtonExtra1;
+ default: // unknown button
return kButtonNone;
}
}
@@ -1860,30 +1879,17 @@ XWindowsScreen::mapButtonFromX(const XButtonEvent* event) const
unsigned int
XWindowsScreen::mapButtonToX(ButtonID id) const
{
- // map button -1 to button 4 (+wheel)
- if (id == static_cast<ButtonID>(-1)) {
- id = 4;
- }
-
- // map button -2 to button 5 (-wheel)
- else if (id == static_cast<ButtonID>(-2)) {
- id = 5;
- }
-
- // map buttons 4, 5, etc. to 6, 7, etc. to make room for buttons
- // 4 and 5 used to simulate the mouse wheel.
- else if (id >= 4) {
- id += 2;
- }
-
- // check button is in legal range
- if (id < 1 || id > m_buttons.size()) {
- // out of range
+ switch (id)
+ {
+ case kButtonLeft: case kButtonMiddle: case kButtonRight:
+ return id;
+ case kButtonExtra0:
+ return 8;
+ case kButtonExtra1:
+ return 9;
+ default:
return 0;
}
-
- // map button
- return static_cast<unsigned int>(id);
}
void
diff --git a/src/lib/platform/XWindowsScreen.h b/src/lib/platform/XWindowsScreen.h
index 7134017..5573839 100644
--- a/src/lib/platform/XWindowsScreen.h
+++ b/src/lib/platform/XWindowsScreen.h
@@ -139,7 +139,8 @@ private:
// Returns the number of scroll events needed after the current delta has
// been taken into account
- int accumulateMouseScroll(SInt32 yDelta) const;
+ int x_accumulateMouseScroll(SInt32 xDelta) const;
+ int y_accumulateMouseScroll(SInt32 yDelta) const;
bool detectXI2();
#ifdef HAVE_XI2
@@ -183,10 +184,11 @@ private:
// The size of a smallest supported scroll event, in points
int m_mouseScrollDelta;
- // Accumulates scrolls of less than m_mouseScrollDelta across multiple
+ // Accumulates scrolls of less than m_?_mouseScrollDelta across multiple
// scroll events. We dispatch a scroll event whenever the accumulated scroll
- // becomes larger than m_mouseScrollDelta
- mutable int m_accumulatedScroll;
+ // becomes larger than m_?_mouseScrollDelta
+ mutable int m_x_accumulatedScroll;
+ mutable int m_y_accumulatedScroll;
Display* m_display;
Window m_root;