Skip to content

input: implement follow_mouse_shrink #10325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,21 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper
static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
static auto PBORDERGRABEXTEND = CConfigValue<Hyprlang::INT>("general:extend_border_grab_area");
static auto PSPECIALFALLTHRU = CConfigValue<Hyprlang::INT>("input:special_fallthrough");
static auto PFOLLOWMSHRINK = CConfigValue<Hyprlang::INT>("input:follow_mouse_shrink");
const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0;
const auto HITBOX_SHRINK = *PFOLLOWMSHRINK;
const auto LASTFOCUSED = m_lastWindow.lock();

// pinned windows on top of floating regardless
if (properties & ALLOW_FLOATING) {
for (auto const& w : m_windows | std::views::reverse) {
if (w->m_isFloating && w->m_isMapped && !w->isHidden() && !w->m_X11ShouldntFocus && w->m_pinned && !w->m_windowData.noFocus.valueOrDefault() && w != pIgnoreWindow) {
const auto BB = w->getWindowBoxUnified(properties);
CBox box = BB.copy().expand(!w->isX11OverrideRedirect() ? BORDER_GRAB_AREA : 0);

if (properties & FOLLOW_MOUSE_CHECK && HITBOX_SHRINK > 0 && w != LASTFOCUSED)
box = box.copy().expand(-HITBOX_SHRINK);

if (box.containsPoint(g_pPointerManager->position()))
return w;

Expand Down Expand Up @@ -916,6 +923,10 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper

const auto BB = w->getWindowBoxUnified(properties);
CBox box = BB.copy().expand(!w->isX11OverrideRedirect() ? BORDER_GRAB_AREA : 0);

if (properties & FOLLOW_MOUSE_CHECK && HITBOX_SHRINK > 0 && w != LASTFOCUSED)
box = box.copy().expand(-HITBOX_SHRINK);

if (box.containsPoint(g_pPointerManager->position())) {

if (w->m_isX11 && w->isX11OverrideRedirect() && !w->m_xwaylandSurface->wantsFocus()) {
Expand Down Expand Up @@ -982,6 +993,10 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper
if (!w->m_isFloating && w->m_isMapped && w->workspaceID() == WSPID && !w->isHidden() && !w->m_X11ShouldntFocus && !w->m_windowData.noFocus.valueOrDefault() &&
w != pIgnoreWindow) {
CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_position, w->m_size};

if (properties & FOLLOW_MOUSE_CHECK && HITBOX_SHRINK > 0 && w != LASTFOCUSED)
box = box.copy().expand(-HITBOX_SHRINK);

if (box.containsPoint(pos))
return w;
}
Expand Down
6 changes: 6 additions & 0 deletions src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_FLOAT,
.data = SConfigOptionDescription::SFloatData{},
},
SConfigOptionDescription{
.value = "input:follow_mouse_shrink",
.description = "Shrinks the inactive window hitboxes by the specified amount of pixels.",
.type = CONFIG_OPTION_INT,
.data = SConfigOptionDescription::SRangeData{0, 0, 300},
},
SConfigOptionDescription{
.value = "input:focus_on_close",
.description = "Controls the window focus behavior when a window is closed. When set to 0, focus will shift to the next window candidate. When set to 1, focus will shift "
Expand Down
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ CConfigManager::CConfigManager() {

registerConfigVar("input:follow_mouse", Hyprlang::INT{1});
registerConfigVar("input:follow_mouse_threshold", Hyprlang::FLOAT{0});
registerConfigVar("input:follow_mouse_shrink", Hyprlang::INT{0});
registerConfigVar("input:focus_on_close", Hyprlang::INT{0});
registerConfigVar("input:mouse_refocus", Hyprlang::INT{1});
registerConfigVar("input:special_fallthrough", Hyprlang::INT{0});
Expand Down
1 change: 1 addition & 0 deletions src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum eGetWindowProperties : uint8_t {
ALLOW_FLOATING = 1 << 4,
USE_PROP_TILED = 1 << 5,
SKIP_FULLSCREEN_PRIORITY = 1 << 6,
FOLLOW_MOUSE_CHECK = 1 << 7,
};

enum eSuppressEvents : uint8_t {
Expand Down
11 changes: 5 additions & 6 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {

// then, we check if the workspace doesnt have a fullscreen window
const auto PWORKSPACE = PMONITOR->m_activeWorkspace;
const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING | FOLLOW_MOUSE_CHECK);
if (PWORKSPACE->m_hasFullscreenWindow && !foundSurface && PWORKSPACE->m_fullscreenMode == FSMODE_FULLSCREEN) {
pFoundWindow = PWORKSPACE->getFullscreenWindow();

Expand Down Expand Up @@ -389,11 +389,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {
if (!foundSurface) {
if (PMONITOR->m_activeSpecialWorkspace) {
if (pFoundWindow != PWINDOWIDEAL)
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING | FOLLOW_MOUSE_CHECK);

if (pFoundWindow && !pFoundWindow->onSpecialWorkspace()) {
if (pFoundWindow && !pFoundWindow->onSpecialWorkspace())
pFoundWindow = PWORKSPACE->getFullscreenWindow();
}
} else {
// if we have a maximized window, allow focusing on a bar or something if in reserved area.
if (g_pCompositor->isPointOnReservedArea(mouseCoords, PMONITOR)) {
Expand All @@ -403,7 +402,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {

if (!foundSurface) {
if (pFoundWindow != PWINDOWIDEAL)
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING | FOLLOW_MOUSE_CHECK);

if (!(pFoundWindow && pFoundWindow->m_isFloating && pFoundWindow->m_createdOverFullscreen))
pFoundWindow = PWORKSPACE->getFullscreenWindow();
Expand All @@ -413,7 +412,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {

} else {
if (pFoundWindow != PWINDOWIDEAL)
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING | FOLLOW_MOUSE_CHECK);
}

if (pFoundWindow) {
Expand Down
Loading