From 23ac33395fc55bb4bc9f31039f73a4d42cb64999 Mon Sep 17 00:00:00 2001 From: pit-ray Date: Thu, 4 Jan 2024 01:15:53 +0900 Subject: [PATCH] add move_window_* and fix the prefix-number parsing. --- CMakeLists.txt | 2 +- res/resources/defaults/small.vindrc | 6 ++ src/bind/bindinglist.cpp | 15 ++-- src/bind/window/move_win.cpp | 123 ++++++++++++++++++++++++++++ src/bind/window/move_win.hpp | 36 ++++++++ src/bind/window/movewindow.cpp | 0 src/bind/window/movewindow.hpp | 4 - src/core/inputhub.cpp | 19 +++-- src/core/mapsolver.cpp | 12 ++- src/core/mapsolver.hpp | 3 + src/core/version.hpp | 2 +- src/util/winwrap.cpp | 6 ++ src/util/winwrap.hpp | 2 + 13 files changed, 210 insertions(+), 20 deletions(-) create mode 100644 src/bind/window/move_win.cpp create mode 100644 src/bind/window/move_win.hpp delete mode 100644 src/bind/window/movewindow.cpp delete mode 100644 src/bind/window/movewindow.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eda9ae1..8fd04ada 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6.0) project(win-vind VERSION 5.6.0) -set(INTERNAL_VERSION ${PROJECT_VERSION}.0) +set(INTERNAL_VERSION ${PROJECT_VERSION}.1) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) diff --git a/res/resources/defaults/small.vindrc b/res/resources/defaults/small.vindrc index 1dbc06e4..bb938f7e 100644 --- a/res/resources/defaults/small.vindrc +++ b/res/resources/defaults/small.vindrc @@ -16,6 +16,12 @@ gnnoremap k gnnoremap j gnnoremap s +" @ Window Movement +gnnoremap +gnnoremap +gnnoremap +gnnoremap + " @ Window Resize gnnoremap = gnnoremap r diff --git a/src/bind/bindinglist.cpp b/src/bind/bindinglist.cpp index 975fec9b..29353727 100644 --- a/src/bind/bindinglist.cpp +++ b/src/bind/bindinglist.cpp @@ -50,6 +50,7 @@ #include "window/close_win.hpp" #include "window/exchange_win.hpp" #include "window/minmax_win.hpp" +#include "window/move_win.hpp" #include "window/reload_win.hpp" #include "window/resize_win.hpp" #include "window/rotate_win.hpp" @@ -135,6 +136,11 @@ namespace vind MakeDir::create(), MaximizeCurrentWindow::create(), MinimizeCurrentWindow::create(), + MoveBckBigWord::create(), + MoveBckEndBigWord::create(), + MoveBckEndWord::create(), + MoveBckWord::create(), + MoveBckWordSimple::create(), MoveCaretDown::create(), MoveCaretLeft::create(), MoveCaretNonBlankWordBackward::create(), @@ -147,16 +153,15 @@ namespace vind MoveCursorLeft::create(), MoveCursorRight::create(), MoveCursorUp::create(), - MoveBckBigWord::create(), - MoveBckEndBigWord::create(), - MoveBckEndWord::create(), - MoveBckWord::create(), - MoveBckWordSimple::create(), MoveEndBigWord::create(), MoveEndWord::create(), MoveFwdBigWord::create(), MoveFwdWord::create(), MoveFwdWordSimple::create(), + MoveWindowDown::create(), + MoveWindowLeft::create(), + MoveWindowRight::create(), + MoveWindowUp::create(), Open::create(), OpenNewTab::create(), OpenNewWindow::create(), diff --git a/src/bind/window/move_win.cpp b/src/bind/window/move_win.cpp new file mode 100644 index 00000000..ec4beb0b --- /dev/null +++ b/src/bind/window/move_win.cpp @@ -0,0 +1,123 @@ +#include "move_win.hpp" + +#include "core/settable.hpp" +#include "util/debug.hpp" +#include "util/screen_metrics.hpp" +#include "util/winwrap.hpp" + +#include + + +namespace vind +{ + namespace bind + { + MoveWindowLeft::MoveWindowLeft() + : BindedFuncVoid("move_window_left") + {} + + void MoveWindowLeft::sprocess( + std::uint16_t count, + const std::string& UNUSED(args)) { + auto hwnd = util::get_foreground_window() ; + if(!hwnd) { + return ; + } + + auto delta = core::SetTable::get_instance().get("window_velocity").get() ; + delta *= static_cast(count) ; + + auto rect = util::get_window_rect(hwnd) ; + auto cb_rect = util::get_combined_metrics() ; + + auto left = (std::max)(rect.left() - delta, cb_rect.left()) ; + auto top = rect.top() ; + auto width = rect.width() ; + auto height = rect.height() ; + + util::move_window(hwnd, left, top, width, height) ; + } + + MoveWindowRight::MoveWindowRight() + : BindedFuncVoid("move_window_right") + {} + + void MoveWindowRight::sprocess( + std::uint16_t count, + const std::string& UNUSED(args)) { + auto hwnd = util::get_foreground_window() ; + if(!hwnd) { + return ; + } + + auto delta = core::SetTable::get_instance().get("window_velocity").get() ; + delta *= static_cast(count) ; + + auto rect = util::get_window_rect(hwnd) ; + auto width = rect.width() ; + auto height = rect.height() ; + + auto cb_rect = util::get_combined_metrics() ; + auto max_x = (std::max)(cb_rect.right() - width, static_cast(0)) ; + + auto left = (std::min)(rect.left() + delta, max_x) ; + auto top = rect.top() ; + + util::move_window(hwnd, left, top, width, height) ; + } + + MoveWindowUp::MoveWindowUp() + : BindedFuncVoid("move_window_up") + {} + + void MoveWindowUp::sprocess( + std::uint16_t count, + const std::string& UNUSED(args)) { + auto hwnd = util::get_foreground_window() ; + if(!hwnd) { + return ; + } + + auto delta = core::SetTable::get_instance().get("window_velocity").get() ; + delta *= static_cast(count) ; + + auto rect = util::get_window_rect(hwnd) ; + auto cb_rect = util::get_combined_metrics() ; + + auto left = rect.left() ; + auto top = (std::max)(rect.top() - delta, cb_rect.top()) ; + auto width = rect.width() ; + auto height = rect.height() ; + + util::move_window(hwnd, left, top, width, height) ; + } + + MoveWindowDown::MoveWindowDown() + : BindedFuncVoid("move_window_down") + {} + + void MoveWindowDown::sprocess( + std::uint16_t count, + const std::string& UNUSED(args)) { + auto hwnd = util::get_foreground_window() ; + if(!hwnd) { + return ; + } + + auto delta = core::SetTable::get_instance().get("window_velocity").get() ; + delta *= static_cast(count) ; + + auto rect = util::get_window_rect(hwnd) ; + auto width = rect.width() ; + auto height = rect.height() ; + + auto cb_rect = util::get_combined_metrics() ; + auto max_y = (std::max)(cb_rect.bottom() - height, static_cast(0)) ; + + auto left = rect.left() ; + auto top = (std::min)(rect.top() + delta, max_y) ; + + util::move_window(hwnd, left, top, width, height) ; + } + } +} diff --git a/src/bind/window/move_win.hpp b/src/bind/window/move_win.hpp new file mode 100644 index 00000000..8a47f649 --- /dev/null +++ b/src/bind/window/move_win.hpp @@ -0,0 +1,36 @@ +#ifndef _MOVEWINDOW_HPP +#define _MOVEWINDOW_HPP + +#include "bind/bindedfunc.hpp" + +namespace vind +{ + namespace bind + { + struct MoveWindowLeft : public BindedFuncVoid { + explicit MoveWindowLeft() ; + static void sprocess( + std::uint16_t count, const std::string& args) ; + } ; + + struct MoveWindowRight : public BindedFuncVoid { + explicit MoveWindowRight() ; + static void sprocess( + std::uint16_t count, const std::string& args) ; + } ; + + struct MoveWindowUp : public BindedFuncVoid { + explicit MoveWindowUp() ; + static void sprocess( + std::uint16_t count, const std::string& args) ; + } ; + + struct MoveWindowDown : public BindedFuncVoid { + explicit MoveWindowDown() ; + static void sprocess( + std::uint16_t count, const std::string& args) ; + } ; + } +} + +#endif diff --git a/src/bind/window/movewindow.cpp b/src/bind/window/movewindow.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/bind/window/movewindow.hpp b/src/bind/window/movewindow.hpp deleted file mode 100644 index 35b2fb12..00000000 --- a/src/bind/window/movewindow.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _MOVEWINDOW_HPP -#define _MOVEWINDOW_HPP - -#endif diff --git a/src/core/inputhub.cpp b/src/core/inputhub.cpp index 4308d7c1..bbef4866 100644 --- a/src/core/inputhub.cpp +++ b/src/core/inputhub.cpp @@ -144,11 +144,7 @@ namespace vind } auto solver = get_solver(mode) ; - if(parse_count && !solver->is_matching_any()) { - if(!pimpl->count_.empty() && pimpl->count_.back() == ';') { - pimpl->count_.clear() ; // Erase previous counts. - } - + if(parse_count && solver->max_history_size() == 0) { // parses the sequence of head counts as the string // and converts them into a number. auto new_count = extract_numbers( @@ -160,13 +156,14 @@ namespace vind } if(!pimpl->count_.empty()) { - pimpl->count_ += ';' ; // Final symbol of counts + if(pimpl->count_.back() != ';') { + pimpl->count_ += ';' ; // Final symbol of counts + } count = util::extract_num(pimpl->count_) ; } else { count = 1 ; } - fetched_input = input ; return true ; } @@ -239,7 +236,13 @@ namespace vind std::uint16_t prefix_count, Mode mode) { auto solver = get_solver(mode) ; - auto map_cmd = solver->map_command_from(*input) ; + auto map_cmd = solver->map_command_from(*input, false) ; + if(solver->is_accepted_any() || solver->is_rejected_all()) { + if(!pimpl->count_.empty() && pimpl->count_.back() == ';') { + pimpl->count_.clear() ; // Erase previous counts. + } + solver->reset_state() ; + } if(map_cmd.empty()) { return false ; } diff --git a/src/core/mapsolver.cpp b/src/core/mapsolver.cpp index 84b414e3..94569ba3 100644 --- a/src/core/mapsolver.cpp +++ b/src/core/mapsolver.cpp @@ -568,7 +568,7 @@ namespace vind bool MapSolver::is_matching_any() const noexcept { for(const auto& map : pimpl->deployed_) { - if(map.trigger_matcher.history_size() > 0) { + if(map.trigger_matcher.is_matching()) { return true ; } } @@ -603,5 +603,15 @@ namespace vind } return flag ; } + + std::size_t MapSolver::max_history_size() const noexcept { + std::size_t size = 0 ; + for(const auto& map : pimpl->deployed_) { + if(map.trigger_matcher.history_size() > size) { + size = map.trigger_matcher.history_size() ; + } + } + return size ; + } } } diff --git a/src/core/mapsolver.hpp b/src/core/mapsolver.hpp index 9d385ffc..33323477 100644 --- a/src/core/mapsolver.hpp +++ b/src/core/mapsolver.hpp @@ -83,6 +83,9 @@ namespace vind bool is_accepted_any() const noexcept ; bool is_rejected_any() const noexcept ; bool is_rejected_all() const noexcept ; + + // Return the maximum history size. + std::size_t max_history_size() const noexcept ; } ; } } diff --git a/src/core/version.hpp b/src/core/version.hpp index 08dd0afc..df49308d 100644 --- a/src/core/version.hpp +++ b/src/core/version.hpp @@ -1,6 +1,6 @@ #ifndef _VERSION_HPP #define _VERSION_HPP -#define WIN_VIND_VERSION "5.5.2.0" +#define WIN_VIND_VERSION "5.6.0.1" #endif diff --git a/src/util/winwrap.cpp b/src/util/winwrap.cpp index 1e54b525..dca8c97c 100644 --- a/src/util/winwrap.cpp +++ b/src/util/winwrap.cpp @@ -68,6 +68,12 @@ namespace vind return rect ; } + void move_window(HWND hwnd, long left, long top, long width, long height) { + if(!MoveWindow(hwnd, left, top, width, height, TRUE)) { + throw RUNTIME_EXCEPT("Could not move the foreground window.") ; + } + } + template inline void create_process_core( StdString&& cmd, diff --git a/src/util/winwrap.hpp b/src/util/winwrap.hpp index f5b73e36..53888efb 100644 --- a/src/util/winwrap.hpp +++ b/src/util/winwrap.hpp @@ -26,6 +26,8 @@ namespace vind Box2D get_window_rect(HWND hwnd) ; Box2D get_client_rect(HWND hwnd) ; + void move_window(HWND hwnd, long left, long top, long width, long height) ; + inline BOOL b_to_B(bool b) noexcept { return b ? TRUE : FALSE ; }