Skip to content

Commit c12ccce

Browse files
committed
Allow disabling keyboard and mouse touch
closes #603, closes #634
1 parent 4876b56 commit c12ccce

File tree

7 files changed

+199
-6
lines changed

7 files changed

+199
-6
lines changed

gui/include/qmlsettings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class QmlSettings : public QObject
7272
Q_PROPERTY(QString psnAuthToken READ psnAuthToken WRITE setPsnAuthToken NOTIFY psnAuthTokenChanged)
7373
Q_PROPERTY(QString psnAuthTokenExpiry READ psnAuthTokenExpiry WRITE setPsnAuthTokenExpiry NOTIFY psnAuthTokenExpiryChanged)
7474
Q_PROPERTY(QString psnAccountId READ psnAccountId WRITE setPsnAccountId NOTIFY psnAccountIdChanged)
75+
Q_PROPERTY(bool mouseTouchEnabled READ mouseTouchEnabled WRITE setMouseTouchEnabled NOTIFY mouseTouchEnabledChanged)
76+
Q_PROPERTY(bool keyboardEnabled READ keyboardEnabled WRITE setKeyboardEnabled NOTIFY keyboardEnabledChanged)
7577
Q_PROPERTY(bool dpadTouchEnabled READ dpadTouchEnabled WRITE setDpadTouchEnabled NOTIFY dpadTouchEnabledChanged)
7678
Q_PROPERTY(uint16_t dpadTouchIncrement READ dpadTouchIncrement WRITE setDpadTouchIncrement NOTIFY dpadTouchIncrementChanged)
7779
Q_PROPERTY(uint dpadTouchShortcut1 READ dpadTouchShortcut1 WRITE setDpadTouchShortcut1 NOTIFY dpadTouchShortcut1Changed)
@@ -493,6 +495,12 @@ class QmlSettings : public QObject
493495
QString psnAccountId() const;
494496
void setPsnAccountId(const QString &account_id);
495497

498+
bool mouseTouchEnabled() const;
499+
void setMouseTouchEnabled(bool enabled);
500+
501+
bool keyboardEnabled() const;
502+
void setKeyboardEnabled(bool enabled);
503+
496504
bool dpadTouchEnabled() const;
497505
void setDpadTouchEnabled(bool enabled);
498506

@@ -615,6 +623,8 @@ class QmlSettings : public QObject
615623
void psnRefreshTokenChanged();
616624
void psnAuthTokenExpiryChanged();
617625
void psnAccountIdChanged();
626+
void mouseTouchEnabledChanged();
627+
void keyboardEnabledChanged();
618628
void dpadTouchEnabledChanged();
619629
void dpadTouchIncrementChanged();
620630
void dpadTouchShortcut1Changed();

gui/include/settings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ class Settings : public QObject
390390
QString GetCurrentProfile() const;
391391
void SetCurrentProfile(QString profile);
392392

393+
bool GetKeyboardEnabled() const;
394+
void SetKeyboardEnabled(bool enabled);
395+
396+
bool GetMouseTouchEnabled() const;
397+
void SetMouseTouchEnabled(bool enabled);
398+
393399
bool GetDpadTouchEnabled() const;
394400
void SetDpadTouchEnabled(bool enabled);
395401

gui/include/streamsession.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct StreamSessionConnectInfo
8686
bool zoom;
8787
bool stretch;
8888
bool enable_keyboard;
89+
bool keyboard_controller_enabled;
90+
bool mouse_touch_enabled;
8991
bool enable_dualsense;
9092
bool auto_regist;
9193
float haptic_override;
@@ -210,6 +212,8 @@ class StreamSession : public QObject
210212
uint16_t dpad_touch_increment;
211213
float trigger_override;
212214
float haptic_override;
215+
bool keyboard_controller_enabled;
216+
bool mouse_touch_enabled;
213217
bool dpad_regular;
214218
bool dpad_regular_touch_switched;
215219
uint dpad_touch_shortcut1;

gui/src/qml/SettingsDialog.qml

Lines changed: 126 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,12 +1882,12 @@ DialogView {
18821882
topMargin: 20
18831883
}
18841884
columns: 3
1885-
rowSpacing: 10
1885+
rowSpacing: 3
18861886
columnSpacing: 10
18871887

18881888
Button {
18891889
text: "Reset All Keys"
1890-
Layout.alignment: Qt.AlignCenter
1890+
Layout.alignment: Qt.AlignRight
18911891
property bool firstInFocusChain: true
18921892
property bool lastInFocusChain: false
18931893
onClicked: Chiaki.settings.clearKeyMapping()
@@ -1937,6 +1937,127 @@ DialogView {
19371937
}
19381938
}
19391939
}
1940+
1941+
CheckBox {
1942+
text: qsTr("Enable Keyboard mapping")
1943+
checked: {
1944+
Chiaki.settings.keyboardEnabled
1945+
}
1946+
onToggled: Chiaki.settings.keyboardEnabled = checked
1947+
Layout.alignment: Qt.AlignRight
1948+
property bool firstInFocusChain: false
1949+
property bool lastInFocusChain: false
1950+
Material.roundedScale: Material.SmallScale
1951+
Material.background: visualFocus ? Material.accent : undefined
1952+
1953+
Component.onDestruction: {
1954+
if (visualFocus) {
1955+
let item = nextItemInFocusChain();
1956+
if (item)
1957+
item.forceActiveFocus(Qt.TabFocusReason);
1958+
}
1959+
}
1960+
Keys.onPressed: (event) => {
1961+
switch (event.key) {
1962+
case Qt.Key_Left:
1963+
if (!firstInFocusChain) {
1964+
let item = nextItemInFocusChain(false);
1965+
if (item)
1966+
item.forceActiveFocus(Qt.TabFocusReason);
1967+
event.accepted = true;
1968+
}
1969+
break;
1970+
case Qt.Key_Right:
1971+
if (!lastInFocusChain) {
1972+
let item = nextItemInFocusChain();
1973+
if (item)
1974+
item.forceActiveFocus(Qt.TabFocusReason);
1975+
event.accepted = true;
1976+
}
1977+
break;
1978+
case Qt.Key_Down:
1979+
if (!lastInFocusChain) {
1980+
let item = nextItemInFocusChain();
1981+
if (item)
1982+
item.forceActiveFocus(Qt.TabFocusReason);
1983+
for(var i = 0; i < 3; i++)
1984+
{
1985+
let item2 = item.nextItemInFocusChain();
1986+
if (item)
1987+
{
1988+
item.forceActiveFocus(Qt.TabFocusReason);
1989+
item = item2;
1990+
}
1991+
}
1992+
event.accepted = true;
1993+
}
1994+
break;
1995+
case Qt.Key_Return:
1996+
if (visualFocus) {
1997+
toggle();
1998+
toggled();
1999+
}
2000+
event.accepted = true;
2001+
break;
2002+
}
2003+
}
2004+
}
2005+
CheckBox {
2006+
text: qsTr("Enable Mouse Touchpad")
2007+
checked: {
2008+
Chiaki.settings.mouseTouchEnabled
2009+
}
2010+
onToggled: Chiaki.settings.mouseTouchEnabled = checked
2011+
Layout.alignment: Qt.AlignRight
2012+
property bool firstInFocusChain: false
2013+
property bool lastInFocusChain: false
2014+
Material.roundedScale: Material.SmallScale
2015+
Material.background: visualFocus ? Material.accent : undefined
2016+
2017+
Component.onDestruction: {
2018+
if (visualFocus) {
2019+
let item = nextItemInFocusChain();
2020+
if (item)
2021+
item.forceActiveFocus(Qt.TabFocusReason);
2022+
}
2023+
}
2024+
Keys.onPressed: (event) => {
2025+
switch (event.key) {
2026+
case Qt.Key_Left:
2027+
if (!firstInFocusChain) {
2028+
let item = nextItemInFocusChain(false);
2029+
if (item)
2030+
item.forceActiveFocus(Qt.TabFocusReason);
2031+
event.accepted = true;
2032+
}
2033+
break;
2034+
case Qt.Key_Down:
2035+
if (!lastInFocusChain) {
2036+
let item = nextItemInFocusChain();
2037+
if (item)
2038+
item.forceActiveFocus(Qt.TabFocusReason);
2039+
for(var i = 0; i < 3; i++)
2040+
{
2041+
let item2 = item.nextItemInFocusChain();
2042+
if (item)
2043+
{
2044+
item.forceActiveFocus(Qt.TabFocusReason);
2045+
item = item2;
2046+
}
2047+
}
2048+
event.accepted = true;
2049+
}
2050+
break;
2051+
case Qt.Key_Return:
2052+
if (visualFocus) {
2053+
toggle();
2054+
toggled();
2055+
}
2056+
event.accepted = true;
2057+
break;
2058+
}
2059+
}
2060+
}
19402061
Repeater {
19412062
id: chiakiKeys
19422063
model: Chiaki.settings.controllerMapping
@@ -1975,23 +2096,23 @@ DialogView {
19752096
Keys.onPressed: (event) => {
19762097
switch (event.key) {
19772098
case Qt.Key_Left:
1978-
if (!firstInFocusChain && (((index + 1)% 3) != 0)) {
2099+
if (!firstInFocusChain && ((index % 3) != 0)) {
19792100
let item = nextItemInFocusChain(false);
19802101
if (item)
19812102
item.forceActiveFocus(Qt.TabFocusReason);
19822103
event.accepted = true;
19832104
}
19842105
break;
19852106
case Qt.Key_Right:
1986-
if (!lastInFocusChain && ((index - 1) % 3) != 0) {
2107+
if (!lastInFocusChain && (index % 3) != 2) {
19872108
let item = nextItemInFocusChain();
19882109
if (item)
19892110
item.forceActiveFocus(Qt.TabFocusReason);
19902111
event.accepted = true;
19912112
}
19922113
break;
19932114
case Qt.Key_Up:
1994-
if (!firstInFocusChain && index > 1)
2115+
if (!firstInFocusChain)
19952116
{
19962117
let item = nextItemInFocusChain(false);
19972118
if (item)

gui/src/qmlsettings.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,28 @@ void QmlSettings::setPsnAccountId(const QString &account_id)
636636
emit psnAccountIdChanged();
637637
}
638638

639+
bool QmlSettings::mouseTouchEnabled() const
640+
{
641+
return settings->GetMouseTouchEnabled();
642+
}
643+
644+
void QmlSettings::setMouseTouchEnabled(bool enabled)
645+
{
646+
settings->SetMouseTouchEnabled(enabled);
647+
emit mouseTouchEnabledChanged();
648+
}
649+
650+
bool QmlSettings::keyboardEnabled() const
651+
{
652+
return settings->GetKeyboardEnabled();
653+
}
654+
655+
void QmlSettings::setKeyboardEnabled(bool enabled)
656+
{
657+
settings->SetKeyboardEnabled(enabled);
658+
emit keyboardEnabledChanged();
659+
}
660+
639661
bool QmlSettings::dpadTouchEnabled() const
640662
{
641663
return settings->GetDpadTouchEnabled();

gui/src/settings.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,25 @@ void Settings::SetCurrentProfile(QString profile)
802802
emit CurrentProfileChanged();
803803
}
804804

805+
bool Settings::GetKeyboardEnabled() const
806+
{
807+
return settings.value("settings/keyboard_enabled", true).toBool();
808+
}
809+
void Settings::SetKeyboardEnabled(bool enabled)
810+
{
811+
settings.setValue("settings/keyboard_enabled", enabled);
812+
}
813+
814+
bool Settings::GetMouseTouchEnabled() const
815+
{
816+
return settings.value("settings/mouse_touch_enabled", true).toBool();
817+
}
818+
void Settings::SetMouseTouchEnabled(bool enabled)
819+
{
820+
settings.setValue("settings/mouse_touch_enabled", enabled);
821+
}
822+
823+
805824
bool Settings::GetDpadTouchEnabled() const
806825
{
807826
return settings.value("settings/dpad_touch_enabled", true).toBool();

gui/src/streamsession.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ StreamSessionConnectInfo::StreamSessionConnectInfo(
107107
this->fullscreen = fullscreen;
108108
this->zoom = zoom;
109109
this->stretch = stretch;
110+
this->keyboard_controller_enabled = settings->GetKeyboardEnabled();
111+
this->mouse_touch_enabled = settings->GetMouseTouchEnabled();
110112
this->enable_keyboard = false; // TODO: from settings
111113
this->enable_dualsense = true;
112114
this->rumble_haptics_intensity = settings->GetRumbleHapticsIntensity();
@@ -258,7 +260,8 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
258260
}
259261
#endif
260262
audio_buffer_size = connect_info.audio_buffer_size;
261-
263+
mouse_touch_enabled = connect_info.mouse_touch_enabled;
264+
keyboard_controller_enabled = connect_info.keyboard_controller_enabled;
262265
host = connect_info.host;
263266
QByteArray host_str = connect_info.host.toUtf8();
264267

@@ -642,6 +645,8 @@ void StreamSession::GoHome()
642645

643646
void StreamSession::HandleMousePressEvent(QMouseEvent *event)
644647
{
648+
if(!mouse_touch_enabled)
649+
return;
645650
// left button for touchpad gestures, others => touchpad click
646651
if (event->button() != Qt::MouseButton::LeftButton)
647652
keyboard_state.buttons |= CHIAKI_CONTROLLER_BUTTON_TOUCHPAD;
@@ -650,6 +655,8 @@ void StreamSession::HandleMousePressEvent(QMouseEvent *event)
650655

651656
void StreamSession::HandleMouseReleaseEvent(QMouseEvent *event)
652657
{
658+
if(!mouse_touch_enabled)
659+
return;
653660
// left button => end of touchpad gesture
654661
if (event->button() == Qt::LeftButton)
655662
{
@@ -665,6 +672,8 @@ void StreamSession::HandleMouseReleaseEvent(QMouseEvent *event)
665672

666673
void StreamSession::HandleMouseMoveEvent(QMouseEvent *event, qreal width, qreal height)
667674
{
675+
if(!mouse_touch_enabled)
676+
return;
668677
// left button with move => touchpad gesture, otherwise ignore
669678
if (event->buttons() == Qt::LeftButton)
670679
{
@@ -683,6 +692,8 @@ void StreamSession::HandleMouseMoveEvent(QMouseEvent *event, qreal width, qreal
683692

684693
void StreamSession::HandleKeyboardEvent(QKeyEvent *event)
685694
{
695+
if(!keyboard_controller_enabled)
696+
return;
686697
if(key_map.contains(Qt::Key(event->key())) == false)
687698
return;
688699

0 commit comments

Comments
 (0)