FINAL CUT
ftermfreebsd.h
1 /***********************************************************************
2 * ftermfreebsd.h - Contains the FreeBSD terminal functions *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2018-2022 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Standalone class
24  * ════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ FTermFreeBSD ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FTERMFREEBSD_H
32 #define FTERMFREEBSD_H
33 
34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
35  #error "Only <final/final.h> can be included directly."
36 #endif
37 
38 #if defined(UNIT_TEST)
39  #define CONS_CURSORTYPE 0x80046307
40  #define GIO_KEYMAP 0x20006b06
41  #define PIO_KEYMAP 0x20006b07
42  #define META 0x84 // Meta key
43  #define NUM_KEYS 256 // Number of keys in table
44  #define NUM_STATES 8 // States per key
45 
46  struct keyent_t
47  {
48  int map[NUM_STATES];
49  int spcl;
50  int flgs;
51  };
52 
53  struct keymap_t
54  {
55  int n_keys;
56  struct keyent_t key[NUM_KEYS];
57  };
58 #elif defined(__FreeBSD__) || defined(__DragonFly__)
59  #undef mouse_info // consio.h
60  #undef buttons // consio.h
61 
62  #include <sys/consio.h>
63  #include <sys/kbio.h>
64 #endif
65 
66 #include "final/fc.h"
67 #include "final/util/fstring.h"
68 
69 namespace finalcut
70 {
71 
72 // class forward declaration
73 class FTermData;
74 
75 //----------------------------------------------------------------------
76 // class FTermFreeBSD
77 //----------------------------------------------------------------------
78 
79 class FTermFreeBSD final
80 {
81  public:
82  // Using-declaration
83  using CursorStyle = FreeBSDConsoleCursorStyle;
84 
85  // Accessors
86  auto getClassName() const -> FString;
87  static auto getInstance() -> FTermFreeBSD&;
88  static auto getCursorStyle() -> CursorStyle;
89 
90  // Inquiry
91  static auto isFreeBSDConsole() -> bool;
92 
93  // Mutators
94  static auto setCursorStyle (CursorStyle) -> bool;
95  static void enableChangeCursorStyle() noexcept;
96  static void disableChangeCursorStyle() noexcept;
97  static void enableMetaSendsEscape() noexcept;
98  static void disableMetaSendsEscape() noexcept;
99  static void setBeep (int, int);
100  static void resetBeep();
101 
102  // Methods
103  static void init();
104  static void initCharMap();
105  static void finish();
106 
107  private:
108  // Methods
109  static void warnNotInitialized();
110  static auto saveFreeBSDAltKey() -> bool;
111  static auto setFreeBSDAltKey (uInt) -> bool;
112  static auto setFreeBSDAlt2Meta() -> bool;
113  static auto resetFreeBSDAlt2Meta() -> bool;
114  static auto setFreeBSDCursorStyle (CursorStyle) -> bool;
115 
116  // Data members
117  static uInt bsd_alt_keymap;
118  static CursorStyle cursor_style;
119  static bool change_cursorstyle;
120  static bool meta_sends_escape;
121 };
122 
123 
124 // FTermFreeBSD inline functions
125 //----------------------------------------------------------------------
126 inline auto FTermFreeBSD::getClassName() const -> FString
127 { return "FTermFreeBSD"; }
128 
129 //----------------------------------------------------------------------
130 #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
131 inline void FTermFreeBSD::enableChangeCursorStyle() noexcept
132 { change_cursorstyle = true; }
133 
134 //----------------------------------------------------------------------
135 inline void FTermFreeBSD::disableChangeCursorStyle() noexcept
136 { change_cursorstyle = false; }
137 
138 //----------------------------------------------------------------------
139 inline void FTermFreeBSD::enableMetaSendsEscape() noexcept
140 { meta_sends_escape = true; }
141 
142 //----------------------------------------------------------------------
143 inline void FTermFreeBSD::disableMetaSendsEscape() noexcept
144 { meta_sends_escape = false; }
145 
146 #endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
147 
148 } // namespace finalcut
149 
150 #endif // FTERMFREEBSD_H
Definition: ftermfreebsd.h:79
Definition: class_template.cpp:25
Definition: fstring.h:79