From b4e8d44967daf863d9717449bb126e1784d6be7d Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 11 Jan 2023 15:18:25 +0100 Subject: [PATCH] remove some macros with questionable usefulness --- src/backends/wayland/wayland_backend.cpp | 13 +++--- src/dbusinterface.cpp | 45 +++++++------------ src/effectloader.cpp | 26 +++++------ src/effects/magiclamp/magiclamp.cpp | 20 ++++----- src/effects/mousemark/mousemark.cpp | 17 ++++--- src/events.cpp | 6 +-- src/group.cpp | 2 - .../aurorae/src/decorationoptions.cpp | 42 ++++++++++------- src/wayland/keyboard_interface.cpp | 27 ++++++----- src/window.cpp | 28 +++++++----- 10 files changed, 116 insertions(+), 110 deletions(-) diff --git a/src/backends/wayland/wayland_backend.cpp b/src/backends/wayland/wayland_backend.cpp index 014ccae48a..d10fabad85 100644 --- a/src/backends/wayland/wayland_backend.cpp +++ b/src/backends/wayland/wayland_backend.cpp @@ -37,8 +37,6 @@ #include "../drm/gbm_dmabuf.h" -#define QSIZE_TO_QPOINT(size) QPointF(size.width(), size.height()) - namespace KWin { namespace Wayland @@ -46,6 +44,11 @@ namespace Wayland using namespace KWayland::Client; +inline static QPointF sizeToPoint(const QSizeF &size) +{ + return QPointF(size.width(), size.height()); +} + WaylandInputDevice::WaylandInputDevice(KWayland::Client::Keyboard *keyboard, WaylandSeat *seat) : m_seat(seat) , m_keyboard(keyboard) @@ -131,7 +134,7 @@ WaylandInputDevice::WaylandInputDevice(KWayland::Client::Pointer *pointer, Wayla Q_EMIT pinchGestureBegin(m_pinchGesture->fingerCount(), std::chrono::milliseconds(time), this); }); connect(m_pinchGesture.get(), &PointerPinchGesture::updated, this, [this](const QSizeF &delta, qreal scale, qreal rotation, quint32 time) { - Q_EMIT pinchGestureUpdate(scale, rotation, QSIZE_TO_QPOINT(delta), std::chrono::milliseconds(time), this); + Q_EMIT pinchGestureUpdate(scale, rotation, sizeToPoint(delta), std::chrono::milliseconds(time), this); }); connect(m_pinchGesture.get(), &PointerPinchGesture::ended, this, [this](quint32 serial, quint32 time) { Q_EMIT pinchGestureEnd(std::chrono::milliseconds(time), this); @@ -145,7 +148,7 @@ WaylandInputDevice::WaylandInputDevice(KWayland::Client::Pointer *pointer, Wayla Q_EMIT swipeGestureBegin(m_swipeGesture->fingerCount(), std::chrono::milliseconds(time), this); }); connect(m_swipeGesture.get(), &PointerSwipeGesture::updated, this, [this](const QSizeF &delta, quint32 time) { - Q_EMIT swipeGestureUpdate(QSIZE_TO_QPOINT(delta), std::chrono::milliseconds(time), this); + Q_EMIT swipeGestureUpdate(sizeToPoint(delta), std::chrono::milliseconds(time), this); }); connect(m_swipeGesture.get(), &PointerSwipeGesture::ended, this, [this](quint32 serial, quint32 time) { Q_EMIT swipeGestureEnd(std::chrono::milliseconds(time), this); @@ -161,7 +164,7 @@ WaylandInputDevice::WaylandInputDevice(KWayland::Client::RelativePointer *relati , m_relativePointer(relativePointer) { connect(relativePointer, &RelativePointer::relativeMotion, this, [this](const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 timestamp) { - Q_EMIT pointerMotion(QSIZE_TO_QPOINT(delta), QSIZE_TO_QPOINT(deltaNonAccelerated), std::chrono::microseconds(timestamp), this); + Q_EMIT pointerMotion(sizeToPoint(delta), sizeToPoint(deltaNonAccelerated), std::chrono::microseconds(timestamp), this); }); } diff --git a/src/dbusinterface.cpp b/src/dbusinterface.cpp index fefaf8abc2..a67b17ee77 100644 --- a/src/dbusinterface.cpp +++ b/src/dbusinterface.cpp @@ -62,43 +62,30 @@ bool DBusInterface::showingDesktop() const return workspace()->showingDesktop(); } -// wrap void methods with no arguments to Workspace -#define WRAP(name) \ - void DBusInterface::name() \ - { \ - Workspace::self()->name(); \ - } - -WRAP(reconfigure) - -#undef WRAP +void DBusInterface::reconfigure() +{ + Workspace::self()->reconfigure(); +} void DBusInterface::killWindow() { Workspace::self()->slotKillWindow(); } -#define WRAP(name) \ - void DBusInterface::name() \ - { \ - workspace()->placement()->name(); \ - } +void DBusInterface::cascadeDesktop() +{ + workspace()->placement()->cascadeDesktop(); +} -WRAP(cascadeDesktop) -WRAP(unclutterDesktop) +void DBusInterface::unclutterDesktop() +{ + workspace()->placement()->unclutterDesktop(); +} -#undef WRAP - -// wrap returning methods with no arguments to Workspace -#define WRAP(rettype, name) \ - rettype DBusInterface::name() \ - { \ - return Workspace::self()->name(); \ - } - -WRAP(QString, supportInformation) - -#undef WRAP +QString DBusInterface::supportInformation() +{ + return Workspace::self()->supportInformation(); +} QString DBusInterface::activeOutputName() { diff --git a/src/effectloader.cpp b/src/effectloader.cpp index 63db469d5f..ced6bd3798 100644 --- a/src/effectloader.cpp +++ b/src/effectloader.cpp @@ -364,21 +364,19 @@ EffectLoader::~EffectLoader() { } -#define BOOL_MERGE(method) \ - bool EffectLoader::method(const QString &name) const \ - { \ - for (auto it = m_loaders.constBegin(); it != m_loaders.constEnd(); ++it) { \ - if ((*it)->method(name)) { \ - return true; \ - } \ - } \ - return false; \ - } +bool EffectLoader::hasEffect(const QString &name) const +{ + return std::any_of(m_loaders.cbegin(), m_loaders.cend(), [&name](const auto &loader) { + return loader->hasEffect(name); + }); +} -BOOL_MERGE(hasEffect) -BOOL_MERGE(isEffectSupported) - -#undef BOOL_MERGE +bool EffectLoader::isEffectSupported(const QString &name) const +{ + return std::any_of(m_loaders.cbegin(), m_loaders.cend(), [&name](const auto &loader) { + return loader->isEffectSupported(name); + }); +} QStringList EffectLoader::listOfKnownEffects() const { diff --git a/src/effects/magiclamp/magiclamp.cpp b/src/effects/magiclamp/magiclamp.cpp index 93ad18c411..f2591a744a 100644 --- a/src/effects/magiclamp/magiclamp.cpp +++ b/src/effects/magiclamp/magiclamp.cpp @@ -181,14 +181,6 @@ void MagicLampEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, Wi } } -#define SANITIZE_PROGRESS \ - if (p_progress[0] < 0) { \ - p_progress[0] = -p_progress[0]; \ - } \ - if (p_progress[1] < 0) { \ - p_progress[1] = -p_progress[1]; \ - } - #define SET_QUADS(_SET_A_, _A_, _DA_, _SET_B_, _B_, _O0_, _O1_, _O2_, _O3_) \ quad[0]._SET_A_((icon._A_() + icon._DA_() * (quad[0]._A_() / geo._DA_()) - (quad[0]._A_() + geo._A_())) * p_progress[_O0_] + quad[0]._A_()); \ quad[1]._SET_A_((icon._A_() + icon._DA_() * (quad[1]._A_() / geo._DA_()) - (quad[1]._A_() + geo._A_())) * p_progress[_O1_] + quad[1]._A_()); \ @@ -231,7 +223,8 @@ void MagicLampEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, Wi lastQuad = quad; } - SANITIZE_PROGRESS; + p_progress[0] = std::abs(p_progress[0]); + p_progress[1] = std::abs(p_progress[1]); // x values are moved towards the center of the icon SET_QUADS(setX, x, width, setY, y, 0, 0, 1, 1); } @@ -253,7 +246,8 @@ void MagicLampEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, Wi offset[0] = -offset[0]; offset[1] = -offset[1]; - SANITIZE_PROGRESS; + p_progress[0] = std::abs(p_progress[0]); + p_progress[1] = std::abs(p_progress[1]); // x values are moved towards the center of the icon SET_QUADS(setX, x, width, setY, y, 0, 0, 1, 1); } @@ -275,7 +269,8 @@ void MagicLampEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, Wi offset[0] = -offset[0]; offset[1] = -offset[1]; - SANITIZE_PROGRESS; + p_progress[0] = std::abs(p_progress[0]); + p_progress[1] = std::abs(p_progress[1]); // y values are moved towards the center of the icon SET_QUADS(setY, y, height, setX, x, 0, 1, 1, 0); } @@ -294,7 +289,8 @@ void MagicLampEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, Wi lastQuad = quad; } - SANITIZE_PROGRESS; + p_progress[0] = std::abs(p_progress[0]); + p_progress[1] = std::abs(p_progress[1]); // y values are moved towards the center of the icon SET_QUADS(setY, y, height, setX, x, 0, 1, 1, 0); } diff --git a/src/effects/mousemark/mousemark.cpp b/src/effects/mousemark/mousemark.cpp index a64d1abe5a..e1a9b889aa 100644 --- a/src/effects/mousemark/mousemark.cpp +++ b/src/effects/mousemark/mousemark.cpp @@ -26,7 +26,10 @@ namespace KWin { -#define NULL_POINT (QPoint(-1, -1)) // null point is (0,0), which is valid :-/ +static consteval QPoint nullPoint() +{ + return QPoint(-1, -1); +} MouseMarkEffect::MouseMarkEffect() { @@ -47,7 +50,7 @@ MouseMarkEffect::MouseMarkEffect() connect(effects, &EffectsHandler::mouseChanged, this, &MouseMarkEffect::slotMouseChanged); connect(effects, &EffectsHandler::screenLockingChanged, this, &MouseMarkEffect::screenLockingChanged); reconfigure(ReconfigureAll); - arrow_start = NULL_POINT; + arrow_start = nullPoint(); effects->startMousePolling(); // We require it to detect activation as well } @@ -141,16 +144,16 @@ void MouseMarkEffect::slotMouseChanged(const QPoint &pos, const QPoint &, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers) { if (modifiers == (Qt::META | Qt::SHIFT | Qt::CTRL)) { // start/finish arrow - if (arrow_start != NULL_POINT) { + if (arrow_start != nullPoint()) { marks.append(createArrow(arrow_start, pos)); - arrow_start = NULL_POINT; + arrow_start = nullPoint(); effects->addRepaintFull(); return; } else { arrow_start = pos; } } - if (arrow_start != NULL_POINT) { + if (arrow_start != nullPoint()) { return; } // TODO the shortcuts now trigger this right before they're activated @@ -182,8 +185,8 @@ void MouseMarkEffect::clear() void MouseMarkEffect::clearLast() { - if (arrow_start != NULL_POINT) { - arrow_start = NULL_POINT; + if (arrow_start != nullPoint()) { + arrow_start = nullPoint(); } else if (!drawing.isEmpty()) { drawing.clear(); effects->addRepaintFull(); diff --git a/src/events.cpp b/src/events.cpp index 600a5763a0..b691c91853 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -698,10 +698,8 @@ void X11Window::enterNotifyEvent(xcb_enter_notify_event_t *e) return; // care only about entering the whole frame } -#define MOUSE_DRIVEN_FOCUS (!options->focusPolicyIsReasonable() || (options->focusPolicy() == Options::FocusFollowsMouse && options->isNextFocusPrefersMouse())) - if (e->mode == XCB_NOTIFY_MODE_NORMAL || (e->mode == XCB_NOTIFY_MODE_UNGRAB && MOUSE_DRIVEN_FOCUS)) { -#undef MOUSE_DRIVEN_FOCUS - + const bool mouseDrivenFocus = !options->focusPolicyIsReasonable() || (options->focusPolicy() == Options::FocusFollowsMouse && options->isNextFocusPrefersMouse()); + if (e->mode == XCB_NOTIFY_MODE_NORMAL || (e->mode == XCB_NOTIFY_MODE_UNGRAB && mouseDrivenFocus)) { pointerEnterEvent(QPoint(e->root_x, e->root_y)); return; } diff --git a/src/group.cpp b/src/group.cpp index 94cb9428eb..7509e758c1 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -8,8 +8,6 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -//#define QT_CLEAN_NAMESPACE - #include "group.h" #include "effects.h" #include "workspace.h" diff --git a/src/plugins/kdecorations/aurorae/src/decorationoptions.cpp b/src/plugins/kdecorations/aurorae/src/decorationoptions.cpp index cc4a0f2084..9af2b6e55a 100644 --- a/src/plugins/kdecorations/aurorae/src/decorationoptions.cpp +++ b/src/plugins/kdecorations/aurorae/src/decorationoptions.cpp @@ -206,22 +206,34 @@ Borders::~Borders() { } -#define SETTER(methodName, name) \ - void Borders::methodName(int name) \ - { \ - if (m_##name == name) { \ - return; \ - } \ - m_##name = name; \ - Q_EMIT name##Changed(); \ +void Borders::setLeft(int left) +{ + if (m_left != left) { + m_left = left; + Q_EMIT leftChanged(); } - -SETTER(setLeft, left) -SETTER(setRight, right) -SETTER(setTop, top) -SETTER(setBottom, bottom) - -#undef SETTER +} +void Borders::setRight(int right) +{ + if (m_right != right) { + m_right = right; + Q_EMIT rightChanged(); + } +} +void Borders::setTop(int top) +{ + if (m_top != top) { + m_top = top; + Q_EMIT topChanged(); + } +} +void Borders::setBottom(int bottom) +{ + if (m_bottom != bottom) { + m_bottom = bottom; + Q_EMIT bottomChanged(); + } +} void Borders::setAllBorders(int border) { diff --git a/src/wayland/keyboard_interface.cpp b/src/wayland/keyboard_interface.cpp index 4fc59fdca8..1570ba4272 100644 --- a/src/wayland/keyboard_interface.cpp +++ b/src/wayland/keyboard_interface.cpp @@ -194,20 +194,23 @@ void KeyboardInterface::sendKey(quint32 key, KeyboardKeyState state) void KeyboardInterface::sendModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group) { bool changed = false; -#define UPDATE(value) \ - if (d->modifiers.value != value) { \ - d->modifiers.value = value; \ - changed = true; \ + if (d->modifiers.depressed != depressed) { + d->modifiers.depressed = depressed; + changed = true; } - UPDATE(depressed) - UPDATE(latched) - UPDATE(locked) - UPDATE(group) - if (!changed) { - return; + if (d->modifiers.latched != latched) { + d->modifiers.latched = latched; + changed = true; } - - if (!d->focusedSurface) { + if (d->modifiers.locked != locked) { + d->modifiers.locked = locked; + changed = true; + } + if (d->modifiers.group != group) { + d->modifiers.group = group; + changed = true; + } + if (!changed || !d->focusedSurface) { return; } diff --git a/src/window.cpp b/src/window.cpp index a59c66d562..73a006b1d2 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2729,17 +2729,25 @@ bool Window::isActiveFullScreen() const return ac && (ac == this || !ac->isOnOutput(output()) || ac->allMainWindows().contains(const_cast(this))); } -#define BORDER(which) \ - int Window::border##which() const \ - { \ - return isDecorated() ? decoration()->border##which() : 0; \ - } +int Window::borderBottom() const +{ + return isDecorated() ? decoration()->borderBottom() : 0; +} -BORDER(Bottom) -BORDER(Left) -BORDER(Right) -BORDER(Top) -#undef BORDER +int Window::borderLeft() const +{ + return isDecorated() ? decoration()->borderLeft() : 0; +} + +int Window::borderRight() const +{ + return isDecorated() ? decoration()->borderRight() : 0; +} + +int Window::borderTop() const +{ + return isDecorated() ? decoration()->borderTop() : 0; +} void Window::updateInitialMoveResizeGeometry() {