Skip to content

Commit

Permalink
if the numbenr of monitor changes, reload settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Jul 3, 2024
1 parent d38567f commit 9d2c55b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
43 changes: 26 additions & 17 deletions src/bind/mouse/gridmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ namespace vind
int grid_w_ ;
int grid_h_ ;

std::vector<util::Point2D> points_ ;
std::vector<std::string> hint_texts_ ;

std::vector<core::CmdMatcher> 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(
Expand All @@ -53,22 +61,8 @@ namespace vind
void GridMove::sprocess(
std::uint16_t UNUSED(count),
const std::string& UNUSED(args)) {
std::vector<util::Point2D> points ;
std::vector<std::string> hint_texts ;
std::vector<core::Hint> hints ;
pimpl->assign_hints(points, hints, hint_texts) ;

std::vector<core::CmdMatcher> matchers{} ;
matchers.reserve(hints.size()) ;
for(const auto& hint : hints) {
std::vector<core::CmdUnit::SPtr> cmds ;
for(const auto& unit : hint) {
cmds.push_back(std::make_shared<core::CmdUnit>(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() {
Expand All @@ -86,6 +80,21 @@ namespace vind
settable.get("gridmove_size").get<std::string>(), "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<core::Hint> hints ;
pimpl->assign_hints(pimpl->points_, hints, pimpl->hint_texts_) ;

pimpl->matchers_.clear() ;
for(const auto& hint : hints) {
std::vector<core::CmdUnit::SPtr> cmds ;
for(const auto& unit : hint) {
cmds.push_back(std::make_shared<core::CmdUnit>(unit)) ;
}
pimpl->matchers_.emplace_back(std::move(cmds)) ;
}
}

void GridMove::Impl::assign_hints(
Expand Down
13 changes: 12 additions & 1 deletion src/core/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -108,6 +109,8 @@ namespace vind

DWORD previous_procid_ ;

std::size_t num_of_monitor_ ;

template <typename ExitFuncType, typename String>
Impl(ExitFuncType&& exitfunc, String&& memname, std::size_t memsize)
: exit_(std::forward<ExitFuncType>(exitfunc)),
Expand All @@ -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 {
Expand Down Expand Up @@ -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 ;
Expand Down

0 comments on commit 9d2c55b

Please sign in to comment.