FINAL CUT
ftermopenbsd.h
1 /***********************************************************************
2 * ftermopenbsd.h - Contains the NetBSD/OpenBSD 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  * ▕ FTermOpenBSD ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FTERMOPENBSD_H
32 #define FTERMOPENBSD_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 #include <sys/ioctl.h>
39 
40 #if defined(UNIT_TEST)
41  #include <cstdint>
42 
43  #define WSKBDIO_GETENCODING uInt32(0x4004570F)
44  #define WSKBDIO_SETENCODING uInt32(0x80045710)
45  #define WSKBDIO_GETDEFAULTBELL uInt32(0x40105706)
46  #define WSKBDIO_SETBELL uInt32(0x80105703)
47  #define WSKBD_BELL_DOPITCH 0x1 // get/set pitch
48  #define WSKBD_BELL_DOPERIOD 0x2 // get/set period
49  #define WSKBD_BELL_DOVOLUME 0x4 // get/set volume
50  #define WSKBD_BELL_DOALL 0x7 // all of the above
51 
52  using kbd_t = std::uint32_t;
53 
54  struct wskbd_bell_data
55  {
56  unsigned int which; // values to get/set
57  unsigned int pitch; // pitch, in Hz
58  unsigned int period; // period, in milliseconds
59  unsigned int volume; // percentage of max volume
60  };
61 #elif defined(__NetBSD__) || defined(__OpenBSD__)
62  #include <sys/time.h>
63  #include <dev/wscons/wsconsio.h>
64 #endif
65 
66 #include "final/util/fstring.h"
67 
68 namespace finalcut
69 {
70 
71 //----------------------------------------------------------------------
72 // class FTermOpenBSD
73 //----------------------------------------------------------------------
74 
75 class FTermOpenBSD final
76 {
77  public:
78  // Accessor
79  auto getClassName() const -> FString;
80  static auto getInstance() -> FTermOpenBSD&;
81 
82  // Inquiries
83  static auto isBSDConsole() -> bool;
84 
85  // Mutators
86  static void disableMetaSendsEscape() noexcept;
87  static void enableMetaSendsEscape() noexcept;
88 
89  // Methods
90  static void init();
91  static void finish();
92  static auto setBeep (int, int) -> bool;
93  static auto resetBeep() -> bool;
94 
95 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
96  private:
97  // Methods
98  static void warnNotInitialized();
99  static auto saveBSDConsoleEncoding() -> bool;
100  static auto setBSDConsoleEncoding (kbd_t) -> bool;
101  static auto setBSDConsoleMetaEsc() -> bool;
102  static auto resetBSDConsoleEncoding() -> bool;
103 
104  // Data members
105  static kbd_t bsd_keyboard_encoding;
106  static bool meta_sends_escape;
107 #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
108 };
109 
110 
111 // FTermOpenBSD inline functions
112 //----------------------------------------------------------------------
113 inline auto FTermOpenBSD::getClassName() const -> FString
114 { return "FTermOpenBSD"; }
115 
116 //----------------------------------------------------------------------
117 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
118 inline void FTermOpenBSD::enableMetaSendsEscape() noexcept
119 { meta_sends_escape = true; }
120 
121 //----------------------------------------------------------------------
122 inline void FTermOpenBSD::disableMetaSendsEscape() noexcept
123 { meta_sends_escape = false; }
124 
125 #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
126 
127 } // namespace finalcut
128 
129 #endif // FTERMOPENBSD_H
Definition: class_template.cpp:25
Definition: ftermopenbsd.h:75
Definition: fstring.h:79