From 0a899ecdc596d6c2b2838a78109faca6c5d8035f Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 1 Nov 2023 17:46:01 +0100 Subject: [PATCH] add a --leave-shift-keys, remove DONT_SHADOW_SHIFTS. refine #13 --- Makefile | 5 --- dist/config.lua | 1 + dist/x48ng.man.1 | 13 +++++--- src/runtime_options.c | 76 +++++++++++++++++++++++++------------------ src/runtime_options.h | 2 ++ src/ui_sdl.c | 8 ++--- src/ui_x11.c | 14 +++++--- 7 files changed, 69 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 09abea9..f204a0c 100644 --- a/Makefile +++ b/Makefile @@ -33,11 +33,6 @@ ifeq ($(FULL_WARNINGS), yes) CFLAGS += -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-unused-function -Wconversion -Wdouble-promotion -Wno-sign-conversion -fsanitize=undefined -fsanitize-trap endif -DONT_SHADOW_SHIFTS = no -ifeq ($(DONT_SHADOW_SHIFTS), yes) - CFLAGS += -DDONT_SHADOW_SHIFTS=1 -endif - DOTOS = src/emu_serial.o \ src/emu_emulate.o \ src/emu_init.o \ diff --git a/dist/config.lua b/dist/config.lua index 7ca2615..cdfbe5c 100644 --- a/dist/config.lua +++ b/dist/config.lua @@ -29,6 +29,7 @@ mono = false gray = false small = false tiny = false +leave_shift_keys = false x11_visual = "default" netbook = false diff --git a/dist/x48ng.man.1 b/dist/x48ng.man.1 index 4216c50..341ebb7 100644 --- a/dist/x48ng.man.1 +++ b/dist/x48ng.man.1 @@ -61,15 +61,15 @@ where options include (depending on compiled front-ends): .br \-\-config\-dir= use as x48ng's home (default: ~/.config/x48ng/) .br - \-\-rom= use (absolute or relative to ) as ROM (default: rom) + \-\-rom= use (absolute or relative to ) as ROM (default: rom) .br - \-\-ram= use (absolute or relative to ) as RAM (default: ram) + \-\-ram= use (absolute or relative to ) as RAM (default: ram) .br - \-\-state= use (absolute or relative to ) as STATE (default: hp48) + \-\-state= use (absolute or relative to ) as STATE (default: hp48) .br - \-\-port1= use (absolute or relative to ) as PORT1 (default: port1) + \-\-port1= use (absolute or relative to ) as PORT1 (default: port1) .br - \-\-port2= use (absolute or relative to ) as PORT2 (default: port2) + \-\-port2= use (absolute or relative to ) as PORT2 (default: port2) .br \-\-serial\-line= use as serial device default: /dev/ttyS0) .br @@ -114,6 +114,9 @@ where options include (depending on compiled front-ends): \-\-small make the text UI small (2×2 pixels per character) (default: false) .br \-\-tiny make the text UI tiny (2×4 pixels per character) (default: false) +.br + \-\-leave\-shift\-keys _not_ mapping the shift keys to let them free for numbers (default: false) + .SH DESCRIPTION .I x48ng diff --git a/src/runtime_options.c b/src/runtime_options.c index af3065d..0246ea6 100644 --- a/src/runtime_options.c +++ b/src/runtime_options.c @@ -37,6 +37,8 @@ char* port2FileName = NULL; int frontend_type = FRONTEND_TEXT; +bool leave_shift_keys = false; + bool mono = false; bool gray = false; @@ -244,50 +246,52 @@ int parse_args( int argc, char* argv[] ) int clopt_gray = -1; int clopt_small = -1; int clopt_tiny = -1; + int clopt_leave_shift_keys = -1; char* optstring = "c:hvVtsirT"; struct option long_options[] = { - {"config", required_argument, NULL, 'c' }, - { "config-dir", required_argument, NULL, 1000 }, - { "rom", required_argument, NULL, 1010 }, - { "ram", required_argument, NULL, 1011 }, - { "state", required_argument, NULL, 1012 }, - { "port1", required_argument, NULL, 1013 }, - { "port2", required_argument, NULL, 1014 }, + {"config", required_argument, NULL, 'c' }, + { "config-dir", required_argument, NULL, 1000 }, + { "rom", required_argument, NULL, 1010 }, + { "ram", required_argument, NULL, 1011 }, + { "state", required_argument, NULL, 1012 }, + { "port1", required_argument, NULL, 1013 }, + { "port2", required_argument, NULL, 1014 }, - { "serial-line", required_argument, NULL, 1015 }, + { "serial-line", required_argument, NULL, 1015 }, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'v' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, - { "print-config", no_argument, ( int* )&print_config, true }, - { "verbose", no_argument, &clopt_verbose, true }, - { "terminal", no_argument, &clopt_useTerminal, true }, - { "serial", no_argument, &clopt_useSerial, true }, + { "print-config", no_argument, ( int* )&print_config, true }, + { "verbose", no_argument, &clopt_verbose, true }, + { "terminal", no_argument, &clopt_useTerminal, true }, + { "serial", no_argument, &clopt_useSerial, true }, - { "reset", no_argument, ( int* )&resetOnStartup, true }, - { "throttle", no_argument, &clopt_throttle, true }, + { "reset", no_argument, ( int* )&resetOnStartup, true }, + { "throttle", no_argument, &clopt_throttle, true }, - { "debug", no_argument, &clopt_useDebugger, true }, + { "debug", no_argument, &clopt_useDebugger, true }, - { "sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL }, - { "no-chrome", no_argument, &clopt_hide_chrome, true }, - { "fullscreen", no_argument, &clopt_show_ui_fullscreen, true }, + { "sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL }, + { "no-chrome", no_argument, &clopt_hide_chrome, true }, + { "fullscreen", no_argument, &clopt_show_ui_fullscreen, true }, - { "x11", no_argument, &clopt_frontend_type, FRONTEND_X11 }, - { "netbook", no_argument, &clopt_netbook, true }, - { "visual", required_argument, NULL, 8110 }, - { "small-font", required_argument, NULL, 8111 }, - { "medium-font", required_argument, NULL, 8112 }, - { "large-font", required_argument, NULL, 8113 }, - { "connection-font", required_argument, NULL, 8114 }, + { "x11", no_argument, &clopt_frontend_type, FRONTEND_X11 }, + { "netbook", no_argument, &clopt_netbook, true }, + { "visual", required_argument, NULL, 8110 }, + { "small-font", required_argument, NULL, 8111 }, + { "medium-font", required_argument, NULL, 8112 }, + { "large-font", required_argument, NULL, 8113 }, + { "connection-font", required_argument, NULL, 8114 }, - { "tui", no_argument, &clopt_frontend_type, FRONTEND_TEXT}, + { "tui", no_argument, &clopt_frontend_type, FRONTEND_TEXT}, - { "mono", no_argument, &clopt_mono, true }, - { "gray", no_argument, &clopt_gray, true }, - { "small", no_argument, &clopt_small, true }, - { "tiny", no_argument, &clopt_tiny, true }, + { "mono", no_argument, &clopt_mono, true }, + { "gray", no_argument, &clopt_gray, true }, + { "small", no_argument, &clopt_small, true }, + { "tiny", no_argument, &clopt_tiny, true }, + { "leave-shift-keys", no_argument, &clopt_leave_shift_keys, true }, { 0, 0, 0, 0 } }; @@ -348,6 +352,8 @@ int parse_args( int argc, char* argv[] ) " --small make the text UI small (2×2 pixels per character) (default: " "false)\n" " --tiny make the text UI tiny (2×4 pixels per character) (default: " + "false)\n" + " --leave-shift-keys _not_ mapping the shift keys to let them free for numbers (default: " "false)\n"; while ( c != EOF ) { c = getopt_long( argc, argv, optstring, long_options, &option_index ); @@ -517,6 +523,9 @@ int parse_args( int argc, char* argv[] ) lua_getglobal( config_lua_values, "tiny" ); tiny = lua_toboolean( config_lua_values, -1 ); + lua_getglobal( config_lua_values, "leave_shift_keys" ); + leave_shift_keys = lua_toboolean( config_lua_values, -1 ); + lua_getglobal( config_lua_values, "x11_visual" ); x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" ); @@ -586,6 +595,8 @@ int parse_args( int argc, char* argv[] ) small = clopt_small; if ( clopt_tiny != -1 ) tiny = clopt_tiny; + if ( clopt_leave_shift_keys != -1 ) + leave_shift_keys = clopt_leave_shift_keys; /* After getting configs and params */ /* normalize config_dir again in case it's been modified */ @@ -637,6 +648,7 @@ int parse_args( int argc, char* argv[] ) fprintf( stdout, "gray = %s\n", gray ? "true" : "false" ); fprintf( stdout, "small = %s\n", small ? "true" : "false" ); fprintf( stdout, "tiny = %s\n", tiny ? "true" : "false" ); + fprintf( stdout, "leave_shift_keys = %s\n", leave_shift_keys ? "true" : "false" ); fprintf( stdout, "\n" ); fprintf( stdout, "x11_visual = \"%s\"\n", x11_visual ); fprintf( stdout, "netbook = %s\n", netbook ? "true" : "false" ); diff --git a/src/runtime_options.h b/src/runtime_options.h index 29aa1d6..0f2ca1a 100644 --- a/src/runtime_options.h +++ b/src/runtime_options.h @@ -19,6 +19,8 @@ extern int frontend_type; extern char* serialLine; +extern bool leave_shift_keys; + extern bool mono; extern bool gray; diff --git a/src/ui_sdl.c b/src/ui_sdl.c index 7cac7b3..fe0c9e7 100644 --- a/src/ui_sdl.c +++ b/src/ui_sdl.c @@ -708,14 +708,14 @@ static int SDLKeyToKey( SDLKey k ) case SDLK_ESCAPE: return HPKEY_ON; break; -#ifndef DONT_SHADOW_SHIFTS case SDLK_LSHIFT: - return HPKEY_SHL; + if ( !leave_shift_keys ) + return HPKEY_SHL; break; case SDLK_RSHIFT: - return HPKEY_SHR; + if ( !leave_shift_keys ) + return HPKEY_SHR; break; -#endif case SDLK_LCTRL: return HPKEY_SHR; break; diff --git a/src/ui_x11.c b/src/ui_x11.c index 0fb4900..fbe304d 100644 --- a/src/ui_x11.c +++ b/src/ui_x11.c @@ -2700,16 +2700,22 @@ int decode_key( XEvent* xev, KeySym sym, char* buf, int buflen ) key_event( HPKEY_ON, xev ); wake = 1; break; -#ifndef DONT_SHADOW_SHIFTS case XK_Shift_L: -#endif + if ( !leave_shift_keys ) { + key_event( HPKEY_SHL, xev ); + wake = 1; + } + break; case XK_Control_R: key_event( HPKEY_SHL, xev ); wake = 1; break; -#ifndef DONT_SHADOW_SHIFTS case XK_Shift_R: -#endif + if ( !leave_shift_keys ) { + key_event( HPKEY_SHR, xev ); + wake = 1; + } + break; case XK_Control_L: key_event( HPKEY_SHR, xev ); wake = 1;