2018-06-12 16:37:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ftermlinux.h - Contains the Linux terminal functions *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-04-15 23:44:08 +02:00
|
|
|
* Copyright 2018-2020 Markus Gans *
|
2018-06-12 16:37:48 +02:00
|
|
|
* *
|
|
|
|
* 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/>. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/* Standalone class
|
|
|
|
* ════════════════
|
|
|
|
*
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTermLinux ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FTERMLINUX_H
|
|
|
|
#define FTERMLINUX_H
|
|
|
|
|
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__linux__)
|
2019-10-08 04:37:19 +02:00
|
|
|
#include <linux/fb.h> // Linux framebuffer console
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2019-10-08 04:37:19 +02:00
|
|
|
#if defined(__arm__) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
|
|
|
|
// ISA sysctl support on arm processors only up to glibc-2.29
|
|
|
|
#if !__GLIBC_PREREQ(2,30)
|
|
|
|
#define ARM_ISA_SYSCTL
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__x86_64__) || defined(__i386) || defined(ARM_ISA_SYSCTL)
|
2019-10-14 01:44:24 +02:00
|
|
|
#define ISA_SYSCTL_SUPPORT
|
2019-10-08 04:37:19 +02:00
|
|
|
#include <sys/io.h>
|
|
|
|
#endif // defined(__x86_64__) || defined(__i386) || defined(ARM_ISA_SYSCTL)
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
#include <sys/kd.h>
|
2018-09-20 23:59:01 +02:00
|
|
|
#endif // defined(__linux__)
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <cstdio> // need for sprintf
|
|
|
|
#include <cstring>
|
2019-08-06 23:45:28 +02:00
|
|
|
#include <vector>
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/ftermdata.h"
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
// class forward declaration
|
|
|
|
class FSystem;
|
|
|
|
class FTermData;
|
|
|
|
class FTermDetection;
|
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FTermLinux
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2019-01-04 02:18:54 +01:00
|
|
|
class FTermLinux final
|
2018-06-12 16:37:48 +02:00
|
|
|
{
|
|
|
|
public:
|
2019-08-04 23:38:47 +02:00
|
|
|
// Typedef
|
|
|
|
typedef fc::linuxConsoleCursorStyle CursorStyle;
|
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
// Constructors
|
2018-12-03 03:22:36 +01:00
|
|
|
FTermLinux() = default;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FTermLinux (const FTermLinux&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
// Destructor
|
2020-04-04 20:58:47 +02:00
|
|
|
~FTermLinux();
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
FTermLinux& operator = (const FTermLinux&) = delete;
|
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
// Accessors
|
2019-10-05 23:20:07 +02:00
|
|
|
const FString getClassName() const;
|
|
|
|
fc::linuxConsoleCursorStyle getCursorStyle();
|
|
|
|
char* getCursorStyleString();
|
2020-05-02 00:07:35 +02:00
|
|
|
int getFramebufferBpp() const;
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
// Mutators
|
2019-10-05 23:20:07 +02:00
|
|
|
bool setCursorStyle (CursorStyle);
|
|
|
|
bool setPalette (FColor, int, int, int);
|
|
|
|
void setUTF8 (bool);
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
// Inquiries
|
2019-10-05 23:20:07 +02:00
|
|
|
bool isLinuxConsole();
|
2020-05-02 00:07:35 +02:00
|
|
|
bool isVGAFontUsed() const;
|
|
|
|
bool isNewFontUsed() const;
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
// Methods
|
2019-10-05 23:20:07 +02:00
|
|
|
void init();
|
|
|
|
void initCharMap();
|
|
|
|
void finish();
|
|
|
|
bool loadVGAFont();
|
|
|
|
bool loadNewFont();
|
|
|
|
bool loadOldFont();
|
|
|
|
bool saveColorMap();
|
|
|
|
bool resetColorMap();
|
|
|
|
void setBeep (int, int);
|
|
|
|
void resetBeep();
|
|
|
|
|
|
|
|
FKey modifierKeyCorrection (const FKey&);
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Typedef
|
2019-10-05 23:20:07 +02:00
|
|
|
struct modifier_key // bit field
|
2018-06-12 16:37:48 +02:00
|
|
|
{
|
|
|
|
uChar shift : 1; // 0..1
|
|
|
|
uChar alt_gr : 1; // 0..1
|
|
|
|
uChar ctrl : 1; // 0..1
|
|
|
|
uChar alt : 1; // 0..1
|
|
|
|
uChar : 4; // padding bits
|
2020-04-20 01:01:20 +02:00
|
|
|
};
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uChar red;
|
|
|
|
uChar green;
|
|
|
|
uChar blue;
|
|
|
|
} rgb;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
rgb color[16];
|
|
|
|
} ColorMap;
|
|
|
|
|
|
|
|
// Accessors
|
2019-10-05 23:20:07 +02:00
|
|
|
int getFramebuffer_bpp();
|
|
|
|
bool getScreenFont();
|
|
|
|
bool getUnicodeMap ();
|
|
|
|
modifier_key& getModifierKey();
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
// Mutators
|
2019-10-05 23:20:07 +02:00
|
|
|
int setScreenFont ( uChar[], uInt, uInt, uInt
|
2018-06-12 16:37:48 +02:00
|
|
|
, bool = false );
|
2019-10-05 23:20:07 +02:00
|
|
|
int setUnicodeMap (struct unimapdesc*);
|
|
|
|
void setLinuxCursorStyle (fc::linuxConsoleCursorStyle);
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
// Methods
|
2019-10-14 01:44:24 +02:00
|
|
|
#if defined(ISA_SYSCTL_SUPPORT)
|
2019-10-05 23:20:07 +02:00
|
|
|
uInt16 getInputStatusRegisterOne();
|
|
|
|
uChar readAttributeController (uChar);
|
|
|
|
void writeAttributeController (uChar, uChar);
|
|
|
|
uChar getAttributeMode();
|
|
|
|
void setAttributeMode (uChar);
|
|
|
|
int setBlinkAsIntensity (bool);
|
2019-11-03 23:34:47 +01:00
|
|
|
bool has9BitCharacters();
|
2019-10-05 23:20:07 +02:00
|
|
|
void getVGAPalette();
|
|
|
|
void setVGADefaultPalette();
|
|
|
|
bool setVGAPalette (FColor, int, int, int);
|
|
|
|
bool saveVGAPalette();
|
|
|
|
bool resetVGAPalette();
|
2019-10-14 01:44:24 +02:00
|
|
|
#endif // defined(ISA_SYSCTL_SUPPORT)
|
2019-10-05 23:20:07 +02:00
|
|
|
FKey shiftKeyCorrection (const FKey&);
|
|
|
|
FKey ctrlKeyCorrection (const FKey&);
|
|
|
|
FKey altKeyCorrection (const FKey&);
|
|
|
|
FKey shiftCtrlKeyCorrection (const FKey&);
|
|
|
|
FKey shiftAltKeyCorrection (const FKey&);
|
|
|
|
FKey ctrlAltKeyCorrection (const FKey&);
|
|
|
|
FKey shiftCtrlAltKeyCorrection (const FKey&);
|
|
|
|
sInt16 getFontPos (wchar_t ucs);
|
|
|
|
void initSpecialCharacter();
|
|
|
|
void characterFallback (wchar_t, std::vector<wchar_t>);
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-06-12 16:37:48 +02:00
|
|
|
#if defined(__linux__)
|
2019-10-05 23:20:07 +02:00
|
|
|
bool vga_font{};
|
|
|
|
bool new_font{};
|
|
|
|
bool has_saved_palette{};
|
|
|
|
FTermData* fterm_data{nullptr};
|
|
|
|
FSystem* fsystem{nullptr};
|
|
|
|
FTermDetection* term_detection{nullptr};
|
|
|
|
CursorStyle linux_console_cursor_style{};
|
|
|
|
console_font_op screen_font{};
|
|
|
|
unimapdesc screen_unicode_map{};
|
|
|
|
ColorMap saved_color_map{};
|
|
|
|
ColorMap cmap{};
|
|
|
|
int framebuffer_bpp{-1};
|
2020-04-20 01:01:20 +02:00
|
|
|
modifier_key mod_key{};
|
2018-06-12 16:37:48 +02:00
|
|
|
#endif // defined(__linux__)
|
|
|
|
};
|
2019-09-08 02:04:24 +02:00
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
// FTermLinux inline functions
|
2018-08-09 00:04:00 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
inline const FString FTermLinux::getClassName() const
|
2018-08-09 00:04:00 +02:00
|
|
|
{ return "FTermLinux"; }
|
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-06-12 16:52:26 +02:00
|
|
|
#if defined(__linux__)
|
2020-05-02 00:07:35 +02:00
|
|
|
inline int FTermLinux::getFramebufferBpp() const
|
2018-06-12 16:37:48 +02:00
|
|
|
{ return framebuffer_bpp; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline bool FTermLinux::isVGAFontUsed() const
|
2018-10-01 22:27:54 +02:00
|
|
|
{ return vga_font; }
|
2018-06-12 16:37:48 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline bool FTermLinux::isNewFontUsed() const
|
2018-10-01 22:27:54 +02:00
|
|
|
{ return new_font; }
|
2018-06-17 23:25:32 +02:00
|
|
|
#endif // defined(__linux__)
|
2018-06-12 16:37:48 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2018-06-12 16:37:48 +02:00
|
|
|
#endif // FTERMLINUX_H
|