mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-05-13 05:40:42 +01:00
core: trigger hover and onclick only for the currently focused surface
This commit is contained in:
parent
ca073eda74
commit
1fdb3367cb
17 changed files with 111 additions and 76 deletions
|
@ -139,3 +139,7 @@ void CSessionLockSurface::onCallback() {
|
|||
render();
|
||||
}
|
||||
}
|
||||
|
||||
SP<CCWlSurface> CSessionLockSurface::getWlSurface() {
|
||||
return surface;
|
||||
}
|
||||
|
|
|
@ -17,15 +17,16 @@ class CSessionLockSurface {
|
|||
CSessionLockSurface(const SP<COutput>& pOutput);
|
||||
~CSessionLockSurface();
|
||||
|
||||
void configure(const Vector2D& size, uint32_t serial);
|
||||
void configure(const Vector2D& size, uint32_t serial);
|
||||
|
||||
bool readyForFrame = false;
|
||||
bool readyForFrame = false;
|
||||
|
||||
float fractionalScale = 1.0;
|
||||
float fractionalScale = 1.0;
|
||||
|
||||
void render();
|
||||
void onCallback();
|
||||
void onScaleUpdate();
|
||||
void render();
|
||||
void onCallback();
|
||||
void onScaleUpdate();
|
||||
SP<CCWlSurface> getWlSurface();
|
||||
|
||||
private:
|
||||
WP<COutput> m_outputRef;
|
||||
|
|
|
@ -53,8 +53,19 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
|
|||
m_pCursorShape->setShape(wpCursorShapeDeviceV1Shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
|
||||
|
||||
g_pHyprlock->m_vLastEnterCoords = {wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)};
|
||||
|
||||
for (const auto& POUTPUT : g_pHyprlock->m_vOutputs) {
|
||||
if (!POUTPUT->m_sessionLockSurface)
|
||||
continue;
|
||||
|
||||
const auto& PWLSURFACE = POUTPUT->m_sessionLockSurface->getWlSurface();
|
||||
if (PWLSURFACE->resource() == surf)
|
||||
g_pHyprlock->m_focusedOutput = POUTPUT;
|
||||
}
|
||||
});
|
||||
|
||||
m_pPointer->setLeave([](CCWlPointer* r, uint32_t serial, wl_proxy* surf) { g_pHyprlock->m_focusedOutput.reset(); });
|
||||
|
||||
m_pPointer->setButton([](CCWlPointer* r, uint32_t serial, uint32_t time, uint32_t button, wl_pointer_button_state state) {
|
||||
g_pHyprlock->onClick(button, state == WL_POINTER_BUTTON_STATE_PRESSED, g_pHyprlock->m_vMouseLocation);
|
||||
});
|
||||
|
|
|
@ -669,55 +669,56 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
|
|||
}
|
||||
|
||||
void CHyprlock::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
for (auto& o : m_vOutputs) {
|
||||
if (!o->m_sessionLockSurface)
|
||||
continue;
|
||||
if (!m_focusedOutput.lock())
|
||||
return;
|
||||
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*o->m_sessionLockSurface);
|
||||
for (const auto& widget : widgets) {
|
||||
if (widget->containsPoint(pos))
|
||||
widget->onClick(button, down, pos);
|
||||
}
|
||||
// TODO: add the UNLIKELY marco from Hyprland
|
||||
if (!m_focusedOutput->m_sessionLockSurface)
|
||||
return;
|
||||
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*m_focusedOutput->m_sessionLockSurface);
|
||||
for (const auto& widget : widgets) {
|
||||
if (widget->containsPoint(pos))
|
||||
widget->onClick(button, down, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void CHyprlock::onHover(const Vector2D& pos) {
|
||||
bool cursorChanged = false;
|
||||
if (!m_focusedOutput.lock())
|
||||
return;
|
||||
|
||||
for (auto& o : m_vOutputs) {
|
||||
if (!o->m_sessionLockSurface)
|
||||
continue;
|
||||
if (!m_focusedOutput->m_sessionLockSurface)
|
||||
return;
|
||||
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*o->m_sessionLockSurface);
|
||||
bool outputNeedsRedraw = false;
|
||||
bool outputNeedsRedraw = false;
|
||||
bool cursorChanged = false;
|
||||
|
||||
for (const auto& widget : widgets) {
|
||||
const bool containsPoint = widget->containsPoint(pos);
|
||||
const bool wasHovered = widget->isHovered();
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*m_focusedOutput->m_sessionLockSurface);
|
||||
for (const auto& widget : widgets) {
|
||||
const bool CONTAINSPOINT = widget->containsPoint(pos);
|
||||
const bool HOVERED = widget->isHovered();
|
||||
|
||||
if (containsPoint) {
|
||||
if (!wasHovered) {
|
||||
widget->setHover(true);
|
||||
widget->onHover(pos);
|
||||
outputNeedsRedraw = true;
|
||||
}
|
||||
|
||||
if (!cursorChanged)
|
||||
cursorChanged = true;
|
||||
|
||||
} else if (wasHovered) {
|
||||
widget->setHover(false);
|
||||
if (CONTAINSPOINT) {
|
||||
if (!HOVERED) {
|
||||
widget->setHover(true);
|
||||
widget->onHover(pos);
|
||||
outputNeedsRedraw = true;
|
||||
}
|
||||
|
||||
if (!cursorChanged)
|
||||
cursorChanged = true;
|
||||
|
||||
} else if (HOVERED) {
|
||||
widget->setHover(false);
|
||||
outputNeedsRedraw = true;
|
||||
}
|
||||
|
||||
if (outputNeedsRedraw)
|
||||
o->m_sessionLockSurface->render();
|
||||
}
|
||||
|
||||
if (!cursorChanged) {
|
||||
if (!cursorChanged)
|
||||
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
|
||||
}
|
||||
|
||||
if (outputNeedsRedraw)
|
||||
m_focusedOutput->m_sessionLockSurface->render();
|
||||
}
|
||||
|
||||
bool CHyprlock::acquireSessionLock() {
|
||||
|
|
|
@ -99,7 +99,9 @@ class CHyprlock {
|
|||
//
|
||||
std::chrono::system_clock::time_point m_tGraceEnds;
|
||||
Vector2D m_vLastEnterCoords = {};
|
||||
Vector2D m_vMouseLocation = {};
|
||||
WP<COutput> m_focusedOutput;
|
||||
|
||||
Vector2D m_vMouseLocation = {};
|
||||
|
||||
std::shared_ptr<CTimer> m_pKeyRepeatTimer = nullptr;
|
||||
|
||||
|
|
|
@ -117,6 +117,6 @@ CFramebuffer::~CFramebuffer() {
|
|||
release();
|
||||
}
|
||||
|
||||
bool CFramebuffer::isAllocated() {
|
||||
bool CFramebuffer::isAllocated() const {
|
||||
return m_iFb != (GLuint)-1;
|
||||
}
|
|
@ -13,7 +13,7 @@ class CFramebuffer {
|
|||
void bind() const;
|
||||
void release();
|
||||
void reset();
|
||||
bool isAllocated();
|
||||
bool isAllocated() const;
|
||||
|
||||
Vector2D m_vSize;
|
||||
|
||||
|
|
|
@ -271,5 +271,5 @@ bool IWidget::isHovered() const {
|
|||
}
|
||||
|
||||
bool IWidget::containsPoint(const Vector2D& pos) const {
|
||||
return getBoundingBox().containsPoint(pos);
|
||||
return getBoundingBoxWl().containsPoint(pos);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class IWidget {
|
|||
static int roundingForBox(const CBox& box, int roundingConfig);
|
||||
static int roundingForBorderBox(const CBox& borderBox, int roundingConfig, int thickness);
|
||||
|
||||
virtual CBox getBoundingBox() const {
|
||||
virtual CBox getBoundingBoxWl() const {
|
||||
return CBox();
|
||||
};
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos) {}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprlang.hpp>
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
|
||||
CImage::~CImage() {
|
||||
reset();
|
||||
|
@ -84,14 +85,14 @@ void CImage::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
configPos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
|
||||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
|
@ -197,10 +198,10 @@ bool CImage::draw(const SRenderData& data) {
|
|||
|
||||
shadow.draw(data);
|
||||
|
||||
const auto TEXPOS = posFromHVAlign(viewport, tex->m_vSize, pos, halign, valign, angle);
|
||||
pos = posFromHVAlign(viewport, tex->m_vSize, configPos, halign, valign, angle);
|
||||
|
||||
texbox.x = TEXPOS.x;
|
||||
texbox.y = TEXPOS.y;
|
||||
texbox.x = pos.x;
|
||||
texbox.y = pos.y;
|
||||
|
||||
texbox.round();
|
||||
texbox.rot = angle;
|
||||
|
@ -235,10 +236,14 @@ void CImage::renderUpdate() {
|
|||
g_pHyprlock->renderOutput(stringPort);
|
||||
}
|
||||
|
||||
CBox CImage::getBoundingBox() const {
|
||||
if (!asset)
|
||||
return {pos.x, abs(pos.y - viewport.y), 0, 0};
|
||||
return {pos.x, abs(pos.y - viewport.y + asset->texture.m_vSize.y), asset->texture.m_vSize.x, asset->texture.m_vSize.y};
|
||||
CBox CImage::getBoundingBoxWl() const {
|
||||
if (!imageFB.isAllocated())
|
||||
return CBox{};
|
||||
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - imageFB.m_cTex.m_vSize.y},
|
||||
imageFB.m_cTex.m_vSize,
|
||||
};
|
||||
}
|
||||
|
||||
void CImage::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
|
|
|
@ -24,7 +24,7 @@ class CImage : public IWidget {
|
|||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual CBox getBoundingBox() const;
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
|
@ -45,6 +45,7 @@ class CImage : public IWidget {
|
|||
double angle;
|
||||
CGradientValueData color;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
|
||||
std::string halign, valign, path;
|
||||
|
||||
|
|
|
@ -174,10 +174,14 @@ void CLabel::renderUpdate() {
|
|||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
|
||||
CBox CLabel::getBoundingBox() const {
|
||||
CBox CLabel::getBoundingBoxWl() const {
|
||||
if (!asset)
|
||||
return {pos.x, abs(pos.y - viewport.y), 0, 0};
|
||||
return {pos.x, abs(pos.y - viewport.y + asset->texture.m_vSize.y), asset->texture.m_vSize.x, asset->texture.m_vSize.y};
|
||||
return CBox{};
|
||||
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - asset->texture.m_vSize.y},
|
||||
asset->texture.m_vSize,
|
||||
};
|
||||
}
|
||||
|
||||
void CLabel::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
|
|
|
@ -21,7 +21,7 @@ class CLabel : public IWidget {
|
|||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual CBox getBoundingBox() const;
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
|
|
|
@ -474,8 +474,11 @@ void CPasswordInputField::updateColors() {
|
|||
colorState.font = fontTarget;
|
||||
}
|
||||
|
||||
CBox CPasswordInputField::getBoundingBox() const {
|
||||
return {pos.x, abs(pos.y - viewport.y + size->value().y), size->value().x, size->value().y};
|
||||
CBox CPasswordInputField::getBoundingBoxWl() const {
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - size->value().y},
|
||||
size->value(),
|
||||
};
|
||||
}
|
||||
|
||||
void CPasswordInputField::onHover(const Vector2D& pos) {
|
||||
|
|
|
@ -24,7 +24,7 @@ class CPasswordInputField : public IWidget {
|
|||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
virtual CBox getBoundingBox() const;
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
|
||||
void reset();
|
||||
void onFadeOutTimer();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../../core/hyprlock.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprlang.hpp>
|
||||
#include <sys/types.h>
|
||||
|
||||
void CShape::registerSelf(const SP<CShape>& self) {
|
||||
m_self = self;
|
||||
|
@ -102,9 +103,11 @@ bool CShape::draw(const SRenderData& data) {
|
|||
|
||||
return data.opacity < 1.0;
|
||||
}
|
||||
|
||||
CBox CShape::getBoundingBox() const {
|
||||
return {pos.x, abs(pos.y - viewport.y + size.y), size.x, size.y};
|
||||
CBox CShape::getBoundingBoxWl() const {
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - size.y},
|
||||
size,
|
||||
};
|
||||
}
|
||||
|
||||
void CShape::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
|
|
|
@ -18,7 +18,7 @@ class CShape : public IWidget {
|
|||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual CBox getBoundingBox() const;
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
|
|
Loading…
Reference in a new issue