File indexing completed on 2024-06-23 05:24:06

0001 // SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl>
0002 //
0003 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0004 
0005 #pragma once
0006 
0007 #include <memory>
0008 
0009 #include <QInputEvent>
0010 #include <QObject>
0011 
0012 #include <freerdp/freerdp.h>
0013 
0014 #include "krdp_export.h"
0015 
0016 namespace KRdp
0017 {
0018 
0019 class RdpConnection;
0020 
0021 /**
0022  * This class processes RDP input events and converts them to Qt events.
0023  *
0024  * One input handler is created per session.
0025  */
0026 class KRDP_EXPORT InputHandler : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit InputHandler(RdpConnection *session);
0032     ~InputHandler() override;
0033 
0034     /**
0035      * Initialize the InputHandler. Called from within Session::initialize().
0036      */
0037     void initialize(rdpInput *input);
0038 
0039     /**
0040      * Emitted whenever a new input event was received from the client.
0041      *
0042      * \param event The input event that was received.
0043      */
0044     Q_SIGNAL void inputEvent(QInputEvent *event);
0045 
0046 private:
0047     // FreeRDP callbacks that need to call the event handler functions in the
0048     // handler.
0049     friend BOOL inputSynchronizeEvent(rdpInput *, uint32_t);
0050     friend BOOL inputMouseEvent(rdpInput *, uint16_t, uint16_t, uint16_t);
0051     friend BOOL inputExtendedMouseEvent(rdpInput *, uint16_t, uint16_t, uint16_t);
0052 #ifdef FREERDP3
0053     friend BOOL inputKeyboardEvent(rdpInput *, uint16_t, uint8_t);
0054 #else
0055     friend BOOL inputKeyboardEvent(rdpInput *, uint16_t, uint16_t);
0056 #endif
0057     friend BOOL inputUnicodeKeyboardEvent(rdpInput *, uint16_t, uint16_t);
0058 
0059     /**
0060      * Called when the state of modifier keys changes.
0061      *
0062      * \param flags The state of modifier keys.
0063      */
0064     bool synchronizeEvent(uint32_t flags);
0065     /**
0066      * Called when a new mouse event was sent.
0067      *
0068      * \param x The X position, in client coordinates.
0069      * \param y The Y position, in client coordinates.
0070      * \param flags Mouse button state and other flags.
0071      */
0072     bool mouseEvent(uint16_t x, uint16_t y, uint16_t flags);
0073     bool extendedMouseEvent(uint16_t x, uint16_t y, uint16_t flags);
0074     bool keyboardEvent(uint16_t code, uint16_t flags);
0075     bool unicodeKeyboardEvent(uint16_t code, uint16_t flags);
0076 
0077     class Private;
0078     const std::unique_ptr<Private> d;
0079 };
0080 
0081 }