Skip to content

Commit

Permalink
Add clipboard support from SDL backend
Browse files Browse the repository at this point in the history
Looks like as part of the backend refactor, copy and paste was partially
broken with the SDL backend.  This fixes that broken functionality and
lays some groundwork for copy and paste in the Wayland Backend.
  • Loading branch information
ForTheReallys authored and misyltoad committed Sep 17, 2024
1 parent a2b45e1 commit d87f6d9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Backends/OpenVRBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,11 @@ namespace gamescope
vr::VROverlay()->ClearOverlayTexture( GetPrimaryPlane()->GetOverlayThumbnail() );
}
}
virtual std::shared_ptr<INestedHints::CursorInfo> GetHostCursor() override
virtual void SetSelection( std::shared_ptr<std::string> szContents, GamescopeSelection eSelection ) override
{
// Do nothing.
}
virtual std::shared_ptr<INestedHints::CursorInfo> GetHostCursor() override
{
return nullptr;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Backends/SDLBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "SDL_clipboard.h"
#include "SDL_events.h"
#include "gamescope_shared.h"
#include "main.hpp"
#include "wlserver.hpp"
#include <SDL.h>
Expand Down Expand Up @@ -162,7 +163,8 @@ namespace gamescope
virtual void SetVisible( bool bVisible ) override;
virtual void SetTitle( std::shared_ptr<std::string> szTitle ) override;
virtual void SetIcon( std::shared_ptr<std::vector<uint32_t>> uIconPixels ) override;
virtual std::shared_ptr<INestedHints::CursorInfo> GetHostCursor() override;
virtual void SetSelection( std::shared_ptr<std::string> szContents, GamescopeSelection eSelection ) override;
virtual std::shared_ptr<INestedHints::CursorInfo> GetHostCursor() override;
protected:
virtual void OnBackendBlobDestroyed( BackendBlob *pBlob ) override;
private:
Expand Down Expand Up @@ -496,7 +498,13 @@ namespace gamescope
m_pApplicationIcon = uIconPixels;
PushUserEvent( GAMESCOPE_SDL_EVENT_ICON );
}

void CSDLBackend::SetSelection( std::shared_ptr<std::string> szContents, GamescopeSelection eSelection )
{
if (eSelection == GAMESCOPE_SELECTION_CLIPBOARD)
SDL_SetClipboardText(szContents->c_str());
else if (eSelection == GAMESCOPE_SELECTION_PRIMARY)
SDL_SetPrimarySelectionText(szContents->c_str());
}
std::shared_ptr<INestedHints::CursorInfo> CSDLBackend::GetHostCursor()
{
return GetX11HostCursor();
Expand Down
5 changes: 5 additions & 0 deletions src/Backends/WaylandBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ namespace gamescope
virtual void SetVisible( bool bVisible ) override;
virtual void SetTitle( std::shared_ptr<std::string> szTitle ) override;
virtual void SetIcon( std::shared_ptr<std::vector<uint32_t>> uIconPixels ) override;
virtual void SetSelection( std::shared_ptr<std::string> szContents, GamescopeSelection eSelection ) override;
virtual std::shared_ptr<INestedHints::CursorInfo> GetHostCursor() override;
protected:
virtual void OnBackendBlobDestroyed( BackendBlob *pBlob ) override;
Expand Down Expand Up @@ -1976,6 +1977,10 @@ namespace gamescope
xdg_toplevel_icon_manager_v1_set_icon( m_pToplevelIconManager, m_Planes[0].GetXdgToplevel(), nullptr );
}
}
void CWaylandBackend::SetSelection( std::shared_ptr<std::string> szContents, GamescopeSelection eSelection )
{
// Do nothing
}

std::shared_ptr<INestedHints::CursorInfo> CWaylandBackend::GetHostCursor()
{
Expand Down
1 change: 1 addition & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace gamescope
virtual void SetVisible( bool bVisible ) = 0;
virtual void SetTitle( std::shared_ptr<std::string> szTitle ) = 0;
virtual void SetIcon( std::shared_ptr<std::vector<uint32_t>> uIconPixels ) = 0;
virtual void SetSelection( std::shared_ptr<std::string> szContents, GamescopeSelection eSelection ) = 0;
virtual std::shared_ptr<CursorInfo> GetHostCursor() = 0;
};

Expand Down
6 changes: 4 additions & 2 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* says above. Not that I can really do anything about it
*/

#include "gamescope_shared.h"
#include "xwayland_ctx.hpp"
#include <X11/X.h>
#include <X11/Xlib.h>
Expand Down Expand Up @@ -4979,13 +4980,14 @@ handle_selection_notify(xwayland_ctx_t *ctx, XSelectionEvent *ev)
&actual_type, &actual_format, &nitems, &bytes_after, &data);
if (data) {
const char *contents = (const char *) data;
auto szContents = std::make_shared<std::string>(contents);
defer( XFree( data ); );

if (ev->selection == ctx->atoms.clipboard)
{
if ( GetBackend()->GetNestedHints() )
{
//GetBackend()->GetNestedHints()->SetSelection()
GetBackend()->GetNestedHints()->SetSelection( szContents, GAMESCOPE_SELECTION_CLIPBOARD );
}
else
{
Expand All @@ -4996,7 +4998,7 @@ handle_selection_notify(xwayland_ctx_t *ctx, XSelectionEvent *ev)
{
if ( GetBackend()->GetNestedHints() )
{
//GetBackend()->GetNestedHints()->SetSelection()
GetBackend()->GetNestedHints()->SetSelection( szContents, GAMESCOPE_SELECTION_PRIMARY );
}
else
{
Expand Down

0 comments on commit d87f6d9

Please sign in to comment.