Skip to content

Commit

Permalink
Merge branch 'elfmz:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-soft authored Nov 7, 2024
2 parents 15a1cb0 + 671e3a9 commit 8d69f43
Show file tree
Hide file tree
Showing 265 changed files with 21,216 additions and 8,591 deletions.
1 change: 1 addition & 0 deletions WinPort/WinCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ typedef void *HKL;
#define ERROR_INSUFFICIENT_BUFFER ENOBUFS
#define ERROR_NO_UNICODE_TRANSLATION EILSEQ
#define ERROR_DIRECTORY EISDIR
#define ERROR_TOO_MANY_POSTS E2BIG
#define ERROR_INVALID_NAME ENAMETOOLONG
#define ERROR_FILE_EXISTS EEXIST
#define ERROR_OUTOFMEMORY ENOMEM
Expand Down
12 changes: 10 additions & 2 deletions WinPort/src/Backend/TTY/TTYInputSequenceParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "TTYInputSequenceParser.h"
#include "Backend.h"


//See:
// http://www.manmrk.net/tutorials/ISPF/XE/xehelp/html/HID00000579.htm
// http://www.leonerd.org.uk/hacks/fixterms/
Expand Down Expand Up @@ -179,7 +178,7 @@ TTYInputSequenceParser::TTYInputSequenceParser(ITTYInputSpecialSequenceHandler *
AddStrF1F5(VK_F2, "Q"); AddStr(VK_F2, 0, "[[B");
AddStrF1F5(VK_F3, "R"); AddStr(VK_F3, 0, "[[C");
AddStrF1F5(VK_F4, "S"); AddStr(VK_F4, 0, "[[D");
AddStrF1F5(VK_F5, "E"); AddStr(VK_F5, 0, "[[E");
AddStrF1F5(VK_CLEAR, "E"); AddStr(VK_CLEAR, 0, "[[E"); // NumPad center (5)

AddStrTilde(VK_HOME, 1);
AddStrTilde(VK_INSERT, 2);
Expand Down Expand Up @@ -420,6 +419,13 @@ size_t TTYInputSequenceParser::ParseIntoPending(const char *s, size_t l)
case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: case 0x08:
case 0x0a: case 0x0b: case 0x0c: case 0x0e: case 0x0f: case 0x10: case 0x11: case 0x12:
case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: case 0x18: case 0x19: case 0x1a:

// workaround for \x0a received instead of \x0d in kitty and wezterm in bracketed paste mode
if (_bracketed_paste_mode && *s == 0x0a) {
AddPendingKeyEvent(TTYInputKey{VK_RETURN, 0});
return 1;
}

AddPendingKeyEvent(TTYInputKey{WORD('A' + (*s - 0x01)), LEFT_CTRL_PRESSED});
return 1;

Expand Down Expand Up @@ -661,6 +667,8 @@ void TTYInputSequenceParser::OnBracketedPaste(bool start)
ir.EventType = BRACKETED_PASTE_EVENT;
ir.Event.BracketedPaste.bStartPaste = start ? TRUE : FALSE;
_ir_pending.emplace_back(ir);

_bracketed_paste_mode = start;
}

//work-around for double encoded events in win32-input mode
Expand Down
1 change: 1 addition & 0 deletions WinPort/src/Backend/TTY/TTYInputSequenceParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class TTYInputSequenceParser
StackSerializer _tmp_stk_ser;
DWORD _extra_control_keys = 0;
std::vector<INPUT_RECORD> _ir_pending;
bool _bracketed_paste_mode = false;
bool _kitty_right_ctrl_down = false;
int _iterm_last_flags = 0;
char _using_extension = 0;
Expand Down
2 changes: 1 addition & 1 deletion WinPort/src/Backend/TTY/TTYInputSequenceParserExts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ size_t TTYInputSequenceParser::TryParseAsKittyEscapeSequence(const char *s, size
ir.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY; break;
case 'D': ir.Event.KeyEvent.wVirtualKeyCode = VK_LEFT;
ir.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY; break;
case 'E': ir.Event.KeyEvent.wVirtualKeyCode = VK_NUMPAD5; break;
case 'E': ir.Event.KeyEvent.wVirtualKeyCode = VK_CLEAR; break; // NumPad center (5)
case 'H': ir.Event.KeyEvent.wVirtualKeyCode = VK_HOME;
ir.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY; break;
case 'F': ir.Event.KeyEvent.wVirtualKeyCode = VK_END;
Expand Down
94 changes: 83 additions & 11 deletions WinPort/src/Backend/WX/wxMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ extern "C" __attribute__ ((visibility("default"))) bool WinPortMainBackend(WinPo
if (!wxInitialize())
return false;

fprintf(stderr, "FAR2L wxWidgets build version %d.%d.%d\n", wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER );
#if wxCHECK_VERSION(2, 9, 2)
wxVersionInfo wxv = wxGetLibraryVersionInfo();
fprintf(stderr, "FAR2L wxWidgets use version %d.%d.%d\n", wxv.GetMajor(), wxv.GetMinor(), wxv.GetMicro() );
#endif

wxSetAssertHandler(WinPortWxAssertHandler);

DetectHostAbilities();
Expand Down Expand Up @@ -1242,6 +1248,50 @@ char* FormatWxKeyState(uint16_t state) {
return buffer;
}

static bool isNumpadNumericKey(int keycode)
{
switch (keycode) {
case WXK_NUMPAD0:
case WXK_NUMPAD1:
case WXK_NUMPAD2:
case WXK_NUMPAD3:
case WXK_NUMPAD4:
case WXK_NUMPAD5:
case WXK_NUMPAD6:
case WXK_NUMPAD7:
case WXK_NUMPAD8:
case WXK_NUMPAD9:
case WXK_NUMPAD_INSERT:
case WXK_NUMPAD_END:
case WXK_NUMPAD_DOWN:
case WXK_NUMPAD_PAGEDOWN:
case WXK_NUMPAD_LEFT:
case WXK_NUMPAD_BEGIN: // NumPad center (5)
case WXK_NUMPAD_RIGHT:
case WXK_NUMPAD_HOME:
case WXK_NUMPAD_UP:
case WXK_NUMPAD_PAGEUP:
return true;
default:
return false;
}
}

bool isLayoutDependentKey( wxKeyEvent& event ) {
switch (event.GetKeyCode()) {
// Those keys generate Unicode key codes, but they are not keyboard layout-dependent keys
case WXK_ESCAPE:
case WXK_DELETE:
case WXK_BACK:
case WXK_TAB:
case WXK_RETURN:
case WXK_SPACE:
return false;
default:
return event.GetUnicodeKey() > 0;
}
}

void WinPortPanel::OnKeyDown( wxKeyEvent& event )
{
ResetTimerIdling();
Expand Down Expand Up @@ -1304,9 +1354,15 @@ void WinPortPanel::OnKeyDown( wxKeyEvent& event )
// also it didnt cause problems yet
if ( (_key_tracker.Shift() && !event.ShiftDown())
|| ((_key_tracker.LeftControl() || _key_tracker.RightControl()) && !event.ControlDown())) {
if ((!_key_tracker.Alt() || _key_tracker.Shift() || g_wayland) && // workaround for #2294, 2464
_key_tracker.CheckForSuddenModifiersUp()) {
_exclusive_hotkeys.Reset();

if (
#ifndef __WXOSX__
(!_key_tracker.Alt() || _key_tracker.Shift() || _key_tracker.LeftControl() || _key_tracker.RightControl()
|| !isNumpadNumericKey(event.GetKeyCode()) || g_wayland) && // workaround for #2294, 2464
#endif

_key_tracker.CheckForSuddenModifiersUp()) {
_exclusive_hotkeys.Reset();
}
}

Expand Down Expand Up @@ -1342,8 +1398,9 @@ void WinPortPanel::OnKeyDown( wxKeyEvent& event )

if ( (dwMods != 0 && event.GetUnicodeKey() < 32)
|| ((dwMods & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED | LEFT_ALT_PRESSED))
#ifndef __WXOSX__
&& (g_wayland || !event.AltDown() || !event.GetUnicodeKey()) // workaround for wx issue #23421
#if !defined(__WXOSX__) && wxCHECK_VERSION(3, 2, 3) // workaround is still needed at least in wx 3.2.6, see wx issue #24772

&& (/*g_wayland ||*/ !event.AltDown() || !isLayoutDependentKey(event)) // workaround for wx issue #23421
#endif
)
|| event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_RETURN
Expand All @@ -1369,6 +1426,8 @@ void WinPortPanel::OnKeyDown( wxKeyEvent& event )
}
#endif

_enqueued_in_onchar = false;

event.Skip();
}

Expand All @@ -1384,6 +1443,11 @@ void WinPortPanel::OnKeyUp( wxKeyEvent& event )

_exclusive_hotkeys.OnKeyUp(event);

if (_enqueued_in_onchar) {
_enqueued_in_onchar = false;
return;
}

if (event.GetSkipped()) {
fprintf(stderr, " SKIPPED\n");
return;
Expand Down Expand Up @@ -1445,18 +1509,23 @@ void WinPortPanel::OnKeyUp( wxKeyEvent& event )
}
#endif

#ifndef __WXOSX__
if (g_wayland || !event.AltDown() || !event.GetUnicodeKey()) { // workaround for wx issue #23421
#if !defined(__WXOSX__) && wxCHECK_VERSION(3, 2, 3)
if (/*g_wayland ||*/ !event.AltDown() || !isLayoutDependentKey(event)) { // workaround for wx issue #23421
#else
{
#endif
wxConsoleInputShim::Enqueue(&ir, 1);
}

}
if ((!_key_tracker.Alt() || _key_tracker.Shift() || g_wayland) && // workaround for #2294, 2464
_key_tracker.CheckForSuddenModifiersUp()) {
_exclusive_hotkeys.Reset();
if (
#ifndef __WXOSX__
(!_key_tracker.Alt() || _key_tracker.Shift() || _key_tracker.LeftControl() || _key_tracker.RightControl()
|| !isNumpadNumericKey(event.GetKeyCode()) || g_wayland) && // workaround for #2294, 2464
#endif

_key_tracker.CheckForSuddenModifiersUp()) {
_exclusive_hotkeys.Reset();
}
//event.Skip();
}
Expand Down Expand Up @@ -1502,6 +1571,7 @@ void WinPortPanel::OnChar( wxKeyEvent& event )
}
ir.Event.KeyEvent.uChar.UnicodeChar = event.GetUnicodeKey();

#if !defined(__WXOSX__) && wxCHECK_VERSION(3, 2, 3)
if (event.AltDown()) {

// workaround for wx issue #23421
Expand All @@ -1515,13 +1585,15 @@ void WinPortPanel::OnChar( wxKeyEvent& event )

ir.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
}
#endif

ir.Event.KeyEvent.bKeyDown = TRUE;
wxConsoleInputShim::Enqueue(&ir, 1);

ir.Event.KeyEvent.bKeyDown = FALSE;
wxConsoleInputShim::Enqueue(&ir, 1);


_enqueued_in_onchar = true;
}
//event.Skip();
}
Expand Down
1 change: 1 addition & 0 deletions WinPort/src/Backend/WX/wxMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class WinPortPanel: public wxPanel, protected IConsoleOutputBackend
unsigned char _force_size_on_paint_state{0};
bool _extra_refresh{false};
bool _last_keydown_enqueued{false};
bool _enqueued_in_onchar{false};
bool _app_entry_started{false};
bool _adhoc_quickedit{false};
enum
Expand Down
23 changes: 15 additions & 8 deletions colorer/src/Colorer-library/src/colorer/common/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void format_log_string(std::ostream& out, std::string_view format, Args&&... arg

#include "unicode/unistr.h"
namespace details {
template <> inline
void ArgumentT<icu::UnicodeString>::print(std::ostream& out) const
template <>
inline void ArgumentT<icu::UnicodeString>::print(std::ostream& out) const
{
std::string result8;
mData.toUTF8String(result8);
Expand All @@ -66,13 +66,13 @@ void ArgumentT<icu::UnicodeString>::print(std::ostream& out) const
#else
#include "colorer/strings/legacy/strings.h"
namespace details {
template <> inline
void details::ArgumentT<UnicodeString>::print(std::ostream& out) const
template <>
inline void details::ArgumentT<UnicodeString>::print(std::ostream& out) const
{
std::string const result8 = mData.getChars();
out << result8;
}
}
} // namespace details
#endif

class Logger
Expand All @@ -83,13 +83,20 @@ class Logger
virtual ~Logger() = default;
virtual void log(LogLevel level, const char* filename_in, int line_in, const char* funcname_in,
const char* message) = 0;
virtual void flush() = 0;
};

class Log
{
public:

static void registerLogger(Logger& logger_) { logger = &logger_; }
static void removeLogger() { logger = nullptr; }
static void flush()
{
if (logger) {
logger->flush();
}
}

template <typename... Args>
static void log(const Logger::LogLevel level, const char* filename_in, const int line_in, const char* funcname_in,
Expand All @@ -106,7 +113,8 @@ class Log
static Logger* logger;
};

#define COLORER_LOGGER_PRINTF(level, ...) Log::log(level, __FILE__, __LINE__, static_cast<const char *>(__FUNCTION__), __VA_ARGS__)
#define COLORER_LOGGER_PRINTF(level, ...) \
Log::log(level, __FILE__, __LINE__, static_cast<const char*>(__FUNCTION__), __VA_ARGS__)
#define COLORER_LOG_ERROR(...) COLORER_LOGGER_PRINTF(Logger::LogLevel::LOG_ERROR, __VA_ARGS__)
#define COLORER_LOG_WARN(...) COLORER_LOGGER_PRINTF(Logger::LogLevel::LOG_WARN, __VA_ARGS__)
#define COLORER_LOG_INFO(...) COLORER_LOGGER_PRINTF(Logger::LogLevel::LOG_INFO, __VA_ARGS__)
Expand All @@ -119,5 +127,4 @@ class Log
#define COLORER_LOG_DEEPTRACE(...)
#endif


#endif // COLORER_LOGGER_H
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ uUnicodeString Encodings::toUnicodeString(char* data, int32_t len)
int32_t signatureLength;
encoding = ucnv_detectUnicodeSignature(data, len, &signatureLength, &status);
if (U_FAILURE(status)) {
COLORER_LOG_ERROR("Encodings: Error \"%\" from ucnv_detectUnicodeSignature()\n",
u_errorName(status));
COLORER_LOG_ERROR("Encodings: Error \"%\" from ucnv_detectUnicodeSignature()\n", u_errorName(status));
throw Exception("Error from ucnv_detectUnicodeSignature");
}
if (encoding == nullptr) {
Expand All @@ -23,6 +22,11 @@ uUnicodeString Encodings::toUnicodeString(char* data, int32_t len)
return std::make_unique<UnicodeString>(data + signatureLength, len - signatureLength, encoding);
}

uUnicodeString Encodings::fromUTF8(char* data, int32_t len)
{
return std::make_unique<UnicodeString>(data , len , ENC_UTF8);
}

int Encodings::toUTF8Bytes(UChar wc, byte* dest)
{
int32_t len = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

#include "colorer/strings/icu/common_icu.h"

constexpr char ENC_UTF8[] = "UTF-8";

class Encodings
{
public:
static constexpr char ENC_UTF8[] = "UTF-8";

static uUnicodeString toUnicodeString(char* data, int32_t len);
static uUnicodeString fromUTF8(char* data, int32_t len);
static int toUTF8Bytes(UChar, byte*);
};

Expand Down
5 changes: 5 additions & 0 deletions colorer/src/Colorer-library/src/colorer/strings/icu/UStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ UnicodeString UStr::to_unistr(const int number)
return {std::to_string(number).c_str()};
}

UnicodeString UStr::to_unistr(const std::string& str)
{
return {str.c_str(), static_cast<int32_t>(str.length()), Encodings::ENC_UTF8};
}

std::string UStr::to_stdstr(const UnicodeString* str)
{
std::string out_str;
Expand Down
1 change: 1 addition & 0 deletions colorer/src/Colorer-library/src/colorer/strings/icu/UStr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class UStr
{
public:
[[nodiscard]] static UnicodeString to_unistr(int number);
[[nodiscard]] static UnicodeString to_unistr(const std::string& str);
[[nodiscard]] static std::string to_stdstr(const UnicodeString* str);
[[nodiscard]] static std::string to_stdstr(const uUnicodeString& str);
#ifdef _WINDOWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ wchar Encodings::toWChar(int eidx, char c)

uUnicodeString Encodings::toUnicodeString(char* data, int32_t len)
{
return std::make_unique<UnicodeString>(data , len , -2);
// TODO change ENC_UTF8 to detect
return std::make_unique<UnicodeString>(data, len, Encodings::ENC_UTF8);
}

uUnicodeString Encodings::fromUTF8(char* data, int32_t len)
{
return std::make_unique<UnicodeString>(data, len, Encodings::ENC_UTF8);
}


Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Encodings
static const char* getEncodingName(int enc);

static uUnicodeString toUnicodeString(char* data, int32_t len);
static uUnicodeString fromUTF8(char* data, int32_t len);
};

#endif
Loading

0 comments on commit 8d69f43

Please sign in to comment.