Changeset View
Standalone View
pointer_input.cpp
Show First 20 Lines • Show All 430 Lines • ▼ Show 20 Line(s) | 428 | { | |||
---|---|---|---|---|---|
431 | } | 431 | } | ||
432 | if (waylandServer()->seat()->isDragPointer()) { | 432 | if (waylandServer()->seat()->isDragPointer()) { | ||
433 | // ignore during drag and drop | 433 | // ignore during drag and drop | ||
434 | return; | 434 | return; | ||
435 | } | 435 | } | ||
436 | if (input()->isSelectingWindow()) { | 436 | if (input()->isSelectingWindow()) { | ||
437 | return; | 437 | return; | ||
438 | } | 438 | } | ||
439 | auto areButtonsPressed = [this] { | ||||
440 | for (auto state : qAsConst(m_buttons)) { | ||||
markg: Just curious, why do you define end as opposed tho this:
for (auto it = m_buttons.constBegin()… | |||||
Because @broulik tends to point out that it is not cached.
does that work in a sensible way for a QHash? The most lean way would have been: if (std::any_of(m_buttons.constBegin(), m_buttons.constEnd(), [] ...)) But that doesn't work with QHash. So I kind of doubt QHash and qAsConst do something sensible. graesslin: > Just curious, why do you define end as opposed tho this:
Because @broulik tends to point out… | |||||
This is where STL and Qt apparently diverge a bit. for (auto value : qAsConst(m_buttons)) { Gives you the values in the map. Not the keys. And that is because it's a QHash container which apparently behaves like that. However, in *this* case you are only using the value thus you are fine when using: Since you seem to mention optimization (you shouldn't have done that ;)), this is the most efficient version, and i looked it up [1], hehe: In fact. You likely always want this version of the range-based-for loop. And "for (auto&& value: ...)" if you want to modify them in place. You nearly never want a plain range-based-for without a reference symbol in there because that makes a copy. Hope that helps :) [1] Read https://blog.petrzemek.net/2016/08/17/auto-type-deduction-in-range-based-for-loops/ for the details markg: This is where STL and Qt apparently diverge a bit.
for (auto value : qAsConst(m_buttons)) {… | |||||
441 | if (state == InputRedirection::PointerButtonPressed) { | ||||
442 | return true; | ||||
443 | } | ||||
444 | } | ||||
445 | return false; | ||||
446 | }; | ||||
447 | if (areButtonsPressed()) { | ||||
448 | return; | ||||
449 | } | ||||
439 | Toplevel *t = m_input->findToplevel(m_pos.toPoint()); | 450 | Toplevel *t = m_input->findToplevel(m_pos.toPoint()); | ||
440 | const auto oldDeco = m_decoration; | 451 | const auto oldDeco = m_decoration; | ||
441 | updateInternalWindow(m_pos); | 452 | updateInternalWindow(m_pos); | ||
442 | if (!m_internalWindow) { | 453 | if (!m_internalWindow) { | ||
443 | updateDecoration(t, m_pos); | 454 | updateDecoration(t, m_pos); | ||
444 | } else { | 455 | } else { | ||
445 | updateDecoration(waylandServer()->findClient(m_internalWindow), m_pos); | 456 | updateDecoration(waylandServer()->findClient(m_internalWindow), m_pos); | ||
446 | if (m_decoration) { | 457 | if (m_decoration) { | ||
▲ Show 20 Lines • Show All 824 Lines • Show Last 20 Lines |
Just curious, why do you define end as opposed tho this:
for (auto it = m_buttons.constBegin(); it != m_buttons.constEnd(); it++) {
}
Another route you can go which looks much cleaner imho (requires Qt 5.7 because of qAsConst):
for (auto entry, qAsConst(m_buttons)) {
}
Just my 2 cents.