Add ARRAY_SIZE() macro

This commit is contained in:
Johan Malm 2023-09-16 22:25:41 +01:00 committed by Johan Malm
parent ae676c1607
commit 8d3b15576b
8 changed files with 30 additions and 12 deletions

View file

@ -7,6 +7,7 @@
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/util/region.h>
#include "action.h"
#include "common/array-size.h"
#include "common/mem.h"
#include "common/scene-helpers.h"
#include "config/mousebind.h"
@ -51,14 +52,12 @@ static const char * const cursors_x11[] = {
"left_side"
};
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
static_assert(
ARRAY_SIZE(cursors_xdg) == LAB_CURSOR_COUNT,
"XDG cursor names are out of sync");
static_assert(
ARRAY_SIZE(cursors_x11) == LAB_CURSOR_COUNT,
"X11 cursor names are out of sync");
#undef ARRAY_SIZE
enum lab_cursors
cursor_get_from_edge(uint32_t resize_edges)

View file

@ -14,6 +14,7 @@
#include <wayland-server.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/util/log.h>
#include "common/array-size.h"
#include "common/list.h"
#include "common/mem.h"
#include "config/rcxml.h"
@ -76,8 +77,7 @@ layers_arrange(struct output *output)
return;
}
int nr_layers = sizeof(output->layer_tree) / sizeof(output->layer_tree[0]);
for (int i = 0; i < nr_layers; i++) {
for (size_t i = 0; i < ARRAY_SIZE(output->layer_tree); i++) {
struct wlr_scene_tree *layer = output->layer_tree[i];
/*

View file

@ -16,6 +16,7 @@
#include <wlr/types/wlr_scene.h>
#include <wlr/util/region.h>
#include <wlr/util/log.h>
#include "common/array-size.h"
#include "common/mem.h"
#include "labwc.h"
#include "layers.h"
@ -48,8 +49,7 @@ output_destroy_notify(struct wl_listener *listener, void *data)
wl_list_remove(&output->frame.link);
wl_list_remove(&output->destroy.link);
int nr_layers = sizeof(output->layer_tree) / sizeof(output->layer_tree[0]);
for (int i = 0; i < nr_layers; i++) {
for (size_t i = 0; i < ARRAY_SIZE(output->layer_tree); i++) {
wlr_scene_node_destroy(&output->layer_tree[i]->node);
}
wlr_scene_node_destroy(&output->layer_popup_tree->node);
@ -186,8 +186,7 @@ new_output_notify(struct wl_listener *listener, void *data)
* Create layer-trees (background, bottom, top and overlay) and
* a layer-popup-tree.
*/
int nr_layers = sizeof(output->layer_tree) / sizeof(output->layer_tree[0]);
for (int i = 0; i < nr_layers; i++) {
for (size_t i = 0; i < ARRAY_SIZE(output->layer_tree); i++) {
output->layer_tree[i] =
wlr_scene_tree_create(&server->scene->tree);
node_descriptor_create(&output->layer_tree[i]->node,

View file

@ -105,7 +105,7 @@ set_squared_corners(struct ssd *ssd, bool enable)
enum ssd_part_type ssd_type[2] = { LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_BUTTON_CLOSE };
FOR_EACH_STATE(ssd, subtree) {
for (size_t i = 0; i < sizeof(ssd_type) / sizeof(ssd_type[0]); i++) {
for (size_t i = 0; i < ARRAY_SIZE(ssd_type); i++) {
part = ssd_get_part(&subtree->parts, ssd_type[i]);
struct ssd_button *button = node_ssd_button_from_node(part->node);

View file

@ -19,6 +19,7 @@
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include <strings.h>
#include "common/array-size.h"
#include "common/dir.h"
#include "common/font.h"
#include "common/graphic-helpers.h"
@ -109,7 +110,7 @@ load_buttons(struct theme *theme)
};
char filename[4096] = {0};
for (size_t i = 0; i < sizeof(buttons) / sizeof(buttons[0]); ++i) {
for (size_t i = 0; i < ARRAY_SIZE(buttons); ++i) {
struct button *b = &buttons[i];
drop(b->active.buffer);