1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
// Copyright 2026 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/SDLHints/SDLHintsWindow.h"
#include "Common/Config/Config.h"
#include "Core/Config/MainSettings.h"
#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
#include "DolphinQt/QtUtils/QtUtils.h"
#include "DolphinQt/QtUtils/SignalBlocking.h"
#include <QDialogButtonBox>
#include <QFrame>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
#include <QResizeEvent>
#include <QTabWidget>
#include <QTableWidget>
#include <QVBoxLayout>
SDLHintsWindow::SDLHintsWindow(QWidget* parent) : QDialog(parent)
{
CreateMainLayout();
setWindowTitle(tr("SDL Controller Settings"));
}
QSize SDLHintsWindow::sizeHint() const
{
return {450, 0};
}
void SDLHintsWindow::CreateMainLayout()
{
setMinimumWidth(300);
setMinimumHeight(270);
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
connect(m_button_box, &QDialogButtonBox::rejected, this, &SDLHintsWindow::OnClose);
// Create hints table
m_hints_table = new QTableWidget(0, 2);
QHeaderView* const hints_table_header = m_hints_table->horizontalHeader();
m_hints_table->setHorizontalHeaderLabels({tr("Name"), tr("Value")});
m_hints_table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_hints_table->setSelectionMode(QTableWidget::SingleSelection);
hints_table_header->setSectionResizeMode(0, QHeaderView::Interactive);
hints_table_header->setSectionResizeMode(1, QHeaderView::Fixed);
hints_table_header->setMinimumSectionSize(60);
m_hints_table->verticalHeader()->setVisible(false);
hints_table_header->installEventFilter(this);
QObject::connect(hints_table_header, &QHeaderView::sectionResized, this,
&SDLHintsWindow::SectionResized);
PopulateTable();
// Create table buttons
auto* const add_row_btn = new NonDefaultQPushButton(tr("Add"));
connect(add_row_btn, &QPushButton::pressed, this, &SDLHintsWindow::AddRow);
m_rem_row_btn = new NonDefaultQPushButton(tr("Remove"));
m_rem_row_btn->setEnabled(false);
connect(m_rem_row_btn, &QPushButton::pressed, this, &SDLHintsWindow::RemoveRow);
connect(m_hints_table, &QTableWidget::itemSelectionChanged, this,
&SDLHintsWindow::SelectionChanged);
auto* const btns_layout = new QDialogButtonBox;
btns_layout->setContentsMargins(0, 0, 5, 5);
btns_layout->addButton(add_row_btn, QDialogButtonBox::ActionRole);
btns_layout->addButton(m_rem_row_btn, QDialogButtonBox::ActionRole);
// Create advanced tab
auto* advanced_layout = new QVBoxLayout();
advanced_layout->addWidget(m_hints_table);
advanced_layout->addWidget(btns_layout);
auto* advanced_frame = new QFrame();
advanced_frame->setLayout(advanced_layout);
// Create default tab
m_directinput_detection = new ToolTipCheckBox(tr("Enable DirectInput Detection"));
m_directinput_detection->SetDescription(
tr("Controls whether SDL should use DirectInput for detecting controllers. Enabling this "
"fixes hotplug detection issues with DualSense controllers but causes Dolphin to hang up "
"on shutdown when using certain 8BitDo controllers.<br><br><dolphin_emphasis>If unsure, "
"leave this checked.</dolphin_emphasis>"));
connect(m_directinput_detection, &ToolTipCheckBox::toggled, [](bool checked) {
Config::SetBase(Config::MAIN_SDL_HINT_JOYSTICK_DIRECTINPUT, checked ? "1" : "0");
});
m_combine_joy_cons = new ToolTipCheckBox(tr("Use Joy-Con Pairs as a Single Controller"));
m_combine_joy_cons->SetDescription(
tr("Controls whether SDL should treat a pair of Joy-Con as a single controller or as two "
"separate controllers.<br><br><dolphin_emphasis>If unsure, leave this "
"checked.</dolphin_emphasis>"));
connect(m_combine_joy_cons, &ToolTipCheckBox::toggled, [](bool checked) {
Config::SetBase(Config::MAIN_SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS, checked ? "1" : "0");
});
m_horizontal_joy_cons = new ToolTipCheckBox(tr("Sideways Joy-Con"));
m_horizontal_joy_cons->SetDescription(
tr("Defines the default orientation for individual Joy-Con. This setting has no effect when "
"Use Joy-Con Pairs as a Single Controller is "
"enabled.<br><br><dolphin_emphasis>If unsure, "
"leave this checked.</dolphin_emphasis>"));
connect(m_horizontal_joy_cons, &ToolTipCheckBox::toggled, [](bool checked) {
Config::SetBase(Config::MAIN_SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS, checked ? "0" : "1");
});
m_dualsense_player_led = new ToolTipCheckBox(tr("Enable DualSense Player LEDs"));
m_dualsense_player_led->SetDescription(
tr("Controls whether the player LEDs should be lit to indicate which player is associated "
"with a DualSense controller.<br><br><dolphin_emphasis>If unsure, leave this "
"unchecked.</dolphin_emphasis>"));
connect(m_dualsense_player_led, &ToolTipCheckBox::toggled, [](bool checked) {
Config::SetBase(Config::MAIN_SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED, checked ? "1" : "0");
});
auto* const default_layout = new QVBoxLayout();
default_layout->setContentsMargins(10, 10, 10, 10);
default_layout->addWidget(m_directinput_detection);
default_layout->addWidget(m_combine_joy_cons);
default_layout->addWidget(m_horizontal_joy_cons);
default_layout->addWidget(m_dualsense_player_led);
default_layout->addStretch(1);
auto* const default_frame = new QFrame();
default_frame->setLayout(default_layout);
PopulateChecklist();
// Create the tab widget
m_tab_widget = new QTabWidget();
m_tab_widget->addTab(default_frame, tr("Main"));
m_tab_widget->addTab(advanced_frame, tr("Advanced"));
m_current_tab_index = 0;
m_tab_widget->setCurrentIndex(m_current_tab_index);
connect(m_tab_widget, &QTabWidget::currentChanged, this, &SDLHintsWindow::TabChanged);
auto* const warning_text =
new QLabel(tr("Dolphin must be restarted for these changes to take effect."));
warning_text->setWordWrap(true);
// Create main layout
auto* const main_layout = new QVBoxLayout();
main_layout->addWidget(
QtUtils::CreateIconWarning(this, QStyle::SP_MessageBoxWarning, warning_text), 0);
main_layout->addWidget(m_tab_widget, 1);
main_layout->addWidget(m_button_box, 0, Qt::AlignBottom | Qt::AlignRight);
setLayout(main_layout);
}
void SDLHintsWindow::PopulateTable()
{
m_hints_table->setRowCount(0);
// Loop through all the values in the SDL_Hints settings section and load them into the table
std::shared_ptr<Config::Layer> layer = Config::GetLayer(Config::LayerType::Base);
const Config::Section& section = layer->GetSection(Config::System::Main, "SDL_Hints");
for (auto& row_data : section)
{
const Config::Location& location = row_data.first;
const std::optional<std::string>& value = row_data.second;
if (value)
{
m_hints_table->insertRow(m_hints_table->rowCount());
m_hints_table->setItem(m_hints_table->rowCount() - 1, 0,
new QTableWidgetItem(QString::fromStdString(location.key)));
m_hints_table->setItem(m_hints_table->rowCount() - 1, 1,
new QTableWidgetItem(QString::fromStdString(*value)));
}
}
}
void SDLHintsWindow::SaveTable()
{
// Clear all the old values from the SDL_Hints section
std::shared_ptr<Config::Layer> layer = Config::GetLayer(Config::LayerType::Base);
Config::Section section = layer->GetSection(Config::System::Main, "SDL_Hints");
for (auto& row_data : section)
row_data.second.reset();
// Add each item still in the table to the config file
for (int row = 0; row < m_hints_table->rowCount(); ++row)
{
QTableWidgetItem* hint_name_item = m_hints_table->item(row, 0);
QTableWidgetItem* hint_value_item = m_hints_table->item(row, 1);
if (hint_name_item != nullptr && hint_value_item != nullptr)
{
const QString& hint_name = hint_name_item->text().trimmed();
const QString& hint_value = hint_value_item->text().trimmed();
if (!hint_name.isEmpty() && !hint_value.isEmpty())
{
const Config::Info<std::string> setting{
{Config::System::Main, "SDL_Hints", hint_name.toStdString()}, ""};
Config::SetBase(setting, hint_value.toStdString());
}
}
}
}
void SDLHintsWindow::PopulateChecklist()
{
// Populate the checklist and default to the SDL default for an invalid value
// Default to checked if incorrectly set
SignalBlocking(m_directinput_detection)
->setChecked(Config::GetBase(Config::MAIN_SDL_HINT_JOYSTICK_DIRECTINPUT) != "0");
// Default to checked if incorrectly set
SignalBlocking(m_combine_joy_cons)
->setChecked(Config::GetBase(Config::MAIN_SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS) != "0");
// Default to checked if incorrectly set
SignalBlocking(m_horizontal_joy_cons)
->setChecked(Config::GetBase(Config::MAIN_SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS) != "1");
// Default to checked if incorrectly set
SignalBlocking(m_dualsense_player_led)
->setChecked(Config::GetBase(Config::MAIN_SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED) != "0");
}
void SDLHintsWindow::AddRow()
{
m_hints_table->insertRow(m_hints_table->rowCount());
m_hints_table->scrollToBottom();
}
void SDLHintsWindow::RemoveRow()
{
QModelIndex index = m_hints_table->selectionModel()->currentIndex();
m_hints_table->removeRow(index.row());
}
void SDLHintsWindow::SelectionChanged()
{
m_rem_row_btn->setEnabled(m_hints_table->selectionModel()->hasSelection());
}
void SDLHintsWindow::OnClose()
{
TabChanged(-1); // Pass -1 to indicate exit
reject();
}
void SDLHintsWindow::TabChanged(int new_index)
{
// Check which tab we're coming from, cur_tab_idx has not been updated yet
switch (m_current_tab_index)
{
case 1: // Coming from the advanced tab
SaveTable();
break;
default:
break;
}
// Check which tab we're going to
switch (new_index)
{
case 0: // Going to the main tab
PopulateChecklist();
break;
case 1: // Going to the advanced tab
PopulateTable();
break;
default:
break;
}
m_current_tab_index = new_index;
}
void SDLHintsWindow::SectionResized(int logical_index, int old_size, int new_size)
{
if (logical_index == 0 && old_size != new_size)
{
QHeaderView* const header = m_hints_table->horizontalHeader();
header->setMaximumSectionSize(header->size().width() - header->minimumSectionSize());
header->resizeSection(1, header->size().width() - new_size);
}
}
bool SDLHintsWindow::eventFilter(QObject* obj, QEvent* event)
{
auto* const table_widget = qobject_cast<QHeaderView*>(obj);
if (table_widget)
{
if (event->type() == QEvent::Resize)
{
auto* const resize_event = static_cast<QResizeEvent*>(event);
QHeaderView* header = m_hints_table->horizontalHeader();
header->setMaximumSectionSize(resize_event->size().width() - header->minimumSectionSize());
header->resizeSection(0, resize_event->size().width() - header->sectionSize(1));
}
}
return QDialog::eventFilter(obj, event);
}
|