Skip to content

Commit

Permalink
Update vtshell.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz authored Dec 14, 2024
1 parent d462ce4 commit 4732c84
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions far2l/src/vt/vtshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
#include "AnsiEsc.hpp"
#include "TestPath.h"

#define BRACKETED_PASTE_SEQ_START "\x1b[200~"
#define BRACKETED_PASTE_SEQ_STOP "\x1b[201~"
#define BRACKETED_PASTE_SEQ_START "\x1b[200~"
#define BRACKETED_PASTE_SEQ_STOP "\x1b[201~"
#define FOCUS_CHANGED_SEQ_ACTIVE "\x1b[I"
#define FOCUS_CHANGED_SEQ_INACTIVE "\x1b[O"

const char *VT_TranslateSpecialKey(const WORD key, bool ctrl, bool alt, bool shift, unsigned char keypad = 0, WCHAR uc = 0);
std::string VT_TranslateKeyToKitty(const KEY_EVENT_RECORD &KeyEvent, int kitty_kb_flags);
Expand Down Expand Up @@ -118,6 +120,7 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor, IVTShell
std::atomic<unsigned char> _keypad{0};
std::atomic<bool> _bracketed_paste_expected{false};
std::atomic<bool> _win32_input_mode_expected{false};
std::atomic<bool> _focus_change_expected{false};
std::atomic<int> _kitty_kb_flags{0};
INPUT_RECORD _last_window_info_ir;
std::unique_ptr<VTFar2lExtensios> _far2l_exts;
Expand Down Expand Up @@ -456,6 +459,21 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor, IVTShell
}
}

virtual void OnFocusChanged() // called from worker thread
{
if (_focus_change_expected) {
bool active = WINPORT(IsConsoleActive)() != FALSE;
const char *seq = active ? FOCUS_CHANGED_SEQ_ACTIVE : FOCUS_CHANGED_SEQ_INACTIVE;
if (!WriteTerm(seq, strlen(seq))) {
fprintf(stderr, "VT: OnFocusChanged - write error %d\n", errno);
} else {
fprintf(stderr, "VT: OnFocusChanged - %s\n", active ? "active" : "inactive");
}
} else {
fprintf(stderr, "VT: OnFocusChanged - SKIPPED\n");
}
}

void OnCtrlC(bool alt)
{
if (alt) {
Expand Down Expand Up @@ -554,6 +572,14 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor, IVTShell
_bracketed_paste_expected = enabled;
}

virtual void OnFocusChangeExpectation(bool enabled)
{
bool was_enabled = _focus_change_expected.exchange(enabled);
if (!was_enabled) {
OnFocusChanged();
}
}

virtual void OnWin32InputMode(bool enabled)
{
_win32_input_mode_expected = enabled;
Expand Down

0 comments on commit 4732c84

Please sign in to comment.