From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1.protonmail.ch (mail1.protonmail.ch [185.70.40.18]) by mx.groups.io with SMTP id smtpd.web09.19984.1581329901847276195 for ; Mon, 10 Feb 2020 02:18:22 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@protonmail.com header.s=default header.b=dmt2QzUQ; spf=pass (domain: protonmail.com, ip: 185.70.40.18, mailfrom: vit9696@protonmail.com) Date: Mon, 10 Feb 2020 10:18:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1581329899; bh=tjGEq5K+VsFqRcJcuMQR05U0Z2Y+UVrTLvVTW6i7zFE=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:Feedback-ID: From; b=dmt2QzUQC1YhhhZSny2wGpRTwpmFt26Eao2c0MmfUyX33XXPRFlxb/nhWuL91SEy3 Xm7gQvK/L0SA0lfA/whi3XV1yfHK+2CTXN0iSHFvfuuvebpiewiOmfrzCzz6B693oB JVOYJklIFldk81aFMtGOpgLoEciBE8WB58YRYYVQ= To: devel@edk2.groups.io From: "Vitaly Cheptsov" Reply-To: Vitaly Cheptsov Subject: [PATCH 1/1] ShellPkg: Add support for input with separately reported modifiers Message-ID: <20200210101811.18741-2-vit9696@protonmail.com> In-Reply-To: <20200210101811.18741-1-vit9696@protonmail.com> References: <20200210101811.18741-1-vit9696@protonmail.com> Feedback-ID: p9QuX-L1wMgUm6nrSvNrf8juLupNs0VSnzXGVXuYDxlEahFdWtaedWDMB9zpwGDklGt7kzs1-RBc0cqz327Gcg==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-0.7 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FREEMAIL_REPLYTO_END_DIGIT shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch X-Groupsio-MsgNum: 54122 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha256; boundary="---------------------1f506a772a6822433163c668a185d8d7"; charset=UTF-8 -----------------------1f506a772a6822433163c668a185d8d7 Content-Transfer-Encoding: quoted-printable Date: Mon, 10 Feb 2020 13:18:11 +0300 From: Vitaly Cheptsov In-Reply-To: <20200210101811.18741-1-vit9696@protonmail.com> Message-Id: <20200210101811.18741-2-vit9696@protonmail.com> Mime-Version: 1.0 References: <20200210101811.18741-1-vit9696@protonmail.com> Subject: [PATCH 1/1] ShellPkg: Add support for input with separately reported modifiers To: devel@edk2.groups.io X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2510 Some firmwares: - Report Shift modifier even when they report upper-case unicode letter. - Report Ctrl modifier with "shifted" UniChar (i.e. X - 'A' + 1). This change provides support for these firmwares preserving the compatibili= ty with the previous input handling. Signed-off-by: Michael Belyaev Reviewed-by: Vitaly Cheptsov --- ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c | 37 += +++++++++++++------ ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c | 28 += +++++++++----- ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c | 6 += +++ ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c | 11 += ++--- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEdito= r.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c index df530f1119..9615a4dfbd 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c @@ -1381,8 +1381,8 @@ MainCommandDisplayHelp ( continue; } =20 - if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) =3D=3D 0= ) || - (KeyData.KeyState.KeyShiftState =3D=3D EFI_SHIFT_STATE_VALID)) { + if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) =3D=3D 0= ) + || (KeyData.KeyState.KeyShiftState =3D=3D EFI_SHIFT_STATE_VALID)) { // // For consoles that don't support/report shift state, // CTRL+W is translated to L'W' - L'A' + 1. @@ -1390,14 +1390,17 @@ MainCommandDisplayHelp ( if (KeyData.Key.UnicodeChar =3D=3D L'W' - L'A' + 1) { break; } - } else if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != =3D 0) && - ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSE= D | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) && - ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID = | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) =3D=3D 0)) { + } else if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != =3D 0) + && ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSE= D | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) + && ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID = | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) =3D=3D 0)) { // // For consoles that supports/reports shift state, // make sure that only CONTROL shift key is pressed. + // For some consoles that report shift state, + // CTRL+W is still translated to L'W' - L'A' + 1. // - if ((KeyData.Key.UnicodeChar =3D=3D 'w') || (KeyData.Key.UnicodeChar= =3D=3D 'W')) { + if ((KeyData.Key.UnicodeChar =3D=3D L'w') || (KeyData.Key.UnicodeCha= r =3D=3D L'W') + || (KeyData.Key.UnicodeChar =3D=3D L'w' - L'a' + 1) || (KeyData.Ke= y.UnicodeChar =3D=3D L'W' - L'A' + 1)) { break; } } @@ -1834,7 +1837,8 @@ MainEditorKeyInput ( EFI_KEY_DATA KeyData; EFI_STATUS Status; EFI_SIMPLE_POINTER_STATE MouseState; - BOOLEAN NoShiftState; + BOOLEAN NoModifierState; + BOOLEAN ShiftOnlyState; =20 do { =20 @@ -1886,17 +1890,28 @@ MainEditorKeyInput ( // StatusBarSetRefresh(); // - // NoShiftState: TRUE when no shift key is pressed. + // NoModifierState: TRUE when no modifier key is pressed. // - NoShiftState =3D ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STAT= E_VALID) =3D=3D 0) || (KeyData.KeyState.KeyShiftState =3D=3D EFI_SHIFT_STAT= E_VALID); + NoModifierState =3D ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_S= TATE_VALID) =3D=3D 0) + || (KeyData.KeyState.KeyShiftState =3D=3D EFI_SHIF= T_STATE_VALID); + // + // ShiftOnlyState: TRUE when no modifier key except Shift is press= ed. + // + ShiftOnlyState =3D ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_ST= ATE_VALID) =3D=3D 0) + || ((KeyData.KeyState.KeyShiftState + & ~(EFI_SHIFT_STATE_VALID | EFI_LEFT_SHIFT_PRESS= ED | EFI_RIGHT_SHIFT_PRESSED)) =3D=3D 0); // // dispatch to different components' key handling function // if (EFI_NOT_FOUND !=3D MenuBarDispatchControlHotKey(&KeyData)) { Status =3D EFI_SUCCESS; - } else if (NoShiftState && ((KeyData.Key.ScanCode =3D=3D SCAN_NULL= ) || ((KeyData.Key.ScanCode >=3D SCAN_UP) && (KeyData.Key.ScanCode <=3D SCA= N_PAGE_DOWN)))) { + } else if ((ShiftOnlyState && (KeyData.Key.ScanCode =3D=3D SCAN_NU= LL)) + || (NoModifierState && (KeyData.Key.ScanCode >=3D SCAN_UP)= && (KeyData.Key.ScanCode <=3D SCAN_PAGE_DOWN))) { + // + // alphanumeric keys with or without shift, or arrow keys withou= t shift + // Status =3D FileBufferHandleInput (&KeyData.Key); - } else if (NoShiftState && (KeyData.Key.ScanCode >=3D SCAN_F1) && = (KeyData.Key.ScanCode <=3D SCAN_F12)) { + } else if (NoModifierState && (KeyData.Key.ScanCode >=3D SCAN_F1) = && (KeyData.Key.ScanCode <=3D SCAN_F12)) { Status =3D MenuBarDispatchFunctionKey (&KeyData.Key); } else { StatusBarSetStatusString (L"Unknown Command"); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c b/S= hellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c index 35b0b701e8..d053059220 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c @@ -130,6 +130,8 @@ InputBarRefresh ( UINTN EventIndex; UINTN CursorRow; UINTN CursorCol; + BOOLEAN ShiftPressed; + BOOLEAN ModifiersPressed; =20 // // variable initialization @@ -180,17 +182,23 @@ InputBarRefresh ( if (EFI_ERROR (Status)) { continue; } - if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) !=3D 0) = && - (KeyData.KeyState.KeyShiftState !=3D EFI_SHIFT_STATE_VALID)) { - // - // Shift key pressed. - // + ModifiersPressed =3D ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STAT= E_VALID) !=3D 0) + && (KeyData.KeyState.KeyShiftState !=3D EFI_SHIFT_STAT= E_VALID); + + // + // TRUE if Shift is pressed and no other modifiers are pressed + // + ShiftPressed =3D ModifiersPressed && + ((KeyData.KeyState.KeyShiftState & + ~(EFI_SHIFT_STATE_VALID | EFI_LEFT_SHIFT_PRESSED | EF= I_RIGHT_SHIFT_PRESSED)) =3D=3D 0); + + if (ModifiersPressed && !ShiftPressed) { continue; } // // pressed ESC // - if (KeyData.Key.ScanCode =3D=3D SCAN_ESC) { + if (!ModifiersPressed && KeyData.Key.ScanCode =3D=3D SCAN_ESC) { Size =3D 0; Status =3D EFI_NOT_READY; break; @@ -198,9 +206,10 @@ InputBarRefresh ( // // return pressed // - if (KeyData.Key.UnicodeChar =3D=3D CHAR_LINEFEED || KeyData.Key.Unicod= eChar =3D=3D CHAR_CARRIAGE_RETURN) { + if (!ModifiersPressed + && (KeyData.Key.UnicodeChar =3D=3D CHAR_LINEFEED || KeyData.Key.Unic= odeChar =3D=3D CHAR_CARRIAGE_RETURN)) { break; - } else if (KeyData.Key.UnicodeChar =3D=3D CHAR_BACKSPACE) { + } else if (!ModifiersPressed && KeyData.Key.UnicodeChar =3D=3D CHAR_BA= CKSPACE) { // // backspace // @@ -213,7 +222,8 @@ InputBarRefresh ( =20 } } - } else if (KeyData.Key.UnicodeChar <=3D 127 && KeyData.Key.UnicodeChar= >=3D 32) { + } else if ((!ModifiersPressed || ShiftPressed) + && KeyData.Key.UnicodeChar <=3D 127 && KeyData.Key.UnicodeChar= >=3D 32) { // // VALID ASCII char pressed // diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c b/Sh= ellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c index ca8bc506d9..eabbf3c571 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c @@ -190,11 +190,17 @@ MenuBarDispatchControlHotKey ( // // For consoles that supports/reports shift state, // make sure only CONTROL is pressed. + // For some consoles that report shift state, + // Ctrl+A is still translated to 1 (UnicodeChar). // if ((KeyData->Key.UnicodeChar >=3D L'A') && (KeyData->Key.UnicodeChar = <=3D L'Z')) { ControlIndex =3D KeyData->Key.UnicodeChar - L'A' + 1; } else if ((KeyData->Key.UnicodeChar >=3D L'a') && (KeyData->Key.Unico= deChar <=3D L'z')) { ControlIndex =3D KeyData->Key.UnicodeChar - L'a' + 1; + } else if ((KeyData->Key.UnicodeChar >=3D L'A' - L'A' + 1) && (KeyData= ->Key.UnicodeChar <=3D L'Z' - L'A' + 1)) { + ControlIndex =3D KeyData->Key.UnicodeChar; + } else if ((KeyData->Key.UnicodeChar >=3D L'a' - L'a' + 1) && (KeyData= ->Key.UnicodeChar <=3D L'z' - L'z' + 1)) { + ControlIndex =3D KeyData->Key.UnicodeChar; } } if ((SCAN_CONTROL_Z < ControlIndex) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEdi= tor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c index a00df49d38..394e531c16 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c @@ -137,14 +137,17 @@ HMainCommandDisplayHelp ( if (KeyData.Key.UnicodeChar =3D=3D L'W' - L'A' + 1) { break; } - } else if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != =3D 0) && - ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSE= D | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) && - ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID = | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) =3D=3D 0)) { + } else if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != =3D 0) + && ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSE= D | EFI_RIGHT_CONTROL_PRESSED)) !=3D 0) + && ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID = | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) =3D=3D 0)) { // // For consoles that supports/reports shift state, // make sure that only CONTROL shift key is pressed. + // For some consoles that report shift state, + // CTRL+W is still translated to L'W' - L'A' + 1. // - if ((KeyData.Key.UnicodeChar =3D=3D 'w') || (KeyData.Key.UnicodeChar= =3D=3D 'W')) { + if ((KeyData.Key.UnicodeChar =3D=3D 'w') || (KeyData.Key.UnicodeChar= =3D=3D 'W') + || (KeyData.Key.UnicodeChar =3D=3D L'w' - L'a' + 1) || (KeyData.Ke= y.UnicodeChar =3D=3D L'W' - L'A' + 1)) { break; } } --=20 2.21.1 (Apple Git-122.3) -----------------------1f506a772a6822433163c668a185d8d7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wsBmBAEBCAAQBQJeQS3nCRBPsoxt7Hy0xQAKCRBPsoxt7Hy0xX1MB/4ninXq VqWzrsCBCh3Ruz1BWKMossEVb/xpMrXoLhI1FQKmdsohr/9FSpri233sjnVy SuXGBrjTsQRIP2HSzZvF3ivWugsBNIOOz1wcYyItMNIVIEoVmoGEr1XSjzXW pKTlr5fadHAHczl5fMRJHJCLy8jYUw/mfxNs/PkNF/mM1tZtUPPvDrqLqgBj OFCN3tMQpYL0IjAWQNYAFZ5omgHW4vAyBNce/C0GUzWhXKGi1HQkaAf7Djil KDONTXa/GxbMPcrA/edtzNCyy2fy5US0+0RQ7KOg0XtlWJyy425hknj+zlLR S814Jmn/OkIJcOtX+msN078mCVCPcIaILgVF =FD6Q -----END PGP SIGNATURE----- -----------------------1f506a772a6822433163c668a185d8d7--