From 54e8cce33c4097af9d0bdb4957b88671dd7fdef0 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 22 Feb 2019 22:38:52 +1100 Subject: [PATCH] [client] core: added initial clipboard interface and x11 stubs --- client/CMakeLists.txt | 1 + client/clipboard/x11.c | 42 ++++++++++++++++++++++++++++++++++++++++++ client/lg-clipboard.h | 35 +++++++++++++++++++++++++++++++++++ client/lg-clipboards.h | 34 ++++++++++++++++++++++++++++++++++ client/main.c | 21 +++++++++++++++++++-- 5 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 client/clipboard/x11.c create mode 100644 client/lg-clipboard.h create mode 100644 client/lg-clipboards.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index e7a6da31..9ad41e0a 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -57,6 +57,7 @@ set(SOURCES utils.c spice/rsa.c spice/spice.c + clipboard/x11.c decoders/null.c decoders/yuv420.c renderers/opengl.c diff --git a/client/clipboard/x11.c b/client/clipboard/x11.c new file mode 100644 index 00000000..142460ef --- /dev/null +++ b/client/clipboard/x11.c @@ -0,0 +1,42 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "lg-clipboard.h" +#include + +static const char * x11_cb_getName() +{ + return "X11"; +} + +static bool x11_cb_init() +{ + return true; +} + +static void x11_cb_free() +{ +} + +const LG_Clipboard LGC_X11 = +{ + .getName = x11_cb_getName, + .init = x11_cb_init, + .free = x11_cb_free +}; \ No newline at end of file diff --git a/client/lg-clipboard.h b/client/lg-clipboard.h new file mode 100644 index 00000000..1bbef75b --- /dev/null +++ b/client/lg-clipboard.h @@ -0,0 +1,35 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#pragma once + +#include + + +typedef const char * (* LG_ClipboardGetName)(); +typedef bool (* LG_ClipboardInit)(); +typedef void (* LG_ClipboardFree)(); + +typedef struct LG_Clipboard +{ + LG_ClipboardGetName getName; + LG_ClipboardInit init; + LG_ClipboardFree free; +} +LG_Clipboard; \ No newline at end of file diff --git a/client/lg-clipboards.h b/client/lg-clipboards.h new file mode 100644 index 00000000..c5fd0d87 --- /dev/null +++ b/client/lg-clipboards.h @@ -0,0 +1,34 @@ +/* +Looking Glass - KVM FrameRelay (KVMFR) Client +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#pragma once + +#include + +#include "lg-clipboard.h" + +extern const LG_Clipboard LGC_X11; + +const LG_Clipboard * LG_Clipboards[] = +{ + &LGC_X11, + NULL +}; + +#define LG_CLIPBOARD_COUNT ((sizeof(LG_Clipboards) / sizeof(LG_Clipboard *)) - 1) \ No newline at end of file diff --git a/client/main.c b/client/main.c index 65e6e3e9..d20105f1 100644 --- a/client/main.c +++ b/client/main.c @@ -42,6 +42,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "kb.h" #include "lg-renderers.h" +#include "lg-clipboards.h" struct AppState { @@ -58,10 +59,12 @@ struct AppState float scaleX, scaleY; float accX, accY; - const LG_Renderer * lgr ; + const LG_Renderer * lgr; void * lgrData; bool lgrResize; + const LG_Clipboard * lgc; + SDL_Window * window; int shmFD; struct KVMFRHeader * shm; @@ -857,7 +860,6 @@ int run() if (try_renderer(i, lgrParams, &sdlFlags)) { state.lgr = LG_Renderers[i]; - DEBUG_INFO("Using: %s", state.lgr->get_name()); break; } } @@ -890,6 +892,18 @@ int run() return 1; } + // choose a clipboard api + for(unsigned int i = 0; i < LG_CLIPBOARD_COUNT; ++i) + { + const LG_Clipboard * cb = LG_Clipboards[i]; + if (cb->init()) + { + state.lgc = cb; + DEBUG_INFO("Using Clipboard: %s", cb->getName()); + break; + } + } + if (params.fullscreen) SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); @@ -1104,6 +1118,9 @@ int run() if (state.lgr) state.lgr->deinitialize(state.lgrData); + if (state.lgc) + state.lgc->free(); + if (state.window) SDL_DestroyWindow(state.window);