fixed bound checks

This commit is contained in:
Sepandar 2025-10-29 19:27:07 -07:00
parent d9cdb15ba8
commit f8a7022924
No known key found for this signature in database
3 changed files with 5 additions and 19 deletions

View file

@ -5,9 +5,7 @@
SMonitor::SMonitor(SP<CCWlOutput> output_) : output(output_) {
output->setGeometry([this](CCWlOutput* r, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, const char* make, const char* model,
int32_t transform_) { //
transform = (wl_output_transform)transform_;
position.x = x;
position.y = y;
transform = (wl_output_transform)transform_;
});
output->setDone([this](CCWlOutput* r) { //
ready = true;

View file

@ -14,7 +14,6 @@ struct SMonitor {
SP<CCWlOutput> output = nullptr;
uint32_t wayland_name = 0;
Vector2D size;
Vector2D position;
int32_t scale;
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;

View file

@ -15,14 +15,6 @@ static void sigHandler(int sig) {
exit(0);
}
static bool inMonitors(const std::vector<std::unique_ptr<SMonitor>>& monitors, const Vector2D& pos) {
for (const auto& m : monitors) {
if ((pos.x >= m->position.x) && (pos.x <= m->position.x + m->size.x) && (pos.y >= m->position.y) && (pos.y <= m->position.y + m->size.y))
return true;
}
return false;
}
void CHyprpicker::init() {
m_pXKBContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!m_pXKBContext)
@ -730,21 +722,18 @@ void CHyprpicker::initKeyboard() {
if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
return;
if (m_pXKBState) {
Vector2D newPosition = m_vLastCoords;
if (xkb_state_key_get_one_sym(m_pXKBState, key + 8) == XKB_KEY_Right)
++newPosition.x;
m_vLastCoords.x += m_vLastCoords.x < m_pLastSurface->m_pMonitor->size.x;
else if (xkb_state_key_get_one_sym(m_pXKBState, key + 8) == XKB_KEY_Left)
--newPosition.x;
m_vLastCoords.x -= m_vLastCoords.x > 0;
else if (xkb_state_key_get_one_sym(m_pXKBState, key + 8) == XKB_KEY_Up)
--newPosition.y;
m_vLastCoords.y -= m_vLastCoords.y > 0;
else if (xkb_state_key_get_one_sym(m_pXKBState, key + 8) == XKB_KEY_Down)
++newPosition.y;
m_vLastCoords.y += m_vLastCoords.y < m_pLastSurface->m_pMonitor->size.y;
else if (xkb_state_key_get_one_sym(m_pXKBState, key + 8) == XKB_KEY_Return)
outputColor();
else if (xkb_state_key_get_one_sym(m_pXKBState, key + 8) == XKB_KEY_Escape)
finish(2);
if (inMonitors(m_vMonitors, newPosition))
m_vLastCoords = newPosition;
} else if (key == 1) // Assume keycode 1 is escape
finish(2);
});