From 9d2c55b6e5a66c0a4d782aef5f0233eb35cbf443 Mon Sep 17 00:00:00 2001 From: pit-ray Date: Wed, 3 Jul 2024 23:50:31 +0900 Subject: [PATCH] if the numbenr of monitor changes, reload settings --- src/bind/mouse/gridmove.cpp | 43 ++++++++++++++++++++++--------------- src/core/entry.cpp | 13 ++++++++++- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/bind/mouse/gridmove.cpp b/src/bind/mouse/gridmove.cpp index f9ee814a..f27b271b 100644 --- a/src/bind/mouse/gridmove.cpp +++ b/src/bind/mouse/gridmove.cpp @@ -28,11 +28,19 @@ namespace vind int grid_w_ ; int grid_h_ ; + std::vector points_ ; + std::vector hint_texts_ ; + + std::vector matchers_ ; + Impl() : hinter_(opt::search_options( opt::VCmdLine().name())), grid_w_(0), - grid_h_(0) + grid_h_(0), + points_(), + hint_texts_(), + matchers_() {} void assign_hints( @@ -53,22 +61,8 @@ namespace vind void GridMove::sprocess( std::uint16_t UNUSED(count), const std::string& UNUSED(args)) { - std::vector points ; - std::vector hint_texts ; - std::vector hints ; - pimpl->assign_hints(points, hints, hint_texts) ; - - std::vector matchers{} ; - matchers.reserve(hints.size()) ; - for(const auto& hint : hints) { - std::vector cmds ; - for(const auto& unit : hint) { - cmds.push_back(std::make_shared(unit)) ; - } - matchers.emplace_back(std::move(cmds)) ; - } - - pimpl->hinter_.start_matching(points, hint_texts, matchers) ; + pimpl->hinter_.start_matching( + pimpl->points_, pimpl->hint_texts_, pimpl->matchers_) ; } void GridMove::reconstruct() { @@ -86,6 +80,21 @@ namespace vind settable.get("gridmove_size").get(), "x") ; pimpl->grid_w_ = std::stoi(size[0]) ; pimpl->grid_h_ = std::stoi(size[1]) ; + + // Pre-computes the coordinates of the hints when some parameters are changed. + pimpl->points_.clear() ; + pimpl->hint_texts_.clear() ; + std::vector hints ; + pimpl->assign_hints(pimpl->points_, hints, pimpl->hint_texts_) ; + + pimpl->matchers_.clear() ; + for(const auto& hint : hints) { + std::vector cmds ; + for(const auto& unit : hint) { + cmds.push_back(std::make_shared(unit)) ; + } + pimpl->matchers_.emplace_back(std::move(cmds)) ; + } } void GridMove::Impl::assign_hints( diff --git a/src/core/entry.cpp b/src/core/entry.cpp index ef9b6dc8..8bbcba1a 100644 --- a/src/core/entry.cpp +++ b/src/core/entry.cpp @@ -84,6 +84,7 @@ SOFTWARE. #include "opt/vcmdline.hpp" #include "util/debug.hpp" #include "util/interval_timer.hpp" +#include "util/screen_metrics.hpp" #include "util/type_traits.hpp" #include "util/winwrap.hpp" @@ -108,6 +109,8 @@ namespace vind DWORD previous_procid_ ; + std::size_t num_of_monitor_ ; + template Impl(ExitFuncType&& exitfunc, String&& memname, std::size_t memsize) : exit_(std::forward(exitfunc)), @@ -117,7 +120,8 @@ namespace vind subprocess_(false), memread_timer_(1000'000), //1 s bg_(opt::all_global_options()), - previous_procid_(0) + previous_procid_(0), + num_of_monitor_(util::get_all_monitor_metrics().size()) {} ~Impl() noexcept { @@ -372,6 +376,13 @@ namespace vind } } + // If the number of monitors changes, reload the settings. + auto current_num_of_monitor = util::get_all_monitor_metrics().size() ; + if(current_num_of_monitor != pimpl->num_of_monitor_) { + reconstruct() ; + pimpl->num_of_monitor_ = current_num_of_monitor ; + } + do { CmdUnit::SPtr input ; std::uint16_t count = 0 ;