Skip to content

Commit 97af2b8

Browse files
committed
Gui: Add event util tab
If it doesn't show up correctly here I don't know what to tell you.
1 parent b43c1d3 commit 97af2b8

File tree

8 files changed

+172
-11
lines changed

8 files changed

+172
-11
lines changed

data/locale/en-US.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ Dialog.RemoteConnection="WebSocket server"
5353
Dialog.Remote.Logging="Enable logging"
5454
Dialog.Remote.Status="Local IP of this machine: "
5555

56+
Dialog.LastKeyboardCode="Last keyboard keycode:"
57+
Dialog.LastMouseCode="Last mouse code:"
58+
Dialog.LastSDLButton="Last gamepad button code:"
59+
Dialog.LastSDLAxis="Last gamepad axis code:"
60+
Dialog.Util="Event util"
61+
5662
Menu.InputOverlay.OpenSettings="input-overlay settings"

src/gui/io_settings_dialog.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ io_settings_dialog::io_settings_dialog(QWidget *parent) : QDialog(parent, Qt::Di
104104
"font-weight: bold;}");
105105
}
106106

107+
void io_settings_dialog::RefreshUi()
108+
{
109+
ui->txt_lastkbcode->setText(QString::number(io_config::last_keycode.load(), 16));
110+
ui->txt_lastmousecode->setText(QString::number(io_config::last_mouse_button.load(), 16));
111+
ui->txt_lastsdlbutton->setText(QString::number(io_config::last_sdl_gamepad_button.load()));
112+
ui->txt_lastsdlaxis->setText(QString::number(io_config::last_sdl_gamepad_axis.load()));
113+
}
114+
107115
void io_settings_dialog::showEvent(QShowEvent *event)
108116
{
109117
Q_UNUSED(event)

src/gui/io_settings_dialog.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ private Q_SLOTS:
6464

6565
static void OpenForums();
6666

67+
void RefreshUi();
68+
6769
private:
6870
Ui::io_config_dialog *ui;
6971
QTimer *m_refresh = nullptr;

src/gui/io_settings_dialog.ui

Lines changed: 135 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
<item>
3030
<widget class="QTabWidget" name="tabs">
3131
<property name="tabPosition">
32-
<enum>QTabWidget::North</enum>
32+
<enum>QTabWidget::TabPosition::North</enum>
3333
</property>
3434
<property name="tabShape">
35-
<enum>QTabWidget::Rounded</enum>
35+
<enum>QTabWidget::TabShape::Rounded</enum>
3636
</property>
3737
<property name="currentIndex">
38-
<number>0</number>
38+
<number>3</number>
3939
</property>
4040
<property name="elideMode">
41-
<enum>Qt::ElideRight</enum>
41+
<enum>Qt::TextElideMode::ElideRight</enum>
4242
</property>
4343
<property name="documentMode">
4444
<bool>false</bool>
@@ -63,7 +63,7 @@
6363
<string>Dialog.LocalFeatures.Info</string>
6464
</property>
6565
<property name="textFormat">
66-
<enum>Qt::RichText</enum>
66+
<enum>Qt::TextFormat::RichText</enum>
6767
</property>
6868
</widget>
6969
</item>
@@ -139,7 +139,7 @@
139139
<item>
140140
<widget class="QFrame" name="frame_entry">
141141
<property name="frameShape">
142-
<enum>QFrame::NoFrame</enum>
142+
<enum>QFrame::Shape::NoFrame</enum>
143143
</property>
144144
<layout class="QHBoxLayout" name="horizontalLayout">
145145
<property name="spacing">
@@ -288,7 +288,7 @@
288288
<item>
289289
<spacer name="verticalSpacer">
290290
<property name="orientation">
291-
<enum>Qt::Vertical</enum>
291+
<enum>Qt::Orientation::Vertical</enum>
292292
</property>
293293
<property name="sizeHint" stdset="0">
294294
<size>
@@ -343,10 +343,10 @@ li.checked::marker { content: &quot;\2612&quot;; }
343343
<item>
344344
<widget class="QFrame" name="frame_about">
345345
<property name="frameShape">
346-
<enum>QFrame::NoFrame</enum>
346+
<enum>QFrame::Shape::NoFrame</enum>
347347
</property>
348348
<property name="frameShadow">
349-
<enum>QFrame::Plain</enum>
349+
<enum>QFrame::Shadow::Plain</enum>
350350
</property>
351351
<layout class="QHBoxLayout" name="horizontalLayout_23">
352352
<property name="leftMargin">
@@ -380,6 +380,130 @@ li.checked::marker { content: &quot;\2612&quot;; }
380380
</item>
381381
</layout>
382382
</widget>
383+
<widget class="QWidget" name="tab_util">
384+
<attribute name="title">
385+
<string>Dialog.Util</string>
386+
</attribute>
387+
<layout class="QVBoxLayout" name="verticalLayout_5">
388+
<item>
389+
<widget class="QFrame" name="frame_3">
390+
<property name="frameShape">
391+
<enum>QFrame::Shape::StyledPanel</enum>
392+
</property>
393+
<property name="frameShadow">
394+
<enum>QFrame::Shadow::Raised</enum>
395+
</property>
396+
<layout class="QHBoxLayout" name="horizontalLayout_5">
397+
<item>
398+
<widget class="QLabel" name="label">
399+
<property name="text">
400+
<string>Dialog.LastKeyboardCode</string>
401+
</property>
402+
</widget>
403+
</item>
404+
<item>
405+
<widget class="QLineEdit" name="txt_lastkbcode">
406+
<property name="readOnly">
407+
<bool>true</bool>
408+
</property>
409+
</widget>
410+
</item>
411+
</layout>
412+
</widget>
413+
</item>
414+
<item>
415+
<widget class="QFrame" name="frame_2">
416+
<property name="frameShape">
417+
<enum>QFrame::Shape::StyledPanel</enum>
418+
</property>
419+
<property name="frameShadow">
420+
<enum>QFrame::Shadow::Raised</enum>
421+
</property>
422+
<layout class="QHBoxLayout" name="horizontalLayout_4">
423+
<item>
424+
<widget class="QLabel" name="label_2">
425+
<property name="text">
426+
<string>Dialog.LastMouseCode</string>
427+
</property>
428+
</widget>
429+
</item>
430+
<item>
431+
<widget class="QLineEdit" name="txt_lastmousecode">
432+
<property name="readOnly">
433+
<bool>true</bool>
434+
</property>
435+
</widget>
436+
</item>
437+
</layout>
438+
</widget>
439+
</item>
440+
<item>
441+
<widget class="QFrame" name="frame">
442+
<property name="frameShape">
443+
<enum>QFrame::Shape::StyledPanel</enum>
444+
</property>
445+
<property name="frameShadow">
446+
<enum>QFrame::Shadow::Raised</enum>
447+
</property>
448+
<layout class="QHBoxLayout" name="horizontalLayout_3">
449+
<item>
450+
<widget class="QLabel" name="label_3">
451+
<property name="text">
452+
<string>Dialog.LastSDLButton</string>
453+
</property>
454+
</widget>
455+
</item>
456+
<item>
457+
<widget class="QLineEdit" name="txt_lastsdlbutton">
458+
<property name="readOnly">
459+
<bool>true</bool>
460+
</property>
461+
</widget>
462+
</item>
463+
</layout>
464+
</widget>
465+
</item>
466+
<item>
467+
<widget class="QFrame" name="frame_4">
468+
<property name="frameShape">
469+
<enum>QFrame::Shape::StyledPanel</enum>
470+
</property>
471+
<property name="frameShadow">
472+
<enum>QFrame::Shadow::Raised</enum>
473+
</property>
474+
<layout class="QHBoxLayout" name="horizontalLayout_6">
475+
<item>
476+
<widget class="QLabel" name="label_4">
477+
<property name="text">
478+
<string>Dialog.LastSDLAxis</string>
479+
</property>
480+
</widget>
481+
</item>
482+
<item>
483+
<widget class="QLineEdit" name="txt_lastsdlaxis">
484+
<property name="readOnly">
485+
<bool>true</bool>
486+
</property>
487+
</widget>
488+
</item>
489+
</layout>
490+
</widget>
491+
</item>
492+
<item>
493+
<spacer name="verticalSpacer_2">
494+
<property name="orientation">
495+
<enum>Qt::Orientation::Vertical</enum>
496+
</property>
497+
<property name="sizeHint" stdset="0">
498+
<size>
499+
<width>318</width>
500+
<height>101</height>
501+
</size>
502+
</property>
503+
</spacer>
504+
</item>
505+
</layout>
506+
</widget>
383507
</widget>
384508
</item>
385509
<item>
@@ -394,10 +518,10 @@ li.checked::marker { content: &quot;\2612&quot;; }
394518
<bool>false</bool>
395519
</property>
396520
<property name="orientation">
397-
<enum>Qt::Horizontal</enum>
521+
<enum>Qt::Orientation::Horizontal</enum>
398522
</property>
399523
<property name="standardButtons">
400-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
524+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
401525
</property>
402526
</widget>
403527
</item>

src/hook/gamepad_hook_helper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ void gamepads::event_loop()
197197
break;
198198

199199
case SDL_EVENT_GAMEPAD_AXIS_MOTION: {
200+
io_config::last_sdl_gamepad_axis = event.gaxis.axis;
200201
auto pad = get_controller_from_instance_id(event.gdevice.which);
201202
std::lock_guard<std::mutex> lock(pad->mutex());
202203
pad->axis()[event.gaxis.axis] = event.gaxis.value / float(INT16_MAX);
203204
} break;
204205
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
205206
case SDL_EVENT_GAMEPAD_BUTTON_UP: {
207+
io_config::last_sdl_gamepad_button = event.gbutton.button;
206208
auto pad = get_controller_from_instance_id(event.gdevice.which);
207209
std::lock_guard<std::mutex> lock(pad->mutex());
208210
pad->buttons()[event.gbutton.button] = event.gbutton.down;

src/hook/uiohook_helper.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@
1919
#pragma once
2020
#include "../network/websocket_server.hpp"
2121
#include "../util/config.hpp"
22+
2223
#include <input_data.hpp>
2324
#include <mutex>
2425
#include <uiohook.h>
2526
#include <util/platform.h>
27+
28+
2629
#define SCROLL_TIMEOUT 120000000
2730

2831
namespace uiohook {
2932
extern uint64_t last_scroll_time;
3033
extern bool state;
3134

35+
3236
inline void check_wheel()
3337
{
3438
if (last_scroll_time && os_gettime_ns() - last_scroll_time >= SCROLL_TIMEOUT) {
@@ -44,6 +48,12 @@ inline void process_event(uiohook_event *event)
4448
static uint64_t last_time = 0;
4549
auto diff = (event->time - last_time);
4650

51+
if (event->type == EVENT_KEY_PRESSED) {
52+
io_config::last_keycode = event->data.keyboard.keycode;
53+
} else if (event->type == EVENT_MOUSE_PRESSED) {
54+
io_config::last_mouse_button = event->data.mouse.button;
55+
}
56+
4757
// Mouse move/drag can get very spammy so those events
4858
// will only be dispatched at 60hz
4959
const bool is_important = event->type < EVENT_MOUSE_MOVED;

src/util/config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ uint16_t server_refresh_rate = 250;
3939
uint16_t server_port = 1608;
4040
uint16_t wss_port = 16899;
4141
std::string wss_bind_address;
42+
std::atomic<uint16_t> last_keycode;
43+
std::atomic<uint16_t> last_mouse_button;
44+
std::atomic<uint16_t> last_sdl_gamepad_button;
45+
std::atomic<uint16_t> last_sdl_gamepad_axis;
4246

4347
void set_defaults()
4448
{

src/util/config.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "input_filter.hpp"
2222
#include <mutex>
2323
#include <util/config-file.h>
24+
#include <atomic>
2425

2526
#define CDEF_STR(id, value) config_set_default_string(io_config::instance, S_REGION, id, value)
2627
#define CDEF_INT(id, value) config_set_default_int(io_config::instance, S_REGION, id, value)
@@ -39,6 +40,10 @@
3940

4041
namespace io_config {
4142
extern config_t *instance;
43+
extern std::atomic<uint16_t> last_keycode;
44+
extern std::atomic<uint16_t> last_mouse_button;
45+
extern std::atomic<uint16_t> last_sdl_gamepad_button;
46+
extern std::atomic<uint16_t> last_sdl_gamepad_axis;
4247

4348
extern input_filter io_window_filters;
4449
extern std::mutex filter_mutex;

0 commit comments

Comments
 (0)