mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 05:23:12 -07:00
Add Basic Keyboard Input
This commit is contained in:
parent
3f76782b6c
commit
bf17d81d25
4 changed files with 64 additions and 0 deletions
|
@ -31,6 +31,7 @@ class QGamepad;
|
||||||
|
|
||||||
class QAudioOutput;
|
class QAudioOutput;
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
|
class QKeyEvent;
|
||||||
|
|
||||||
class StreamSession : public QObject
|
class StreamSession : public QObject
|
||||||
{
|
{
|
||||||
|
@ -45,6 +46,8 @@ class StreamSession : public QObject
|
||||||
QGamepad *gamepad;
|
QGamepad *gamepad;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ChiakiControllerState keyboard_state;
|
||||||
|
|
||||||
VideoDecoder video_decoder;
|
VideoDecoder video_decoder;
|
||||||
|
|
||||||
QAudioOutput *audio_output;
|
QAudioOutput *audio_output;
|
||||||
|
@ -62,6 +65,8 @@ class StreamSession : public QObject
|
||||||
#endif
|
#endif
|
||||||
VideoDecoder *GetVideoDecoder() { return &video_decoder; }
|
VideoDecoder *GetVideoDecoder() { return &video_decoder; }
|
||||||
|
|
||||||
|
void HandleKeyboardEvent(QKeyEvent *event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void CurrentImageUpdated();
|
void CurrentImageUpdated();
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,10 @@ class StreamWindow: public QMainWindow
|
||||||
|
|
||||||
void SetImage(const QImage &image);
|
void SetImage(const QImage &image);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
void keyReleaseEvent(QKeyEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void FramesAvailable();
|
void FramesAvailable();
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,9 +24,11 @@
|
||||||
#include <QGamepad>
|
#include <QGamepad>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user);
|
static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user);
|
||||||
static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
||||||
|
@ -88,6 +90,8 @@ StreamSession::StreamSession(const QString &host, const QString ®istkey, cons
|
||||||
audio_output = new QAudioOutput(audio_format, this);
|
audio_output = new QAudioOutput(audio_format, this);
|
||||||
audio_io = audio_output->start();
|
audio_io = audio_output->start();
|
||||||
|
|
||||||
|
memset(&keyboard_state, 0, sizeof(keyboard_state));
|
||||||
|
|
||||||
chiaki_session_init(&session, &connect_info);
|
chiaki_session_init(&session, &connect_info);
|
||||||
chiaki_session_set_audio_frame_cb(&session, AudioFrameCb, this);
|
chiaki_session_set_audio_frame_cb(&session, AudioFrameCb, this);
|
||||||
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
||||||
|
@ -108,6 +112,42 @@ StreamSession::~StreamSession()
|
||||||
chiaki_session_fini(&session);
|
chiaki_session_fini(&session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StreamSession::HandleKeyboardEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
uint64_t button_mask;
|
||||||
|
switch(event->key())
|
||||||
|
{
|
||||||
|
case Qt::Key::Key_Left:
|
||||||
|
button_mask = CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
|
||||||
|
break;
|
||||||
|
case Qt::Key::Key_Right:
|
||||||
|
button_mask = CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
|
||||||
|
break;
|
||||||
|
case Qt::Key::Key_Up:
|
||||||
|
button_mask = CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
|
||||||
|
break;
|
||||||
|
case Qt::Key::Key_Down:
|
||||||
|
button_mask = CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
|
||||||
|
break;
|
||||||
|
case Qt::Key::Key_Return:
|
||||||
|
button_mask = CHIAKI_CONTROLLER_BUTTON_CROSS;
|
||||||
|
break;
|
||||||
|
case Qt::Key::Key_Backspace:
|
||||||
|
button_mask = CHIAKI_CONTROLLER_BUTTON_MOON;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// not interested
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event->type() == QEvent::KeyPress)
|
||||||
|
keyboard_state.buttons |= button_mask;
|
||||||
|
else
|
||||||
|
keyboard_state.buttons &= ~button_mask;
|
||||||
|
|
||||||
|
SendFeedbackState();
|
||||||
|
}
|
||||||
|
|
||||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
void StreamSession::UpdateGamepads()
|
void StreamSession::UpdateGamepads()
|
||||||
{
|
{
|
||||||
|
@ -183,6 +223,8 @@ void StreamSession::SendFeedbackState()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
state.buttons |= keyboard_state.buttons;
|
||||||
|
|
||||||
chiaki_session_set_controller_state(&session, &state);
|
chiaki_session_set_controller_state(&session, &state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ StreamWindow::StreamWindow(StreamSession *session, QWidget *parent)
|
||||||
|
|
||||||
connect(session->GetVideoDecoder(), &VideoDecoder::FramesAvailable, this, &StreamWindow::FramesAvailable);
|
connect(session->GetVideoDecoder(), &VideoDecoder::FramesAvailable, this, &StreamWindow::FramesAvailable);
|
||||||
FramesAvailable();
|
FramesAvailable();
|
||||||
|
|
||||||
|
grabKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamWindow::~StreamWindow()
|
StreamWindow::~StreamWindow()
|
||||||
|
@ -44,6 +46,17 @@ void StreamWindow::SetImage(const QImage &image)
|
||||||
imageLabel->setPixmap(QPixmap::fromImage(image));
|
imageLabel->setPixmap(QPixmap::fromImage(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StreamWindow::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
session->HandleKeyboardEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamWindow::keyReleaseEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
session->HandleKeyboardEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void StreamWindow::FramesAvailable()
|
void StreamWindow::FramesAvailable()
|
||||||
{
|
{
|
||||||
QImage prev;
|
QImage prev;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue