Repository: hyprwm/Hyprland
File: src/protocols/LayerShell.cpp (C++)

Code before:
            return;
        }

        m_configured = true;
        m_size       = serialFound->second;

        m_serials.erase(serialFound);
    });

    m_resource->setSetLayer([this](CZwlrLayerSurfaceV1* r, uint32_t layer) {
        if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
            r->error(ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER, "Invalid layer");
            return;
        }

        m_pending.committed |= STATE_LAYER;
        m_pending.layer = sc<zwlrLayerShellV1Layer>(layer);
    });

    m_resource->setSetExclusiveEdge([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1Anchor anchor) {
        if (anchor > (ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
            r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_EXCLUSIVE_EDGE, "Invalid exclusive edge");
            return;
        }

        if (anchor && (!m_pending.anchor || !(m_pending.anchor & anchor))) {
            r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_EXCLUSIVE_EDGE, "Exclusive edge doesn't align with anchor");
            return;
        }

        m_pending.committed |= STATE_EDGE;
        m_pending.exclusiveEdge = anchor;
    });
}

CLayerShellResource::~CLayerShellResource() {
    m_events.destroy.emit();
    if (m_surface)
        m_surface->resetRole();
}

bool CLayerShellResource::good() {
    return m_resource->resource();
}

void CLayerShellResource::sendClosed() {
    if (m_closed)
        return;
    m_closed = true;
    m_resource->sendClosed();
}

Review comment (bug):
https://discord.com/channels/961691461554950145/1270460936301314048/1422223299995500556

`zwlrLayerSurfaceV1Anchor` doesn't have a falsy value. if it can be 0 then this value should be added to the enum or the input type should be changed to uint32_t and cast to enum after the check. otherwise bugprone-non-zero-enum-to-bool-conversion will keep reporting this check. https://wayland.app/protocols/wlr-layer-shell-unstable-v1#zwlr_layer_surface_v1:request:set_exclusive_edge doesn't mention a zero value so zwlr_layer_surface_v1#39.set_exclusive_edge(0) shouldn't be valid.

Code after:
            return;
        }

        m_configured = true;
        m_size       = serialFound->second;

        m_serials.erase(serialFound);
    });

    m_resource->setSetLayer([this](CZwlrLayerSurfaceV1* r, uint32_t layer) {
        if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
            r->error(ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER, "Invalid layer");
            return;
        }

        m_pending.committed |= STATE_LAYER;
        m_pending.layer = sc<zwlrLayerShellV1Layer>(layer);
    });

    m_resource->setSetExclusiveEdge([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1Anchor anchor) {
        if (anchor > (ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
            r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_EXCLUSIVE_EDGE, "Invalid exclusive edge");
            return;
        }

        if (!m_pending.anchor || !(m_pending.anchor & anchor)) {
            r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_EXCLUSIVE_EDGE, "Exclusive edge doesn't align with anchor");
            return;
        }

        m_pending.committed |= STATE_EDGE;
        m_pending.exclusiveEdge = anchor;
    });
}

CLayerShellResource::~CLayerShellResource() {
    m_events.destroy.emit();
    if (m_surface)
        m_surface->resetRole();
}

bool CLayerShellResource::good() {
    return m_resource->resource();
}

void CLayerShellResource::sendClosed() {
    if (m_closed)
        return;
    m_closed = true;
    m_resource->sendClosed();
}