linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Caps in not always shift
@ 2015-05-29  9:58 Dinar valeev
  2015-07-06  5:57 ` Nikunj A Dadhania
  0 siblings, 1 reply; 2+ messages in thread
From: Dinar valeev @ 2015-05-29  9:58 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Dinar Valeev

From: Dinar Valeev <dvaleev@suse.com>

Caps behaves like shift only for latin characters.
In case we're typing - for example with caps enabled, SLOF picks _ char
from shifted table.

Threat caps as shift only for letters.

Signed-off-by: Dinar Valeev <dvaleev@suse.com>
---
 lib/libusb/usb-hid.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/libusb/usb-hid.c b/lib/libusb/usb-hid.c
index f0cab8a..9e14cf5 100644
--- a/lib/libusb/usb-hid.c
+++ b/lib/libusb/usb-hid.c
@@ -83,6 +83,8 @@ uint8_t set_leds;
 const uint8_t *key_std       = NULL;
 const uint8_t *key_std_shift = NULL;
 
+uint8_t ctrl; /* modifiers */
+
 /**
  * read character from Keyboard-Buffer
  *
@@ -120,22 +122,27 @@ static void write_key(uint8_t key)
 static void get_char(uint8_t ctrl, uint8_t keypos)
 {
 	uint8_t ch;
+	int caps = 0;
+//key position for latin letters
+#define KEYP_LATIN_A 4
+#define KEYP_LATIN_Z 29
 
 #ifdef KEY_DEBUG
 	printf("pos %02X\n", keypos);
 #endif
 
 	if (set_leds & LED_CAPS_LOCK)	                /* is CAPS Lock set ? */
-		ctrl |= MODIFIER_SHIFT;	                    /* simulate shift */
+		caps = 1;
 
-	if (ctrl == 0) {
+	/* caps is a shift only for latin chars */
+	if ((caps == 0 && ctrl == 0) || (caps == 1 && (keypos < KEYP_LATIN_A || keypos > KEYP_LATIN_Z))) {
 		ch = key_std[keypos];
 		if (ch != 0)
 			write_key(ch);
 		return;
 	}
 
-	if (ctrl & MODIFIER_SHIFT) {
+	if ((ctrl & MODIFIER_SHIFT) || caps == 1) {
 		ch = key_std_shift[keypos];
 		if (ch != 0)
 			write_key(ch);
@@ -187,6 +194,12 @@ static void check_key_code(uint8_t *buf)
 					set_leds ^= LED_CAPS_LOCK;
 					break;
 
+				case 0x36:		                /*Shift pressed*/
+					ctrl |= MODIFIER_SHIFT;
+					break;
+				case 0xb6:		                /*Shift unpressed*/
+					ctrl &= ~MODIFIER_SHIFT;
+					break;
 				case 0x3a:	                        /* F1 */
 					write_key(0x1b);
 					write_key(0x5b);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Caps in not always shift
  2015-05-29  9:58 [PATCH] Caps in not always shift Dinar valeev
@ 2015-07-06  5:57 ` Nikunj A Dadhania
  0 siblings, 0 replies; 2+ messages in thread
From: Nikunj A Dadhania @ 2015-07-06  5:57 UTC (permalink / raw)
  To: Dinar valeev, linuxppc-dev; +Cc: Dinar Valeev

Dinar valeev <k0da@opensuse.org> writes:

> From: Dinar Valeev <dvaleev@suse.com>
>
> Caps behaves like shift only for latin characters.
> In case we're typing - for example with caps enabled, SLOF picks _ char
> from shifted table.
>
> Threat caps as shift only for letters.
>
> Signed-off-by: Dinar Valeev <dvaleev@suse.com>

Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>

> ---
>  lib/libusb/usb-hid.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/lib/libusb/usb-hid.c b/lib/libusb/usb-hid.c
> index f0cab8a..9e14cf5 100644
> --- a/lib/libusb/usb-hid.c
> +++ b/lib/libusb/usb-hid.c
> @@ -83,6 +83,8 @@ uint8_t set_leds;
>  const uint8_t *key_std       = NULL;
>  const uint8_t *key_std_shift = NULL;
>  
> +uint8_t ctrl; /* modifiers */
> +
>  /**
>   * read character from Keyboard-Buffer
>   *
> @@ -120,22 +122,27 @@ static void write_key(uint8_t key)
>  static void get_char(uint8_t ctrl, uint8_t keypos)
>  {
>  	uint8_t ch;
> +	int caps = 0;
> +//key position for latin letters
> +#define KEYP_LATIN_A 4
> +#define KEYP_LATIN_Z 29
>  
>  #ifdef KEY_DEBUG
>  	printf("pos %02X\n", keypos);
>  #endif
>  
>  	if (set_leds & LED_CAPS_LOCK)	                /* is CAPS Lock set ? */
> -		ctrl |= MODIFIER_SHIFT;	                    /* simulate shift */
> +		caps = 1;
>  
> -	if (ctrl == 0) {
> +	/* caps is a shift only for latin chars */
> +	if ((caps == 0 && ctrl == 0) || (caps == 1 && (keypos < KEYP_LATIN_A || keypos > KEYP_LATIN_Z))) {
>  		ch = key_std[keypos];
>  		if (ch != 0)
>  			write_key(ch);
>  		return;
>  	}
>  
> -	if (ctrl & MODIFIER_SHIFT) {
> +	if ((ctrl & MODIFIER_SHIFT) || caps == 1) {
>  		ch = key_std_shift[keypos];
>  		if (ch != 0)
>  			write_key(ch);
> @@ -187,6 +194,12 @@ static void check_key_code(uint8_t *buf)
>  					set_leds ^= LED_CAPS_LOCK;
>  					break;
>  
> +				case 0x36:		                /*Shift pressed*/
> +					ctrl |= MODIFIER_SHIFT;
> +					break;
> +				case 0xb6:		                /*Shift unpressed*/
> +					ctrl &= ~MODIFIER_SHIFT;
> +					break;
>  				case 0x3a:	                        /* F1 */
>  					write_key(0x1b);
>  					write_key(0x5b);
> -- 
> 2.1.4
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-06  5:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-29  9:58 [PATCH] Caps in not always shift Dinar valeev
2015-07-06  5:57 ` Nikunj A Dadhania

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).