diff --git a/src/localization/localization.h b/src/localization/localization.h index 9b9fc9a..8dac78f 100644 --- a/src/localization/localization.h +++ b/src/localization/localization.h @@ -21,6 +21,8 @@ static std::vector disconnect = {u8"断开连接", "Disconnect"}; static std::vector fullscreen = {u8"全屏", "Fullscreen"}; static std::vector exit_fullscreen = {u8"退出全屏", "Exit fullscreen"}; +static std::vector control_mouse = {u8"控制鼠标", "Mouse Control"}; +static std::vector release_mouse = {u8"释放鼠标", "Release Mouse"}; static std::vector settings_window_width = {188.0f, 228.0f}; static std::vector settings = {u8"设置", "Settings"}; static std::vector language = {u8"语言:", "Language:"}; diff --git a/src/main_window/main_window.cpp b/src/main_window/main_window.cpp index 8d765de..aaa0d66 100644 --- a/src/main_window/main_window.cpp +++ b/src/main_window/main_window.cpp @@ -314,17 +314,25 @@ int MainWindow::Run() { LOG_INFO("Connected with signal server, create p2p connection"); } - connect_button_label_ = - connect_button_pressed_ - ? localization::disconnect[localization_language_index_] - : localization::connect[localization_language_index_]; - fullscreen_button_label_ = - fullscreen_button_pressed_ - ? localization::exit_fullscreen[localization_language_index_] - : localization::fullscreen[localization_language_index_]; + if (!inited_) { + connect_button_label_ = + connect_button_pressed_ + ? localization::disconnect[localization_language_index_] + : localization::connect[localization_language_index_]; + fullscreen_button_label_ = + fullscreen_button_pressed_ + ? localization::exit_fullscreen[localization_language_index_] + : localization::fullscreen[localization_language_index_]; - settings_button_label_ = - localization::settings[localization_language_index_]; + mouse_control_button_label_ = + mouse_control_button_pressed_ + ? localization::release_mouse[localization_language_index_] + : localization::control_mouse[localization_language_index_]; + + settings_button_label_ = + localization::settings[localization_language_index_]; + inited_ = true; + } if (start_screen_capture_ && !screen_capture_is_started_) { StartScreenCapture(); @@ -347,7 +355,7 @@ int MainWindow::Run() { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - if (connection_established_ && !subwindow_hovered_) { + if (connection_established_ && !subwindow_hovered_ && control_mouse_) { ImGui::SetMouseCursor(ImGuiMouseCursor_None); } @@ -356,9 +364,9 @@ int MainWindow::Run() { ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Once); if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) { - ImGui::SetNextWindowSize(ImVec2(160, 210)); + ImGui::SetNextWindowSize(ImVec2(160, 245)); } else { - ImGui::SetNextWindowSize(ImVec2(180, 210)); + ImGui::SetNextWindowSize(ImVec2(190, 245)); } if (!connection_established_) { @@ -525,28 +533,44 @@ int MainWindow::Run() { ImGui::Spacing(); + if (ImGui::Button(mouse_control_button_label_.c_str())) { + if (mouse_control_button_label_ == + localization::control_mouse[localization_language_index_]) { + mouse_control_button_pressed_ = true; + control_mouse_ = true; + mouse_control_button_label_ = + localization::release_mouse[localization_language_index_]; + } else { + control_mouse_ = false; + mouse_control_button_label_ = + localization::control_mouse[localization_language_index_]; + } + } + + ImGui::SameLine(); + if (ImGui::Button(fullscreen_button_label_.c_str())) { if (fullscreen_button_label_ == localization::fullscreen[localization_language_index_]) { main_window_width_before_fullscreen_ = main_window_width_; main_window_height_before_fullscreen_ = main_window_height_; SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP); - fullscreen_button_pressed_ = true; + fullscreen_button_label_ = + localization::exit_fullscreen[localization_language_index_]; } else { SDL_SetWindowFullscreen(main_window_, SDL_FALSE); SDL_SetWindowSize(main_window_, main_window_width_before_fullscreen_, main_window_height_before_fullscreen_); + fullscreen_button_label_ = + localization::fullscreen[localization_language_index_]; } - fullscreen_button_pressed_ = !fullscreen_button_pressed_; - fullscreen_button_label_ = - fullscreen_button_pressed_ - ? localization::exit_fullscreen[localization_language_index_] - - : localization::fullscreen[localization_language_index_]; - fullscreen_button_pressed_ = false; } - ImGui::SameLine(); + ImGui::Spacing(); + + ImGui::Separator(); + + ImGui::Spacing(); if (ImGui::Button(settings_button_label_.c_str())) { settings_button_pressed_ = !settings_button_pressed_; diff --git a/src/main_window/main_window.h b/src/main_window/main_window.h index a36afd6..c5b14ca 100644 --- a/src/main_window/main_window.h +++ b/src/main_window/main_window.h @@ -93,6 +93,7 @@ class MainWindow { std::string mac_addr_str_ = ""; std::string connect_button_label_ = "Connect"; std::string fullscreen_button_label_ = "Fullscreen"; + std::string mouse_control_button_label_ = "Mouse Control"; std::string settings_button_label_ = "Setting"; char input_password_tmp_[7] = ""; char input_password_[7] = ""; @@ -118,16 +119,19 @@ class MainWindow { SDL_Window *main_window_; uint32_t pixformat_ = 0; + bool inited_ = false; bool exit_ = false; bool connection_established_ = false; bool subwindow_hovered_ = false; bool connect_button_pressed_ = false; bool fullscreen_button_pressed_ = false; + bool mouse_control_button_pressed_ = false; bool settings_button_pressed_ = false; bool received_frame_ = false; bool is_create_connection_ = false; bool audio_buffer_fresh_ = false; bool rejoin_ = false; + bool control_mouse_ = false; int fps_ = 0; uint32_t start_time_; diff --git a/src/main_window/main_window_callback_func.cpp b/src/main_window/main_window_callback_func.cpp index 86a871c..3929154 100644 --- a/src/main_window/main_window_callback_func.cpp +++ b/src/main_window/main_window_callback_func.cpp @@ -12,6 +12,10 @@ #endif int MainWindow::ProcessMouseKeyEven(SDL_Event &ev) { + if (!control_mouse_) { + return 0; + } + float ratio = (float)(1280.0 / main_window_width_); RemoteAction remote_action; @@ -178,6 +182,7 @@ void MainWindow::OnConnectionStatusCb(ConnectionStatus status, main_window->start_screen_capture_ = false; main_window->start_mouse_control_ = false; main_window->connection_established_ = false; + main_window->control_mouse_ = false; if (main_window->dst_buffer_) { memset(main_window->dst_buffer_, 0, 1280 * 720 * 3); SDL_UpdateTexture(main_window->sdl_texture_, NULL,