Skip to content
Snippets Groups Projects
Commit 70648683 authored by Campbell Barton's avatar Campbell Barton
Browse files

Cleanup: add C++ compatible WL_ARRAY_FOR_EACH macro

parent cc09661c
No related branches found
No related tags found
No related merge requests found
...@@ -265,6 +265,7 @@ ForEachMacros: ...@@ -265,6 +265,7 @@ ForEachMacros:
- SET_SLOT_PROBING_BEGIN - SET_SLOT_PROBING_BEGIN
- MAP_SLOT_PROBING_BEGIN - MAP_SLOT_PROBING_BEGIN
- VECTOR_SET_SLOT_PROBING_BEGIN - VECTOR_SET_SLOT_PROBING_BEGIN
- WL_ARRAY_FOR_EACH
StatementMacros: StatementMacros:
- PyObject_HEAD - PyObject_HEAD
......
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup GHOST
*/
#pragma once
#ifdef __cplusplus
# undef wl_array_for_each
/**
* This macro causes a warning for C++ code, define our own.
* See: https://gitlab.freedesktop.org/wayland/wayland/-/issues/34
*/
# define WL_ARRAY_FOR_EACH(pos, array) \
for (pos = (decltype(pos))((array)->data); \
(const char *)pos < ((const char *)(array)->data + (array)->size); \
(pos)++)
#endif
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "GHOST_WindowWayland.h" #include "GHOST_WindowWayland.h"
#include "GHOST_SystemWayland.h" #include "GHOST_SystemWayland.h"
#include "GHOST_WaylandUtils.h"
#include "GHOST_WindowManager.h" #include "GHOST_WindowManager.h"
#include "GHOST_Event.h" #include "GHOST_Event.h"
...@@ -134,12 +135,8 @@ static void xdg_toplevel_handle_configure(void *data, ...@@ -134,12 +135,8 @@ static void xdg_toplevel_handle_configure(void *data,
win->is_fullscreen = false; win->is_fullscreen = false;
win->is_active = false; win->is_active = false;
/* Note that the macro 'wl_array_for_each' would typically be used to simplify this logic, enum xdg_toplevel_state *state;
* however it's not compatible with C++, so perform casts instead. WL_ARRAY_FOR_EACH (state, states) {
* If this needs to be done more often we could define our own C++ compatible macro. */
for (enum xdg_toplevel_state *state = static_cast<xdg_toplevel_state *>(states->data);
reinterpret_cast<uint8_t *>(state) < (static_cast<uint8_t *>(states->data) + states->size);
state++) {
switch (*state) { switch (*state) {
case XDG_TOPLEVEL_STATE_MAXIMIZED: case XDG_TOPLEVEL_STATE_MAXIMIZED:
win->is_maximised = true; win->is_maximised = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment