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.
@ -22,6 +22,8 @@
*******************************************************************************/
#include <stdint.h>
#include <sortix/keycodes.h>
#include <sortix/kernel/kernel.h>
@ -29,15 +31,15 @@
#include "us.h"
namespace Sortix
{
const unsigned MOD_SHIFT = (1U<<0U);
const unsigned MOD_CAPS = (1U<<1U);
const unsigned MOD_LSHIFT = (1U<<2U);
const unsigned MOD_RSHIFT = (1U<<3U);
namespace Sortix {
const uint32_t LAYOUT_US[4UL*128UL] =
{
const unsigned MOD_SHIFT = 1U << 0U;
const unsigned MOD_CAPS = 1U << 1U;
const unsigned MOD_LSHIFT = 1U << 2U;
const unsigned MOD_RSHIFT = 1U << 3U;
const uint32_t LAYOUT_US[4UL*128UL] =
{
0, 0, 0, 0, /* unused: kbkey 0 is invalid */
0, 0, 0, 0, /* KBKEY_ESC */
'1', '!', '1', '!',
@ -118,33 +120,40 @@ namespace Sortix
0, 0, 0, 0, /* KBKEY_KPAD6 */
'+', '+', '+', '+',
/* Nothing printable after this point */
};
};
KBLayoutUS::KBLayoutUS()
{
KBLayoutUS::KBLayoutUS()
{
modifiers = 0;
}
}
KBLayoutUS::~KBLayoutUS()
{
}
KBLayoutUS::~KBLayoutUS()
{
}
bool KBLayoutUS::ProcessModifier(int logickey, int modkey, unsigned flag)
{
if ( logickey == modkey ) { modifiers |= flag; return true; }
if ( logickey == -modkey ) { modifiers &= ~flag; return true; }
bool KBLayoutUS::ProcessModifier(int logickey, int modkey, unsigned flag)
{
if ( logickey == modkey )
return modifiers |= flag, true;
if ( logickey == -modkey )
return modifiers &= ~flag, true;
return false;
}
}
uint32_t KBLayoutUS::Translate(int kbkey)
{
if ( kbkey == KBKEY_LSHIFT ) { modifiers |= MOD_LSHIFT; return 0; }
if ( kbkey == -KBKEY_LSHIFT ) { modifiers &= ~MOD_LSHIFT; return 0; }
if ( kbkey == KBKEY_RSHIFT ) { modifiers |= MOD_RSHIFT; return 0; }
if ( kbkey == -KBKEY_RSHIFT ) { modifiers &= ~MOD_RSHIFT; return 0; }
if ( kbkey == KBKEY_CAPSLOCK ) { modifiers ^= MOD_CAPS; return 0; }
uint32_t KBLayoutUS::Translate(int kbkey)
{
if ( kbkey == KBKEY_LSHIFT )
return modifiers |= MOD_LSHIFT, 0;
if ( kbkey == -KBKEY_LSHIFT )
return modifiers &= ~MOD_LSHIFT, 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) )
modifiers |= MOD_SHIFT;
@ -152,12 +161,14 @@ namespace Sortix
modifiers &= ~MOD_SHIFT;
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).
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];
}
}
} // 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.
@ -25,24 +25,27 @@
#ifndef SORTIX_KB_LAYOUT_US_H
#define SORTIX_KB_LAYOUT_US_H
#include <stdint.h>
#include <sortix/kernel/keyboard.h>
namespace Sortix
namespace Sortix {
class KBLayoutUS : public KeyboardLayout
{
class KBLayoutUS : public KeyboardLayout
{
public:
public:
KBLayoutUS();
virtual ~KBLayoutUS();
virtual uint32_t Translate(int kbkey);
public:
public:
bool ProcessModifier(int kbkey, int modkey, unsigned flag);
private:
private:
unsigned modifiers;
};
}
};
} // namespace Sortix
#endif