diff --git a/libs/fluent_tray/fluent_tray.hpp b/libs/fluent_tray/fluent_tray.hpp index a608c92a..234f2d4d 100644 --- a/libs/fluent_tray/fluent_tray.hpp +++ b/libs/fluent_tray/fluent_tray.hpp @@ -937,26 +937,24 @@ namespace fluent_tray } POINT pos ; - if(!GetCursorPos(&pos)) { - return false ; - } - - if(pos.x != previous_mouse_pos_.x || pos.y != previous_mouse_pos_.y) { - // The mouse cursor is moved, so switch to the mouse-mode. - for(int i = 0 ; i < static_cast(menus_.size()) ; i ++) { - auto& menu = menus_[i] ; - auto detected_hwnd = WindowFromPoint(pos) ; - if(!detected_hwnd) { - return false ; - } - // Checks whether the mouse cursor is over the menu or not. - if(detected_hwnd == menu.window_handle()) { - // Start selection by key from the currently selected menu. - select_index_ = i ; - break ; + if(GetCursorPos(&pos)) { + if(pos.x != previous_mouse_pos_.x || pos.y != previous_mouse_pos_.y) { + // The mouse cursor is moved, so switch to the mouse-mode. + for(int i = 0 ; i < static_cast(menus_.size()) ; i ++) { + auto& menu = menus_[i] ; + auto detected_hwnd = WindowFromPoint(pos) ; + if(!detected_hwnd) { + return false ; + } + // Checks whether the mouse cursor is over the menu or not. + if(detected_hwnd == menu.window_handle()) { + // Start selection by key from the currently selected menu. + select_index_ = i ; + break ; + } } + previous_mouse_pos_ = pos ; } - previous_mouse_pos_ = pos ; } if(select_index_ < 0) { @@ -1422,7 +1420,10 @@ namespace fluent_tray if(!Shell_NotifyIconW(NIM_ADD, &icon_data_)) { return false ; } - hide_menu_window() ; + + if(!hide_menu_window()) { + return false ; + } return true ; } diff --git a/src/bind/emu/motion.cpp b/src/bind/emu/motion.cpp index 5a71cffc..252f33f5 100644 --- a/src/bind/emu/motion.cpp +++ b/src/bind/emu/motion.cpp @@ -56,7 +56,9 @@ namespace vind auto solver = ihub.get_solver(Mode::EDI_NORMAL) ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } core::CmdUnit::SPtr input ; std::uint16_t in_count ; @@ -118,7 +120,9 @@ namespace vind auto solver = ihub.get_solver(Mode::EDI_NORMAL) ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } core::CmdUnit::SPtr input ; std::uint16_t in_count ; @@ -178,7 +182,9 @@ namespace vind auto solver = ihub.get_solver(Mode::EDI_NORMAL) ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } core::CmdUnit::SPtr input ; std::uint16_t in_count ; diff --git a/src/bind/emu/replacetext.cpp b/src/bind/emu/replacetext.cpp index 98189e7b..247495f5 100644 --- a/src/bind/emu/replacetext.cpp +++ b/src/bind/emu/replacetext.cpp @@ -66,7 +66,9 @@ namespace } while(true) { - bg_.update() ; + if(!bg_.update()) { + continue ; + } if(igate.is_pressed(KEYCODE_ESC)) { return ; diff --git a/src/bind/mode/command_mode.cpp b/src/bind/mode/command_mode.cpp index df012e44..553020e9 100644 --- a/src/bind/mode/command_mode.cpp +++ b/src/bind/mode/command_mode.cpp @@ -355,7 +355,9 @@ namespace vind auto result = SystemCall::SUCCEEDED ; ac.apply(core::get_enter_event(core::Mode::COMMAND)) ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } bool break_flag = false ; do { diff --git a/src/bind/mode/instant_mode.cpp b/src/bind/mode/instant_mode.cpp index 6ab75ec3..4edad75d 100644 --- a/src/bind/mode/instant_mode.cpp +++ b/src/bind/mode/instant_mode.cpp @@ -58,7 +58,9 @@ namespace vind auto res = SystemCall::SUCCEEDED ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } std::vector inputs ; std::vector in_counts ; diff --git a/src/bind/mouse/hinter.cpp b/src/bind/mouse/hinter.cpp index 2b644a42..aa9b9a9f 100644 --- a/src/bind/mouse/hinter.cpp +++ b/src/bind/mouse/hinter.cpp @@ -182,7 +182,9 @@ namespace vind points, hint_texts, start_indices, mtxes) ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } // To use combined macros like , // get the keys from the input queue rather than the mapped queue. diff --git a/src/bind/mouse/jump_keybrd.cpp b/src/bind/mouse/jump_keybrd.cpp index 80c4edfe..fca78a5a 100644 --- a/src/bind/mouse/jump_keybrd.cpp +++ b/src/bind/mouse/jump_keybrd.cpp @@ -70,7 +70,9 @@ namespace vind auto toggle_keys = igate.pressed_list() ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } core::CmdUnit::SPtr inputs ; std::uint16_t count ; diff --git a/src/bind/window/switch_win.cpp b/src/bind/window/switch_win.cpp index 288a131b..9f1bd633 100644 --- a/src/bind/window/switch_win.cpp +++ b/src/bind/window/switch_win.cpp @@ -60,7 +60,9 @@ namespace vind auto mode = core::get_global_mode() ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } bool break_flag = false ; do { diff --git a/src/bind/window/winresizer.cpp b/src/bind/window/winresizer.cpp index bc4e51b2..587bc421 100644 --- a/src/bind/window/winresizer.cpp +++ b/src/bind/window/winresizer.cpp @@ -234,7 +234,9 @@ namespace vind core::InstantKeyAbsorber ika ; while(true) { - pimpl->bg_.update() ; + if(!pimpl->bg_.update()) { + continue ; + } bool break_flag = false ; do { diff --git a/src/core/background.cpp b/src/core/background.cpp index ca923227..5c529a3a 100644 --- a/src/core/background.cpp +++ b/src/core/background.cpp @@ -14,11 +14,19 @@ namespace vind { struct Background::Impl { std::vector opts_ ; + bool screen_is_locked_ ; template Impl(T&& opts) - : opts_(std::forward(opts)) + : opts_(std::forward(opts)), + screen_is_locked_(false) {} + + bool is_screen_locked() { + // GetCursorPos fails when the screen is locked. + POINT pos ; + return GetCursorPos(&pos) == 0 ; + } } ; Background::Background() @@ -35,22 +43,37 @@ namespace vind Background::~Background() noexcept = default ; - void Background::update() { - util::get_win_message() ; - + bool Background::update() { + auto& igate = InputGate::get_instance() ; Sleep(5) ; + if(pimpl->is_screen_locked()) { + if(!pimpl->screen_is_locked_) { + // Release all keys when the screen is locked. + for(auto& key : igate.pressed_list()) { + igate.release_virtually(key) ; + } + pimpl->screen_is_locked_ = true ; + } + return false ; + } + else if(pimpl->screen_is_locked_) { + pimpl->screen_is_locked_ = false ; + } + + util::get_win_message() ; + for(const auto& op : pimpl->opts_) { op->process() ; } - auto& igate = InputGate::get_instance() ; igate.refresh_toggle_state() ; if(igate.is_really_pressed(KEYCODE_F8) && \ igate.is_really_pressed(KEYCODE_F9)) { throw SafeForcedTermination() ; } + return true ; } } } diff --git a/src/core/background.hpp b/src/core/background.hpp index d5d648a3..c01a7287 100644 --- a/src/core/background.hpp +++ b/src/core/background.hpp @@ -28,7 +28,8 @@ namespace vind // If you make some loop functions, the function is needed to call. // It includes Sleep(). - void update() ; + // If this function returns false, should skip an iteration. + bool update() ; Background(const Background&) = delete ; Background& operator=(const Background&) = delete ; diff --git a/src/core/entry.cpp b/src/core/entry.cpp index 435035b0..ef9b6dc8 100644 --- a/src/core/entry.cpp +++ b/src/core/entry.cpp @@ -324,6 +324,10 @@ namespace vind static const auto desktop_hwnd = GetDesktopWindow() ; static const auto taskbar_hwnd = FindWindowA("Shell_TrayWnd", NULL) ; + if(!pimpl->bg_.update()) { + return ; + } + auto& ac = AutoCmd::get_instance() ; auto hwnd = util::get_foreground_window() ; auto procid = static_cast(0) ; @@ -343,8 +347,6 @@ namespace vind } } - pimpl->bg_.update() ; - // TODO: It is necessary to add exclusive handling when // write and read operations are performed at the same // time by multiple processes. However, these are extremely diff --git a/src/core/version.hpp b/src/core/version.hpp index b63522c3..b1a7e9c2 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.13.0.0" +#define WIN_VIND_VERSION "5.13.1.0" #endif