From 32097d4bf0d1c2b8edd923b3007dde555b72ac99 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 17 Jun 2018 23:25:32 +0200 Subject: [PATCH] Added special console options for FreeBSD, NetBSD and OpenBSD --- ChangeLog | 3 ++ include/final/fterm.h | 30 ++++++++++++++++--- include/final/ftermfreebsd.h | 26 ++++++++++++++-- include/final/ftermlinux.h | 2 +- include/final/ftermopenbsd.h | 28 +++++++++++++---- src/fapplication.cpp | 58 +++++++++++++++++++++++++++++++----- src/fterm.cpp | 38 ++++++++++++++++++----- src/ftermdetection.cpp | 2 +- src/ftermfreebsd.cpp | 31 +++++++++++++------ src/ftermopenbsd.cpp | 41 ++++++++++++++----------- 10 files changed, 204 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3de66536..6b180b83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-06-17 Markus Gans + * Added special console options for FreeBSD, NetBSD and OpenBSD + 2017-06-12 Markus Gans * Linux functions from FTerm moved into the FTermLinux class diff --git a/include/final/fterm.h b/include/final/fterm.h index 5f8d4669..18556097 100644 --- a/include/final/fterm.h +++ b/include/final/fterm.h @@ -336,21 +336,43 @@ class FTerm public: void setDefault() { - terminal_detection = true; cursor_optimisation = true; + mouse_support = true; + terminal_detection = true; color_change = true; vgafont = false; newfont = false; encoding = fc::UNKNOWN; + + #if defined(__FreeBSD__) || defined(__DragonFly__) + meta_sends_escape = true; + change_cursorstyle = true; + #endif + + #if defined(__NetBSD__) || defined(__OpenBSD__) + meta_sends_escape = true; + #endif } - uInt8 terminal_detection : 1; uInt8 cursor_optimisation : 1; + uInt8 mouse_support : 1; + uInt8 terminal_detection : 1; uInt8 color_change : 1; uInt8 vgafont : 1; uInt8 newfont : 1; - uInt8 : 3; // padding bits + uInt8 : 2; // padding bits fc::encoding encoding; + + #if defined(__FreeBSD__) || defined(__DragonFly__) + uInt8 meta_sends_escape : 1; + uInt8 change_cursorstyle : 1; + uInt8 : 6; // padding bits + #endif + + #if defined(__NetBSD__) || defined(__OpenBSD__) + uInt8 meta_sends_escape : 1; + uInt8 : 7; // padding bits + #endif } init_values; private: @@ -407,7 +429,7 @@ class FTerm void initOSspecifics(); void finish(); void finishOSspecifics1(); - void finishOSspecifics2(); + void finish_encoding(); static uInt cp437_to_unicode (uChar); static int getMouseProtocolKey (char[]); static int getTermcapKey (char[], int); diff --git a/include/final/ftermfreebsd.h b/include/final/ftermfreebsd.h index d3235e6c..b8de063d 100644 --- a/include/final/ftermfreebsd.h +++ b/include/final/ftermfreebsd.h @@ -73,6 +73,10 @@ class FTermFreeBSD // Mutators static void setCursorStyle (CursorStyle, bool); + static void enableChangeCursorStyle(); + static void disableChangeCursorStyle(); + static void enableMetaSendsEscape(); + static void disableMetaSendsEscape(); // Methods static void init(); @@ -96,10 +100,28 @@ class FTermFreeBSD // Data Members static uInt bsd_alt_keymap; static CursorStyle cursor_style; + static bool change_cursorstyle; + static bool meta_sends_escape; }; #pragma pack(pop) +// FTermFreeBSD inline functions +//---------------------------------------------------------------------- +#if defined(__FreeBSD__) || defined(__DragonFly__) +inline void FTermFreeBSD::enableChangeCursorStyle() +{ change_cursorstyle = true; } + +//---------------------------------------------------------------------- +inline void FTermFreeBSD::disableChangeCursorStyle() +{ change_cursorstyle = false; } + +//---------------------------------------------------------------------- +inline void FTermFreeBSD::enableMetaSendsEscape() +{ meta_sends_escape = true; } + +//---------------------------------------------------------------------- +inline void FTermFreeBSD::disableMetaSendsEscape() +{ meta_sends_escape = false; } +#endif // defined(__FreeBSD__) || defined(__DragonFly__) #endif // FTERMFREEBSD_H - - diff --git a/include/final/ftermlinux.h b/include/final/ftermlinux.h index 4c7ab4af..cfa90b5b 100644 --- a/include/final/ftermlinux.h +++ b/include/final/ftermlinux.h @@ -210,6 +210,6 @@ inline bool FTermLinux::isVGAFontUsed() //---------------------------------------------------------------------- inline bool FTermLinux::isNewFontUsed() { return NewFont; } -#endif +#endif // defined(__linux__) #endif // FTERMLINUX_H diff --git a/include/final/ftermopenbsd.h b/include/final/ftermopenbsd.h index 03f43afc..4a0568d0 100644 --- a/include/final/ftermopenbsd.h +++ b/include/final/ftermopenbsd.h @@ -59,7 +59,11 @@ class FTermOpenBSD ~FTermOpenBSD(); // Inquiries - static bool isWSConsConsole(); + static bool isBSDConsole(); + + // Mutators + static void disableMetaSendsEscape(); + static void enableMetaSendsEscape(); // Methods static void init(); @@ -74,15 +78,27 @@ class FTermOpenBSD #if defined(__NetBSD__) || defined(__OpenBSD__) // Methods - static bool saveWSConsEncoding(); - static bool setWSConsEncoding (kbd_t); - static bool setWSConsMetaEsc(); - static bool resetWSConsEncoding(); + static bool saveBSDConsoleEncoding(); + static bool setBSDConsoleEncoding (kbd_t); + static bool setBSDConsoleMetaEsc(); + static bool resetBSDConsoleEncoding(); // Data Members - static kbd_t wscons_keyboard_encoding; + static kbd_t bsd_keyboard_encoding; + static bool meta_sends_escape; #endif }; #pragma pack(pop) +// FTermOpenBSD inline functions +//---------------------------------------------------------------------- +#if defined(__NetBSD__) || defined(__OpenBSD__) +inline void FTermOpenBSD::enableMetaSendsEscape() +{ meta_sends_escape = true; } + +//---------------------------------------------------------------------- +inline void FTermOpenBSD::disableMetaSendsEscape() +{ meta_sends_escape = false; } +#endif // defined(__NetBSD__) || defined(__OpenBSD__) + #endif // FTERMOPENBSD_H diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 8f35da9b..11cf41ca 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -321,11 +321,13 @@ void FApplication::showParameterUsage() << " -h, --help " << " Display this help and exit" << std::endl << std::endl - << "FinalCut Options:" << std::endl + << "The Final Cut options:" << std::endl << " --encoding " << " Sets the character encoding mode" << std::endl << " " << " {utf8, vt100, pc, ascii}" << std::endl + << " --no-mouse " + << " Disable mouse support" << std::endl << " --no-optimized-cursor " << " Disable cursor optimization" << std::endl << " --no-terminal-detection" @@ -335,7 +337,25 @@ void FApplication::showParameterUsage() << " --vgafont " << " Set the standard vga 8x16 font" << std::endl << " --newfont " - << " Enables the graphical font" << std::endl; + << " Enables the graphical font" << std::endl + +#if defined(__FreeBSD__) || defined(__DragonFly__) + << std::endl + << "FreeBSD console options:" << std::endl + << " --no-esc-for-alt-meta " + << " Do not send a ESC prefix for the alt/meta key" << std::endl + << " --no-cursorstyle-change" + << " Do not change the current cursor style" << std::endl +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) + << std::endl + << "NetBSD/OpenBSD console options:" << std::endl + << " --no-esc-for-alt-meta " + << " Do not send a ESC prefix for the alt/meta key" << std::endl +#endif + + << std::endl; std::exit(EXIT_SUCCESS); } @@ -402,20 +422,28 @@ void FApplication::cmd_options (const int& argc, char* argv[]) static struct option long_options[] = { {C_STR("encoding"), required_argument, 0, 0 }, + {C_STR("no-mouse"), no_argument, 0, 0 }, {C_STR("no-optimized-cursor"), no_argument, 0, 0 }, {C_STR("no-terminal-detection"), no_argument, 0, 0 }, {C_STR("no-color-change"), no_argument, 0, 0 }, {C_STR("vgafont"), no_argument, 0, 0 }, {C_STR("newfont"), no_argument, 0, 0 }, + + #if defined(__FreeBSD__) || defined(__DragonFly__) + {C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 }, + {C_STR("no-cursorstyle-change"), no_argument, 0, 0 }, + #endif + + #if defined(__NetBSD__) || defined(__OpenBSD__) + {C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 }, + #endif + {0, 0, 0, 0 } }; opterr = 0; - c = getopt_long ( argc - , argv - , "" - , long_options - , &idx ); + c = getopt_long (argc, argv, "", long_options, &idx); + if ( c == -1 ) break; @@ -441,6 +469,9 @@ void FApplication::cmd_options (const int& argc, char* argv[]) + std::string(encoding.c_str()) ); } + if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 ) + init_values.mouse_support = false; + if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 ) init_values.cursor_optimisation = false; @@ -455,6 +486,19 @@ void FApplication::cmd_options (const int& argc, char* argv[]) if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) init_values.newfont = true; + + #if defined(__FreeBSD__) || defined(__DragonFly__) + if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) + init_values.meta_sends_escape = false; + + if ( std::strcmp(long_options[idx].name, "no-cursorstyle-change") == 0 ) + init_values.change_cursorstyle = false; + #endif + + #if defined(__NetBSD__) || defined(__OpenBSD__) + if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) + init_values.meta_sends_escape = false; + #endif } } } diff --git a/src/fterm.cpp b/src/fterm.cpp index 430734f3..be16e5cd 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -731,12 +731,15 @@ void FTerm::setPalette (short index, int r, int g, int b) } //---------------------------------------------------------------------- +#if defined(__linux__) void FTerm::setBeep (int Hz, int ms) { -#if defined(__linux__) linux->setBeep (Hz, ms); -#endif } +#else +void FTerm::setBeep (int, int) +{ } +#endif //---------------------------------------------------------------------- void FTerm::resetBeep() @@ -1013,7 +1016,7 @@ void FTerm::initScreenSettings() #endif #if defined(__FreeBSD__) || defined(__DragonFly__) - freebsd->initCharMap(); + freebsd->initCharMap (fc::character); #endif // set xterm underline cursor @@ -2109,7 +2112,8 @@ void FTerm::init() init_encoding(); // Enable the terminal mouse support - enableMouse(); + if ( init_values.mouse_support ) + enableMouse(); // Activate meta key sends escape if ( isXTerminal() ) @@ -2184,10 +2188,25 @@ void FTerm::initOSspecifics() #endif #if defined(__FreeBSD__) || defined(__DragonFly__) + if ( init_values.meta_sends_escape ) + freebsd->enableMetaSendsEscape(); + else + freebsd->disableMetaSendsEscape(); + + if ( init_values.change_cursorstyle ) + freebsd->enableChangeCursorStyle(); + else + freebsd->disableChangeCursorStyle(); + freebsd->init(); // Initialize BSD console #endif #if defined(__NetBSD__) || defined(__OpenBSD__) + if ( init_values.meta_sends_escape ) + openbsd->enableMetaSendsEscape(); + else + openbsd->disableMetaSendsEscape(); + openbsd->init(); // Initialize wscons console #endif } @@ -2243,7 +2262,8 @@ void FTerm::finish() resetBeep(); // Disable the terminal mouse support - disableMouse(); + if ( init_values.mouse_support ) + disableMouse(); // Deactivate meta key sends escape if ( isXTerminal() ) @@ -2258,7 +2278,7 @@ void FTerm::finish() std::fflush(stdout); } - finishOSspecifics2(); + finish_encoding(); if ( NewFont || VGAFont ) setOldFont(); @@ -2283,7 +2303,7 @@ void FTerm::finishOSspecifics1() } //---------------------------------------------------------------------- -void FTerm::finishOSspecifics2() +void FTerm::finish_encoding() { #if defined(__linux__) if ( isLinuxTerm() && utf8_console ) @@ -2312,6 +2332,10 @@ uInt FTerm::cp437_to_unicode (uChar c) inline int FTerm::getMouseProtocolKey (char buffer[]) { // Looking for mouse string in the key buffer + + if ( ! init_values.mouse_support ) + return -1; + register std::size_t buf_len = std::strlen(buffer); // x11 mouse tracking diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index ab2d270e..a4515a1d 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -808,7 +808,7 @@ inline char* FTermDetection::secDA_Analysis_24 (char current_termtype[]) #if defined(__NetBSD__) || defined(__OpenBSD__) if ( secondary_da.terminal_id_version == 20 - && FTermOpenBSD::isWSConsConsole() ) + && FTermOpenBSD::isBSDConsole() ) { // NetBSD/OpenBSD workstation console if ( std::strncmp(termtype, C_STR("wsvt25"), 6) == 0 ) diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index d2b8e6ed..90ea7dcb 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -25,8 +25,10 @@ // static class attributes #if defined(__FreeBSD__) || defined(__DragonFly__) - uInt FTermFreeBSD::bsd_alt_keymap = 0; - FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style; + uInt FTermFreeBSD::bsd_alt_keymap = 0; + FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style = fc::normal_cursor; + bool FTermFreeBSD::change_cursorstyle = true; + bool FTermFreeBSD::meta_sends_escape = true; #endif @@ -59,6 +61,9 @@ void FTermFreeBSD::setCursorStyle (CursorStyle style, bool hidden) if ( ! isFreeBSDConsole() ) return; + if ( ! change_cursorstyle ) + return; + cursor_style = style; if ( hidden ) @@ -88,14 +93,20 @@ void FTermFreeBSD::init() if ( ! isFreeBSDConsole() ) return; - // save current left alt key mapping - saveFreeBSDAltKey(); + if ( meta_sends_escape ) + { + // save current left alt key mapping + saveFreeBSDAltKey(); - // map meta key to left alt key - setFreeBSDAlt2Meta(); + // map meta key to left alt key + setFreeBSDAlt2Meta(); + } - // Initialize FreeBSD console cursor - setCursorStyle (fc::destructive_cursor, true); + if ( change_cursorstyle ) + { + // Initialize FreeBSD console cursor + setCursorStyle (fc::destructive_cursor, true); + } } //---------------------------------------------------------------------- @@ -119,7 +130,9 @@ void FTermFreeBSD::finish() if ( ! isFreeBSDConsole() ) return; - resetFreeBSDAlt2Meta(); + if ( meta_sends_escape ) + resetFreeBSDAlt2Meta(); + setCursorStyle (fc::normal_cursor, false); } diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index d070153c..0ca1734f 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -24,7 +24,8 @@ // static class attributes #if defined(__NetBSD__) || defined(__OpenBSD__) - kbd_t FTermOpenBSD::wscons_keyboard_encoding = 0; + kbd_t FTermOpenBSD::bsd_keyboard_encoding = 0; + bool FTermOpenBSD::meta_sends_escape = true; #endif @@ -44,9 +45,9 @@ FTermOpenBSD::~FTermOpenBSD() // destructor // public methods of FTermOpenBSD //---------------------------------------------------------------------- #if defined(__NetBSD__) || defined(__OpenBSD__) -bool FTermOpenBSD::isWSConsConsole() +bool FTermOpenBSD::isBSDConsole() { - // Check if it's a NetBSD/OpenBSD console + // Check if it's a NetBSD/OpenBSD workstation console static kbd_t kbdencoding; @@ -59,31 +60,35 @@ bool FTermOpenBSD::isWSConsConsole() //---------------------------------------------------------------------- void FTermOpenBSD::init() { - // initialize wscons console + // initialize BSD workstation console - if ( ! isWSConsConsole() ) + if ( ! isBSDConsole() ) return; - // save current left alt key mapping - saveWSConsEncoding(); + if ( meta_sends_escape ) + { + // save current left alt key mapping + saveBSDConsoleEncoding(); - // alt key generate ESC prefix - setWSConsMetaEsc(); + // alt key generate ESC prefix + setBSDConsoleMetaEsc(); + } } //---------------------------------------------------------------------- void FTermOpenBSD::finish() { - if ( ! isWSConsConsole() ) + if ( ! isBSDConsole() ) return; - resetWSConsEncoding(); + if ( meta_sends_escape ) + resetBSDConsoleEncoding(); } // private methods of FTermOpenBSD //---------------------------------------------------------------------- -bool FTermOpenBSD::saveWSConsEncoding() +bool FTermOpenBSD::saveBSDConsoleEncoding() { static kbd_t k_encoding; int ret = ioctl(0, WSKBDIO_GETENCODING, &k_encoding); @@ -92,12 +97,12 @@ bool FTermOpenBSD::saveWSConsEncoding() return false; // save current encoding - wscons_keyboard_encoding = k_encoding; + bsd_keyboard_encoding = k_encoding; return true; } //---------------------------------------------------------------------- -bool FTermOpenBSD::setWSConsEncoding (kbd_t k_encoding) +bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding) { if ( ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) return false; @@ -106,17 +111,17 @@ bool FTermOpenBSD::setWSConsEncoding (kbd_t k_encoding) } //---------------------------------------------------------------------- -bool FTermOpenBSD::setWSConsMetaEsc() +bool FTermOpenBSD::setBSDConsoleMetaEsc() { static const kbd_t meta_esc = 0x20; // generate ESC prefix on ALT-key - return setWSConsEncoding (wscons_keyboard_encoding | meta_esc); + return setBSDConsoleEncoding (bsd_keyboard_encoding | meta_esc); } //---------------------------------------------------------------------- -bool FTermOpenBSD::resetWSConsEncoding() +bool FTermOpenBSD::resetBSDConsoleEncoding() { - return setWSConsEncoding (wscons_keyboard_encoding); + return setBSDConsoleEncoding (bsd_keyboard_encoding); } #endif