Update kernel/kb/layout/us.{cpp,h} to current coding conventions.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-04 01:21:37 +01:00
parent 263cc21058
commit 6e6df64fa8
2 changed files with 158 additions and 144 deletions

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of Sortix. This file is part of Sortix.
@ -22,6 +22,8 @@
*******************************************************************************/ *******************************************************************************/
#include <stdint.h>
#include <sortix/keycodes.h> #include <sortix/keycodes.h>
#include <sortix/kernel/kernel.h> #include <sortix/kernel/kernel.h>
@ -29,12 +31,12 @@
#include "us.h" #include "us.h"
namespace Sortix namespace Sortix {
{
const unsigned MOD_SHIFT = (1U<<0U); const unsigned MOD_SHIFT = 1U << 0U;
const unsigned MOD_CAPS = (1U<<1U); const unsigned MOD_CAPS = 1U << 1U;
const unsigned MOD_LSHIFT = (1U<<2U); const unsigned MOD_LSHIFT = 1U << 2U;
const unsigned MOD_RSHIFT = (1U<<3U); const unsigned MOD_RSHIFT = 1U << 3U;
const uint32_t LAYOUT_US[4UL*128UL] = const uint32_t LAYOUT_US[4UL*128UL] =
{ {
@ -131,20 +133,27 @@ namespace Sortix
bool KBLayoutUS::ProcessModifier(int logickey, int modkey, unsigned flag) bool KBLayoutUS::ProcessModifier(int logickey, int modkey, unsigned flag)
{ {
if ( logickey == modkey ) { modifiers |= flag; return true; } if ( logickey == modkey )
if ( logickey == -modkey ) { modifiers &= ~flag; return true; } return modifiers |= flag, true;
if ( logickey == -modkey )
return modifiers &= ~flag, true;
return false; return false;
} }
uint32_t KBLayoutUS::Translate(int kbkey) uint32_t KBLayoutUS::Translate(int kbkey)
{ {
if ( kbkey == KBKEY_LSHIFT ) { modifiers |= MOD_LSHIFT; return 0; } if ( kbkey == KBKEY_LSHIFT )
if ( kbkey == -KBKEY_LSHIFT ) { modifiers &= ~MOD_LSHIFT; return 0; } return modifiers |= MOD_LSHIFT, 0;
if ( kbkey == KBKEY_RSHIFT ) { modifiers |= MOD_RSHIFT; return 0; } if ( kbkey == -KBKEY_LSHIFT )
if ( kbkey == -KBKEY_RSHIFT ) { modifiers &= ~MOD_RSHIFT; return 0; } return modifiers &= ~MOD_LSHIFT, 0;
if ( kbkey == KBKEY_CAPSLOCK ) { modifiers ^= MOD_CAPS; return 0; } if ( kbkey == KBKEY_RSHIFT )
return modifiers |= MOD_RSHIFT, 0;
if ( kbkey == -KBKEY_RSHIFT )
return modifiers &= ~MOD_RSHIFT, 0;
if ( kbkey == KBKEY_CAPSLOCK )
return modifiers ^= MOD_CAPS, 0;
int abskbkey = (kbkey < 0) ? -kbkey : kbkey; int abskbkey = kbkey < 0 ? -kbkey : kbkey;
if ( (modifiers & MOD_LSHIFT) || (modifiers & MOD_RSHIFT) ) if ( (modifiers & MOD_LSHIFT) || (modifiers & MOD_RSHIFT) )
modifiers |= MOD_SHIFT; modifiers |= MOD_SHIFT;
@ -152,12 +161,14 @@ namespace Sortix
modifiers &= ~MOD_SHIFT; modifiers &= ~MOD_SHIFT;
unsigned usedmods = modifiers & (MOD_SHIFT | MOD_CAPS); unsigned usedmods = modifiers & (MOD_SHIFT | MOD_CAPS);
size_t index = (abskbkey<<2) | usedmods; size_t index = abskbkey << 2 | usedmods;
// Check if the kbkey is outside the layout structure (not printable). // Check if the kbkey is outside the layout structure (not printable).
size_t numchars = sizeof(LAYOUT_US) / 4UL / sizeof(uint32_t); size_t numchars = sizeof(LAYOUT_US) / 4UL / sizeof(uint32_t);
if ( numchars < (size_t) abskbkey ) { return 0; } if ( numchars < (size_t) abskbkey )
return 0;
return LAYOUT_US[index]; return LAYOUT_US[index];
} }
}
} // namespace Sortix

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of Sortix. This file is part of Sortix.
@ -25,10 +25,12 @@
#ifndef SORTIX_KB_LAYOUT_US_H #ifndef SORTIX_KB_LAYOUT_US_H
#define SORTIX_KB_LAYOUT_US_H #define SORTIX_KB_LAYOUT_US_H
#include <stdint.h>
#include <sortix/kernel/keyboard.h> #include <sortix/kernel/keyboard.h>
namespace Sortix namespace Sortix {
{
class KBLayoutUS : public KeyboardLayout class KBLayoutUS : public KeyboardLayout
{ {
public: public:
@ -43,6 +45,7 @@ namespace Sortix
unsigned modifiers; unsigned modifiers;
}; };
}
} // namespace Sortix
#endif #endif