2019-03-30 01:26:06 +00:00
|
|
|
/*
|
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
|
|
|
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
|
|
|
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 <stdbool.h>
|
2020-08-09 05:14:17 +00:00
|
|
|
#include <stdatomic.h>
|
2019-03-30 01:26:06 +00:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
|
|
#include "interface/app.h"
|
2021-01-15 09:30:03 +00:00
|
|
|
#include "dynamic/displayservers.h"
|
2019-03-30 01:26:06 +00:00
|
|
|
#include "dynamic/renderers.h"
|
2020-01-03 04:17:14 +00:00
|
|
|
#include "common/ivshmem.h"
|
2019-03-30 01:26:06 +00:00
|
|
|
|
|
|
|
#include "spice/spice.h"
|
2020-01-09 09:32:42 +00:00
|
|
|
#include <lgmp/client.h>
|
2019-03-30 01:26:06 +00:00
|
|
|
|
2020-08-11 05:14:58 +00:00
|
|
|
enum RunState
|
|
|
|
{
|
|
|
|
APP_STATE_RUNNING,
|
|
|
|
APP_STATE_RESTART,
|
|
|
|
APP_STATE_SHUTDOWN
|
|
|
|
};
|
|
|
|
|
2019-03-30 01:26:06 +00:00
|
|
|
struct AppState
|
|
|
|
{
|
2021-01-15 09:30:03 +00:00
|
|
|
enum RunState state;
|
|
|
|
|
|
|
|
struct LG_DisplayServerOps * ds;
|
|
|
|
|
2020-10-14 08:32:21 +00:00
|
|
|
bool stopVideo;
|
2019-03-30 01:26:06 +00:00
|
|
|
bool ignoreInput;
|
|
|
|
bool escapeActive;
|
|
|
|
SDL_Scancode escapeAction;
|
|
|
|
KeybindHandle bindings[SDL_NUM_SCANCODES];
|
|
|
|
bool keyDown[SDL_NUM_SCANCODES];
|
|
|
|
|
|
|
|
bool haveSrcSize;
|
2020-12-04 06:32:28 +00:00
|
|
|
SDL_Point windowPos;
|
2019-03-30 01:26:06 +00:00
|
|
|
int windowW, windowH;
|
2021-01-04 01:59:14 +00:00
|
|
|
int windowCX, windowCY;
|
2021-01-08 09:26:32 +00:00
|
|
|
bool focused;
|
2020-12-04 06:32:28 +00:00
|
|
|
SDL_Rect border;
|
2019-03-30 01:26:06 +00:00
|
|
|
SDL_Point srcSize;
|
|
|
|
LG_RendererRect dstRect;
|
2020-08-20 04:52:24 +00:00
|
|
|
|
2019-03-30 01:26:06 +00:00
|
|
|
const LG_Renderer * lgr;
|
|
|
|
void * lgrData;
|
2021-01-04 02:40:03 +00:00
|
|
|
atomic_int lgrResize;
|
2019-03-30 01:26:06 +00:00
|
|
|
|
2021-01-15 09:30:03 +00:00
|
|
|
bool cbAvailable;
|
2019-03-30 01:26:06 +00:00
|
|
|
SpiceDataType cbType;
|
2020-12-03 01:01:51 +00:00
|
|
|
bool cbChunked;
|
|
|
|
size_t cbXfer;
|
2019-03-30 01:26:06 +00:00
|
|
|
struct ll * cbRequestList;
|
|
|
|
|
2020-01-03 05:51:24 +00:00
|
|
|
SDL_SysWMinfo wminfo;
|
2019-03-30 01:26:06 +00:00
|
|
|
SDL_Window * window;
|
2020-01-03 04:17:14 +00:00
|
|
|
|
|
|
|
struct IVSHMEM shm;
|
2020-01-09 09:32:42 +00:00
|
|
|
PLGMPClient lgmp;
|
2020-01-10 00:00:46 +00:00
|
|
|
PLGMPClientQueue frameQueue;
|
|
|
|
PLGMPClientQueue pointerQueue;
|
2019-03-30 01:26:06 +00:00
|
|
|
|
2020-08-09 05:14:17 +00:00
|
|
|
atomic_uint_least64_t frameTime;
|
|
|
|
uint64_t lastFrameTime;
|
|
|
|
uint64_t renderTime;
|
2020-10-29 02:30:15 +00:00
|
|
|
atomic_uint_least64_t frameCount;
|
2020-08-09 05:14:17 +00:00
|
|
|
uint64_t renderCount;
|
2019-03-30 01:26:06 +00:00
|
|
|
|
2020-01-03 04:53:44 +00:00
|
|
|
|
|
|
|
uint64_t resizeTimeout;
|
|
|
|
bool resizeDone;
|
|
|
|
|
2019-03-30 01:26:06 +00:00
|
|
|
KeybindHandle kbFS;
|
2020-10-14 08:32:21 +00:00
|
|
|
KeybindHandle kbVideo;
|
2019-03-30 01:26:06 +00:00
|
|
|
KeybindHandle kbInput;
|
2020-04-22 16:31:30 +00:00
|
|
|
KeybindHandle kbQuit;
|
2019-05-23 19:29:38 +00:00
|
|
|
KeybindHandle kbMouseSensInc;
|
|
|
|
KeybindHandle kbMouseSensDec;
|
2019-05-31 06:39:55 +00:00
|
|
|
KeybindHandle kbCtrlAltFn[12];
|
2021-01-04 07:07:09 +00:00
|
|
|
KeybindHandle kbPass[2];
|
2019-03-30 01:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AppParams
|
|
|
|
{
|
2021-01-15 01:40:59 +00:00
|
|
|
bool autoResize;
|
|
|
|
bool allowResize;
|
|
|
|
bool keepAspect;
|
|
|
|
bool forceAspect;
|
|
|
|
bool dontUpscale;
|
|
|
|
bool borderless;
|
|
|
|
bool fullscreen;
|
|
|
|
bool maximize;
|
|
|
|
bool minimizeOnFocusLoss;
|
|
|
|
bool center;
|
|
|
|
int x, y;
|
|
|
|
unsigned int w, h;
|
|
|
|
int fpsMin;
|
|
|
|
bool showFPS;
|
|
|
|
LG_RendererRotate winRotate;
|
|
|
|
bool useSpiceInput;
|
|
|
|
bool useSpiceClipboard;
|
|
|
|
const char * spiceHost;
|
|
|
|
unsigned int spicePort;
|
|
|
|
bool clipboardToVM;
|
|
|
|
bool clipboardToLocal;
|
|
|
|
bool scaleMouseInput;
|
|
|
|
bool hideMouse;
|
|
|
|
bool ignoreQuit;
|
|
|
|
bool noScreensaver;
|
|
|
|
bool grabKeyboard;
|
|
|
|
bool grabKeyboardOnFocus;
|
|
|
|
SDL_Scancode escapeKey;
|
|
|
|
bool ignoreWindowsKeys;
|
|
|
|
bool showAlerts;
|
|
|
|
bool captureOnStart;
|
|
|
|
bool quickSplash;
|
|
|
|
bool alwaysShowCursor;
|
|
|
|
|
|
|
|
unsigned int cursorPollInterval;
|
|
|
|
unsigned int framePollInterval;
|
|
|
|
bool allowDMA;
|
|
|
|
|
|
|
|
bool forceRenderer;
|
|
|
|
unsigned int forceRendererIndex;
|
|
|
|
|
|
|
|
const char * windowTitle;
|
|
|
|
bool mouseRedraw;
|
|
|
|
int mouseSens;
|
|
|
|
bool mouseSmoothing;
|
|
|
|
bool rawMouse;
|
|
|
|
bool autoCapture;
|
|
|
|
bool captureInputOnly;
|
2019-03-30 01:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CBRequest
|
|
|
|
{
|
|
|
|
SpiceDataType type;
|
|
|
|
LG_ClipboardReplyFn replyFn;
|
|
|
|
void * opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeybindHandle
|
|
|
|
{
|
|
|
|
SDL_Scancode key;
|
|
|
|
SuperEventFn callback;
|
|
|
|
void * opaque;
|
|
|
|
};
|
|
|
|
|
2021-01-04 01:04:43 +00:00
|
|
|
enum WarpState
|
|
|
|
{
|
|
|
|
WARP_STATE_ON,
|
|
|
|
WARP_STATE_OFF
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CursorInfo
|
|
|
|
{
|
|
|
|
/* x & y postiion */
|
|
|
|
int x , y;
|
|
|
|
|
|
|
|
/* pointer hotspot offsets */
|
|
|
|
int hx, hy;
|
|
|
|
|
|
|
|
/* true if the pointer is visible on the guest */
|
|
|
|
bool visible;
|
|
|
|
|
|
|
|
/* true if the details in this struct are valid */
|
|
|
|
bool valid;
|
2021-01-04 22:48:30 +00:00
|
|
|
|
|
|
|
/* the DPI scaling of the guest */
|
|
|
|
uint32_t dpiScale;
|
2021-01-04 01:04:43 +00:00
|
|
|
};
|
|
|
|
|
2021-01-08 02:17:42 +00:00
|
|
|
struct DoublePoint
|
|
|
|
{
|
|
|
|
double x, y;
|
|
|
|
};
|
|
|
|
|
2021-01-04 01:04:43 +00:00
|
|
|
struct CursorState
|
|
|
|
{
|
|
|
|
/* cursor is in grab mode */
|
2021-01-08 09:49:20 +00:00
|
|
|
bool grab;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
|
|
|
/* true if we are to draw the cursor on screen */
|
2021-01-08 09:49:20 +00:00
|
|
|
bool draw;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
|
|
|
/* true if the cursor is currently in our window */
|
2021-01-08 09:49:20 +00:00
|
|
|
bool inWindow;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
|
|
|
/* true if the cursor is currently in the guest view area */
|
2021-01-08 09:49:20 +00:00
|
|
|
bool inView;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
2021-01-17 01:53:55 +00:00
|
|
|
/* true if the guest should be realigned to the host when next drawn */
|
|
|
|
bool realign;
|
|
|
|
|
2021-01-04 01:04:43 +00:00
|
|
|
/* true if the cursor needs re-drawing/updating */
|
2021-01-08 09:49:20 +00:00
|
|
|
bool redraw;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
|
|
|
/* true if the cursor movements should be scaled */
|
2021-01-08 09:49:20 +00:00
|
|
|
bool useScale;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
|
|
|
/* the amount to scale the X & Y movements by */
|
2021-01-08 09:49:20 +00:00
|
|
|
struct DoublePoint scale;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
2021-01-04 22:48:30 +00:00
|
|
|
/* the dpi scale factor from the guest as a fraction */
|
2021-01-08 02:17:42 +00:00
|
|
|
double dpiScale;
|
2021-01-04 22:48:30 +00:00
|
|
|
|
2021-01-08 09:49:20 +00:00
|
|
|
/* the error accumulator */
|
|
|
|
struct DoublePoint acc;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
2021-01-08 09:49:20 +00:00
|
|
|
/* the local position */
|
2021-01-08 02:17:42 +00:00
|
|
|
struct DoublePoint pos;
|
2021-01-06 11:11:28 +00:00
|
|
|
|
2021-01-17 04:13:45 +00:00
|
|
|
/* the button state */
|
|
|
|
unsigned int buttons;
|
|
|
|
|
2021-01-08 08:41:10 +00:00
|
|
|
/* the delta since last warp when in auto capture mode */
|
|
|
|
struct DoublePoint delta;
|
|
|
|
|
2021-01-08 02:17:42 +00:00
|
|
|
/* the scale factor for the mouse sensitiviy */
|
|
|
|
int sens;
|
2021-01-04 01:04:43 +00:00
|
|
|
|
2021-01-08 02:17:42 +00:00
|
|
|
/* the mouse warp state */
|
2021-01-04 01:04:43 +00:00
|
|
|
enum WarpState warpState;
|
|
|
|
|
|
|
|
/* the guest's cursor position */
|
|
|
|
struct CursorInfo guest;
|
|
|
|
};
|
|
|
|
|
2019-03-30 01:26:06 +00:00
|
|
|
// forwards
|
2021-01-04 01:06:54 +00:00
|
|
|
extern struct AppState g_state;
|
2020-05-22 08:15:17 +00:00
|
|
|
extern struct AppParams params;
|