From 6fc8f92a8e3958a7b5f10076c5d18bfb3bf7202b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 12 Jan 2020 15:53:43 -0300 Subject: [PATCH] On Screen Keyboard support on Linux by using "onboard" as a child process. --HG-- branch : dev --- src/eepp/window/backend/SDL2/windowsdl2.cpp | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/eepp/window/backend/SDL2/windowsdl2.cpp b/src/eepp/window/backend/SDL2/windowsdl2.cpp index c0e841010..b61b6be07 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,34 @@ int hideOSK() { WIN_OSK_VISIBLE = false; return PostMessage( GetDesktopWindow(), WM_SYSCOMMAND, (int)SC_CLOSE, 0 ); } +#elif defined( EE_X11_PLATFORM ) +#include +#include + +static pid_t ONBOARD_PID = 0; + +void showOSK() { + if ( ONBOARD_PID == 0 ) { + if ( FileSystem::fileExists( "/usr/bin/onboard" ) ) { + pid_t pid = fork(); + + if ( pid == 0 ) { + execl( "/usr/bin/onboard", "onboard", NULL ); + } else if ( pid != -1 ) { + ONBOARD_PID = pid; + } + } else { + EE::eePRINTL( "onboard must be installed to be able to use the On Screen Keyboard" ); + } + } +} + +void hideOSK() { + if ( ONBOARD_PID != 0 ) { + kill( ONBOARD_PID, SIGTERM ); + ONBOARD_PID = 0; + } +} #endif namespace EE { namespace Window { namespace Backend { namespace SDL2 { @@ -156,6 +185,10 @@ WindowSDL::~WindowSDL() { if ( NULL != mSDLWindow ) { SDL_DestroyWindow( mSDLWindow ); } + +#if defined( EE_X11_PLATFORM ) + hideOSK(); +#endif } bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) { @@ -731,6 +764,8 @@ void WindowSDL::startTextInput() { if ( mWindow.WindowConfig.UseScreenKeyboard ) { #if EE_PLATFORM == EE_PLATFORM_WIN showOSK( getWindowHandler() ); +#elif defined( EE_X11_PLATFORM ) + showOSK(); #else SDL_StartTextInput(); #endif @@ -740,6 +775,8 @@ void WindowSDL::startTextInput() { bool WindowSDL::isTextInputActive() { #if EE_PLATFORM == EE_PLATFORM_WIN return WIN_OSK_VISIBLE; +#elif defined( EE_X11_PLATFORM ) + return ONBOARD_PID != 0; #else return SDL_TRUE == SDL_IsTextInputActive(); #endif @@ -749,6 +786,8 @@ void WindowSDL::stopTextInput() { if ( mWindow.WindowConfig.UseScreenKeyboard ) { #if EE_PLATFORM == EE_PLATFORM_WIN hideOSK(); +#elif defined( EE_X11_PLATFORM ) + hideOSK(); #else SDL_StopTextInput(); #endif