mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +00:00
[client] main: add options to control spice features
This commit is contained in:
parent
41f4166aed
commit
5de25f2b43
@ -103,9 +103,12 @@ struct AppParams
|
||||
unsigned int shmSize;
|
||||
unsigned int fpsLimit;
|
||||
bool showFPS;
|
||||
bool useSpice;
|
||||
bool useSpiceInput;
|
||||
bool useSpiceClipboard;
|
||||
char * spiceHost;
|
||||
unsigned int spicePort;
|
||||
bool clipboardToVM;
|
||||
bool clipboardToLocal;
|
||||
bool scaleMouseInput;
|
||||
bool hideMouse;
|
||||
bool ignoreQuit;
|
||||
@ -137,9 +140,12 @@ struct AppParams params =
|
||||
.shmSize = 0,
|
||||
.fpsLimit = 200,
|
||||
.showFPS = false,
|
||||
.useSpice = true,
|
||||
.useSpiceInput = true,
|
||||
.useSpiceClipboard = true,
|
||||
.spiceHost = "127.0.0.1",
|
||||
.spicePort = 5900,
|
||||
.clipboardToVM = true,
|
||||
.clipboardToLocal = true,
|
||||
.scaleMouseInput = true,
|
||||
.hideMouse = true,
|
||||
.ignoreQuit = false,
|
||||
@ -531,11 +537,17 @@ static SpiceDataType clipboard_type_to_spice_type(const LG_ClipboardData type)
|
||||
|
||||
void clipboardRelease()
|
||||
{
|
||||
if (!params.clipboardToVM)
|
||||
return;
|
||||
|
||||
spice_clipboard_release();
|
||||
}
|
||||
|
||||
void clipboardNotify(const LG_ClipboardData type)
|
||||
{
|
||||
if (!params.clipboardToVM)
|
||||
return;
|
||||
|
||||
if (type == LG_CLIPBOARD_DATA_NONE)
|
||||
{
|
||||
spice_clipboard_release();
|
||||
@ -547,6 +559,9 @@ void clipboardNotify(const LG_ClipboardData type)
|
||||
|
||||
void clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size)
|
||||
{
|
||||
if (!params.clipboardToVM)
|
||||
return;
|
||||
|
||||
uint8_t * buffer = data;
|
||||
|
||||
// unix2dos
|
||||
@ -577,6 +592,9 @@ void clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size)
|
||||
|
||||
void clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque)
|
||||
{
|
||||
if (!params.clipboardToLocal)
|
||||
return;
|
||||
|
||||
struct CBRequest * cbr = (struct CBRequest *)malloc(sizeof(struct CBRequest()));
|
||||
|
||||
cbr->type = state.cbType;
|
||||
@ -589,6 +607,9 @@ void clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque)
|
||||
|
||||
void spiceClipboardNotice(const SpiceDataType type)
|
||||
{
|
||||
if (!params.clipboardToLocal)
|
||||
return;
|
||||
|
||||
if (!state.lgc || !state.lgc->notice)
|
||||
return;
|
||||
|
||||
@ -598,6 +619,9 @@ void spiceClipboardNotice(const SpiceDataType type)
|
||||
|
||||
void spiceClipboardData(const SpiceDataType type, uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
if (!params.clipboardToLocal)
|
||||
return;
|
||||
|
||||
if (type == SPICE_DATA_TEXT)
|
||||
{
|
||||
// dos2unix
|
||||
@ -626,12 +650,18 @@ void spiceClipboardData(const SpiceDataType type, uint8_t * buffer, uint32_t siz
|
||||
|
||||
void spiceClipboardRelease()
|
||||
{
|
||||
if (!params.clipboardToLocal)
|
||||
return;
|
||||
|
||||
if (state.lgc && state.lgc->release)
|
||||
state.lgc->release();
|
||||
}
|
||||
|
||||
void spiceClipboardRequest(const SpiceDataType type)
|
||||
{
|
||||
if (!params.clipboardToVM)
|
||||
return;
|
||||
|
||||
if (state.lgc && state.lgc->request)
|
||||
state.lgc->request(spice_type_to_clipboard_type(type));
|
||||
}
|
||||
@ -666,20 +696,20 @@ int eventFilter(void * userdata, SDL_Event * event)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
case SDL_SYSWMEVENT:
|
||||
{
|
||||
if (params.useSpiceClipboard && state.lgc && state.lgc->wmevent)
|
||||
state.lgc->wmevent(event->syswm.msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!params.useSpice)
|
||||
if (!params.useSpiceInput)
|
||||
return 0;
|
||||
|
||||
switch(event->type)
|
||||
{
|
||||
case SDL_SYSWMEVENT:
|
||||
{
|
||||
if (state.lgc && state.lgc->wmevent)
|
||||
state.lgc->wmevent(event->syswm.msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
if (
|
||||
@ -1120,13 +1150,14 @@ int run()
|
||||
break;
|
||||
}
|
||||
|
||||
if (params.useSpice)
|
||||
if (params.useSpiceInput || params.useSpiceClipboard)
|
||||
{
|
||||
spice_set_clipboard_cb(
|
||||
spiceClipboardNotice,
|
||||
spiceClipboardData,
|
||||
spiceClipboardRelease,
|
||||
spiceClipboardRequest);
|
||||
|
||||
if (!spice_connect(params.spiceHost, params.spicePort, ""))
|
||||
{
|
||||
DEBUG_ERROR("Failed to connect to spice server");
|
||||
@ -1236,7 +1267,7 @@ int run()
|
||||
SDL_WaitThread(t_main, NULL);
|
||||
|
||||
// if spice is still connected send key up events for any pressed keys
|
||||
if (params.useSpice && spice_ready())
|
||||
if (params.useSpiceInput && spice_ready())
|
||||
{
|
||||
for(int i = 0; i < SDL_NUM_SCANCODES; ++i)
|
||||
if (state.keyDown[i])
|
||||
@ -1300,7 +1331,14 @@ void doHelp(char * app)
|
||||
" -f PATH Specify the path to the shared memory file [current: %s]\n"
|
||||
" -L SIZE Specify the size in MB of the shared memory file (0 = detect) [current: %d]\n"
|
||||
"\n"
|
||||
" -s Disable spice client\n"
|
||||
" -s FEATURE Disable spice feature (specify multiple times for each feature)\n"
|
||||
"\n"
|
||||
" ALL Disable the spice client entirely\n"
|
||||
" INPUT Disable spice keyboard & mouse input\n"
|
||||
" CIPBOARD Disable spice clipboard support\n"
|
||||
" CLIPBOARD_TO_VM Disable local clipboard to VM sync\n"
|
||||
" CLIPBOARD_TO_LOCAL Disable VM clipboard to local sync\n"
|
||||
"\n"
|
||||
" -c HOST Specify the spice host or UNIX socket [current: %s]\n"
|
||||
" -p PORT Specify the spice port or 0 for UNIX socket [current: %d]\n"
|
||||
" -j Disable cursor position scaling\n"
|
||||
@ -1483,8 +1521,17 @@ static bool load_config(const char * configFile)
|
||||
config_setting_t * spice = config_lookup(&cfg, "spice");
|
||||
if (spice)
|
||||
{
|
||||
if (config_setting_lookup_bool(spice, "use", &itmp))
|
||||
params.useSpice = (itmp != 0);
|
||||
if (config_setting_lookup_bool(spice, "useInput", &itmp))
|
||||
params.useSpiceInput = (itmp != 0);
|
||||
|
||||
if (config_setting_lookup_bool(spice, "useClipboard", &itmp))
|
||||
params.useSpiceClipboard = (itmp != 0);
|
||||
|
||||
if (config_setting_lookup_bool(spice, "clipboardToVM", &itmp))
|
||||
params.clipboardToVM = (itmp != 0);
|
||||
|
||||
if (config_setting_lookup_bool(spice, "clipboardToLocal", &itmp))
|
||||
params.clipboardToLocal = (itmp != 0);
|
||||
|
||||
if (config_setting_lookup_string(spice, "host", &stmp))
|
||||
{
|
||||
@ -1571,7 +1618,7 @@ int main(int argc, char * argv[])
|
||||
|
||||
for(;;)
|
||||
{
|
||||
switch(getopt(argc, argv, "hC:f:L:sc:p:jMvK:kg:o:anrdFx:y:w:b:QSGm:lq"))
|
||||
switch(getopt(argc, argv, "hC:f:L:s:c:p:jMvK:kg:o:anrdFx:y:w:b:QSGm:lq"))
|
||||
{
|
||||
case '?':
|
||||
case 'h':
|
||||
@ -1598,8 +1645,24 @@ int main(int argc, char * argv[])
|
||||
continue;
|
||||
|
||||
case 's':
|
||||
params.useSpice = false;
|
||||
{
|
||||
if (strcasecmp("ALL", optarg) == 0)
|
||||
{
|
||||
params.useSpiceInput = false;
|
||||
params.useSpiceClipboard = false;
|
||||
}
|
||||
else if (strcasecmp("INPUT" , optarg) == 0) params.useSpiceInput = false;
|
||||
else if (strcasecmp("CLIPBOARD" , optarg) == 0) params.useSpiceClipboard = false;
|
||||
else if (strcasecmp("CLIPBOARD_TO_VM" , optarg) == 0) params.clipboardToVM = false;
|
||||
else if (strcasecmp("CLIPBOARD_TO_LOCAL", optarg) == 0) params.clipboardToLocal = false;
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid spice option %s\n", optarg);
|
||||
doHelp(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'c':
|
||||
free(params.spiceHost);
|
||||
|
Loading…
Reference in New Issue
Block a user