[client] all: move all SDL specific code into displayservers/sdl

This commit is contained in:
Geoffrey McRae
2021-01-26 21:46:30 +11:00
parent 7ff5da4d62
commit ca5c3938e4
24 changed files with 569 additions and 406 deletions

View File

@@ -28,7 +28,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "kb.h"
#include "common/debug.h"
#include <stdarg.h>
#include <math.h>
#include <string.h>
void app_alert(LG_MsgAlert type, const char * fmt, ...)
{
@@ -98,9 +101,14 @@ bool app_getProp(LG_DSProperty prop, void * ret)
return g_state.ds->getProp(prop, ret);
}
SDL_Window * app_getWindow(void)
EGLNativeWindowType app_getEGLNativeWindow(void)
{
return g_state.window;
return g_state.ds->getEGLNativeWindow();
}
EGLDisplay app_getEGLDisplay(void)
{
return g_state.ds->getEGLDisplay();
}
bool app_inputEnabled(void)
@@ -280,7 +288,7 @@ void app_handleButtonPress(int button)
g_cursor.buttons |= (1U << button);
if (!spice_mouse_press(button))
DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message");
DEBUG_ERROR("app_handleButtonPress: failed to send message");
}
void app_handleButtonRelease(int button)
@@ -291,7 +299,7 @@ void app_handleButtonRelease(int button)
g_cursor.buttons &= ~(1U << button);
if (!spice_mouse_release(button))
DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message");
DEBUG_ERROR("app_handleButtonRelease: failed to send message");
}
void app_handleKeyPress(int sc)
@@ -325,7 +333,7 @@ void app_handleKeyPress(int sc)
g_state.keyDown[sc] = true;
else
{
DEBUG_ERROR("SDL_KEYDOWN: failed to send message");
DEBUG_ERROR("app_handleKeyPress: failed to send message");
return;
}
}
@@ -372,7 +380,7 @@ void app_handleKeyRelease(int sc)
g_state.keyDown[sc] = false;
else
{
DEBUG_ERROR("SDL_KEYUP: failed to send message");
DEBUG_ERROR("app_handleKeyRelease: failed to send message");
return;
}
}
@@ -613,3 +621,13 @@ void app_handleCloseEvent(void)
if (!g_params.ignoreQuit || !g_cursor.inView)
g_state.state = APP_STATE_SHUTDOWN;
}
void app_setFullscreen(bool fs)
{
g_state.ds->setFullscreen(fs);
}
void app_glSwapBuffers(void)
{
g_state.ds->glSwapBuffers();
}

View File

@@ -19,6 +19,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "main.h"
#include "config.h"
#include "kb.h"
#include "common/option.h"
#include "common/debug.h"
#include "common/stringutils.h"
@@ -26,10 +28,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
//FIXME: this should really not be included here and is an ugly hack to retain
//backwards compatibility with the escape key scancode
extern uint32_t sdl_to_xfree86[];
#include <string.h>
// forwards
static bool optRendererParse (struct Option * opt, const char * str);
@@ -41,6 +40,7 @@ static char * optPosToString (struct Option * opt);
static bool optSizeParse (struct Option * opt, const char * str);
static StringList optSizeValues (struct Option * opt);
static char * optSizeToString (struct Option * opt);
static bool optScancodeValidate(struct Option * opt, const char ** error);
static char * optScancodeToString(struct Option * opt);
static bool optRotateValidate (struct Option * opt, const char ** error);
@@ -267,11 +267,12 @@ static struct Option options[] =
{
.module = "input",
.name = "escapeKey",
.description = "Specify the escape key, see https://wiki.libsdl.org/SDLScancodeLookup for valid values",
.description = "Specify the escape key, see <linux/input-event-codes.h> for valid values",
.shortopt = 'm',
.type = OPTION_TYPE_INT,
.value.x_int = SDL_SCANCODE_SCROLLLOCK,
.toString = optScancodeToString
.value.x_int = KEY_SCROLLLOCK,
.validator = optScancodeValidate,
.toString = optScancodeToString,
},
{
.module = "input",
@@ -532,9 +533,6 @@ bool config_load(int argc, char * argv[])
g_params.alwaysShowCursor = option_get_bool("spice", "alwaysShowCursor");
}
//FIXME, this should be using linux keycodes
g_params.escapeKey = sdl_to_xfree86[g_params.escapeKey];
return true;
}
@@ -682,11 +680,20 @@ static char * optSizeToString(struct Option * opt)
return str;
}
static bool optScancodeValidate(struct Option * opt, const char ** error)
{
if (opt->value.x_int >= 0 && opt->value.x_int < KEY_MAX)
return true;
*error = "Out of range";
return false;
}
static char * optScancodeToString(struct Option * opt)
{
char * str;
alloc_sprintf(&str, "%d = %s", opt->value.x_int,
SDL_GetScancodeName(opt->value.x_int));
xfree86_to_str[opt->value.x_int]);
return str;
}

View File

@@ -26,6 +26,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "common/debug.h"
#include <assert.h>
#include <math.h>
#define RESIZE_TIMEOUT (10 * 1000) // 10ms

36
client/src/egl_dynprocs.c Normal file
View File

@@ -0,0 +1,36 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2021 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
*/
#ifdef ENABLE_EGL
#include "egl_dynprocs.h"
struct EGLDynProcs g_egl_dynProcs = {0};
void egl_dynProcsInit(void)
{
g_egl_dynProcs.eglGetPlatformDisplay = (eglGetPlatformDisplayEXT_t)
eglGetProcAddress("eglGetPlatformDisplay");
g_egl_dynProcs.eglGetPlatformDisplayEXT = (eglGetPlatformDisplayEXT_t)
eglGetProcAddress("eglGetPlatformDisplayEXT");
g_egl_dynProcs.glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_t)
eglGetProcAddress("glEGLImageTargetTexture2DOES");
};
#endif

View File

@@ -145,4 +145,127 @@ const uint32_t xfree86_to_ps2[KEY_MAX] =
[KEY_PRINT] /* = USB 70 */ = 0x00E037,
};
const char * xfree86_to_str[KEY_MAX] =
{
[KEY_RESERVED] = "KEY_RESERVED",
[KEY_ESC] = "KEY_ESC",
[KEY_1] = "KEY_1",
[KEY_2] = "KEY_2",
[KEY_3] = "KEY_3",
[KEY_4] = "KEY_4",
[KEY_5] = "KEY_5",
[KEY_6] = "KEY_6",
[KEY_7] = "KEY_7",
[KEY_8] = "KEY_8",
[KEY_9] = "KEY_9",
[KEY_0] = "KEY_0",
[KEY_MINUS] = "KEY_MINUS",
[KEY_EQUAL] = "KEY_EQUAL",
[KEY_BACKSPACE] = "KEY_BACKSPACE",
[KEY_TAB] = "KEY_TAB",
[KEY_Q] = "KEY_Q",
[KEY_W] = "KEY_W",
[KEY_E] = "KEY_E",
[KEY_R] = "KEY_R",
[KEY_T] = "KEY_T",
[KEY_Y] = "KEY_Y",
[KEY_U] = "KEY_U",
[KEY_I] = "KEY_I",
[KEY_O] = "KEY_O",
[KEY_P] = "KEY_P",
[KEY_LEFTBRACE] = "KEY_LEFTBRACE",
[KEY_RIGHTBRACE] = "KEY_RIGHTBRACE",
[KEY_ENTER] = "KEY_ENTER",
[KEY_LEFTCTRL] = "KEY_LEFTCTRL",
[KEY_A] = "KEY_A",
[KEY_S] = "KEY_S",
[KEY_D] = "KEY_D",
[KEY_F] = "KEY_F",
[KEY_G] = "KEY_G",
[KEY_H] = "KEY_H",
[KEY_J] = "KEY_J",
[KEY_K] = "KEY_K",
[KEY_L] = "KEY_L",
[KEY_SEMICOLON] = "KEY_SEMICOLON",
[KEY_APOSTROPHE] = "KEY_APOSTROPHE",
[KEY_GRAVE] = "KEY_GRAVE",
[KEY_LEFTSHIFT] = "KEY_LEFTSHIFT",
[KEY_BACKSLASH] = "KEY_BACKSLASH",
[KEY_Z] = "KEY_Z",
[KEY_X] = "KEY_X",
[KEY_C] = "KEY_C",
[KEY_V] = "KEY_V",
[KEY_B] = "KEY_B",
[KEY_N] = "KEY_N",
[KEY_M] = "KEY_M",
[KEY_COMMA] = "KEY_COMMA",
[KEY_DOT] = "KEY_DOT",
[KEY_SLASH] = "KEY_SLASH",
[KEY_RIGHTSHIFT] = "KEY_RIGHTSHIFT",
[KEY_KPASTERISK] = "KEY_KPASTERISK",
[KEY_LEFTALT] = "KEY_LEFTALT",
[KEY_SPACE] = "KEY_SPACE",
[KEY_CAPSLOCK] = "KEY_CAPSLOCK",
[KEY_F1] = "KEY_F1",
[KEY_F2] = "KEY_F2",
[KEY_F3] = "KEY_F3",
[KEY_F4] = "KEY_F4",
[KEY_F5] = "KEY_F5",
[KEY_F6] = "KEY_F6",
[KEY_F7] = "KEY_F7",
[KEY_F8] = "KEY_F8",
[KEY_F9] = "KEY_F9",
[KEY_F10] = "KEY_F10",
[KEY_NUMLOCK] = "KEY_NUMLOCK",
[KEY_SCROLLLOCK] = "KEY_SCROLLLOCK",
[KEY_KP7] = "KEY_KP7",
[KEY_KP8] = "KEY_KP8",
[KEY_KP9] = "KEY_KP9",
[KEY_KPMINUS] = "KEY_KPMINUS",
[KEY_KP4] = "KEY_KP4",
[KEY_KP5] = "KEY_KP5",
[KEY_KP6] = "KEY_KP6",
[KEY_KPPLUS] = "KEY_KPPLUS",
[KEY_KP1] = "KEY_KP1",
[KEY_KP2] = "KEY_KP2",
[KEY_KP3] = "KEY_KP3",
[KEY_KP0] = "KEY_KP0",
[KEY_KPDOT] = "KEY_KPDOT",
[KEY_102ND] = "KEY_102ND",
[KEY_F11] = "KEY_F11",
[KEY_F12] = "KEY_F12",
[KEY_RO] = "KEY_RO",
[KEY_HENKAN] = "KEY_HENKAN",
[KEY_KATAKANAHIRAGANA] = "KEY_KATAKANAHIRAGANA",
[KEY_MUHENKAN] = "KEY_MUHENKAN",
[KEY_KPENTER] = "KEY_KPENTER",
[KEY_RIGHTCTRL] = "KEY_RIGHTCTRL",
[KEY_KPSLASH] = "KEY_KPSLASH",
[KEY_SYSRQ] = "KEY_SYSRQ",
[KEY_RIGHTALT] = "KEY_RIGHTALT",
[KEY_HOME] = "KEY_HOME",
[KEY_UP] = "KEY_UP",
[KEY_PAGEUP] = "KEY_PAGEUP",
[KEY_LEFT] = "KEY_LEFT",
[KEY_RIGHT] = "KEY_RIGHT",
[KEY_END] = "KEY_END",
[KEY_DOWN] = "KEY_DOWN",
[KEY_PAGEDOWN] = "KEY_PAGEDOWN",
[KEY_INSERT] = "KEY_INSERT",
[KEY_DELETE] = "KEY_DELETE",
[KEY_KPEQUAL] = "KEY_KPEQUAL",
[KEY_PAUSE] = "KEY_PAUSE",
[KEY_KPCOMMA] = "KEY_KPCOMMA",
[KEY_HANGEUL] = "KEY_HANGEUL",
[KEY_HANJA] = "KEY_HANJA",
[KEY_YEN] = "KEY_YEN",
[KEY_LEFTMETA] = "KEY_LEFTMETA",
[KEY_RIGHTMETA] = "KEY_RIGHTMETA",
[KEY_COMPOSE] = "KEY_COMPOSE",
[KEY_F13] = "KEY_F13",
[KEY_F14] = "KEY_F14",
[KEY_F15] = "KEY_F15",
[KEY_PRINT] = "KEY_PRINT",
};
#endif

View File

@@ -21,3 +21,4 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdint.h>
extern const uint32_t xfree86_to_ps2[KEY_MAX];
extern const char * xfree86_to_str[KEY_MAX];

View File

@@ -26,10 +26,12 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "spice/spice.h"
#include <stdio.h>
static void bind_fullscreen(int sc, void * opaque)
{
SDL_SetWindowFullscreen(g_state.window, g_params.fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
g_params.fullscreen = !g_params.fullscreen;
app_setFullscreen(g_params.fullscreen);
}
static void bind_video(int sc, void * opaque)

View File

@@ -22,7 +22,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <getopt.h>
#include <signal.h>
#include <SDL2/SDL_syswm.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
@@ -53,6 +52,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "keybind.h"
#include "clipboard.h"
#include "ll.h"
#include "egl_dynprocs.h"
// forwards
static int cursorThread(void * unused);
@@ -63,7 +63,6 @@ static LGEvent *e_frame = NULL;
static LGThread *t_spice = NULL;
static LGThread *t_render = NULL;
static LGThread *t_cursor = NULL;
static SDL_Cursor *cursor = NULL;
struct AppState g_state;
struct CursorState g_cursor;
@@ -89,14 +88,14 @@ static void lgInit(void)
// if spice is not in use, hide the local cursor
if (!app_inputEnabled() && g_params.hideMouse)
SDL_ShowCursor(SDL_DISABLE);
g_state.ds->showPointer(false);
else
SDL_ShowCursor(SDL_ENABLE);
g_state.ds->showPointer(true);
}
static int renderThread(void * unused)
{
if (!g_state.lgr->render_startup(g_state.lgrData, g_state.window))
if (!g_state.lgr->render_startup(g_state.lgrData))
{
g_state.state = APP_STATE_SHUTDOWN;
@@ -129,7 +128,7 @@ static int renderThread(void * unused)
atomic_compare_exchange_weak(&g_state.lgrResize, &resize, 0);
}
if (!g_state.lgr->render(g_state.lgrData, g_state.window, g_params.winRotate))
if (!g_state.lgr->render(g_state.lgrData, g_params.winRotate))
break;
if (g_params.showFPS)
@@ -158,8 +157,7 @@ static int renderThread(void * unused)
if (!g_state.resizeDone && g_state.resizeTimeout < microtime())
{
SDL_SetWindowSize(
g_state.window,
g_state.ds->setWindowSize(
g_state.dstRect.w,
g_state.dstRect.h
);
@@ -347,7 +345,6 @@ int main_frameThread(void * unused)
if (useDMA)
DEBUG_INFO("Using DMA buffer support");
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
lgWaitEvent(e_startup, TIMEOUT_INFINITE);
if (g_state.state != APP_STATE_RUNNING)
return 0;
@@ -404,7 +401,7 @@ int main_frameThread(void * unused)
break;
}
KVMFRFrame * frame = (KVMFRFrame *)msg.mem;
KVMFRFrame * frame = (KVMFRFrame *)msg.mem;
struct DMAFrameInfo *dma = NULL;
if (!g_state.formatValid || frame->formatVer != formatVer)
@@ -473,7 +470,7 @@ int main_frameThread(void * unused)
g_state.srcSize.y = lgrFormat.height;
g_state.haveSrcSize = true;
if (g_params.autoResize)
SDL_SetWindowSize(g_state.window, lgrFormat.width, lgrFormat.height);
g_state.ds->setWindowSize(lgrFormat.width, lgrFormat.height);
g_cursor.guest.dpiScale = frame->mouseScalePercent;
core_updatePositionInfo();
@@ -572,20 +569,6 @@ int spiceThread(void * arg)
return 0;
}
int eventFilter(void * userdata, SDL_Event * event)
{
if (g_state.ds->eventFilter(event))
return 0;
// always include the default handler (SDL) for any unhandled events
if (g_state.ds != LG_DisplayServers[0])
if (LG_DisplayServers[0]->eventFilter(event))
return 0;
// consume all events
return 0;
}
void intHandler(int sig)
{
switch(sig)
@@ -607,7 +590,7 @@ void intHandler(int sig)
}
}
static bool tryRenderer(const int index, const LG_RendererParams lgrParams, Uint32 * sdlFlags)
static bool tryRenderer(const int index, const LG_RendererParams lgrParams)
{
const LG_Renderer *r = LG_Renderers[index];
@@ -623,7 +606,7 @@ static bool tryRenderer(const int index, const LG_RendererParams lgrParams, Uint
return false;
// initialize the renderer
if (!r->initialize(g_state.lgrData, sdlFlags))
if (!r->initialize(g_state.lgrData))
{
r->deinitialize(g_state.lgrData);
return false;
@@ -633,14 +616,6 @@ static bool tryRenderer(const int index, const LG_RendererParams lgrParams, Uint
return true;
}
static void initSDLCursor(void)
{
const uint8_t data[4] = {0xf, 0x9, 0x9, 0xf};
const uint8_t mask[4] = {0xf, 0xf, 0xf, 0xf};
cursor = SDL_CreateCursor(data, mask, 8, 4, 4, 0);
SDL_SetCursor(cursor);
}
static int lg_run(void)
{
memset(&g_state, 0, sizeof(g_state));
@@ -649,16 +624,9 @@ static int lg_run(void)
if (g_cursor.sens < -9) g_cursor.sens = -9;
else if (g_cursor.sens > 9) g_cursor.sens = 9;
// try to early detect the platform
SDL_SYSWM_TYPE subsystem = SDL_SYSWM_UNKNOWN;
if (getenv("WAYLAND_DISPLAY")) subsystem = SDL_SYSWM_WAYLAND;
else if (getenv("DISPLAY" )) subsystem = SDL_SYSWM_X11;
else
DEBUG_WARN("Unknown subsystem, falling back to SDL default");
// search for the best displayserver ops to use
for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i)
if (LG_DisplayServers[i]->subsystem == subsystem)
if (LG_DisplayServers[i]->probe())
{
g_state.ds = LG_DisplayServers[i];
break;
@@ -666,30 +634,6 @@ static int lg_run(void)
assert(g_state.ds);
// set any null methods to the fallback
#define SET_FALLBACK(x) \
if (!g_state.ds->x) g_state.ds->x = LG_DisplayServers[0]->x;
SET_FALLBACK(earlyInit);
SET_FALLBACK(getProp);
SET_FALLBACK(init);
SET_FALLBACK(startup);
SET_FALLBACK(shutdown);
SET_FALLBACK(free);
SET_FALLBACK(eventFilter);
SET_FALLBACK(showPointer);
SET_FALLBACK(grabPointer);
SET_FALLBACK(ungrabKeyboard);
SET_FALLBACK(warpPointer);
SET_FALLBACK(realignPointer);
SET_FALLBACK(isValidPointerPos);
SET_FALLBACK(inhibitIdle);
SET_FALLBACK(uninhibitIdle);
SET_FALLBACK(cbInit);
SET_FALLBACK(cbNotice);
SET_FALLBACK(cbRelease);
SET_FALLBACK(cbRequest);
#undef SET_FALLBACK
// init the subsystem
if (!g_state.ds->earlyInit())
{
@@ -697,16 +641,7 @@ static int lg_run(void)
return -1;
}
// Allow screensavers for now: we will enable and disable as needed.
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
DEBUG_ERROR("SDL_Init Failed");
return -1;
}
// override SDL's SIGINIT handler so that we can tell the difference between
// override the SIGINIT handler so that we can tell the difference between
// SIGINT and the user sending a close event, such as ALT+F4
signal(SIGINT , intHandler);
signal(SIGTERM, intHandler);
@@ -753,13 +688,11 @@ static int lg_run(void)
LG_RendererParams lgrParams;
lgrParams.showFPS = g_params.showFPS;
lgrParams.quickSplash = g_params.quickSplash;
Uint32 sdlFlags;
if (g_params.forceRenderer)
{
DEBUG_INFO("Trying forced renderer");
sdlFlags = 0;
if (!tryRenderer(g_params.forceRendererIndex, lgrParams, &sdlFlags))
if (!tryRenderer(g_params.forceRendererIndex, lgrParams))
{
DEBUG_ERROR("Forced renderer failed to iniailize");
return -1;
@@ -771,8 +704,7 @@ static int lg_run(void)
// probe for a a suitable renderer
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
{
sdlFlags = 0;
if (tryRenderer(i, lgrParams, &sdlFlags))
if (tryRenderer(i, lgrParams))
{
g_state.lgr = LG_Renderers[i];
break;
@@ -786,59 +718,26 @@ static int lg_run(void)
return -1;
}
// all our ducks are in a line, create the window
g_state.window = SDL_CreateWindow(
g_params.windowTitle,
g_params.center ? SDL_WINDOWPOS_CENTERED : g_params.x,
g_params.center ? SDL_WINDOWPOS_CENTERED : g_params.y,
g_params.w,
g_params.h,
(
SDL_WINDOW_HIDDEN |
(g_params.allowResize ? SDL_WINDOW_RESIZABLE : 0) |
(g_params.borderless ? SDL_WINDOW_BORDERLESS : 0) |
(g_params.maximize ? SDL_WINDOW_MAXIMIZED : 0) |
sdlFlags
)
);
if (g_state.window == NULL)
const LG_DSInitParams params =
{
DEBUG_ERROR("Could not create an SDL window: %s\n", SDL_GetError());
return 1;
}
.title = g_params.windowTitle,
.x = g_params.x,
.y = g_params.y,
.w = g_params.w,
.h = g_params.h,
.center = g_params.center,
.fullscreen = g_params.fullscreen,
.resizable = g_params.allowResize,
.borderless = g_params.borderless,
.maximize = g_params.maximize,
.minimizeOnFocusLoss = g_params.minimizeOnFocusLoss
};
SDL_VERSION(&g_state.wminfo.version);
if (!SDL_GetWindowWMInfo(g_state.window, &g_state.wminfo))
{
DEBUG_ERROR("Could not get SDL window information %s", SDL_GetError());
return -1;
}
// enable WM events
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
g_state.ds->init(&g_state.wminfo);
// now init has been done we can show the window, doing this before init for
// X11 causes us to miss the first focus event
SDL_ShowWindow(g_state.window);
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
g_params.minimizeOnFocusLoss ? "1" : "0");
if (g_params.fullscreen)
SDL_SetWindowFullscreen(g_state.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
if (!g_params.center)
SDL_SetWindowPosition(g_state.window, g_params.x, g_params.y);
g_state.ds->init(params);
if (g_params.noScreensaver)
g_state.ds->inhibitIdle();
// ensure the initial window size is stored in the state
SDL_GetWindowSize(g_state.window, &g_state.windowW, &g_state.windowH);
// ensure renderer viewport is aware of the current window size
core_updatePositionInfo();
@@ -855,8 +754,6 @@ static int lg_run(void)
keybind_register();
initSDLCursor();
// setup the startup condition
if (!(e_startup = lgCreateEvent(false, 0)))
{
@@ -880,10 +777,6 @@ static int lg_run(void)
return -1;
}
// ensure mouse acceleration is identical in server mode
SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
SDL_SetEventFilter(eventFilter, NULL);
// wait for startup to complete so that any error messages below are output at
// the end of the output
lgWaitEvent(e_startup, TIMEOUT_INFINITE);
@@ -906,7 +799,7 @@ static int lg_run(void)
/* this short timeout is to allow the LGMP host to update the timestamp before
* we start checking for a valid session */
SDL_WaitEventTimeout(NULL, 200);
g_state.ds->wait(200);
if (g_params.captureOnStart)
core_setGrab(true);
@@ -942,7 +835,7 @@ restart:
DEBUG_INFO("Continuing to wait...");
}
SDL_WaitEventTimeout(NULL, 1000);
g_state.ds->wait(1000);
}
if (g_state.state != APP_STATE_RUNNING)
@@ -975,7 +868,7 @@ restart:
{
DEBUG_INFO("Waiting for you to upgrade the host application");
while (g_state.state == APP_STATE_RUNNING && udata->version != KVMFR_VERSION)
SDL_WaitEventTimeout(NULL, 1000);
g_state.ds->wait(1000);
if (g_state.state != APP_STATE_RUNNING)
return -1;
@@ -1005,7 +898,7 @@ restart:
g_state.state = APP_STATE_RESTART;
break;
}
SDL_WaitEventTimeout(NULL, 100);
g_state.ds->wait(100);
}
if (g_state.state == APP_STATE_RESTART)
@@ -1077,21 +970,9 @@ static void lg_shutdown(void)
g_state.cbRequestList = NULL;
}
if (g_state.window)
{
g_state.ds->free();
SDL_DestroyWindow(g_state.window);
}
if (cursor)
SDL_FreeCursor(cursor);
ivshmemClose(&g_state.shm);
// this must run last to ensure that we don't free any pointers still in use
app_releaseAllKeybinds();
SDL_Quit();
g_state.ds->free();
ivshmemClose(&g_state.shm);
}
int main(int argc, char * argv[])
@@ -1110,6 +991,7 @@ int main(int argc, char * argv[])
config_init();
ivshmemOptionsInit();
egl_dynProcsInit();
// early renderer setup for option registration
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)

View File

@@ -19,7 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdbool.h>
#include <stdatomic.h>
#include <SDL2/SDL.h>
#include <linux/input.h>
#include "dynamic/displayservers.h"
@@ -48,18 +47,18 @@ struct AppState
bool stopVideo;
bool ignoreInput;
bool escapeActive;
SDL_Scancode escapeAction;
int escapeAction;
KeybindHandle bindings[KEY_MAX];
bool keyDown[KEY_MAX];
bool haveSrcSize;
SDL_Point windowPos;
struct Point windowPos;
int windowW, windowH;
int windowCX, windowCY;
LG_RendererRotate rotate;
bool focused;
struct Border border;
SDL_Point srcSize;
struct Point srcSize;
LG_RendererRect dstRect;
bool posInfoValid;
bool alignToGuest;
@@ -74,9 +73,6 @@ struct AppState
size_t cbXfer;
struct ll * cbRequestList;
SDL_SysWMinfo wminfo;
SDL_Window * window;
struct IVSHMEM shm;
PLGMPClient lgmp;
PLGMPClientQueue frameQueue;
@@ -124,7 +120,7 @@ struct AppParams
bool noScreensaver;
bool grabKeyboard;
bool grabKeyboardOnFocus;
SDL_Scancode escapeKey;
int escapeKey;
bool ignoreWindowsKeys;
bool showAlerts;
bool captureOnStart;

View File

@@ -25,6 +25,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
bool util_fileGetContents(const char * filename, char ** buffer, size_t * length)
{