Skip to content

Commit

Permalink
Add support for mousewheel movement
Browse files Browse the repository at this point in the history
  • Loading branch information
MSuih committed Dec 29, 2019
1 parent 0b78404 commit a85454c
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 4 deletions.
69 changes: 69 additions & 0 deletions rpcs3/Input/keyboard_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ bool keyboard_pad_handler::eventFilter(QObject* target, QEvent* ev)
case QEvent::MouseMove:
mouseMoveEvent(static_cast<QMouseEvent*>(ev));
break;
case QEvent::Wheel:
mouseWheelEvent(static_cast<QWheelEvent*>(ev));
break;
default:
break;
}
Expand Down Expand Up @@ -378,6 +381,46 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
event->ignore();
}

void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
{
QPoint direction = event->angleDelta();

if (direction.isNull())
{
// Scrolling started/ended event, no direction given
return;
}

if (const int x = direction.x() != 0)
{
bool to_left = event->inverted() ? x < 0 : x > 0;
if (to_left)
{
Key(mouse::wheel_left, true);
m_last_wheel_move_left = std::chrono::steady_clock::now();
}
else
{
Key(mouse::wheel_right, true);
m_last_wheel_move_right = std::chrono::steady_clock::now();
}
}
else if (const int y = direction.y() != 0)
{
bool to_up = event->inverted() ? y < 0 : y > 0;
if (to_up)
{
Key(mouse::wheel_up, true);
m_last_wheel_move_up = std::chrono::steady_clock::now();
}
else
{
Key(mouse::wheel_down, true);
m_last_wheel_move_down = std::chrono::steady_clock::now();
}
}
}

std::vector<std::string> keyboard_pad_handler::ListDevices()
{
std::vector<std::string> list_devices;
Expand Down Expand Up @@ -659,4 +702,30 @@ void keyboard_pad_handler::ThreadProc()
}
}
}

// Releases the wheel buttons 0,1 sec after they've been triggered
// Next activation is set to distant future to avoid activating this on every proc
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
const auto update_treshold = std::chrono::milliseconds(100);
const auto delay = std::chrono::hours(24);
if (now >= m_last_wheel_move_up + update_treshold)
{
Key(mouse::wheel_up, false);
m_last_wheel_move_up = now + delay;
}
if (now >= m_last_wheel_move_down + update_treshold)
{
Key(mouse::wheel_down, false);
m_last_wheel_move_down = now + delay;
}
if (now >= m_last_wheel_move_left + update_treshold)
{
Key(mouse::wheel_left, false);
m_last_wheel_move_left = now + delay;
}
if (now >= m_last_wheel_move_right + update_treshold)
{
Key(mouse::wheel_right, false);
m_last_wheel_move_right = now + delay;
}
}
24 changes: 20 additions & 4 deletions rpcs3/Input/keyboard_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

enum mouse
{
move_left = 0x05555550,
move_right = 0x05555551,
move_up = 0x05555552,
move_down = 0x05555553
move_left = 0x05555550,
move_right = 0x05555551,
move_up = 0x05555552,
move_down = 0x05555553,
wheel_up = 0x05555554,
wheel_down = 0x05555555,
wheel_left = 0x05555556,
wheel_right = 0x05555557
};

class keyboard_pad_handler final : public QObject, public PadHandlerBase
Expand Down Expand Up @@ -52,6 +56,11 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase
{ mouse::move_right , "Mouse MRight" },
{ mouse::move_up , "Mouse MUp" },
{ mouse::move_down , "Mouse MDown" },

{ mouse::wheel_up , "Wheel Up" },
{ mouse::wheel_down , "Wheel Down" },
{ mouse::wheel_left , "Wheel Left" },
{ mouse::wheel_right , "Wheel Right" },
};

public:
Expand All @@ -66,6 +75,7 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseWheelEvent(QWheelEvent* event);

bool eventFilter(QObject* obj, QEvent* ev) override;

Expand Down Expand Up @@ -108,4 +118,10 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase
int m_deadzone_y = 60;
double m_multi_x = 2;
double m_multi_y = 2.5;

// Mousewheel
std::chrono::steady_clock::time_point m_last_wheel_move_up;
std::chrono::steady_clock::time_point m_last_wheel_move_down;
std::chrono::steady_clock::time_point m_last_wheel_move_left;
std::chrono::steady_clock::time_point m_last_wheel_move_right;
};
55 changes: 55 additions & 0 deletions rpcs3/rpcs3qt/pad_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,61 @@ void pad_settings_dialog::mouseReleaseEvent(QMouseEvent* event)
ReactivateButtons();
}

void pad_settings_dialog::wheelEvent(QWheelEvent *event)
{
if (m_handler->m_type != pad_handler::keyboard)
{
return;
}

if (m_button_id == button_ids::id_pad_begin)
{
return;
}

if (m_button_id <= button_ids::id_pad_begin || m_button_id >= button_ids::id_pad_end)
{
LOG_NOTICE(HLE, "Pad Settings: Handler Type: %d, Unknown button ID: %d", static_cast<int>(m_handler->m_type), m_button_id);
return;
}

QPoint direction = event->angleDelta();
if (direction.isNull())
{
// Scrolling started/ended event, no direction given
return;
}

u32 key;
if (const int x = direction.x() != 0)
{
bool to_left = event->inverted() ? x < 0 : x > 0;
if (to_left)
{
key = mouse::wheel_left;
}
else
{
key = mouse::wheel_right;
}
}
else if (const int y = direction.y() != 0)
{
bool to_up = event->inverted() ? y < 0 : y > 0;
if (to_up)
{
key = mouse::wheel_up;
}
else
{
key = mouse::wheel_down;
}
}
m_cfg_entries[m_button_id].key = (static_cast<keyboard_pad_handler*>(m_handler.get()))->GetMouseName(key);
m_cfg_entries[m_button_id].text = qstr(m_cfg_entries[m_button_id].key);
ReactivateButtons();
}

void pad_settings_dialog::mouseMoveEvent(QMouseEvent* /*event*/)
{
if (m_handler->m_type != pad_handler::keyboard)
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/pad_settings_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,6 @@ private Q_SLOTS:
void keyPressEvent(QKeyEvent *keyEvent) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
bool eventFilter(QObject* object, QEvent* event) override;
};

0 comments on commit a85454c

Please sign in to comment.