2018-05-27 19:43:18 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ftermopenbsd.cpp - Contains the NetBSD/OpenBSD terminal functions *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
|
|
|
* Copyright 2018 Markus Gans *
|
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#include "final/ftermopenbsd.h"
|
|
|
|
|
|
|
|
// static class attributes
|
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
2018-06-17 23:25:32 +02:00
|
|
|
kbd_t FTermOpenBSD::bsd_keyboard_encoding = 0;
|
|
|
|
bool FTermOpenBSD::meta_sends_escape = true;
|
2018-05-27 19:43:18 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2018-05-27 19:43:18 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FTermOpenBSD
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FTermOpenBSD::FTermOpenBSD()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FTermOpenBSD::~FTermOpenBSD() // destructor
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// public methods of FTermOpenBSD
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
2018-06-17 23:25:32 +02:00
|
|
|
bool FTermOpenBSD::isBSDConsole()
|
2018-05-27 19:43:18 +02:00
|
|
|
{
|
2018-06-17 23:25:32 +02:00
|
|
|
// Check if it's a NetBSD/OpenBSD workstation console
|
2018-05-27 19:43:18 +02:00
|
|
|
|
|
|
|
static kbd_t kbdencoding;
|
|
|
|
|
|
|
|
if ( ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 )
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermOpenBSD::init()
|
|
|
|
{
|
2018-06-17 23:25:32 +02:00
|
|
|
// initialize BSD workstation console
|
2018-05-27 19:43:18 +02:00
|
|
|
|
2018-06-17 23:25:32 +02:00
|
|
|
if ( ! isBSDConsole() )
|
2018-05-27 19:43:18 +02:00
|
|
|
return;
|
|
|
|
|
2018-06-17 23:25:32 +02:00
|
|
|
if ( meta_sends_escape )
|
|
|
|
{
|
|
|
|
// save current left alt key mapping
|
|
|
|
saveBSDConsoleEncoding();
|
2018-05-27 19:43:18 +02:00
|
|
|
|
2018-06-17 23:25:32 +02:00
|
|
|
// alt key generate ESC prefix
|
|
|
|
setBSDConsoleMetaEsc();
|
|
|
|
}
|
2018-05-27 19:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermOpenBSD::finish()
|
|
|
|
{
|
2018-06-17 23:25:32 +02:00
|
|
|
if ( ! isBSDConsole() )
|
2018-05-27 19:43:18 +02:00
|
|
|
return;
|
|
|
|
|
2018-06-17 23:25:32 +02:00
|
|
|
if ( meta_sends_escape )
|
|
|
|
resetBSDConsoleEncoding();
|
2018-05-27 19:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FTermOpenBSD
|
|
|
|
//----------------------------------------------------------------------
|
2018-06-17 23:25:32 +02:00
|
|
|
bool FTermOpenBSD::saveBSDConsoleEncoding()
|
2018-05-27 19:43:18 +02:00
|
|
|
{
|
|
|
|
static kbd_t k_encoding;
|
|
|
|
int ret = ioctl(0, WSKBDIO_GETENCODING, &k_encoding);
|
|
|
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// save current encoding
|
2018-06-17 23:25:32 +02:00
|
|
|
bsd_keyboard_encoding = k_encoding;
|
2018-05-27 19:43:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-06-17 23:25:32 +02:00
|
|
|
bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding)
|
2018-05-27 19:43:18 +02:00
|
|
|
{
|
|
|
|
if ( ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 )
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-06-17 23:25:32 +02:00
|
|
|
bool FTermOpenBSD::setBSDConsoleMetaEsc()
|
2018-05-27 19:43:18 +02:00
|
|
|
{
|
|
|
|
static const kbd_t meta_esc = 0x20; // generate ESC prefix on ALT-key
|
|
|
|
|
2018-06-17 23:25:32 +02:00
|
|
|
return setBSDConsoleEncoding (bsd_keyboard_encoding | meta_esc);
|
2018-05-27 19:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-06-17 23:25:32 +02:00
|
|
|
bool FTermOpenBSD::resetBSDConsoleEncoding()
|
2018-05-27 19:43:18 +02:00
|
|
|
{
|
2018-06-17 23:25:32 +02:00
|
|
|
return setBSDConsoleEncoding (bsd_keyboard_encoding);
|
2018-05-27 19:43:18 +02:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
#endif // defined(__NetBSD__) || defined(__OpenBSD__)
|
2018-05-27 19:43:18 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|