mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-07-01 19:36:15 +08:00
[fix] use SDL keyboard capture on Wayland only
This commit is contained in:
+18
-11
@@ -794,16 +794,21 @@ int Render::StopMouseController() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Render::StartKeyboardCapturer() {
|
int Render::StartKeyboardCapturer() {
|
||||||
|
keyboard_capturer_uses_sdl_events_ = false;
|
||||||
|
|
||||||
#if defined(__linux__) && !defined(__APPLE__)
|
#if defined(__linux__) && !defined(__APPLE__)
|
||||||
if (IsWaylandSession()) {
|
if (IsWaylandSession()) {
|
||||||
|
keyboard_capturer_uses_sdl_events_ = true;
|
||||||
LOG_INFO("Start keyboard capturer with SDL Wayland backend");
|
LOG_INFO("Start keyboard capturer with SDL Wayland backend");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!keyboard_capturer_) {
|
if (!keyboard_capturer_) {
|
||||||
LOG_INFO("keyboard capturer is nullptr");
|
keyboard_capturer_uses_sdl_events_ = true;
|
||||||
return -1;
|
LOG_WARN(
|
||||||
|
"keyboard capturer is nullptr, falling back to SDL keyboard events");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int keyboard_capturer_init_ret = keyboard_capturer_->Hook(
|
int keyboard_capturer_init_ret = keyboard_capturer_->Hook(
|
||||||
@@ -815,21 +820,23 @@ int Render::StartKeyboardCapturer() {
|
|||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
if (0 != keyboard_capturer_init_ret) {
|
if (0 != keyboard_capturer_init_ret) {
|
||||||
LOG_ERROR("Start keyboard capturer failed");
|
keyboard_capturer_uses_sdl_events_ = true;
|
||||||
|
LOG_WARN(
|
||||||
|
"Start keyboard capturer failed, falling back to SDL keyboard "
|
||||||
|
"events");
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Start keyboard capturer");
|
LOG_INFO("Start keyboard capturer with native hook");
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyboard_capturer_init_ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Render::StopKeyboardCapturer() {
|
int Render::StopKeyboardCapturer() {
|
||||||
#if defined(__linux__) && !defined(__APPLE__)
|
if (keyboard_capturer_uses_sdl_events_) {
|
||||||
if (IsWaylandSession()) {
|
keyboard_capturer_uses_sdl_events_ = false;
|
||||||
LOG_INFO("Stop keyboard capturer with SDL Wayland backend");
|
LOG_INFO("Stop keyboard capturer with SDL keyboard backend");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (keyboard_capturer_) {
|
if (keyboard_capturer_) {
|
||||||
keyboard_capturer_->Unhook();
|
keyboard_capturer_->Unhook();
|
||||||
@@ -2719,8 +2726,8 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
|
|
||||||
case SDL_EVENT_KEY_DOWN:
|
case SDL_EVENT_KEY_DOWN:
|
||||||
case SDL_EVENT_KEY_UP:
|
case SDL_EVENT_KEY_UP:
|
||||||
if (keyboard_capturer_is_started_ && focus_on_stream_window_ &&
|
if (keyboard_capturer_is_started_ && keyboard_capturer_uses_sdl_events_ &&
|
||||||
stream_window_ &&
|
focus_on_stream_window_ && stream_window_ &&
|
||||||
SDL_GetWindowID(stream_window_) == event.key.windowID) {
|
SDL_GetWindowID(stream_window_) == event.key.windowID) {
|
||||||
ProcessKeyboardEvent(event);
|
ProcessKeyboardEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -282,8 +282,6 @@ class Render {
|
|||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
void DrawReceivingScreenText(
|
void DrawReceivingScreenText(
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
void DrawRemoteUnlockStateText(
|
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
|
||||||
void ResetRemoteServiceStatus(SubStreamWindowProperties& props);
|
void ResetRemoteServiceStatus(SubStreamWindowProperties& props);
|
||||||
void ApplyRemoteServiceStatus(SubStreamWindowProperties& props,
|
void ApplyRemoteServiceStatus(SubStreamWindowProperties& props,
|
||||||
const ServiceStatus& status);
|
const ServiceStatus& status);
|
||||||
@@ -478,6 +476,7 @@ class Render {
|
|||||||
bool start_keyboard_capturer_ = false;
|
bool start_keyboard_capturer_ = false;
|
||||||
bool show_cursor_ = false;
|
bool show_cursor_ = false;
|
||||||
bool keyboard_capturer_is_started_ = false;
|
bool keyboard_capturer_is_started_ = false;
|
||||||
|
bool keyboard_capturer_uses_sdl_events_ = false;
|
||||||
bool foucs_on_main_window_ = false;
|
bool foucs_on_main_window_ = false;
|
||||||
bool focus_on_stream_window_ = false;
|
bool focus_on_stream_window_ = false;
|
||||||
bool main_window_minimized_ = false;
|
bool main_window_minimized_ = false;
|
||||||
|
|||||||
@@ -193,94 +193,6 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
text_pos, IM_COL32(0, 0, 0, 255),
|
text_pos, IM_COL32(0, 0, 0, 255),
|
||||||
std::to_string(props->selected_display_ + 1).c_str());
|
std::to_string(props->selected_display_ + 1).c_str());
|
||||||
|
|
||||||
if (props->remote_service_status_received_) {
|
|
||||||
ImGui::SameLine();
|
|
||||||
const RemoteUnlockState unlock_state = GetRemoteUnlockState(*props);
|
|
||||||
bool sas_button_style_pushed = false;
|
|
||||||
switch (unlock_state) {
|
|
||||||
case RemoteUnlockState::service_unavailable:
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
||||||
ImVec4(185 / 255.0f, 28 / 255.0f,
|
|
||||||
28 / 255.0f, 1.0f));
|
|
||||||
sas_button_style_pushed = true;
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::credential_ui:
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
||||||
ImVec4(22 / 255.0f, 163 / 255.0f,
|
|
||||||
74 / 255.0f, 1.0f));
|
|
||||||
sas_button_style_pushed = true;
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::lock_screen:
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
||||||
ImVec4(202 / 255.0f, 138 / 255.0f,
|
|
||||||
4 / 255.0f, 1.0f));
|
|
||||||
sas_button_style_pushed = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool can_send_sas =
|
|
||||||
props->connection_status_ == ConnectionStatus::Connected &&
|
|
||||||
props->peer_ != nullptr && props->remote_service_available_;
|
|
||||||
if (!can_send_sas) {
|
|
||||||
ImGui::BeginDisabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string sas_button = ICON_FA_UNLOCK_KEYHOLE;
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
|
||||||
if (ImGui::Button(sas_button.c_str(),
|
|
||||||
ImVec2(button_width, button_height))) {
|
|
||||||
RemoteAction remote_action{};
|
|
||||||
remote_action.type = ControlType::service_command;
|
|
||||||
remote_action.c.flag = ServiceCommandFlag::send_sas;
|
|
||||||
std::string msg = remote_action.to_json();
|
|
||||||
SendReliableDataFrame(props->peer_, msg.c_str(), msg.size(),
|
|
||||||
props->control_data_label_.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!can_send_sas) {
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::IsItemHovered()) {
|
|
||||||
std::string tooltip = localization::send_sas[localization_language_index_];
|
|
||||||
switch (unlock_state) {
|
|
||||||
case RemoteUnlockState::service_unavailable:
|
|
||||||
tooltip = localization::remote_service_unavailable
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::credential_ui:
|
|
||||||
tooltip = localization::remote_password_box_visible
|
|
||||||
[localization_language_index_] +
|
|
||||||
"\n" +
|
|
||||||
localization::remote_unlock_requires_secure_desktop
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::lock_screen:
|
|
||||||
tooltip = localization::remote_lock_screen_hint
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::secure_desktop:
|
|
||||||
tooltip = localization::remote_secure_desktop_active
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::BeginTooltip();
|
|
||||||
ImGui::PushTextWrapPos(button_width * 8.0f);
|
|
||||||
ImGui::TextWrapped("%s", tooltip.c_str());
|
|
||||||
ImGui::PopTextWrapPos();
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sas_button_style_pushed) {
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
float mouse_x = ImGui::GetCursorScreenPos().x;
|
float mouse_x = ImGui::GetCursorScreenPos().x;
|
||||||
float mouse_y = ImGui::GetCursorScreenPos().y;
|
float mouse_y = ImGui::GetCursorScreenPos().y;
|
||||||
|
|||||||
@@ -257,4 +257,3 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
|||||||
@@ -59,62 +59,6 @@ void Render::DrawReceivingScreenText(
|
|||||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.92f), "%s", text.c_str());
|
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.92f), "%s", text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render::DrawRemoteUnlockStateText(
|
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props) {
|
|
||||||
if (!props->remote_service_status_received_ ||
|
|
||||||
!props->connection_established_ ||
|
|
||||||
props->connection_status_ != ConnectionStatus::Connected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RemoteUnlockState unlock_state = GetRemoteUnlockState(*props);
|
|
||||||
std::string text;
|
|
||||||
ImU32 background_color = IM_COL32(37, 99, 235, 220);
|
|
||||||
|
|
||||||
switch (unlock_state) {
|
|
||||||
case RemoteUnlockState::service_unavailable:
|
|
||||||
text = localization::remote_service_unavailable
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(185, 28, 28, 220);
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::credential_ui:
|
|
||||||
text = localization::remote_password_box_visible
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(22, 163, 74, 220);
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::lock_screen:
|
|
||||||
text = localization::remote_lock_screen_hint
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(202, 138, 4, 220);
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::secure_desktop:
|
|
||||||
text = localization::remote_secure_desktop_active
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(147, 51, 234, 220);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
||||||
ImVec2 window_pos = ImGui::GetWindowPos();
|
|
||||||
ImVec2 window_size = ImGui::GetWindowSize();
|
|
||||||
ImVec2 text_size = ImGui::CalcTextSize(text.c_str());
|
|
||||||
float padding_x = title_bar_height_ * 0.45f;
|
|
||||||
float padding_y = title_bar_height_ * 0.18f;
|
|
||||||
float top_margin = fullscreen_button_pressed_ ? title_bar_height_ * 0.35f
|
|
||||||
: title_bar_height_ * 0.18f;
|
|
||||||
ImVec2 text_pos(window_pos.x + (window_size.x - text_size.x) * 0.5f,
|
|
||||||
window_pos.y + top_margin + padding_y);
|
|
||||||
ImVec2 rect_min(text_pos.x - padding_x, text_pos.y - padding_y);
|
|
||||||
ImVec2 rect_max(text_pos.x + text_size.x + padding_x,
|
|
||||||
text_pos.y + text_size.y + padding_y);
|
|
||||||
|
|
||||||
draw_list->AddRectFilled(rect_min, rect_max, background_color,
|
|
||||||
window_rounding_ * 0.9f);
|
|
||||||
draw_list->AddText(text_pos, IM_COL32(255, 255, 255, 255), text.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Render::CloseTab(decltype(client_properties_)::iterator& it) {
|
void Render::CloseTab(decltype(client_properties_)::iterator& it) {
|
||||||
// std::unique_lock lock(client_properties_mutex_);
|
// std::unique_lock lock(client_properties_mutex_);
|
||||||
if (it != client_properties_.end()) {
|
if (it != client_properties_.end()) {
|
||||||
@@ -229,7 +173,6 @@ int Render::StreamWindow() {
|
|||||||
FileTransferWindow(props);
|
FileTransferWindow(props);
|
||||||
|
|
||||||
DrawReceivingScreenText(props);
|
DrawReceivingScreenText(props);
|
||||||
DrawRemoteUnlockStateText(props);
|
|
||||||
|
|
||||||
focused_remote_id_ = props->remote_id_;
|
focused_remote_id_ = props->remote_id_;
|
||||||
|
|
||||||
@@ -332,7 +275,6 @@ int Render::StreamWindow() {
|
|||||||
FileTransferWindow(props);
|
FileTransferWindow(props);
|
||||||
|
|
||||||
DrawReceivingScreenText(props);
|
DrawReceivingScreenText(props);
|
||||||
DrawRemoteUnlockStateText(props);
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user