Copy server invite code to the clipboard automatically

This commit is contained in:
Sergii Pylypenko
2021-12-10 01:40:51 +02:00
parent 6c28ef9960
commit 9b2e51b755
4 changed files with 23 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
#include "../rev.h"
#include "../settings_type.h"
#include "../strings_func.h"
#include "../video/video_driver.hpp"
#include "../window_func.h"
#include "../window_type.h"
#include "network.h"
@@ -193,6 +194,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet *p)
* and _settings_client.network.server_invite_code contains the one we will
* attempt to re-use when registering again. */
_network_server_invite_code = _settings_client.network.server_invite_code;
VideoDriver::GetInstance()->SetClipboardContents(_network_server_invite_code);
SetWindowDirty(WC_CLIENT_LIST, 0);

View File

@@ -604,6 +604,11 @@ void VideoDriver_SDL_Base::InputLoop()
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
old_ctrl_pressed = _ctrl_pressed;
if (!this->set_clipboard_text.empty()) {
SDL_SetClipboardText(this->set_clipboard_text.c_str());
this->set_clipboard_text = "";
}
}
void VideoDriver_SDL_Base::LoopOnce()

View File

@@ -711,6 +711,13 @@ void VideoDriver_SDL::InputLoop()
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
old_ctrl_pressed = _ctrl_pressed;
#ifdef __ANDROID__
if (!this->set_clipboard_text.empty()) {
SDL_SetClipboardText(this->set_clipboard_text.c_str());
this->set_clipboard_text = "";
}
#endif /* __ANDROID__ */
}
void VideoDriver_SDL::MainLoop()

View File

@@ -193,6 +193,14 @@ public:
void GameLoopPause();
/**
* Set clipboard contents, the video thread will call the OS clipboard API
*/
void SetClipboardContents(const std::string &text)
{
this->set_clipboard_text = text;
}
/**
* Get the currently active instance of the video driver.
*/
@@ -342,6 +350,7 @@ protected:
bool fast_forward_key_pressed; ///< The fast-forward key is being pressed.
bool fast_forward_via_key; ///< The fast-forward was enabled by key press.
std::string set_clipboard_text; ///< New clipboard contents to set
bool is_game_threaded;
std::thread game_thread;