Skip to content

Commit

Permalink
config: add general:grace
Browse files Browse the repository at this point in the history
fixes #48
  • Loading branch information
vaxerski committed Feb 21, 2024
1 parent 06b07c5 commit 6355216
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CConfigManager::CConfigManager() : m_config(getMainConfigPath().c_str(), Hyprlan
void CConfigManager::init() {
m_config.addConfigValue("general:disable_loading_bar", Hyprlang::INT{0});
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
m_config.addConfigValue("general:grace", Hyprlang::INT{0});

m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""});
Expand Down
12 changes: 11 additions & 1 deletion src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ CHyprlock::CHyprlock(const std::string& wlDisplay) {
Debug::log(ERR, "Failed to create xkb context");

g_pRenderer = std::make_unique<CRenderer>();

const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0);
}

// wl_seat
Expand Down Expand Up @@ -265,6 +268,8 @@ static void handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint32
g_pHyprlock->m_pCursorShape->hideCursor(serial);
else
g_pHyprlock->m_pCursorShape->setShape(serial, wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER);

g_pHyprlock->m_vLastEnterCoords = {wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)};
}

static void handlePointerLeave(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface) {
Expand All @@ -276,7 +281,12 @@ static void handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time,
}

static void handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
;
if (g_pHyprlock->m_vLastEnterCoords.distance({wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)}) > 5 &&
std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds) {

Debug::log(LOG, "In grace and cursor moved more than 5px, unlocking!");
g_pHyprlock->unlockSession();
}
}

static void handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) {
Expand Down
4 changes: 4 additions & 0 deletions src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class CHyprlock {

bool m_bTerminate = false;

//
std::chrono::system_clock::time_point m_tGraceEnds;
Vector2D m_vLastEnterCoords = {};

private:
struct {
wl_display* display = nullptr;
Expand Down

0 comments on commit 6355216

Please sign in to comment.