diff --git a/src/gui/render.cpp b/src/gui/render.cpp index 0d6b4c1..c5affab 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -1060,13 +1060,18 @@ int Render::DestroyStreamWindow() { if (stream_renderer_) { SDL_DestroyRenderer(stream_renderer_); + stream_renderer_ = nullptr; } if (stream_window_) { SDL_DestroyWindow(stream_window_); + stream_window_ = nullptr; } stream_window_created_ = false; + focus_on_stream_window_ = false; + stream_window_grabbed_ = false; + control_mouse_ = false; return 0; } diff --git a/src/gui/render.h b/src/gui/render.h index 992414c..400eb12 100644 --- a/src/gui/render.h +++ b/src/gui/render.h @@ -439,7 +439,7 @@ class Render { bool screen_capturer_is_started_ = false; bool start_speaker_capturer_ = false; bool speaker_capturer_is_started_ = false; - bool start_keyboard_capturer_ = true; + bool start_keyboard_capturer_ = false; bool show_cursor_ = false; bool keyboard_capturer_is_started_ = false; bool foucs_on_main_window_ = false; diff --git a/src/gui/render_callback.cpp b/src/gui/render_callback.cpp index a4b9d76..edc7b44 100644 --- a/src/gui/render_callback.cpp +++ b/src/gui/render_callback.cpp @@ -72,17 +72,16 @@ int Render::SendKeyCommand(int key_code, bool is_down) { } remote_action.k.key_value = key_code; - if (!controlled_remote_id_.empty()) { - // std::shared_lock lock(client_properties_mutex_); - if (client_properties_.find(controlled_remote_id_) != - client_properties_.end()) { - auto props = client_properties_[controlled_remote_id_]; - if (props->connection_status_ == ConnectionStatus::Connected) { + std::string target_id = controlled_remote_id_.empty() ? focused_remote_id_ + : controlled_remote_id_; + if (!target_id.empty()) { + if (client_properties_.find(target_id) != client_properties_.end()) { + auto props = client_properties_[target_id]; + if (props->connection_status_ == ConnectionStatus::Connected && + props->peer_) { std::string msg = remote_action.to_json(); - if (props->peer_) { - SendDataFrame(props->peer_, msg.c_str(), msg.size(), - props->data_label_.c_str()); - } + SendDataFrame(props->peer_, msg.c_str(), msg.size(), + props->data_label_.c_str()); } } } @@ -758,6 +757,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id, 0, (int)render->title_bar_height_, (int)render->stream_window_width_, (int)(render->stream_window_height_ - render->title_bar_height_)}; + render->start_keyboard_capturer_ = true; break; } case ConnectionStatus::Disconnected: @@ -782,6 +782,8 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id, event.user.data1 = props.get(); SDL_PushEvent(&event); + render->focus_on_stream_window_ = false; + break; } case ConnectionStatus::IncorrectPassword: { @@ -861,12 +863,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id, render->start_screen_capturer_ = true; render->start_speaker_capturer_ = true; render->remote_client_id_ = remote_id; -#ifdef CROSSDESK_DEBUG - render->start_mouse_controller_ = false; - render->start_keyboard_capturer_ = false; -#else render->start_mouse_controller_ = true; -#endif if (std::all_of(render->connection_status_.begin(), render->connection_status_.end(), [](const auto& kv) { return kv.first.find("web") != std::string::npos;