mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-14 13:07:54 +00:00
[client] port all configuration parsing to use the new option helper
This commit is contained in:
parent
db0d966102
commit
e3c98ddc35
10 changed files with 555 additions and 759 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
a12-199-ga29639fceb+1
|
||||
a12-200-gdb0d966102+1
|
|
@ -41,7 +41,6 @@ find_package(PkgConfig)
|
|||
pkg_check_modules(PKGCONFIG REQUIRED
|
||||
sdl2
|
||||
x11
|
||||
libconfig
|
||||
)
|
||||
|
||||
execute_process(
|
||||
|
|
|
@ -40,28 +40,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
(x)->render && \
|
||||
(x)->update_fps)
|
||||
|
||||
#define LGR_OPTION_COUNT(x) (sizeof(x) / sizeof(LG_RendererOpt))
|
||||
|
||||
typedef bool(* LG_RendererOptValidator)(const char * value);
|
||||
typedef void(* LG_RendererOptHandler )(void * opaque, const char * value);
|
||||
|
||||
typedef struct LG_RendererOpt
|
||||
{
|
||||
const char * name;
|
||||
const char * desc;
|
||||
LG_RendererOptValidator validator;
|
||||
LG_RendererOptHandler handler;
|
||||
}
|
||||
LG_RendererOpt;
|
||||
|
||||
typedef struct LG_RendererOptValue
|
||||
{
|
||||
const LG_RendererOpt * opt;
|
||||
char * value;
|
||||
} LG_RendererOptValue;
|
||||
|
||||
typedef LG_RendererOpt * LG_RendererOptions;
|
||||
|
||||
typedef struct LG_RendererParams
|
||||
{
|
||||
// TTF_Font * font;
|
||||
|
@ -99,7 +77,12 @@ typedef enum LG_RendererCursor
|
|||
}
|
||||
LG_RendererCursor;
|
||||
|
||||
typedef const char * (* LG_RendererGetName )();
|
||||
// returns the friendly name of the renderer
|
||||
typedef const char * (* LG_RendererGetName)();
|
||||
|
||||
// called pre-creation to allow the renderer to register any options it might have
|
||||
typedef void (* LG_RendererSetup)();
|
||||
|
||||
typedef bool (* LG_RendererCreate )(void ** opaque, const LG_RendererParams params);
|
||||
typedef bool (* LG_RendererInitialize )(void * opaque, Uint32 * sdlFlags);
|
||||
typedef void (* LG_RendererDeInitialize)(void * opaque);
|
||||
|
@ -113,10 +96,10 @@ typedef void (* LG_RendererUpdateFPS )(void * opaque, const float avgU
|
|||
|
||||
typedef struct LG_Renderer
|
||||
{
|
||||
LG_RendererCreate create;
|
||||
LG_RendererGetName get_name;
|
||||
LG_RendererOptions options;
|
||||
unsigned int option_count;
|
||||
LG_RendererSetup setup;
|
||||
|
||||
LG_RendererCreate create;
|
||||
LG_RendererInitialize initialize;
|
||||
LG_RendererDeInitialize deinitialize;
|
||||
LG_RendererOnResize on_resize;
|
||||
|
@ -128,8 +111,4 @@ typedef struct LG_Renderer
|
|||
LG_RendererRender render;
|
||||
LG_RendererUpdateFPS update_fps;
|
||||
}
|
||||
LG_Renderer;
|
||||
|
||||
// generic option helpers
|
||||
bool LG_RendererValidatorBool(const char * value);
|
||||
bool LG_RendererValueToBool (const char * value);
|
||||
LG_Renderer;
|
|
@ -20,6 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
#include "interface/renderer.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/option.h"
|
||||
#include "utils.h"
|
||||
#include "dynamic/fonts.h"
|
||||
|
||||
|
@ -46,11 +47,6 @@ struct Options
|
|||
bool vsync;
|
||||
};
|
||||
|
||||
static struct Options defaultOptions =
|
||||
{
|
||||
.vsync = false
|
||||
};
|
||||
|
||||
struct Inst
|
||||
{
|
||||
LG_RendererParams params;
|
||||
|
@ -96,6 +92,18 @@ struct Inst
|
|||
};
|
||||
|
||||
|
||||
static struct Option egl_options[] =
|
||||
{
|
||||
{
|
||||
.module = "egl",
|
||||
.name = "vsync",
|
||||
.description = "Enable vsync",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = false
|
||||
},
|
||||
{0}
|
||||
};
|
||||
|
||||
void update_mouse_shape(struct Inst * this);
|
||||
|
||||
const char * egl_get_name()
|
||||
|
@ -103,6 +111,11 @@ const char * egl_get_name()
|
|||
return "EGL";
|
||||
}
|
||||
|
||||
void egl_setup()
|
||||
{
|
||||
option_register(egl_options);
|
||||
}
|
||||
|
||||
bool egl_create(void ** opaque, const LG_RendererParams params)
|
||||
{
|
||||
// create our local storage
|
||||
|
@ -116,8 +129,9 @@ bool egl_create(void ** opaque, const LG_RendererParams params)
|
|||
|
||||
// safe off parameteres and init our default option values
|
||||
struct Inst * this = (struct Inst *)*opaque;
|
||||
memcpy(&this->params, ¶ms , sizeof(LG_RendererParams));
|
||||
memcpy(&this->opt , &defaultOptions, sizeof(struct Options ));
|
||||
memcpy(&this->params, ¶ms, sizeof(LG_RendererParams));
|
||||
|
||||
this->opt.vsync = option_get_bool("egl", "vsync");
|
||||
|
||||
this->translateX = 0;
|
||||
this->translateY = 0;
|
||||
|
@ -484,31 +498,11 @@ void egl_update_fps(void * opaque, const float avgUPS, const float avgFPS)
|
|||
egl_fps_update(this->fps, avgUPS, avgFPS);
|
||||
}
|
||||
|
||||
static void handle_opt_vsync(void * opaque, const char *value)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
this->opt.vsync = LG_RendererValueToBool(value);
|
||||
}
|
||||
|
||||
static LG_RendererOpt egl_options[] =
|
||||
{
|
||||
{
|
||||
.name = "vsync",
|
||||
.desc ="Enable or disable vsync [default: enabled]",
|
||||
.validator = LG_RendererValidatorBool,
|
||||
.handler = handle_opt_vsync
|
||||
}
|
||||
};
|
||||
|
||||
struct LG_Renderer LGR_EGL =
|
||||
{
|
||||
.create = egl_create,
|
||||
.get_name = egl_get_name,
|
||||
.options = egl_options,
|
||||
.option_count = LGR_OPTION_COUNT(egl_options),
|
||||
.setup = egl_setup,
|
||||
.create = egl_create,
|
||||
.initialize = egl_initialize,
|
||||
.deinitialize = egl_deinitialize,
|
||||
.on_resize = egl_on_resize,
|
||||
|
|
|
@ -31,6 +31,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
#include <GL/glx.h>
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/option.h"
|
||||
#include "utils.h"
|
||||
#include "lg-decoders.h"
|
||||
#include "dynamic/fonts.h"
|
||||
|
@ -47,7 +48,39 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
||||
#define FADE_TIME 1000000
|
||||
|
||||
struct Options
|
||||
static struct Option opengl_options[] =
|
||||
{
|
||||
{
|
||||
.module = "opengl",
|
||||
.name = "mipmap",
|
||||
.description = "Enable mipmapping",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = true
|
||||
},
|
||||
{
|
||||
.module = "opengl",
|
||||
.name = "vsync",
|
||||
.description = "Enable vsync",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = true
|
||||
},
|
||||
{
|
||||
.module = "opengl",
|
||||
.name = "preventBuffer",
|
||||
.description = "Prevent the driver from buffering frames",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = true
|
||||
},
|
||||
{
|
||||
.module = "opengl",
|
||||
.name = "amdPinnedMem",
|
||||
.description = "Use GL_AMD_pinned_memory if it is available",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = true
|
||||
}
|
||||
};
|
||||
|
||||
struct OpenGL_Options
|
||||
{
|
||||
bool mipmap;
|
||||
bool vsync;
|
||||
|
@ -55,14 +88,6 @@ struct Options
|
|||
bool amdPinnedMem;
|
||||
};
|
||||
|
||||
static struct Options defaultOptions =
|
||||
{
|
||||
.mipmap = true,
|
||||
.vsync = true,
|
||||
.preventBuffer = true,
|
||||
.amdPinnedMem = true,
|
||||
};
|
||||
|
||||
struct Alert
|
||||
{
|
||||
bool ready;
|
||||
|
@ -76,8 +101,8 @@ struct Alert
|
|||
|
||||
struct Inst
|
||||
{
|
||||
LG_RendererParams params;
|
||||
struct Options opt;
|
||||
LG_RendererParams params;
|
||||
struct OpenGL_Options opt;
|
||||
|
||||
bool amdPinnedMemSupport;
|
||||
bool renderStarted;
|
||||
|
@ -157,6 +182,11 @@ const char * opengl_get_name()
|
|||
return "OpenGL";
|
||||
}
|
||||
|
||||
static void opengl_setup()
|
||||
{
|
||||
option_register(opengl_options);
|
||||
}
|
||||
|
||||
bool opengl_create(void ** opaque, const LG_RendererParams params)
|
||||
{
|
||||
// create our local storage
|
||||
|
@ -169,8 +199,13 @@ bool opengl_create(void ** opaque, const LG_RendererParams params)
|
|||
memset(*opaque, 0, sizeof(struct Inst));
|
||||
|
||||
struct Inst * this = (struct Inst *)*opaque;
|
||||
memcpy(&this->params, ¶ms , sizeof(LG_RendererParams));
|
||||
memcpy(&this->opt , &defaultOptions, sizeof(struct Options ));
|
||||
memcpy(&this->params, ¶ms, sizeof(LG_RendererParams));
|
||||
|
||||
this->opt.mipmap = option_get_bool("opengl", "mipmap" );
|
||||
this->opt.vsync = option_get_bool("opengl", "vsync" );
|
||||
this->opt.preventBuffer = option_get_bool("opengl", "preventBuffer");
|
||||
this->opt.amdPinnedMem = option_get_bool("opengl", "amdPinnedMem" );
|
||||
|
||||
|
||||
LG_LOCK_INIT(this->formatLock);
|
||||
LG_LOCK_INIT(this->syncLock );
|
||||
|
@ -770,76 +805,11 @@ static void render_wait(struct Inst * this)
|
|||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
static void handle_opt_mipmap(void * opaque, const char *value)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
this->opt.mipmap = LG_RendererValueToBool(value);
|
||||
}
|
||||
|
||||
static void handle_opt_vsync(void * opaque, const char *value)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
this->opt.vsync = LG_RendererValueToBool(value);
|
||||
}
|
||||
|
||||
static void handle_opt_prevent_buffer(void * opaque, const char *value)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
this->opt.preventBuffer = LG_RendererValueToBool(value);
|
||||
}
|
||||
|
||||
static void handle_opt_amd_pinned_mem(void * opaque, const char *value)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
this->opt.amdPinnedMem = LG_RendererValueToBool(value);
|
||||
}
|
||||
|
||||
|
||||
static LG_RendererOpt opengl_options[] =
|
||||
{
|
||||
{
|
||||
.name = "mipmap",
|
||||
.desc = "Enable or disable mipmapping [default: enabled]",
|
||||
.validator = LG_RendererValidatorBool,
|
||||
.handler = handle_opt_mipmap
|
||||
},
|
||||
{
|
||||
.name = "vsync",
|
||||
.desc ="Enable or disable vsync [default: enabled]",
|
||||
.validator = LG_RendererValidatorBool,
|
||||
.handler = handle_opt_vsync
|
||||
},
|
||||
{
|
||||
.name = "preventBuffer",
|
||||
.desc = "Prevent the driver from buffering frames [default: disabled]",
|
||||
.validator = LG_RendererValidatorBool,
|
||||
.handler = handle_opt_prevent_buffer
|
||||
},
|
||||
{
|
||||
.name = "amdPinnedMem",
|
||||
.desc = "Use GL_AMD_pinned_memory if it is available [default: enabled]",
|
||||
.validator = LG_RendererValidatorBool,
|
||||
.handler = handle_opt_amd_pinned_mem
|
||||
}
|
||||
};
|
||||
|
||||
const LG_Renderer LGR_OpenGL =
|
||||
{
|
||||
.get_name = opengl_get_name,
|
||||
.options = opengl_options,
|
||||
.option_count = LGR_OPTION_COUNT(opengl_options),
|
||||
.setup = opengl_setup,
|
||||
|
||||
.create = opengl_create,
|
||||
.initialize = opengl_initialize,
|
||||
.deinitialize = opengl_deinitialize,
|
||||
|
|
|
@ -23,7 +23,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
||||
void app_alert(LG_MsgAlert type, const char * fmt, ...)
|
||||
{
|
||||
if (!state.lgr || params.disableAlerts)
|
||||
if (!state.lgr || !params.showAlerts)
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
|
|
1011
client/src/config.c
1011
client/src/config.c
File diff suppressed because it is too large
Load diff
|
@ -19,5 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
void config_init();
|
||||
bool config_load(int argc, char * argv[]);
|
||||
void config_free();
|
|
@ -48,39 +48,9 @@ static int renderThread(void * unused);
|
|||
static int frameThread (void * unused);
|
||||
|
||||
struct AppState state;
|
||||
struct AppParams params =
|
||||
{
|
||||
.configFile = "/etc/looking-glass.conf",
|
||||
.autoResize = false,
|
||||
.allowResize = true,
|
||||
.keepAspect = true,
|
||||
.borderless = false,
|
||||
.fullscreen = false,
|
||||
.center = true,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.w = 1024,
|
||||
.h = 768,
|
||||
.shmFile = "/dev/shm/looking-glass",
|
||||
.shmSize = 0,
|
||||
.fpsLimit = 200,
|
||||
.showFPS = false,
|
||||
.useSpiceInput = true,
|
||||
.useSpiceClipboard = true,
|
||||
.spiceHost = "127.0.0.1",
|
||||
.spicePort = 5900,
|
||||
.clipboardToVM = true,
|
||||
.clipboardToLocal = true,
|
||||
.scaleMouseInput = true,
|
||||
.hideMouse = true,
|
||||
.ignoreQuit = false,
|
||||
.allowScreensaver = true,
|
||||
.grabKeyboard = true,
|
||||
.escapeKey = SDL_SCANCODE_SCROLLLOCK,
|
||||
.disableAlerts = false,
|
||||
.forceRenderer = false,
|
||||
.windowTitle = "Looking Glass (Client)"
|
||||
};
|
||||
|
||||
// this structure is initialized in config.c
|
||||
struct AppParams params = { 0 };
|
||||
|
||||
static void updatePositionInfo()
|
||||
{
|
||||
|
@ -888,8 +858,7 @@ static void * map_memory()
|
|||
|
||||
static bool try_renderer(const int index, const LG_RendererParams lgrParams, Uint32 * sdlFlags)
|
||||
{
|
||||
const LG_Renderer *r = LG_Renderers[index];
|
||||
RendererOpts *opts = ¶ms.rendererOpts[index];
|
||||
const LG_Renderer *r = LG_Renderers[index];
|
||||
|
||||
if (!IS_LG_RENDERER_VALID(r))
|
||||
{
|
||||
|
@ -902,10 +871,6 @@ static bool try_renderer(const int index, const LG_RendererParams lgrParams, Uin
|
|||
if (!r->create(&state.lgrData, lgrParams))
|
||||
return false;
|
||||
|
||||
// set it's options
|
||||
for(unsigned int i = 0; i < opts->argc; ++i)
|
||||
opts->argv[i].opt->handler(state.lgrData, opts->argv[i].value);
|
||||
|
||||
// initialize the renderer
|
||||
if (!r->initialize(state.lgrData, sdlFlags))
|
||||
{
|
||||
|
@ -1050,7 +1015,7 @@ int run()
|
|||
if (params.fullscreen)
|
||||
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
|
||||
|
||||
if (params.allowScreensaver)
|
||||
if (!params.noScreensaver)
|
||||
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
|
||||
|
||||
if (!params.center)
|
||||
|
@ -1219,7 +1184,7 @@ int run()
|
|||
{
|
||||
if (state.shm->flags & KVMFR_HEADER_FLAG_PAUSED)
|
||||
{
|
||||
if (state.lgr && !params.disableAlerts)
|
||||
if (state.lgr && params.showAlerts)
|
||||
state.lgr->on_alert(
|
||||
state.lgrData,
|
||||
LG_ALERT_WARNING,
|
||||
|
@ -1302,10 +1267,15 @@ int main(int argc, char * argv[])
|
|||
if (!installCrashHandler(argv[0]))
|
||||
DEBUG_WARN("Failed to install the crash handler");
|
||||
|
||||
config_init();
|
||||
|
||||
// early renderer setup for option registration
|
||||
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
|
||||
LG_Renderers[i]->setup();
|
||||
|
||||
if (!config_load(argc, argv))
|
||||
return -1;
|
||||
|
||||
|
||||
if (params.grabKeyboard)
|
||||
{
|
||||
SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
|
||||
|
|
|
@ -68,17 +68,8 @@ struct AppState
|
|||
KeybindHandle kbInput;
|
||||
};
|
||||
|
||||
typedef struct RenderOpts
|
||||
{
|
||||
unsigned int size;
|
||||
unsigned int argc;
|
||||
LG_RendererOptValue * argv;
|
||||
}
|
||||
RendererOpts;
|
||||
|
||||
struct AppParams
|
||||
{
|
||||
const char * configFile;
|
||||
bool autoResize;
|
||||
bool allowResize;
|
||||
bool keepAspect;
|
||||
|
@ -87,29 +78,28 @@ struct AppParams
|
|||
bool center;
|
||||
int x, y;
|
||||
unsigned int w, h;
|
||||
char * shmFile;
|
||||
const char * shmFile;
|
||||
unsigned int shmSize;
|
||||
unsigned int fpsLimit;
|
||||
bool showFPS;
|
||||
bool useSpiceInput;
|
||||
bool useSpiceClipboard;
|
||||
char * spiceHost;
|
||||
const char * spiceHost;
|
||||
unsigned int spicePort;
|
||||
bool clipboardToVM;
|
||||
bool clipboardToLocal;
|
||||
bool scaleMouseInput;
|
||||
bool hideMouse;
|
||||
bool ignoreQuit;
|
||||
bool allowScreensaver;
|
||||
bool noScreensaver;
|
||||
bool grabKeyboard;
|
||||
SDL_Scancode escapeKey;
|
||||
bool disableAlerts;
|
||||
bool showAlerts;
|
||||
|
||||
bool forceRenderer;
|
||||
unsigned int forceRendererIndex;
|
||||
RendererOpts rendererOpts[LG_RENDERER_COUNT];
|
||||
|
||||
char * windowTitle;
|
||||
const char * windowTitle;
|
||||
};
|
||||
|
||||
struct CBRequest
|
||||
|
|
Loading…
Reference in a new issue