diff --git a/client/SDL/CMakeLists.txt b/client/SDL/CMakeLists.txt index 301180837..35ff2e41c 100644 --- a/client/SDL/CMakeLists.txt +++ b/client/SDL/CMakeLists.txt @@ -15,10 +15,36 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(MODULE_NAME "sdl-client") -set(MODULE_PREFIX "FREERDP_CLIENT_X11_CONTROL") +cmake_minimum_required(VERSION 3.13) + +project(sdl-client CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +list(APPEND CMAKE_MODULE_PATH ../../cmake/) + +include(GNUInstallDirsWrapper) +# RPATH configuration + set(CMAKE_SKIP_BUILD_RPATH FALSE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + if (APPLE) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) + set(CMAKE_INSTALL_RPATH "@loader_path/../Frameworks") + else (APPLE) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + if (NOT FREEBSD) + set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:\$ORIGIN/..") + option(WITH_ADD_PLUGIN_TO_RPATH "Add extension and plugin path to RPATH" OFF) + if (WITH_ADD_PLUGIN_TO_RPATH) + set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${FREERDP_EXTENSION_REL_PATH}:\$ORIGIN/../${FREERDP_PLUGIN_PATH}:${CMAKE_INSTALL_RPATH}") + endif() + endif() + endif(APPLE) -include(ConfigOptions) option(WITH_DEBUG_SDL_EVENTS "[dangerous, not for release builds!] Debug SDL events" OFF) option(WITH_DEBUG_SDL_KBD_EVENTS "[dangerous, not for release builds!] Debug SDL keyboard events" OFF) @@ -29,31 +55,53 @@ if (WITH_DEBUG_SDL_KBD_EVENTS) add_definitions(-DWITH_DEBUG_SDL_KBD_EVENTS) endif() +find_package(SDL2 REQUIRED) +include_directories(${SDL2_INCLUDE_DIR}) include_directories(${SDL2_INCLUDE_DIRS}) + +# Here we add dependencies for stand alone builds. +# Only add these if not build within FreeRDP source tree +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + find_package(WinPR 3 REQUIRED) + include_directories(${WinPR_INCLUDE_DIR}) + + find_package(FreeRDP 3 REQUIRED) + include_directories(${FreeRDP_INCLUDE_DIR}) + + find_package(FreeRDP-Client 3 REQUIRED) + include_directories(${FreeRDP-Client_INCLUDE_DIR}) +endif() + set(SRCS - sdl_utils.c + sdl_utils.cpp sdl_utils.h - sdl_kbd.c + sdl_kbd.cpp sdl_kbd.h - sdl_touch.c + sdl_touch.cpp sdl_touch.h - sdl_pointer.c + sdl_pointer.cpp sdl_pointer.h - sdl_disp.c + sdl_disp.cpp sdl_disp.h - sdl_monitor.c + sdl_monitor.cpp sdl_monitor.h sdl_freerdp.h - sdl_freerdp.c + sdl_freerdp.cpp sdl_channels.h - sdl_channels.c) + sdl_channels.cpp) set(LIBS ${SDL2_LIBRARIES} - freerdp-client) + winpr + freerdp + freerdp-client + ) -add_executable(${MODULE_NAME} ${SRCS}) -set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "sdl-freerdp") -target_link_libraries(${MODULE_NAME} PRIVATE ${LIBS}) -set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/SDL") -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) +add_executable(${PROJECT_NAME} + ${SRCS} + ) + +set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "sdl-freerdp") +target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS}) +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Client/SDL") +install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) diff --git a/client/SDL/sdl_channels.c b/client/SDL/sdl_channels.cpp similarity index 78% rename from client/SDL/sdl_channels.c rename to client/SDL/sdl_channels.cpp index 97b07cd2a..c0ab38304 100644 --- a/client/SDL/sdl_channels.c +++ b/client/SDL/sdl_channels.cpp @@ -31,7 +31,7 @@ void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); WINPR_ASSERT(e); @@ -41,13 +41,15 @@ void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEve } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { - CliprdrClientContext* clip = (CliprdrClientContext*)e->pInterface; + auto clip = reinterpret_cast(e->pInterface); WINPR_ASSERT(clip); clip->custom = context; } else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0) { - sdl_disp_init(sdl->disp, (DispClientContext*)e->pInterface); + auto disp = reinterpret_cast(e->pInterface); + WINPR_ASSERT(disp); + sdl_disp_init(sdl->disp, disp); } else freerdp_client_OnChannelConnectedEventHandler(context, e); @@ -55,7 +57,7 @@ void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEve void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); WINPR_ASSERT(e); @@ -66,13 +68,15 @@ void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnec } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { - CliprdrClientContext* clip = (CliprdrClientContext*)e->pInterface; + auto clip = reinterpret_cast(e->pInterface); WINPR_ASSERT(clip); - clip->custom = NULL; + clip->custom = nullptr; } else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0) { - sdl_disp_uninit(sdl->disp, (DispClientContext*)e->pInterface); + auto disp = reinterpret_cast(e->pInterface); + WINPR_ASSERT(disp); + sdl_disp_uninit(sdl->disp, disp); } else freerdp_client_OnChannelDisconnectedEventHandler(context, e); diff --git a/client/SDL/sdl_channels.h b/client/SDL/sdl_channels.h index 5eb9f0c46..a5c9f7d34 100644 --- a/client/SDL/sdl_channels.h +++ b/client/SDL/sdl_channels.h @@ -17,8 +17,7 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_CHANNELS_H -#define FREERDP_CLIENT_SDL_CHANNELS_H +#pragma once #include #include @@ -28,5 +27,3 @@ int sdl_on_channel_disconnected(freerdp* instance, const char* name, void* pInte void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e); void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e); - -#endif /* FREERDP_CLIENT_SDL_CHANNELS_H */ diff --git a/client/SDL/sdl_disp.c b/client/SDL/sdl_disp.cpp similarity index 96% rename from client/SDL/sdl_disp.c rename to client/SDL/sdl_disp.cpp index e59022d76..eae7c3d89 100644 --- a/client/SDL/sdl_disp.c +++ b/client/SDL/sdl_disp.cpp @@ -17,6 +17,7 @@ * limitations under the License. */ +#include #include #include @@ -26,6 +27,7 @@ #include "sdl_disp.h" #include "sdl_kbd.h" +#include "sdl_utils.h" #include #define TAG CLIENT_TAG("sdl.disp") @@ -248,14 +250,14 @@ sdlDispContext* sdl_disp_new(sdlContext* sdl) rdpSettings* settings; if (!sdl || !sdl->common.context.settings || !sdl->common.context.pubSub) - return NULL; + return nullptr; settings = sdl->common.context.settings; pubSub = sdl->common.context.pubSub; - ret = calloc(1, sizeof(sdlDispContext)); + ret = new (sdlDispContext); if (!ret) - return NULL; + return nullptr; ret->sdl = sdl; ret->lastSentWidth = ret->targetWidth = settings->DesktopWidth; @@ -279,14 +281,13 @@ void sdl_disp_free(sdlDispContext* disp) PubSub_UnsubscribeTimer(pubSub, sdl_disp_OnTimer); } - free(disp); + delete (disp); } static UINT sdl_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monitors, size_t nmonitors) { UINT ret = CHANNEL_RC_OK; - DISPLAY_CONTROL_MONITOR_LAYOUT* layouts; size_t i; sdlDispContext* sdlDisp; rdpSettings* settings; @@ -302,15 +303,13 @@ static UINT sdl_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monit settings = sdlDisp->sdl->common.context.settings; WINPR_ASSERT(settings); - layouts = calloc(nmonitors, sizeof(DISPLAY_CONTROL_MONITOR_LAYOUT)); - - if (!layouts) - return CHANNEL_RC_NO_MEMORY; + std::vector layouts; + layouts.resize(nmonitors); for (i = 0; i < nmonitors; i++) { - const rdpMonitor* monitor = &monitors[i]; - DISPLAY_CONTROL_MONITOR_LAYOUT* layout = &layouts[i]; + auto monitor = &monitors[i]; + auto layout = &layouts[i]; layout->Flags = (monitor->is_primary ? DISPLAY_CONTROL_MONITOR_PRIMARY : 0); layout->Left = monitor->x; @@ -352,8 +351,8 @@ static UINT sdl_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monit layout->DeviceScaleFactor = settings->DeviceScaleFactor; } - ret = IFCALLRESULT(CHANNEL_RC_OK, disp->SendMonitorLayout, disp, nmonitors, layouts); - free(layouts); + ret = + IFCALLRESULT(CHANNEL_RC_OK, disp->SendMonitorLayout, disp, layouts.size(), layouts.data()); return ret; } @@ -530,7 +529,7 @@ BOOL sdl_disp_uninit(sdlDispContext* sdlDisp, DispClientContext* disp) if (!sdlDisp || !disp) return FALSE; - sdlDisp->disp = NULL; + sdlDisp->disp = nullptr; update_resizeable(sdlDisp->sdl, FALSE); return TRUE; } diff --git a/client/SDL/sdl_disp.h b/client/SDL/sdl_disp.h index 06e89fb85..925e1cb6c 100644 --- a/client/SDL/sdl_disp.h +++ b/client/SDL/sdl_disp.h @@ -16,8 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_DISP_H -#define FREERDP_CLIENT_SDL_DISP_H +#pragma once #include #include @@ -38,5 +37,3 @@ BOOL sdl_disp_handle_window_event(sdlDispContext* disp, const SDL_WindowEvent* e BOOL sdl_grab_keyboard(sdlContext* sdl, Uint32 windowID, SDL_bool enable); BOOL sdl_grab_mouse(sdlContext* sdl, Uint32 windowID, SDL_bool enable); - -#endif /* FREERDP_CLIENT_SDL_DISP_H */ diff --git a/client/SDL/sdl_freerdp.c b/client/SDL/sdl_freerdp.cpp similarity index 91% rename from client/SDL/sdl_freerdp.c rename to client/SDL/sdl_freerdp.cpp index 390c22b68..5123adfa9 100644 --- a/client/SDL/sdl_freerdp.c +++ b/client/SDL/sdl_freerdp.cpp @@ -17,6 +17,8 @@ * limitations under the License. */ +#include + #include #include @@ -208,7 +210,7 @@ static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(int exit_code) if (cur->code == exit_code) return cur; } - return NULL; + return nullptr; } static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(DWORD error) @@ -220,7 +222,7 @@ static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(DWORD error) if (cur->error == error) return cur; } - return NULL; + return nullptr; } static int sdl_map_error_to_exit_code(DWORD error) @@ -237,7 +239,7 @@ static const char* sdl_map_error_to_code_tag(DWORD error) const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error); if (entry) return entry->code_tag; - return NULL; + return nullptr; } static const char* sdl_map_to_code_tag(int code) @@ -245,7 +247,7 @@ static const char* sdl_map_to_code_tag(int code) const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_code(code); if (entry) return entry->code_tag; - return NULL; + return nullptr; } static int error_info_to_error(freerdp* instance, DWORD* pcode) @@ -267,7 +269,7 @@ static int error_info_to_error(freerdp* instance, DWORD* pcode) static BOOL sdl_begin_paint(rdpContext* context) { rdpGdi* gdi; - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); @@ -303,13 +305,29 @@ static BOOL sdl_redraw(sdlContext* sdl) return gdi_send_suppress_output(gdi, FALSE); } +class EventGuard +{ + private: + sdlContext* _sdl; + + public: + EventGuard(sdlContext* sdl) : _sdl(sdl) + { + } + ~EventGuard() + { + SetEvent(_sdl->update_complete); + } +}; static BOOL sdl_end_paint_process(rdpContext* context) { rdpGdi* gdi; - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(context); + EventGuard guard(sdl); + gdi = context->gdi; WINPR_ASSERT(gdi); WINPR_ASSERT(gdi->primary); @@ -317,13 +335,13 @@ static BOOL sdl_end_paint_process(rdpContext* context) WINPR_ASSERT(gdi->primary->hdc->hwnd); WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid); if (gdi->suppressOutput || gdi->primary->hdc->hwnd->invalid->null) - goto out; + return TRUE; const INT32 ninvalid = gdi->primary->hdc->hwnd->ninvalid; const GDI_RGN* cinvalid = gdi->primary->hdc->hwnd->cinvalid; if (ninvalid < 1) - goto out; + return TRUE; // TODO: Support multiple windows for (size_t x = 0; x < sdl->windowCount; x++) @@ -376,7 +394,7 @@ static BOOL sdl_end_paint_process(rdpContext* context) } out: - return SetEvent(sdl->update_complete); + return TRUE; } /* This function is called when the library completed composing a new @@ -385,7 +403,7 @@ out: */ static BOOL sdl_end_paint(rdpContext* context) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); EnterCriticalSection(&sdl->critical); @@ -408,14 +426,14 @@ static BOOL sdl_create_primary(sdlContext* sdl) sdl->primary = SDL_CreateRGBSurfaceWithFormatFrom( gdi->primary_buffer, (int)gdi->width, (int)gdi->height, (int)FreeRDPGetBitsPerPixel(gdi->dstFormat), (int)gdi->stride, sdl->sdl_pixel_format); - return sdl->primary != NULL; + return sdl->primary != nullptr; } static BOOL sdl_desktop_resize(rdpContext* context) { rdpGdi* gdi; rdpSettings* settings; - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(context); @@ -530,7 +548,7 @@ static const char* sdl_window_get_title(rdpSettings* settings) const char* prefix = "FreeRDP:"; if (!settings) - return NULL; + return nullptr; windowTitle = freerdp_settings_get_string(settings, FreeRDP_WindowTitle); if (windowTitle) @@ -554,7 +572,7 @@ static const char* sdl_window_get_title(rdpSettings* settings) static void sdl_cleanup_sdl(sdlContext* sdl) { - const sdl_window_t empty = { 0 }; + const sdl_window_t empty = {}; if (!sdl) return; @@ -566,7 +584,7 @@ static void sdl_cleanup_sdl(sdlContext* sdl) *window = empty; } SDL_FreeSurface(sdl->primary); - sdl->primary = NULL; + sdl->primary = nullptr; sdl->windowCount = 0; SDL_Quit(); @@ -587,7 +605,7 @@ static BOOL sdl_create_windows(sdlContext* sdl) const UINT32 h = freerdp_settings_get_uint32(sdl->common.context.settings, FreeRDP_DesktopHeight); - sdl_window_t* window = NULL; + sdl_window_t* window = nullptr; for (size_t x = 0; x < sdl->windowCount; x++) { Uint32 flags = SDL_WINDOW_SHOWN; @@ -645,45 +663,6 @@ unlock: } } -BOOL update_resizeable(sdlContext* sdl, BOOL enable) -{ - WINPR_ASSERT(sdl); - - EnterCriticalSection(&sdl->critical); - - const rdpSettings* settings = sdl->common.context.settings; - const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate); - const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing); - BOOL use = (dyn && enable) || smart; - - for (uint32_t x = 0; x < sdl->windowCount; x++) - { - sdl_window_t* window = &sdl->windows[x]; - if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_RESIZEABLE, window->window, use)) - return FALSE; - } - sdl->resizeable = use; - - LeaveCriticalSection(&sdl->critical); - return TRUE; -} - -BOOL update_fullscreen(sdlContext* sdl, BOOL enter) -{ - WINPR_ASSERT(sdl); - - EnterCriticalSection(&sdl->critical); - for (uint32_t x = 0; x < sdl->windowCount; x++) - { - sdl_window_t* window = &sdl->windows[x]; - if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, window->window, enter)) - return FALSE; - } - sdl->fullscreen = enter; - LeaveCriticalSection(&sdl->critical); - return TRUE; -} - static int sdl_run(sdlContext* sdl) { int rc = -1; @@ -792,22 +771,28 @@ static int sdl_run(sdlContext* sdl) sdl_redraw(sdl); break; case SDL_USEREVENT_UPDATE: - sdl_end_paint_process(windowEvent.user.data1); - break; + { + auto context = static_cast(windowEvent.user.data1); + sdl_end_paint_process(context); + } + break; case SDL_USEREVENT_CREATE_WINDOWS: - sdl_create_windows(windowEvent.user.data1); - break; + { + auto sdl = static_cast(windowEvent.user.data1); + sdl_create_windows(sdl); + } + break; case SDL_USEREVENT_WINDOW_RESIZEABLE: { - SDL_Window* window = windowEvent.user.data1; - const SDL_bool use = windowEvent.user.code != 0; + auto window = static_cast(windowEvent.user.data1); + const SDL_bool use = windowEvent.user.code != 0 ? SDL_TRUE : SDL_FALSE; SDL_SetWindowResizable(window, use); } break; case SDL_USEREVENT_WINDOW_FULLSCREEN: { - SDL_Window* window = windowEvent.user.data1; - const SDL_bool enter = windowEvent.user.code != 0; + auto window = static_cast(windowEvent.user.data1); + const SDL_bool enter = windowEvent.user.code != 0 ? SDL_TRUE : SDL_FALSE; Uint32 curFlags = SDL_GetWindowFlags(window); const BOOL isSet = (curFlags & SDL_WINDOW_FULLSCREEN); @@ -964,7 +949,7 @@ static void sdl_post_final_disconnect(freerdp* instance) context = (sdlContext*)instance->context; sdl_disp_free(context->disp); - context->disp = NULL; + context->disp = nullptr; } /* RDP main loop. @@ -976,7 +961,7 @@ static DWORD WINAPI sdl_client_thread_proc(void* arg) DWORD nCount; DWORD status; int exit_code = SDL_EXIT_SUCCESS; - HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 }; + HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {}; WINPR_ASSERT(sdl); @@ -1132,22 +1117,21 @@ static void sdl_client_global_uninit(void) static int sdl_logon_error_info(freerdp* instance, UINT32 data, UINT32 type) { - sdlContext* tf; const char* str_data = freerdp_get_logon_error_info_data(data); const char* str_type = freerdp_get_logon_error_info_type(type); if (!instance || !instance->context) return -1; - tf = (sdlContext*)instance->context; - WLog_Print(tf->log, WLOG_INFO, "Logon Error Info %s [%s]", str_data, str_type); + auto sdl = reinterpret_cast(instance->context); + WLog_Print(sdl->log, WLOG_INFO, "Logon Error Info %s [%s]", str_data, str_type); return 1; } static BOOL sdl_client_new(freerdp* instance, rdpContext* context) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); if (!instance || !context) return FALSE; @@ -1165,16 +1149,16 @@ static BOOL sdl_client_new(freerdp* instance, rdpContext* context) instance->LogonErrorInfo = sdl_logon_error_info; /* TODO: Client display set up */ - sdl->initialize = CreateEventA(NULL, TRUE, FALSE, NULL); - sdl->initialized = CreateEventA(NULL, TRUE, FALSE, NULL); - sdl->update_complete = CreateEventA(NULL, TRUE, TRUE, NULL); - sdl->windows_created = CreateEventA(NULL, TRUE, FALSE, NULL); + sdl->initialize = CreateEventA(nullptr, TRUE, FALSE, nullptr); + sdl->initialized = CreateEventA(nullptr, TRUE, FALSE, nullptr); + sdl->update_complete = CreateEventA(nullptr, TRUE, TRUE, nullptr); + sdl->windows_created = CreateEventA(nullptr, TRUE, FALSE, nullptr); return sdl->initialize && sdl->initialized && sdl->update_complete && sdl->windows_created; } static void sdl_client_free(freerdp* instance, rdpContext* context) { - sdlContext* sdl = (sdlContext*)instance->context; + auto sdl = reinterpret_cast(instance->context); if (!context) return; @@ -1186,19 +1170,19 @@ static void sdl_client_free(freerdp* instance, rdpContext* context) CloseHandle(sdl->update_complete); CloseHandle(sdl->windows_created); - sdl->thread = NULL; - sdl->initialize = NULL; - sdl->initialized = NULL; - sdl->update_complete = NULL; - sdl->windows_created = NULL; + sdl->thread = nullptr; + sdl->initialize = nullptr; + sdl->initialized = nullptr; + sdl->update_complete = nullptr; + sdl->windows_created = nullptr; } static int sdl_client_start(rdpContext* context) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); - sdl->thread = CreateThread(NULL, 0, sdl_client_thread_proc, sdl, 0, NULL); + sdl->thread = CreateThread(nullptr, 0, sdl_client_thread_proc, sdl, 0, nullptr); if (!sdl->thread) return -1; return 0; @@ -1206,7 +1190,7 @@ static int sdl_client_start(rdpContext* context) static int sdl_client_stop(rdpContext* context) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); /* We do not want to use freerdp_abort_connect_context here. @@ -1236,20 +1220,28 @@ static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) return 0; } +static void context_free(sdlContext* sdl) +{ + if (sdl) + freerdp_client_context_free(&sdl->common.context); +} + int main(int argc, char* argv[]) { int rc = -1; int status; - rdpContext* context = NULL; - RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 }; + rdpContext* context = nullptr; + RDP_CLIENT_ENTRY_POINTS clientEntryPoints = {}; freerdp_client_warn_experimental(argc, argv); RdpClientEntry(&clientEntryPoints); - sdlContext* sdl = (sdlContext*)freerdp_client_context_new(&clientEntryPoints); + std::unique_ptr sdl( + reinterpret_cast(freerdp_client_context_new(&clientEntryPoints)), + context_free); if (!sdl) - goto fail; + return -1; rdpSettings* settings = sdl->common.context.settings; WINPR_ASSERT(settings); @@ -1259,26 +1251,25 @@ int main(int argc, char* argv[]) { rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv); if (settings->ListMonitors) - sdl_list_monitors(sdl); - goto fail; + sdl_list_monitors(sdl.get()); + return rc; } context = &sdl->common.context; WINPR_ASSERT(context); if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE)) - goto fail; + return -1; if (freerdp_client_start(context) != 0) - goto fail; + return -1; - rc = sdl_run(sdl); + rc = sdl_run(sdl.get()); if (freerdp_client_stop(context) != 0) - rc = -1; + return -1; rc = sdl->exit_code; -fail: - freerdp_client_context_free(context); + return rc; } diff --git a/client/SDL/sdl_freerdp.h b/client/SDL/sdl_freerdp.h index 3679b752a..1477d85fb 100644 --- a/client/SDL/sdl_freerdp.h +++ b/client/SDL/sdl_freerdp.h @@ -17,8 +17,7 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_H -#define FREERDP_CLIENT_SDL_H +#pragma once #include #include @@ -67,7 +66,3 @@ typedef struct wLog* log; } sdlContext; -BOOL update_resizeable(sdlContext* sdl, BOOL enable); -BOOL update_fullscreen(sdlContext* sdl, BOOL enter); - -#endif /* FREERDP_CLIENT_SDL_H */ diff --git a/client/SDL/sdl_kbd.c b/client/SDL/sdl_kbd.cpp similarity index 98% rename from client/SDL/sdl_kbd.c rename to client/SDL/sdl_kbd.cpp index 940a93504..f8b87d816 100644 --- a/client/SDL/sdl_kbd.c +++ b/client/SDL/sdl_kbd.cpp @@ -20,6 +20,7 @@ #include "sdl_kbd.h" #include "sdl_disp.h" #include "sdl_freerdp.h" +#include "sdl_utils.h" #include @@ -350,7 +351,7 @@ BOOL sdl_keyboard_set_indicators(rdpContext* context, UINT16 led_flags) { WINPR_UNUSED(context); - SDL_Keymod state = KMOD_NONE; + int state = KMOD_NONE; if ((led_flags & KBD_SYNC_NUM_LOCK) != 0) state |= KMOD_NUM; @@ -363,7 +364,7 @@ BOOL sdl_keyboard_set_indicators(rdpContext* context, UINT16 led_flags) // TODO: KBD_SYNC_KANA_LOCK - SDL_SetModState(state); + SDL_SetModState(static_cast(state)); return TRUE; } @@ -421,7 +422,8 @@ static UINT32 sdl_scancode_to_rdp(Uint32 scancode) } #if defined(WITH_DEBUG_SDL_KBD_EVENTS) - WLog_DBG(TAG, "got %s [%s] -> [%s]", SDL_GetScancodeName(scancode), sdl_scancode_name(scancode), + auto code = static_cast(scancode); + WLog_DBG(TAG, "got %s [%s] -> [%s]", SDL_GetScancodeName(code), sdl_scancode_name(scancode), sdl_rdp_scancode_name(rdp)); #endif return rdp; @@ -453,7 +455,7 @@ BOOL sdl_handle_keyboard_event(sdlContext* sdl, const SDL_KeyboardEvent* ev) case SDL_SCANCODE_G: if (ev->type == SDL_KEYDOWN) { - sdl_grab_keyboard(sdl, ev->windowID, !sdl->grab_kbd); + sdl_grab_keyboard(sdl, ev->windowID, sdl->grab_kbd ? SDL_FALSE : SDL_TRUE); } return TRUE; default: diff --git a/client/SDL/sdl_kbd.h b/client/SDL/sdl_kbd.h index 761aa7346..4a44f3387 100644 --- a/client/SDL/sdl_kbd.h +++ b/client/SDL/sdl_kbd.h @@ -17,8 +17,7 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_KBD_H -#define FREERDP_CLIENT_SDL_KBD_H +#pragma once #include #include @@ -34,5 +33,3 @@ BOOL sdl_keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeSt UINT32 imeConvMode); BOOL sdl_handle_keyboard_event(sdlContext* sdl, const SDL_KeyboardEvent* ev); - -#endif /* FREERDP_CLIENT_SDL_KBD_H */ diff --git a/client/SDL/sdl_monitor.c b/client/SDL/sdl_monitor.cpp similarity index 96% rename from client/SDL/sdl_monitor.c rename to client/SDL/sdl_monitor.cpp index 33a3f7221..7937c983f 100644 --- a/client/SDL/sdl_monitor.c +++ b/client/SDL/sdl_monitor.cpp @@ -175,14 +175,15 @@ static BOOL sdl_apply_display_properties(sdlContext* sdl) WINPR_ASSERT(settings); const UINT32 numIds = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds); - if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorDefArray, NULL, numIds)) + if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorDefArray, nullptr, numIds)) return FALSE; if (!freerdp_settings_set_uint32(settings, FreeRDP_MonitorCount, numIds)) return FALSE; for (UINT32 x = 0; x < numIds; x++) { - const UINT32* id = freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x); + auto id = static_cast( + freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x)); WINPR_ASSERT(id); float hdpi; @@ -190,7 +191,7 @@ static BOOL sdl_apply_display_properties(sdlContext* sdl) SDL_Rect rect = { 0 }; SDL_GetDisplayBounds(*id, &rect); - SDL_GetDisplayDPI(*id, NULL, &hdpi, &vdpi); + SDL_GetDisplayDPI(*id, nullptr, &hdpi, &vdpi); if (sdl->highDpi) { // HighDPI is problematic with SDL: We can only get native resolution by creating a @@ -230,9 +231,10 @@ static BOOL sdl_apply_display_properties(sdlContext* sdl) const UINT32 rdp_orientation = ORIENTATION_LANDSCAPE; #endif - rdpMonitor* monitor = - freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x); + auto monitor = static_cast( + freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x)); WINPR_ASSERT(monitor); + monitor->orig_screen = x; monitor->x = rect.x; monitor->y = rect.y; @@ -297,7 +299,7 @@ BOOL sdl_detect_monitors(sdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight) WINPR_ASSERT(settings); const int numDisplays = SDL_GetNumVideoDisplays(); - if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, NULL, numDisplays)) + if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, numDisplays)) return FALSE; for (size_t x = 0; x < numDisplays; x++) diff --git a/client/SDL/sdl_monitor.h b/client/SDL/sdl_monitor.h index ada4214bf..cab8f45c6 100644 --- a/client/SDL/sdl_monitor.h +++ b/client/SDL/sdl_monitor.h @@ -17,8 +17,7 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_MONITOR_H -#define FREERDP_CLIENT_SDL_MONITOR_H +#pragma once #include #include @@ -27,5 +26,3 @@ int sdl_list_monitors(sdlContext* sdl); BOOL sdl_detect_monitors(sdlContext* sdl, UINT32* pWidth, UINT32* pHeight); - -#endif /* FREERDP_CLIENT_SDL_MONITOR_H */ diff --git a/client/SDL/sdl_pointer.c b/client/SDL/sdl_pointer.cpp similarity index 82% rename from client/SDL/sdl_pointer.c rename to client/SDL/sdl_pointer.cpp index 0d8199a3f..6d81852a9 100644 --- a/client/SDL/sdl_pointer.c +++ b/client/SDL/sdl_pointer.cpp @@ -41,7 +41,7 @@ typedef struct static BOOL sdl_Pointer_New(rdpContext* context, rdpPointer* pointer) { - sdlPointer* ptr = (sdlPointer*)pointer; + auto ptr = reinterpret_cast(pointer); WINPR_ASSERT(context); if (!ptr) @@ -56,10 +56,11 @@ static BOOL sdl_Pointer_New(rdpContext* context, rdpPointer* pointer) if (!ptr->data) return FALSE; + auto data = static_cast(ptr->data); if (!freerdp_image_copy_from_pointer_data( - ptr->data, gdi->dstFormat, 0, 0, 0, pointer->width, pointer->height, - pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData, - pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette)) + data, gdi->dstFormat, 0, 0, 0, pointer->width, pointer->height, pointer->xorMaskData, + pointer->lengthXorMask, pointer->andMaskData, pointer->lengthAndMask, pointer->xorBpp, + &context->gdi->palette)) { winpr_aligned_free(ptr->data); return FALSE; @@ -73,8 +74,8 @@ static void sdl_Pointer_Clear(sdlPointer* ptr) WINPR_ASSERT(ptr); SDL_FreeCursor(ptr->cursor); SDL_FreeSurface(ptr->image); - ptr->cursor = NULL; - ptr->image = NULL; + ptr->cursor = nullptr; + ptr->image = nullptr; } static void sdl_Pointer_Free(rdpContext* context, rdpPointer* pointer) @@ -86,7 +87,7 @@ static void sdl_Pointer_Free(rdpContext* context, rdpPointer* pointer) { sdl_Pointer_Clear(ptr); winpr_aligned_free(ptr->data); - ptr->data = NULL; + ptr->data = nullptr; } } @@ -110,11 +111,11 @@ BOOL sdl_Pointer_Set_Process(SDL_UserEvent* uptr) WINPR_ASSERT(uptr); - sdlContext* sdl = uptr->data2; + auto sdl = static_cast(uptr->data2); WINPR_ASSERT(sdl); rdpContext* context = &sdl->common.context; - sdlPointer* ptr = uptr->data1; + auto ptr = static_cast(uptr->data1); WINPR_ASSERT(ptr); rdpPointer* pointer = &ptr->pointer; @@ -145,9 +146,11 @@ BOOL sdl_Pointer_Set_Process(SDL_UserEvent* uptr) return FALSE; SDL_LockSurface(ptr->image); + auto pixels = static_cast(ptr->image->pixels); + auto data = static_cast(ptr->data); const BOOL rc = - freerdp_image_scale(ptr->image->pixels, gdi->dstFormat, ptr->image->pitch, 0, 0, - ptr->image->w, ptr->image->h, ptr->data, gdi->dstFormat, 0, 0, 0, w, h); + freerdp_image_scale(pixels, gdi->dstFormat, ptr->image->pitch, 0, 0, ptr->image->w, + ptr->image->h, data, gdi->dstFormat, 0, 0, 0, w, h); SDL_UnlockSurface(ptr->image); if (!rc) return FALSE; @@ -170,7 +173,7 @@ static BOOL sdl_Pointer_SetNull(rdpContext* context) static BOOL sdl_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) { - sdlContext* sdl = (sdlContext*)context; + auto sdl = reinterpret_cast(context); WINPR_ASSERT(sdl); return sdl_push_user_event(SDL_USEREVENT_POINTER_POSITION, x, y); @@ -178,7 +181,7 @@ static BOOL sdl_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) BOOL sdl_register_pointer(rdpGraphics* graphics) { - rdpPointer* pointer = NULL; + rdpPointer* pointer = nullptr; if (!(pointer = (rdpPointer*)calloc(1, sizeof(rdpPointer)))) return FALSE; diff --git a/client/SDL/sdl_pointer.h b/client/SDL/sdl_pointer.h index bfe1b65ff..9155137d4 100644 --- a/client/SDL/sdl_pointer.h +++ b/client/SDL/sdl_pointer.h @@ -17,8 +17,7 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_POINTER_H -#define FREERDP_CLIENT_SDL_POINTER_H +#pragma once #include #include "sdl_freerdp.h" @@ -26,5 +25,3 @@ BOOL sdl_register_pointer(rdpGraphics* graphics); BOOL sdl_Pointer_Set_Process(SDL_UserEvent* uptr); - -#endif /* FREERDP_CLIENT_SDL_POINTER_H */ diff --git a/client/SDL/sdl_touch.c b/client/SDL/sdl_touch.cpp similarity index 100% rename from client/SDL/sdl_touch.c rename to client/SDL/sdl_touch.cpp diff --git a/client/SDL/sdl_touch.h b/client/SDL/sdl_touch.h index afb1e0325..a8cc5350c 100644 --- a/client/SDL/sdl_touch.h +++ b/client/SDL/sdl_touch.h @@ -17,8 +17,7 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_TOUCH_H -#define FREERDP_CLIENT_SDL_TOUCH_H +#pragma once #include "sdl_freerdp.h" @@ -32,5 +31,3 @@ BOOL sdl_handle_mouse_button(sdlContext* sdl, const SDL_MouseButtonEvent* ev); BOOL sdl_handle_touch_down(sdlContext* sdl, const SDL_TouchFingerEvent* ev); BOOL sdl_handle_touch_up(sdlContext* sdl, const SDL_TouchFingerEvent* ev); BOOL sdl_handle_touch_motion(sdlContext* sdl, const SDL_TouchFingerEvent* ev); - -#endif /* FREERDP_CLIENT_SDL_TOUCH_H */ diff --git a/client/SDL/sdl_utils.c b/client/SDL/sdl_utils.cpp similarity index 81% rename from client/SDL/sdl_utils.c rename to client/SDL/sdl_utils.cpp index 5b7b51433..08888e09e 100644 --- a/client/SDL/sdl_utils.c +++ b/client/SDL/sdl_utils.cpp @@ -20,6 +20,8 @@ #include #include "sdl_utils.h" +#include "sdl_freerdp.h" + #include const char* sdl_event_type_str(Uint32 type) @@ -113,7 +115,7 @@ const char* sdl_event_type_str(Uint32 type) const char* sdl_error_string(Uint32 res) { if (res == 0) - return NULL; + return nullptr; return SDL_GetError(); } @@ -165,8 +167,48 @@ BOOL sdl_push_user_event(Uint32 type, ...) case SDL_USEREVENT_POINTER_DEFAULT: break; default: + va_end(ap); return FALSE; } va_end(ap); return SDL_PushEvent(&ev) == 1; } + +BOOL update_fullscreen(sdlContext* sdl, BOOL enter) +{ + WINPR_ASSERT(sdl); + + EnterCriticalSection(&sdl->critical); + for (uint32_t x = 0; x < sdl->windowCount; x++) + { + sdl_window_t* window = &sdl->windows[x]; + if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, window->window, enter)) + return FALSE; + } + sdl->fullscreen = enter; + LeaveCriticalSection(&sdl->critical); + return TRUE; +} + +BOOL update_resizeable(sdlContext* sdl, BOOL enable) +{ + WINPR_ASSERT(sdl); + + EnterCriticalSection(&sdl->critical); + + const rdpSettings* settings = sdl->common.context.settings; + const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate); + const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing); + BOOL use = (dyn && enable) || smart; + + for (uint32_t x = 0; x < sdl->windowCount; x++) + { + sdl_window_t* window = &sdl->windows[x]; + if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_RESIZEABLE, window->window, use)) + return FALSE; + } + sdl->resizeable = use; + + LeaveCriticalSection(&sdl->critical); + return TRUE; +} diff --git a/client/SDL/sdl_utils.h b/client/SDL/sdl_utils.h index 5a8473125..e96ae3bd6 100644 --- a/client/SDL/sdl_utils.h +++ b/client/SDL/sdl_utils.h @@ -17,14 +17,15 @@ * limitations under the License. */ -#ifndef FREERDP_CLIENT_SDL_UTILS_H -#define FREERDP_CLIENT_SDL_UTILS_H +#pragma once #include #include #include +#include "sdl_freerdp.h" + enum { SDL_USEREVENT_UPDATE = SDL_USEREVENT + 1, @@ -37,6 +38,9 @@ enum SDL_USEREVENT_POINTER_SET }; +BOOL update_resizeable(sdlContext* sdl, BOOL enable); +BOOL update_fullscreen(sdlContext* sdl, BOOL enter); + BOOL sdl_push_user_event(Uint32 type, ...); const char* sdl_event_type_str(Uint32 type); @@ -46,5 +50,3 @@ const char* sdl_error_string(Uint32 res); sdl_log_error_ex(res, log, what, __FILE__, __LINE__, __FUNCTION__) BOOL sdl_log_error_ex(Uint32 res, wLog* log, const char* what, const char* file, size_t line, const char* fkt); - -#endif /* FREERDP_CLIENT_SDL_UTILS_H */