Open/NetBSD (wscons): Alt key generate Esc prefix

This commit is contained in:
Markus Gans 2017-04-14 23:55:44 +02:00
parent 2ec425480a
commit cb2e2e2045
5 changed files with 168 additions and 57 deletions

View File

@ -1,3 +1,8 @@
2017-04-14 Markus Gans <guru.mail@muenster.de>
* The Final Cut compiles also under OpenBSD
* The alt key now always generates an esc prefix
on an OpenBSD and a NetBSD console
2017-04-11 Markus Gans <guru.mail@muenster.de>
* Enable xterm "metaSendsEscape" switch

View File

@ -552,7 +552,7 @@ void FApplication::processKeyboardEvent()
{
#if defined(__linux__)
key = modifierKeyCorrection (key);
key = linuxModifierKeyCorrection (key);
#endif
switch ( key )
@ -711,10 +711,10 @@ void FApplication::processKeyboardEvent()
#if defined(__linux__)
//----------------------------------------------------------------------
int FApplication::modifierKeyCorrection (int& key_id)
int FApplication::linuxModifierKeyCorrection (int& key_id)
{
// get the current modifier key state
FTerm::modifier_key& m = getModifierKey();
FTerm::modifier_key& m = getLinuxModifierKey();
if ( ! (m.shift || m.ctrl || m.alt) )
{

View File

@ -130,7 +130,7 @@ class FApplication : public FWidget
ssize_t readKey();
void processKeyboardEvent();
#if defined(__linux__)
int modifierKeyCorrection (int& key);
int linuxModifierKeyCorrection (int& key);
#endif
bool processDialogSwitchAccelerator();
bool processAccelerator (FWidget*&);

View File

@ -120,7 +120,14 @@ fc::freebsdConsoleCursorStyle FTerm::freebsd_console_cursor_style;
unimapdesc FTerm::screen_unicode_map;
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
uInt FTerm::bsd_alt_keymap = 0;
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
kbd_t FTerm::wscons_keyboard_encoding = 0;
#endif
//----------------------------------------------------------------------
// class FTerm
@ -148,11 +155,9 @@ FTerm::~FTerm() // destructor
finish();
if ( exit_message[0] )
{
std::fprintf (stderr, "Warning: %s\n", exit_message);
}
}
}
// public methods of FTerm
@ -197,7 +202,7 @@ const FString FTerm::getKeyName (int keynum)
#if defined(__linux__)
//----------------------------------------------------------------------
FTerm::modifier_key& FTerm::getModifierKey()
FTerm::modifier_key& FTerm::getLinuxModifierKey()
{
char subcode = 6;
// fill bit field with 0
@ -1858,55 +1863,18 @@ bool FTerm::isFreeBSDConsole()
else
return false;
}
#endif
//----------------------------------------------------------------------
bool FTerm::saveFreeBSDAltKey()
#if defined(__NetBSD__) || defined(__OpenBSD__)
bool FTerm::isWSConsConsole()
{
keymap_t keymap;
int ret;
static const int left_alt = 0x38;
static kbd_t kbdencoding;
ret = ioctl(0, GIO_KEYMAP, &keymap);
if ( ret < 0 )
return false;
// save current mapping
bsd_alt_keymap = keymap.key[left_alt].map[0];
if ( ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 )
return true;
}
//----------------------------------------------------------------------
bool FTerm::setFreeBSDAltKey (uInt key)
{
keymap_t keymap;
int ret;
static const int left_alt = 0x38;
ret = ioctl(0, GIO_KEYMAP, &keymap);
if ( ret < 0 )
return false;
// map to meta key
keymap.key[left_alt].map[0] = key;
if ( (keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0))
return false;
else
return true;
}
//----------------------------------------------------------------------
bool FTerm::setFreeBSDAlt2Meta()
{
return setFreeBSDAltKey (META);
}
//----------------------------------------------------------------------
bool FTerm::resetFreeBSDAlt2Meta()
{
return setFreeBSDAltKey (bsd_alt_keymap);
return false;
}
#endif
@ -2391,6 +2359,56 @@ void FTerm::initLinuxConsole()
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
//----------------------------------------------------------------------
bool FTerm::saveFreeBSDAltKey()
{
keymap_t keymap;
int ret;
static const int left_alt = 0x38;
ret = ioctl(0, GIO_KEYMAP, &keymap);
if ( ret < 0 )
return false;
// save current mapping
bsd_alt_keymap = keymap.key[left_alt].map[0];
return true;
}
//----------------------------------------------------------------------
bool FTerm::setFreeBSDAltKey (uInt key)
{
keymap_t keymap;
int ret;
static const int left_alt = 0x38;
ret = ioctl(0, GIO_KEYMAP, &keymap);
if ( ret < 0 )
return false;
// map to meta key
keymap.key[left_alt].map[0] = key;
if ( (keymap.n_keys > 0) && (ioctl(0, PIO_KEYMAP, &keymap) < 0))
return false;
else
return true;
}
//----------------------------------------------------------------------
bool FTerm::setFreeBSDAlt2Meta()
{
return setFreeBSDAltKey (META);
}
//----------------------------------------------------------------------
bool FTerm::resetFreeBSDAlt2Meta()
{
return setFreeBSDAltKey (bsd_alt_keymap);
}
//----------------------------------------------------------------------
void FTerm::initFreeBSDConsole()
{
@ -2407,6 +2425,60 @@ void FTerm::initFreeBSDConsole()
}
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
//----------------------------------------------------------------------
bool FTerm::saveWSConsEncoding()
{
static kbd_t k_encoding;
int ret = ioctl(0, WSKBDIO_GETENCODING, &k_encoding);
if ( ret < 0 )
return false;
// save current encoding
wscons_keyboard_encoding = k_encoding;
return true;
}
//----------------------------------------------------------------------
bool FTerm::setWSConsEncoding (kbd_t k_encoding)
{
if ( ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 )
return false;
else
return true;
}
//----------------------------------------------------------------------
bool FTerm::setWSConsMetaEsc()
{
static const kbd_t meta_esc = 0x20; // generate ESC prefix on ALT-key
return setWSConsEncoding (wscons_keyboard_encoding | meta_esc);
}
//----------------------------------------------------------------------
bool FTerm::resetWSConsEncoding()
{
return setWSConsEncoding (wscons_keyboard_encoding);
}
//----------------------------------------------------------------------
void FTerm::initWSConsConsole()
{
// initialize wscons console
if ( isWSConsConsole() )
{
// save current left alt key mapping
saveWSConsEncoding();
// alt key generate ESC prefix
setWSConsMetaEsc();
}
}
#endif
//----------------------------------------------------------------------
uInt FTerm::getBaudRate (const struct termios* termios_p)
{
@ -3558,6 +3630,11 @@ void FTerm::init()
initFreeBSDConsole();
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
// Initialize wscons console
initWSConsConsole();
#endif
// Save termios settings
storeTTYsettings();
@ -3921,6 +3998,10 @@ void FTerm::finish()
setFreeBSDConsoleCursorStyle (fc::normal_cursor, false);
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
resetWSConsEncoding();
#endif
if ( kde_konsole )
setKDECursor(fc::BlockCursor);

View File

@ -45,6 +45,11 @@
#include <sys/kbio.h>
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
@ -122,7 +127,7 @@ class FTerm
static const FString getKeyName (int);
#if defined(__linux__)
static modifier_key& getModifierKey();
static modifier_key& getLinuxModifierKey();
#endif
static char* getTermType();
@ -279,6 +284,7 @@ class FTerm
#if defined(__FreeBSD__) || defined(__DragonFly__)
static void initFreeBSDConsoleCharMap();
#endif
static void initCygwinCharMap();
static void initTeraTermCharMap();
@ -348,10 +354,10 @@ class FTerm
#if defined(__FreeBSD__) || defined(__DragonFly__)
static bool isFreeBSDConsole();
static bool saveFreeBSDAltKey();
static bool setFreeBSDAltKey (uInt);
static bool setFreeBSDAlt2Meta();
static bool resetFreeBSDAlt2Meta();
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
static bool isWSConsConsole();
#endif
// Methods
@ -380,9 +386,21 @@ class FTerm
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
static bool saveFreeBSDAltKey();
static bool setFreeBSDAltKey (uInt);
static bool setFreeBSDAlt2Meta();
static bool resetFreeBSDAlt2Meta();
static void initFreeBSDConsole();
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
static bool saveWSConsEncoding();
static bool setWSConsEncoding (kbd_t);
static bool setWSConsMetaEsc();
static bool resetWSConsEncoding();
static void initWSConsConsole();
#endif
static uInt getBaudRate (const struct termios*);
static char* init_256colorTerminal();
static char* parseAnswerbackMsg (char*&);
@ -453,7 +471,14 @@ class FTerm
static fc::freebsdConsoleCursorStyle freebsd_console_cursor_style;
static struct console_font_op screen_font;
static struct unimapdesc screen_unicode_map;
#if defined(__FreeBSD__) || defined(__DragonFly__)
static uInt bsd_alt_keymap;
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
static kbd_t wscons_keyboard_encoding;
#endif
static FOptiMove* opti_move;
static FOptiAttr* opti_attr;