Skip to content

Commit

Permalink
Implement touch events support for Windows on Host side (based on Chr…
Browse files Browse the repository at this point in the history
…omium code).
  • Loading branch information
dchapyshev committed Jun 7, 2024
1 parent cd0ac63 commit a398a0c
Show file tree
Hide file tree
Showing 24 changed files with 619 additions and 3 deletions.
3 changes: 3 additions & 0 deletions source/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ if (WIN32)
win/rdp_client_window.h
win/sas_injector.cc
win/sas_injector.h
win/touch_injector.cc
win/touch_injector.h
win/touch_injector_defines.h
win/updater_launcher.cc
win/updater_launcher.h)
endif()
Expand Down
12 changes: 12 additions & 0 deletions source/host/client_session_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ void ClientSessionDesktop::onReceived(uint8_t /* channel_id */, const base::Byte
LOG(LS_ERROR) << "Key event for non-desktop-manage session";
}
}
else if (incoming_message_->has_touch_event())
{
if (sessionType() == proto::SESSION_TYPE_DESKTOP_MANAGE)
{
desktop_session_proxy_->injectTouchEvent(incoming_message_->touch_event());
stat_counter_.addTouchEvent();
}
else
{
LOG(LS_ERROR) << "Touch event for non-desktop-manage session";
}
}
else if (incoming_message_->has_text_event())
{
if (sessionType() == proto::SESSION_TYPE_DESKTOP_MANAGE)
Expand Down
1 change: 1 addition & 0 deletions source/host/desktop_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class DesktopSession
virtual void injectKeyEvent(const proto::KeyEvent& event) = 0;
virtual void injectTextEvent(const proto::TextEvent& event) = 0;
virtual void injectMouseEvent(const proto::MouseEvent& event) = 0;
virtual void injectTouchEvent(const proto::TouchEvent& event) = 0;
virtual void injectClipboardEvent(const proto::ClipboardEvent& event) = 0;

static const char* controlActionToString(proto::internal::DesktopControl::Action action);
Expand Down
11 changes: 11 additions & 0 deletions source/host/desktop_session_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ void DesktopSessionAgent::onIpcMessageReceived(const base::ByteArray& buffer)
LOG(LS_ERROR) << "Input injector NOT initialized";
}
}
else if (incoming_message_->has_touch_event())
{
if (input_injector_)
{
input_injector_->injectTouchEvent(incoming_message_->touch_event());
}
else
{
LOG(LS_ERROR) << "Input injector NOT initialized";
}
}
else if (incoming_message_->has_text_event())
{
if (input_injector_)
Expand Down
5 changes: 5 additions & 0 deletions source/host/desktop_session_fake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ void DesktopSessionFake::injectMouseEvent(const proto::MouseEvent& /* event */)
// Nothing
}

void DesktopSessionFake::injectTouchEvent(const proto::TouchEvent& /* event */)
{
// Nothing
}

//--------------------------------------------------------------------------------------------------
void DesktopSessionFake::injectClipboardEvent(const proto::ClipboardEvent& /* event */)
{
Expand Down
1 change: 1 addition & 0 deletions source/host/desktop_session_fake.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DesktopSessionFake final : public DesktopSession
void injectKeyEvent(const proto::KeyEvent& event) final;
void injectTextEvent(const proto::TextEvent& event) final;
void injectMouseEvent(const proto::MouseEvent& event) final;
void injectTouchEvent(const proto::TouchEvent& event) final;
void injectClipboardEvent(const proto::ClipboardEvent& event) final;

private:
Expand Down
8 changes: 8 additions & 0 deletions source/host/desktop_session_ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ void DesktopSessionIpc::injectMouseEvent(const proto::MouseEvent& event)
channel_->send(serializer_.serialize(*outgoing_message_));
}

//--------------------------------------------------------------------------------------------------
void DesktopSessionIpc::injectTouchEvent(const proto::TouchEvent &event)
{
outgoing_message_->Clear();
outgoing_message_->mutable_touch_event()->CopyFrom(event);
channel_->send(serializer_.serialize(*outgoing_message_));
}

//--------------------------------------------------------------------------------------------------
void DesktopSessionIpc::injectClipboardEvent(const proto::ClipboardEvent& event)
{
Expand Down
1 change: 1 addition & 0 deletions source/host/desktop_session_ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DesktopSessionIpc final
void injectKeyEvent(const proto::KeyEvent& event) final;
void injectTextEvent(const proto::TextEvent& event) final;
void injectMouseEvent(const proto::MouseEvent& event) final;
void injectTouchEvent(const proto::TouchEvent& event) final;
void injectClipboardEvent(const proto::ClipboardEvent& event) final;

protected:
Expand Down
10 changes: 10 additions & 0 deletions source/host/desktop_session_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ void DesktopSessionProxy::injectMouseEvent(const proto::MouseEvent& event)
desktop_session_->injectMouseEvent(event);
}

//--------------------------------------------------------------------------------------------------
void DesktopSessionProxy::injectTouchEvent(const proto::TouchEvent &event)
{
if (is_mouse_locked_ || is_paused_)
return;

if (desktop_session_)
desktop_session_->injectTouchEvent(event);
}

//--------------------------------------------------------------------------------------------------
void DesktopSessionProxy::injectClipboardEvent(const proto::ClipboardEvent& event)
{
Expand Down
1 change: 1 addition & 0 deletions source/host/desktop_session_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DesktopSessionProxy final : public base::enable_shared_from_this<DesktopSe
void injectKeyEvent(const proto::KeyEvent& event);
void injectTextEvent(const proto::TextEvent& event);
void injectMouseEvent(const proto::MouseEvent& event);
void injectTouchEvent(const proto::TouchEvent& event);
void injectClipboardEvent(const proto::ClipboardEvent& event);

bool isMouseLocked() const { return is_mouse_locked_; }
Expand Down
1 change: 1 addition & 0 deletions source/host/input_injector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class InputInjector
virtual void injectKeyEvent(const proto::KeyEvent& event) = 0;
virtual void injectTextEvent(const proto::TextEvent& event) = 0;
virtual void injectMouseEvent(const proto::MouseEvent& event) = 0;
virtual void injectTouchEvent(const proto::TouchEvent& event) = 0;
};

} // namespace host
Expand Down
1 change: 1 addition & 0 deletions source/host/input_injector_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InputInjectorMac final : public InputInjector
void setBlockInput(bool enable) final;
void injectKeyEvent(const proto::KeyEvent& event) final;
void injectMouseEvent(const proto::MouseEvent& event) final;
void injectTouchEvent(const proto::TouchEvent& event) final;

private:
DISALLOW_COPY_AND_ASSIGN(InputInjectorMac);
Expand Down
6 changes: 6 additions & 0 deletions source/host/input_injector_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@
NOTIMPLEMENTED();
}

//--------------------------------------------------------------------------------------------------
void InputInjectorX11::injectTouchEvent(const proto::TouchEvent& /* event */)
{
NOTIMPLEMENTED();
}

} // namespace host
8 changes: 8 additions & 0 deletions source/host/input_injector_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "base/strings/unicode.h"
#include "common/keycode_converter.h"
#include "host/win/sas_injector.h"
#include "host/win/touch_injector.h"

#include <Windows.h>

Expand Down Expand Up @@ -100,6 +101,7 @@ void sendKeyboardUnicodeChar(WORD unicode_char, DWORD flags)

//--------------------------------------------------------------------------------------------------
InputInjectorWin::InputInjectorWin()
: touch_injector_(std::make_unique<TouchInjector>())
{
LOG(LS_INFO) << "Ctor";
}
Expand Down Expand Up @@ -324,6 +326,12 @@ void InputInjectorWin::injectMouseEvent(const proto::MouseEvent& event)
last_mouse_mask_ = mask;
}

//--------------------------------------------------------------------------------------------------
void InputInjectorWin::injectTouchEvent(const proto::TouchEvent& event)
{
touch_injector_->injectTouchEvent(event);
}

//--------------------------------------------------------------------------------------------------
void InputInjectorWin::beforeInput()
{
Expand Down
6 changes: 6 additions & 0 deletions source/host/input_injector_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

#include "host/input_injector.h"

#include <memory>
#include <set>

namespace host {

class TouchInjector;

class InputInjectorWin final : public InputInjector
{
public:
Expand All @@ -37,6 +40,7 @@ class InputInjectorWin final : public InputInjector
void injectKeyEvent(const proto::KeyEvent& event) final;
void injectTextEvent(const proto::TextEvent& event) final;
void injectMouseEvent(const proto::MouseEvent& event) final;
void injectTouchEvent(const proto::TouchEvent& event) final;

private:
void beforeInput();
Expand All @@ -50,6 +54,8 @@ class InputInjectorWin final : public InputInjector
base::Point last_mouse_pos_;
uint32_t last_mouse_mask_ = 0;

std::unique_ptr<TouchInjector> touch_injector_;

DISALLOW_COPY_AND_ASSIGN(InputInjectorWin);
};

Expand Down
6 changes: 6 additions & 0 deletions source/host/input_injector_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ void InputInjectorX11::injectMouseEvent(const proto::MouseEvent& event)
XFlush(display_);
}

//--------------------------------------------------------------------------------------------------
void InputInjectorX11::injectTouchEvent(const proto::TouchEvent& /* event */)
{
NOTIMPLEMENTED();
}

//--------------------------------------------------------------------------------------------------
bool InputInjectorX11::init()
{
Expand Down
1 change: 1 addition & 0 deletions source/host/input_injector_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class InputInjectorX11 final : public InputInjector
void injectKeyEvent(const proto::KeyEvent& event) final;
void injectTextEvent(const proto::TextEvent& event) final;
void injectMouseEvent(const proto::MouseEvent& event) final;
void injectTouchEvent(const proto::TouchEvent& event) final;

private:
InputInjectorX11();
Expand Down
8 changes: 7 additions & 1 deletion source/host/stat_counter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ void StatCounter::addMouseEvent()
++mouse_events_;
}

//--------------------------------------------------------------------------------------------------
void StatCounter::addTouchEvent()
{
++touch_events_;
}

//--------------------------------------------------------------------------------------------------
void StatCounter::addVideoError()
{
Expand All @@ -99,7 +105,7 @@ void StatCounter::onTimeout()
LOG(LS_INFO) << "Clipboard: in=" << incoming_clipboard_events_
<< " out=" << outgoing_clipboard_events_;
LOG(LS_INFO) << "Input: keyboard=" << keyboard_events_ << " mouse=" << mouse_events_
<< " text=" << text_events_;
<< " touch=" << touch_events_ << " text=" << text_events_;
LOG(LS_INFO) << "Cursor positions: " << cursor_positions_;
}

Expand Down
2 changes: 2 additions & 0 deletions source/host/stat_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class StatCounter
void addKeyboardEvent();
void addTextEvent();
void addMouseEvent();
void addTouchEvent();
void addVideoError();
void addCursorPosition();

Expand All @@ -56,6 +57,7 @@ class StatCounter
uint64_t keyboard_events_ = 0;
uint64_t text_events_ = 0;
uint64_t mouse_events_ = 0;
uint64_t touch_events_ = 0;
uint64_t video_error_count_ = 0;
uint64_t cursor_positions_ = 0;

Expand Down
Loading

0 comments on commit a398a0c

Please sign in to comment.