mirror of
				https://github.com/kunkundi/crossdesk.git
				synced 2025-10-26 20:25:34 +08:00 
			
		
		
		
	[feat] remove screen resolution info in HostInfo
This commit is contained in:
		| @@ -42,8 +42,6 @@ typedef struct { | ||||
| typedef struct { | ||||
|   char host_name[64]; | ||||
|   size_t host_name_size; | ||||
|   size_t original_display_width; | ||||
|   size_t original_display_height; | ||||
| } HostInfo; | ||||
|  | ||||
| typedef struct { | ||||
|   | ||||
| @@ -830,10 +830,6 @@ void Render::MainLoop() { | ||||
|       remote_action.type = ControlType::host_infomation; | ||||
|       memcpy(&remote_action.i.host_name, host_name.data(), host_name.size()); | ||||
|       remote_action.i.host_name_size = host_name.size(); | ||||
|       remote_action.i.original_display_width = | ||||
|           screen_width_ * main_window_dpi_scaling_w_; | ||||
|       remote_action.i.original_display_height = | ||||
|           screen_height_ * main_window_dpi_scaling_h_; | ||||
|       int ret = SendDataFrame(peer_, (const char*)&remote_action, | ||||
|                               sizeof(remote_action)); | ||||
|       if (0 == ret) { | ||||
| @@ -969,6 +965,56 @@ void Render::CleanupPeers() { | ||||
|   } | ||||
| } | ||||
|  | ||||
| void Render::UpdateRenderRect() { | ||||
|   for (auto& [_, props] : client_properties_) { | ||||
|     if (!props->reset_control_bar_pos_) { | ||||
|       props->mouse_diff_control_bar_pos_x_ = 0; | ||||
|       props->mouse_diff_control_bar_pos_y_ = 0; | ||||
|     } | ||||
|  | ||||
|     if (!just_created_) { | ||||
|       props->reset_control_bar_pos_ = true; | ||||
|     } | ||||
|  | ||||
|     int stream_window_width, stream_window_height; | ||||
|     SDL_GetWindowSize(stream_window_, &stream_window_width, | ||||
|                       &stream_window_height); | ||||
|     stream_window_width_ = (float)stream_window_width; | ||||
|     stream_window_height_ = (float)stream_window_height; | ||||
|  | ||||
|     float video_ratio = | ||||
|         (float)props->video_width_ / (float)props->video_height_; | ||||
|     float video_ratio_reverse = | ||||
|         (float)props->video_height_ / (float)props->video_width_; | ||||
|  | ||||
|     float render_area_width = stream_window_width_; | ||||
|     float render_area_height = | ||||
|         stream_window_height_ - | ||||
|         (fullscreen_button_pressed_ ? 0 : title_bar_height_); | ||||
|  | ||||
|     props->stream_render_rect_last_ = props->stream_render_rect_; | ||||
|     if (render_area_width < render_area_height * video_ratio) { | ||||
|       props->stream_render_rect_ = { | ||||
|           0, | ||||
|           (int)(abs(render_area_height - | ||||
|                     render_area_width * video_ratio_reverse) / | ||||
|                     2 + | ||||
|                 (fullscreen_button_pressed_ ? 0 : title_bar_height_)), | ||||
|           (int)render_area_width, | ||||
|           (int)(render_area_width * video_ratio_reverse)}; | ||||
|     } else if (render_area_width > render_area_height * video_ratio) { | ||||
|       props->stream_render_rect_ = { | ||||
|           (int)abs(render_area_width - render_area_height * video_ratio) / 2, | ||||
|           fullscreen_button_pressed_ ? 0 : (int)title_bar_height_, | ||||
|           (int)(render_area_height * video_ratio), (int)render_area_height}; | ||||
|     } else { | ||||
|       props->stream_render_rect_ = { | ||||
|           0, fullscreen_button_pressed_ ? 0 : (int)title_bar_height_, | ||||
|           (int)render_area_width, (int)render_area_height}; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| void Render::ProcessSdlEvent() { | ||||
|   SDL_Event event; | ||||
|   while (SDL_PollEvent(&event)) { | ||||
| @@ -1048,57 +1094,7 @@ void Render::ProcessSdlEvent() { | ||||
|         } else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED && | ||||
|                    stream_window_created_ && | ||||
|                    event.window.windowID == SDL_GetWindowID(stream_window_)) { | ||||
|           for (auto& [_, props] : client_properties_) { | ||||
|             if (!props->reset_control_bar_pos_) { | ||||
|               props->mouse_diff_control_bar_pos_x_ = 0; | ||||
|               props->mouse_diff_control_bar_pos_y_ = 0; | ||||
|             } | ||||
|  | ||||
|             if (!just_created_) { | ||||
|               props->reset_control_bar_pos_ = true; | ||||
|             } | ||||
|  | ||||
|             int stream_window_width, stream_window_height; | ||||
|             SDL_GetWindowSize(stream_window_, &stream_window_width, | ||||
|                               &stream_window_height); | ||||
|             stream_window_width_ = (float)stream_window_width; | ||||
|             stream_window_height_ = (float)stream_window_height; | ||||
|  | ||||
|             float video_ratio = (float)props->original_display_width_ / | ||||
|                                 (float)props->original_display_height_; | ||||
|             float video_ratio_reverse = (float)props->original_display_height_ / | ||||
|                                         (float)props->original_display_width_; | ||||
|  | ||||
|             float render_area_width = stream_window_width_; | ||||
|             float render_area_height = | ||||
|                 stream_window_height_ - | ||||
|                 (fullscreen_button_pressed_ ? 0 : title_bar_height_); | ||||
|  | ||||
|             props->stream_render_rect_last_ = props->stream_render_rect_; | ||||
|             if (render_area_width < render_area_height * video_ratio) { | ||||
|               props->stream_render_rect_ = { | ||||
|                   0, | ||||
|                   (int)(abs(render_area_height - | ||||
|                             render_area_width * video_ratio_reverse) / | ||||
|                             2 + | ||||
|                         (fullscreen_button_pressed_ ? 0 : title_bar_height_)), | ||||
|                   (int)render_area_width, | ||||
|                   (int)(render_area_width * video_ratio_reverse)}; | ||||
|             } else if (render_area_width > render_area_height * video_ratio) { | ||||
|               props->stream_render_rect_ = { | ||||
|                   (int)abs(render_area_width - | ||||
|                            render_area_height * video_ratio) / | ||||
|                       2, | ||||
|                   fullscreen_button_pressed_ ? 0 : (int)title_bar_height_, | ||||
|                   (int)(render_area_height * video_ratio), | ||||
|                   (int)render_area_height}; | ||||
|             } else { | ||||
|               props->stream_render_rect_ = { | ||||
|                   0, fullscreen_button_pressed_ ? 0 : (int)title_bar_height_, | ||||
|                   (int)render_area_width, (int)render_area_height}; | ||||
|             } | ||||
|           } | ||||
|  | ||||
|           UpdateRenderRect(); | ||||
|         } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED || | ||||
|                    event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { | ||||
|           bool focus_gained = | ||||
|   | ||||
| @@ -74,16 +74,14 @@ class Render { | ||||
|     int mouse_pos_y_last_ = 0; | ||||
|     int texture_width_ = 1280; | ||||
|     int texture_height_ = 720; | ||||
|     int video_width_ = 1280; | ||||
|     int video_height_ = 720; | ||||
|     size_t video_size_ = 1280 * 720 * 3; | ||||
|     int video_width_ = 0; | ||||
|     int video_height_ = 0; | ||||
|     size_t video_size_ = 0; | ||||
|     std::string fullscreen_button_label_ = "Fullscreen"; | ||||
|     std::string net_traffic_stats_button_label_ = "Show Net Traffic Stats"; | ||||
|     std::string mouse_control_button_label_ = "Mouse Control"; | ||||
|     std::string audio_capture_button_label_ = "Audio Capture"; | ||||
|     std::string remote_host_name_ = ""; | ||||
|     int original_display_width_ = 0; | ||||
|     int original_display_height_ = 0; | ||||
|     SDL_Texture *stream_texture_ = nullptr; | ||||
|     SDL_Rect stream_render_rect_; | ||||
|     SDL_Rect stream_render_rect_last_; | ||||
| @@ -113,6 +111,7 @@ class Render { | ||||
|   void Cleanup(); | ||||
|   void CleanupFactories(); | ||||
|   void CleanupPeers(); | ||||
|   void UpdateRenderRect(); | ||||
|   void ProcessSdlEvent(); | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -62,8 +62,8 @@ int Render::ProcessMouseEvent(SDL_Event &event) { | ||||
|       last_mouse_event.button.x = event.button.x; | ||||
|       last_mouse_event.button.y = event.button.y; | ||||
|  | ||||
|       ratio_x = (float)props->original_display_width_ / (float)render_width; | ||||
|       ratio_y = (float)props->original_display_height_ / (float)render_height; | ||||
|       ratio_x = (float)props->video_width_ / (float)render_width; | ||||
|       ratio_y = (float)props->video_height_ / (float)render_height; | ||||
|  | ||||
|       remote_action.m.x = | ||||
|           (size_t)((event.button.x - props->stream_render_rect_.x) * ratio_x); | ||||
| @@ -123,8 +123,8 @@ int Render::ProcessMouseEvent(SDL_Event &event) { | ||||
|  | ||||
|       render_width = props->stream_render_rect_.w; | ||||
|       render_height = props->stream_render_rect_.h; | ||||
|       ratio_x = (float)props->original_display_width_ / (float)render_width; | ||||
|       ratio_y = (float)props->original_display_height_ / (float)render_height; | ||||
|       ratio_x = (float)props->video_width_ / (float)render_width; | ||||
|       ratio_y = (float)props->video_height_ / (float)render_height; | ||||
|       remote_action.m.x = | ||||
|           (size_t)((last_mouse_event.button.x - props->stream_render_rect_.x) * | ||||
|                    ratio_x); | ||||
| @@ -219,10 +219,18 @@ void Render::OnReceiveVideoBufferCb(const XVideoFrame *video_frame, | ||||
|     } | ||||
|  | ||||
|     memcpy(props->dst_buffer_, video_frame->data, video_frame->size); | ||||
|     bool need_to_update_render_rect = false; | ||||
|     if (props->video_width_ == 0 && props->video_height_ == 0) { | ||||
|       need_to_update_render_rect = true; | ||||
|     } | ||||
|     props->video_width_ = video_frame->width; | ||||
|     props->video_height_ = video_frame->height; | ||||
|     props->video_size_ = video_frame->size; | ||||
|  | ||||
|     if (need_to_update_render_rect) { | ||||
|       render->UpdateRenderRect(); | ||||
|     } | ||||
|  | ||||
|     SDL_Event event; | ||||
|     event.type = STREAM_FRASH; | ||||
|     event.user.type = STREAM_FRASH; | ||||
| @@ -262,11 +270,8 @@ void Render::OnReceiveDataBufferCb(const char *data, size_t size, | ||||
|     if (ControlType::host_infomation == remote_action.type) { | ||||
|       props->remote_host_name_ = std::string(remote_action.i.host_name, | ||||
|                                              remote_action.i.host_name_size); | ||||
|       props->original_display_width_ = remote_action.i.original_display_width; | ||||
|       props->original_display_height_ = remote_action.i.original_display_height; | ||||
|       LOG_INFO("Remote hostname: [{}], resolution: [{}x{}]", | ||||
|                props->remote_host_name_, remote_action.i.original_display_width, | ||||
|                remote_action.i.original_display_height); | ||||
|                props->remote_host_name_); | ||||
|     } | ||||
|   } else { | ||||
|     if (ControlType::mouse == remote_action.type && render->mouse_controller_) { | ||||
|   | ||||
							
								
								
									
										2
									
								
								thirdparty/projectx
									
									
									
									
										vendored
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								thirdparty/projectx
									
									
									
									
										vendored
									
									
								
							 Submodule thirdparty/projectx updated: df6f4321e8...38c88e27e0
									
								
							
		Reference in New Issue
	
	Block a user