[FarGroup/FarManager] master: Refactoring & minor fixes (bf318ad50)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Feb 2, 2026, 7:30:57 PM (4 days ago) Feb 2
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/bf318ad508e0715f5b4a1f55d65ed73980856673

>---------------------------------------------------------------

commit bf318ad508e0715f5b4a1f55d65ed73980856673
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Tue Feb 3 00:21:09 2026 +0000

Refactoring & minor fixes


>---------------------------------------------------------------

bf318ad508e0715f5b4a1f55d65ed73980856673
far/changelog | 5 +++++
far/keyboard.cpp | 6 +++---
far/log.cpp | 8 ++++----
far/platform.concurrency.cpp | 19 -------------------
far/platform.concurrency.hpp | 6 +-----
far/string_sort.cpp | 21 ++++++++++++---------
far/taskbar.cpp | 18 ++++++++++--------
far/vbuild.m4 | 2 +-
far/wm_listener.cpp | 28 +++++++++++++---------------
9 files changed, 49 insertions(+), 64 deletions(-)

diff --git a/far/changelog b/far/changelog
index 4f3a5ffe8..95869de87 100644
--- a/far/changelog
+++ b/far/changelog
@@ -1,3 +1,8 @@
+--------------------------------------------------------------------------------
+drkns 2026-02-03 00:20:49+00:00 - build 6641
+
+1. Refactoring & minor fixes.
+
--------------------------------------------------------------------------------
birdie-github 2026-01-31 16:27:32+00:00 - build 6640

diff --git a/far/keyboard.cpp b/far/keyboard.cpp
index caa6b1a63..7f6807050 100644
--- a/far/keyboard.cpp
+++ b/far/keyboard.cpp
@@ -641,13 +641,13 @@ public:
static auto& ref()
{
if (!s_WakeEvent)
- s_WakeEvent = os::concurrency::event(os::event::type::automatic, os::event::state::nonsignaled);
+ s_WakeEvent.emplace(os::event::type::automatic, os::event::state::nonsignaled);

- return s_WakeEvent;
+ return *s_WakeEvent;
}

private:
- static inline os::concurrency::event s_WakeEvent;
+ static inline std::optional<os::concurrency::event> s_WakeEvent;
};

void main_loop_process_messages()
diff --git a/far/log.cpp b/far/log.cpp
index 788cb9fa8..8bb363a96 100644
--- a/far/log.cpp
+++ b/far/log.cpp
@@ -601,7 +601,7 @@ namespace
class async_impl
{
protected:
- explicit async_impl(std::function<void(message&&)> Out, bool const IsDiscardable, string_view const Name):
+ explicit async_impl(std::function<void(message const&)> Out, bool const IsDiscardable, string_view const Name):
m_Out(std::move(Out)),
m_IsDiscardable(IsDiscardable),
m_Thread(&async_impl::poll, this, Name)
@@ -649,7 +649,7 @@ namespace
if (m_IsDiscardable && m_FinishEvent.is_signaled())
return;

- m_Out(std::move(Messages.front()));
+ m_Out(Messages.front());
}
}
},
@@ -662,7 +662,7 @@ namespace
os::synced_queue<message> m_Messages;
os::event m_MessageEvent { os::event::type::automatic, os::event::state::nonsignaled };
os::event m_FinishEvent { os::event::type::manual, os::event::state::nonsignaled };
- std::function<void(message&&)> m_Out;
+ std::function<void(message const&)> m_Out;
bool m_IsDiscardable;
os::thread m_Thread;
};
@@ -680,7 +680,7 @@ namespace
static constexpr auto mode = sink_mode::async;

explicit async(bool const IsDiscardable):
- synchronized_impl([&](message const& Message){ sink_boilerplate<sink_type>::handle_impl(Message); }, IsDiscardable, sink_type::name)
+ synchronized_impl([this](message const& Message){ this->sink_boilerplate<sink_type>::handle_impl(Message); }, IsDiscardable, sink_type::name)
{
}

diff --git a/far/platform.concurrency.cpp b/far/platform.concurrency.cpp
index 6a34893a3..68692eba7 100644
--- a/far/platform.concurrency.cpp
+++ b/far/platform.concurrency.cpp
@@ -262,32 +262,21 @@ namespace os::concurrency

void event::set() const
{
- check_valid();
if (!SetEvent(get()))
throw far_fatal_exception(L"SetEvent failed"sv);
}

void event::reset() const
{
- check_valid();
if (!ResetEvent(get()))
throw far_fatal_exception(L"ResetEvent failed"sv);
}

void event::associate(OVERLAPPED& o) const
{
- check_valid();
o.hEvent = get();
}

- void event::check_valid() const
- {
- if (!*this)
- {
- throw far_fatal_exception(L"Event is not initialized properly"sv);
- }
- }
-
static void CALLBACK wrapper(void* const Parameter, BOOLEAN)
{
const auto& Callable = view_as<std::function<void()>>(Parameter);
@@ -401,14 +390,6 @@ TEST_CASE("platform.concurrency.event")
Event.reset();
REQUIRE(!Event.is_signaled());
}
-
- {
- os::event const Event;
- OVERLAPPED o;
- REQUIRE_THROWS_AS(Event.associate(o), far_fatal_exception);
- REQUIRE_THROWS_AS(Event.set(), far_fatal_exception);
- REQUIRE_THROWS_AS(Event.reset(), far_fatal_exception);
- }
}

TEST_CASE("platform.concurrency.timer")
diff --git a/far/platform.concurrency.hpp b/far/platform.concurrency.hpp
index d7573ee1c..369b0d3c9 100644
--- a/far/platform.concurrency.hpp
+++ b/far/platform.concurrency.hpp
@@ -179,12 +179,11 @@ namespace os::concurrency
{
public:
NONCOPYABLE(event);
- MOVABLE(event);
+ MOVE_CONSTRUCTIBLE(event);

enum class type { automatic, manual };
enum class state { nonsignaled, signaled };

- event() = default;
event(type Type, state InitialState, string_view Name = {});

[[nodiscard]]
@@ -193,9 +192,6 @@ namespace os::concurrency
void set() const;
void reset() const;
void associate(OVERLAPPED& o) const;
-
- private:
- void check_valid() const;
};

class timer
diff --git a/far/string_sort.cpp b/far/string_sort.cpp
index 34e7d1585..e637e324f 100644
--- a/far/string_sort.cpp
+++ b/far/string_sort.cpp
@@ -205,7 +205,10 @@ static const auto& create_alt_sort_table()
return a < b;
});

- int u_beg = 0, u_end = 0xffff;
+ int
+ u_beg = std::numeric_limits<wchar_t>::min(),
+ u_end = std::numeric_limits<wchar_t>::max();
+
for (const auto ic: std::views::iota(0, TableSize))
{
if (chars[ic] == L'a')
@@ -216,7 +219,7 @@ static const auto& create_alt_sort_table()
alt_sort_table[chars[ic]] = static_cast<wchar_t>(ic);
}

- for (int ic=0xffff; ic > u_beg; --ic)
+ for (int ic = u_end; ic > u_beg; --ic)
{
if (is_upper(chars[ic]))
{
@@ -225,7 +228,7 @@ static const auto& create_alt_sort_table()
}
alt_sort_table[chars[ic]] = static_cast<wchar_t>(ic);
}
- assert(u_beg > 0 && u_beg < u_end && u_end < 0xffff);
+ assert(u_beg > std::numeric_limits<wchar_t>::min() && u_beg < u_end && u_end < std::numeric_limits<wchar_t>::max());

int cc = u_beg;
for (const auto ic: std::views::iota(u_beg, u_end + 1)) // uppercase first
@@ -268,7 +271,7 @@ struct invariant_comparer_icase

static auto compare_invariant(const string_view Str1, const string_view Str2)
{
- return per_char_compare(Str1, Str2, [&](string_view::const_iterator& It1, string_view::const_iterator, string_view::const_iterator& It2, string_view::const_iterator)
+ return per_char_compare(Str1, Str2, [](string_view::const_iterator& It1, string_view::const_iterator, string_view::const_iterator& It2, string_view::const_iterator)
{
return invariant_comparer{}(*It1++, *It2++);
});
@@ -276,7 +279,7 @@ static auto compare_invariant(const string_view Str1, const string_view Str2)

static auto compare_invariant_icase(const string_view Str1, const string_view Str2)
{
- return per_char_compare(Str1, Str2, [&](string_view::const_iterator& It1, string_view::const_iterator, string_view::const_iterator& It2, string_view::const_iterator)
+ return per_char_compare(Str1, Str2, [](string_view::const_iterator& It1, string_view::const_iterator, string_view::const_iterator& It2, string_view::const_iterator)
{
return invariant_comparer{}(upper(*It1++), upper(*It2++));
});
@@ -321,7 +324,7 @@ static auto compare_natural_base(const string_view Str1, const string_view Str2,
if (const auto Result = CompareString(LOCALE_USER_DEFAULT, Flags, Str1.data(), static_cast<int>(Str1.size()), Str2.data(), static_cast<int>(Str2.size())))
return windows_to_std(Result);

- static const decltype(&string_sort::compare) FallbackComparers[2][2]
+ static constexpr decltype(&string_sort::compare) FallbackComparers[2][2]
{
{ compare_invariant_icase, compare_invariant },
{ compare_invariant_numeric_icase, compare_invariant_numeric },
@@ -375,9 +378,9 @@ void string_sort::adjust_comparer(size_t const Collation, bool const CaseSensiti
},
};

- const auto CollationIdex = std::clamp(0uz, Collation, std::size(Comparers) - 1uz);
+ const auto CollationIndex = std::clamp(Collation, 0uz, std::size(Comparers) - 1uz);

- DefaultComparer = Comparers[CollationIdex][DigitsAsNumbers][CaseSensitive];
+ DefaultComparer = Comparers[CollationIndex][DigitsAsNumbers][CaseSensitive];
}

bool string_sort::less_icase_t::operator()(string_view Str1, string_view Str2) const
@@ -440,7 +443,7 @@ TEST_CASE("strings.sorting")
{ L"a1"sv, L"A2"sv, gt, lt, },
};

- const auto invert = [&](std::strong_ordering const Result)
+ const auto invert = [](std::strong_ordering const Result)
{
return Result == lt? gt : Result == gt? lt : eq;
};
diff --git a/far/taskbar.cpp b/far/taskbar.cpp
index 06137e4f1..2ff1949f3 100644
--- a/far/taskbar.cpp
+++ b/far/taskbar.cpp
@@ -61,6 +61,9 @@ class taskbar_impl : public singleton<taskbar_impl>
public:
void set_state(TBPFLAG const State)
{
+ if (!m_ComThread)
+ return;
+
if (m_State == State)
return;

@@ -73,6 +76,9 @@ public:

void set_value(unsigned long long const Completed, unsigned long long const Total)
{
+ if (!m_ComThread)
+ return;
+
const auto NewState = any_of(m_State, TBPF_NOPROGRESS, TBPF_INDETERMINATE)? TBPF_NORMAL : m_State.load();

if (m_State == NewState && m_Completed == Completed && m_Total == Total)
@@ -115,12 +121,6 @@ private:
return;
}

- if (!TaskbarList)
- {
- LOGWARNING(L"!TaskbarList"sv);
- return;
- }
-
for (;;)
{
switch (os::handle::wait_any(m_ExitEvent, m_StateEvent, m_ValueEvent))
@@ -129,11 +129,13 @@ private:
return;

case 1:
- TaskbarList->SetProgressState(console.GetWindow(), m_State);
+ if (const auto Result = TaskbarList->SetProgressState(console.GetWindow(), m_State); FAILED(Result))
+ LOGWARNING(L"SetProgressState(): {}"sv, os::format_error(Result));
break;

case 2:
- TaskbarList->SetProgressValue(console.GetWindow(), m_Completed, m_Total);
+ if (const auto Result = TaskbarList->SetProgressValue(console.GetWindow(), m_Completed, m_Total); FAILED(Result))
+ LOGWARNING(L"SetProgressValue(): {}"sv, os::format_error(Result));
break;
}
}
diff --git a/far/vbuild.m4 b/far/vbuild.m4
index 28d2ab292..9f9cfdb8c 100644
--- a/far/vbuild.m4
+++ b/far/vbuild.m4
@@ -1 +1 @@
-6640
+6641
diff --git a/far/wm_listener.cpp b/far/wm_listener.cpp
index b335eb788..b03be1fc2 100644
--- a/far/wm_listener.cpp
+++ b/far/wm_listener.cpp
@@ -39,7 +39,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Internal:
#include "imports.hpp"
#include "notification.hpp"
-#include "global.hpp"
#include "exception_handler.hpp"
#include "log.hpp"

@@ -64,10 +63,6 @@ static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lPara
{
switch (Msg)
{
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
case WM_DEVICECHANGE:
{
switch (wParam)
@@ -167,8 +162,10 @@ void wm_listener::enable_power_notifications()
if (!imports.RegisterPowerSettingNotification)
return;

- m_PowerNotify.reset(imports.RegisterPowerSettingNotification(m_Hwnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE));
+ if (!m_Hwnd)
+ return;

+ m_PowerNotify.reset(imports.RegisterPowerSettingNotification(m_Hwnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE));
if (!m_PowerNotify)
LOGWARNING(L"RegisterPowerSettingNotification(): {}"sv, os::last_error());
}
@@ -196,9 +193,7 @@ wm_listener::wm_listener()
wm_listener::~wm_listener()
{
if(m_Hwnd)
- {
- SendMessage(m_Hwnd, WM_CLOSE, 0, 0);
- }
+ PostMessage(m_Hwnd, WM_QUIT, 0, 0);
}

void wm_listener::Check()
@@ -214,9 +209,6 @@ void wm_listener::WindowThreadRoutine(const os::event& ReadyEvent)
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"FarHiddenWindowClass";

- if (UnregisterClass(wc.lpszClassName, nullptr))
- LOGWARNING(L"Class {} was already registered"sv, wc.lpszClassName);
-
if (!RegisterClassEx(&wc))
{
LOGERROR(L"RegisterClassEx(): {}"sv, os::last_error());
@@ -230,6 +222,8 @@ void wm_listener::WindowThreadRoutine(const os::event& ReadyEvent)
LOGWARNING(L"UnregisterClass(): {}"sv, os::last_error());
};

+ WndProcExceptionPtr = &m_ExceptionPtr;
+
m_Hwnd = CreateWindowEx(0, wc.lpszClassName, nullptr, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, nullptr, nullptr);
if (!m_Hwnd)
{
@@ -239,7 +233,6 @@ void wm_listener::WindowThreadRoutine(const os::event& ReadyEvent)
}

MSG Msg;
- WndProcExceptionPtr = &m_ExceptionPtr;

ReadyEvent.set();

@@ -247,15 +240,20 @@ void wm_listener::WindowThreadRoutine(const os::event& ReadyEvent)
{
const auto Result = GetMessage(&Msg, nullptr, 0, 0);
if (!Result)
- return;
+ break;

if (Result < 0)
{
LOGERROR(L"GetMessage(): {}"sv, os::last_error());
- return;
+ break;
}

TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
+
+ if (!DestroyWindow(m_Hwnd))
+ LOGWARNING(L"DestroyWindow(): {}"sv, os::last_error());
+
+ m_Hwnd = {};
}


Reply all
Reply to author
Forward
0 new messages