mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-13 13:29:44 -05:00
Use struct initializers instead of memset()
This is a bit more type-safe.
This commit is contained in:
parent
4966857f21
commit
7a9f8d8d6b
34 changed files with 134 additions and 113 deletions
|
|
@ -11,10 +11,11 @@ void wlr_buffer_init(struct wlr_buffer *buffer,
|
|||
assert(impl->begin_data_ptr_access && impl->end_data_ptr_access);
|
||||
}
|
||||
|
||||
memset(buffer, 0, sizeof(*buffer));
|
||||
buffer->impl = impl;
|
||||
buffer->width = width;
|
||||
buffer->height = height;
|
||||
*buffer = (struct wlr_buffer){
|
||||
.impl = impl,
|
||||
.width = width,
|
||||
.height = height,
|
||||
};
|
||||
wl_signal_init(&buffer->events.destroy);
|
||||
wl_signal_init(&buffer->events.release);
|
||||
wlr_addon_set_init(&buffer->addons);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ bool dmabuf_buffer_drop(struct wlr_dmabuf_buffer *buffer) {
|
|||
if (!wlr_dmabuf_attributes_copy(&saved_dmabuf, &buffer->dmabuf)) {
|
||||
wlr_log(WLR_ERROR, "Failed to save DMA-BUF");
|
||||
ok = false;
|
||||
memset(&buffer->dmabuf, 0, sizeof(buffer->dmabuf));
|
||||
buffer->dmabuf = (struct wlr_dmabuf_attributes){0};
|
||||
} else {
|
||||
buffer->dmabuf = saved_dmabuf;
|
||||
buffer->saved = true;
|
||||
|
|
|
|||
|
|
@ -14,11 +14,12 @@ void wlr_data_source_init(struct wlr_data_source *source,
|
|||
const struct wlr_data_source_impl *impl) {
|
||||
assert(impl->send);
|
||||
|
||||
memset(source, 0, sizeof(*source));
|
||||
source->impl = impl;
|
||||
*source = (struct wlr_data_source){
|
||||
.impl = impl,
|
||||
.actions = -1,
|
||||
};
|
||||
wl_array_init(&source->mime_types);
|
||||
wl_signal_init(&source->events.destroy);
|
||||
source->actions = -1;
|
||||
}
|
||||
|
||||
void wlr_data_source_send(struct wlr_data_source *source, const char *mime_type,
|
||||
|
|
|
|||
|
|
@ -332,15 +332,17 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
|||
assert(impl->set_cursor && impl->move_cursor);
|
||||
}
|
||||
|
||||
memset(output, 0, sizeof(*output));
|
||||
output->backend = backend;
|
||||
output->impl = impl;
|
||||
output->display = display;
|
||||
*output = (struct wlr_output){
|
||||
.backend = backend,
|
||||
.impl = impl,
|
||||
.display = display,
|
||||
.render_format = DRM_FORMAT_XRGB8888,
|
||||
.transform = WL_OUTPUT_TRANSFORM_NORMAL,
|
||||
.scale = 1,
|
||||
.commit_seq = 0,
|
||||
};
|
||||
|
||||
wl_list_init(&output->modes);
|
||||
output->render_format = DRM_FORMAT_XRGB8888;
|
||||
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
output->scale = 1;
|
||||
output->commit_seq = 0;
|
||||
wl_list_init(&output->cursors);
|
||||
wl_list_init(&output->layers);
|
||||
wl_list_init(&output->resources);
|
||||
|
|
|
|||
|
|
@ -57,10 +57,11 @@ struct wlr_scene *scene_node_get_root(struct wlr_scene_node *node) {
|
|||
|
||||
static void scene_node_init(struct wlr_scene_node *node,
|
||||
enum wlr_scene_node_type type, struct wlr_scene_tree *parent) {
|
||||
memset(node, 0, sizeof(*node));
|
||||
node->type = type;
|
||||
node->parent = parent;
|
||||
node->enabled = true;
|
||||
*node = (struct wlr_scene_node){
|
||||
.type = type,
|
||||
.parent = parent,
|
||||
.enabled = true,
|
||||
};
|
||||
|
||||
wl_list_init(&node->link);
|
||||
|
||||
|
|
@ -141,7 +142,7 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) {
|
|||
|
||||
static void scene_tree_init(struct wlr_scene_tree *tree,
|
||||
struct wlr_scene_tree *parent) {
|
||||
memset(tree, 0, sizeof(*tree));
|
||||
*tree = (struct wlr_scene_tree){0};
|
||||
scene_node_init(&tree->node, WLR_SCENE_NODE_TREE, parent);
|
||||
wl_list_init(&tree->children);
|
||||
}
|
||||
|
|
@ -386,8 +387,8 @@ static void update_node_update_outputs(struct wlr_scene_node *node,
|
|||
}
|
||||
|
||||
if (old_primary_output != scene_buffer->primary_output) {
|
||||
memset(&scene_buffer->prev_feedback_options, 0,
|
||||
sizeof(scene_buffer->prev_feedback_options));
|
||||
scene_buffer->prev_feedback_options =
|
||||
(struct wlr_linux_dmabuf_feedback_v1_init_options){0};
|
||||
}
|
||||
|
||||
uint64_t old_active = scene_buffer->active_outputs;
|
||||
|
|
|
|||
|
|
@ -588,10 +588,10 @@ struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource) {
|
|||
}
|
||||
|
||||
static void surface_state_init(struct wlr_surface_state *state) {
|
||||
memset(state, 0, sizeof(*state));
|
||||
|
||||
state->scale = 1;
|
||||
state->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
*state = (struct wlr_surface_state){
|
||||
.scale = 1,
|
||||
.transform = WL_OUTPUT_TRANSFORM_NORMAL,
|
||||
};
|
||||
|
||||
wl_list_init(&state->subsurfaces_above);
|
||||
wl_list_init(&state->subsurfaces_below);
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ static void get_mapping(struct wlr_cursor *cur,
|
|||
struct wlr_input_device *dev, struct wlr_box *box) {
|
||||
assert(cur->state->layout);
|
||||
|
||||
memset(box, 0, sizeof(*box));
|
||||
*box = (struct wlr_box){0};
|
||||
|
||||
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
||||
if (c_device) {
|
||||
|
|
@ -1146,7 +1146,7 @@ void wlr_cursor_map_input_to_output(struct wlr_cursor *cur,
|
|||
|
||||
void wlr_cursor_map_to_region(struct wlr_cursor *cur,
|
||||
const struct wlr_box *box) {
|
||||
memset(&cur->state->mapped_box, 0, sizeof(cur->state->mapped_box));
|
||||
cur->state->mapped_box = (struct wlr_box){0};
|
||||
|
||||
if (box) {
|
||||
if (wlr_box_empty(box)) {
|
||||
|
|
@ -1159,7 +1159,7 @@ void wlr_cursor_map_to_region(struct wlr_cursor *cur,
|
|||
|
||||
void wlr_cursor_map_input_to_region(struct wlr_cursor *cur,
|
||||
struct wlr_input_device *dev, const struct wlr_box *box) {
|
||||
memset(&cur->state->mapped_box, 0, sizeof(cur->state->mapped_box));
|
||||
cur->state->mapped_box = (struct wlr_box){0};
|
||||
|
||||
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
||||
if (!c_device) {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
#define WLR_DAMAGE_RING_MAX_RECTS 20
|
||||
|
||||
void wlr_damage_ring_init(struct wlr_damage_ring *ring) {
|
||||
memset(ring, 0, sizeof(*ring));
|
||||
|
||||
ring->width = INT_MAX;
|
||||
ring->height = INT_MAX;
|
||||
*ring = (struct wlr_damage_ring){
|
||||
.width = INT_MAX,
|
||||
.height = INT_MAX,
|
||||
};
|
||||
|
||||
pixman_region32_init(&ring->current);
|
||||
for (size_t i = 0; i < WLR_DAMAGE_RING_PREVIOUS_LEN; ++i) {
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
void wlr_input_device_init(struct wlr_input_device *dev,
|
||||
enum wlr_input_device_type type, const char *name) {
|
||||
memset(dev, 0, sizeof(*dev));
|
||||
dev->type = type;
|
||||
dev->name = strdup(name);
|
||||
dev->vendor = 0;
|
||||
dev->product = 0;
|
||||
*dev = (struct wlr_input_device){
|
||||
.type = type,
|
||||
.name = strdup(name),
|
||||
};
|
||||
|
||||
wl_signal_init(&dev->events.destroy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,20 +121,20 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard,
|
|||
|
||||
void wlr_keyboard_init(struct wlr_keyboard *kb,
|
||||
const struct wlr_keyboard_impl *impl, const char *name) {
|
||||
memset(kb, 0, sizeof(*kb));
|
||||
*kb = (struct wlr_keyboard){
|
||||
.impl = impl,
|
||||
.keymap_fd = -1,
|
||||
|
||||
// Sane defaults
|
||||
.repeat_info.rate = 25,
|
||||
.repeat_info.delay = 600,
|
||||
};
|
||||
wlr_input_device_init(&kb->base, WLR_INPUT_DEVICE_KEYBOARD, name);
|
||||
|
||||
kb->impl = impl;
|
||||
wl_signal_init(&kb->events.key);
|
||||
wl_signal_init(&kb->events.modifiers);
|
||||
wl_signal_init(&kb->events.keymap);
|
||||
wl_signal_init(&kb->events.repeat_info);
|
||||
|
||||
kb->keymap_fd = -1;
|
||||
|
||||
// Sane defaults
|
||||
kb->repeat_info.rate = 25;
|
||||
kb->repeat_info.delay = 600;
|
||||
}
|
||||
|
||||
static void keyboard_unset_keymap(struct wlr_keyboard *kb) {
|
||||
|
|
|
|||
|
|
@ -1025,7 +1025,7 @@ struct wlr_linux_dmabuf_feedback_v1_tranche *wlr_linux_dmabuf_feedback_add_tranc
|
|||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
memset(tranche, 0, sizeof(*tranche));
|
||||
*tranche = (struct wlr_linux_dmabuf_feedback_v1_tranche){0};
|
||||
return tranche;
|
||||
}
|
||||
|
||||
|
|
@ -1053,7 +1053,7 @@ bool wlr_linux_dmabuf_feedback_v1_init_with_options(struct wlr_linux_dmabuf_feed
|
|||
assert(options->scanout_primary_output == NULL ||
|
||||
options->output_layer_feedback_event == NULL);
|
||||
|
||||
memset(feedback, 0, sizeof(*feedback));
|
||||
*feedback = (struct wlr_linux_dmabuf_feedback_v1){0};
|
||||
|
||||
int renderer_drm_fd = wlr_renderer_get_drm_fd(options->main_renderer);
|
||||
if (renderer_drm_fd < 0) {
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
|
|||
|
||||
void wlr_output_layout_get_box(struct wlr_output_layout *layout,
|
||||
struct wlr_output *reference, struct wlr_box *dest_box) {
|
||||
memset(dest_box, 0, sizeof(*dest_box));
|
||||
*dest_box = (struct wlr_box){0};
|
||||
|
||||
struct wlr_output_layout_output *l_output;
|
||||
if (reference) {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ struct wlr_pointer *wlr_pointer_from_input_device(
|
|||
|
||||
void wlr_pointer_init(struct wlr_pointer *pointer,
|
||||
const struct wlr_pointer_impl *impl, const char *name) {
|
||||
memset(pointer, 0, sizeof(*pointer));
|
||||
*pointer = (struct wlr_pointer){
|
||||
.impl = impl,
|
||||
};
|
||||
wlr_input_device_init(&pointer->base, WLR_INPUT_DEVICE_POINTER, name);
|
||||
|
||||
pointer->impl = impl;
|
||||
wl_signal_init(&pointer->events.motion);
|
||||
wl_signal_init(&pointer->events.motion_absolute);
|
||||
wl_signal_init(&pointer->events.button);
|
||||
|
|
|
|||
|
|
@ -249,13 +249,14 @@ void wlr_presentation_feedback_destroy(
|
|||
|
||||
void wlr_presentation_event_from_output(struct wlr_presentation_event *event,
|
||||
const struct wlr_output_event_present *output_event) {
|
||||
memset(event, 0, sizeof(*event));
|
||||
event->output = output_event->output;
|
||||
event->tv_sec = (uint64_t)output_event->when->tv_sec;
|
||||
event->tv_nsec = (uint32_t)output_event->when->tv_nsec;
|
||||
event->refresh = (uint32_t)output_event->refresh;
|
||||
event->seq = (uint64_t)output_event->seq;
|
||||
event->flags = output_event->flags;
|
||||
*event = (struct wlr_presentation_event){
|
||||
.output = output_event->output,
|
||||
.tv_sec = (uint64_t)output_event->when->tv_sec,
|
||||
.tv_nsec = (uint32_t)output_event->when->tv_nsec,
|
||||
.refresh = (uint32_t)output_event->refresh,
|
||||
.seq = (uint64_t)output_event->seq,
|
||||
.flags = output_event->flags,
|
||||
};
|
||||
}
|
||||
|
||||
static void feedback_unset_output(struct wlr_presentation_feedback *feedback) {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ void wlr_primary_selection_source_init(
|
|||
struct wlr_primary_selection_source *source,
|
||||
const struct wlr_primary_selection_source_impl *impl) {
|
||||
assert(impl->send);
|
||||
memset(source, 0, sizeof(*source));
|
||||
*source = (struct wlr_primary_selection_source){
|
||||
.impl = impl,
|
||||
};
|
||||
wl_array_init(&source->mime_types);
|
||||
wl_signal_init(&source->events.destroy);
|
||||
source->impl = impl;
|
||||
}
|
||||
|
||||
void wlr_primary_selection_source_destroy(
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ struct wlr_switch *wlr_switch_from_input_device(
|
|||
|
||||
void wlr_switch_init(struct wlr_switch *switch_device,
|
||||
const struct wlr_switch_impl *impl, const char *name) {
|
||||
memset(switch_device, 0, sizeof(*switch_device));
|
||||
*switch_device = (struct wlr_switch){
|
||||
.impl = impl,
|
||||
};
|
||||
wlr_input_device_init(&switch_device->base, WLR_INPUT_DEVICE_SWITCH, name);
|
||||
|
||||
switch_device->impl = impl;
|
||||
wl_signal_init(&switch_device->events.toggle);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@ struct wlr_tablet_pad *wlr_tablet_pad_from_input_device(
|
|||
|
||||
void wlr_tablet_pad_init(struct wlr_tablet_pad *pad,
|
||||
const struct wlr_tablet_pad_impl *impl, const char *name) {
|
||||
memset(pad, 0, sizeof(*pad));
|
||||
*pad = (struct wlr_tablet_pad){
|
||||
.impl = impl,
|
||||
};
|
||||
wlr_input_device_init(&pad->base, WLR_INPUT_DEVICE_TABLET_PAD, name);
|
||||
|
||||
pad->impl = impl;
|
||||
wl_signal_init(&pad->events.button);
|
||||
wl_signal_init(&pad->events.ring);
|
||||
wl_signal_init(&pad->events.strip);
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ struct wlr_tablet *wlr_tablet_from_input_device(
|
|||
|
||||
void wlr_tablet_init(struct wlr_tablet *tablet,
|
||||
const struct wlr_tablet_impl *impl, const char *name) {
|
||||
memset(tablet, 0, sizeof(*tablet));
|
||||
*tablet = (struct wlr_tablet){
|
||||
.impl = impl,
|
||||
};
|
||||
wlr_input_device_init(&tablet->base, WLR_INPUT_DEVICE_TABLET_TOOL, name);
|
||||
|
||||
tablet->impl = impl;
|
||||
wl_signal_init(&tablet->events.axis);
|
||||
wl_signal_init(&tablet->events.proximity);
|
||||
wl_signal_init(&tablet->events.tip);
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ struct wlr_touch *wlr_touch_from_input_device(
|
|||
|
||||
void wlr_touch_init(struct wlr_touch *touch,
|
||||
const struct wlr_touch_impl *impl, const char *name) {
|
||||
memset(touch, 0, sizeof(*touch));
|
||||
*touch = (struct wlr_touch){
|
||||
.impl = impl,
|
||||
};
|
||||
wlr_input_device_init(&touch->base, WLR_INPUT_DEVICE_TOUCH, name);
|
||||
|
||||
touch->impl = impl;
|
||||
wl_signal_init(&touch->events.down);
|
||||
wl_signal_init(&touch->events.up);
|
||||
wl_signal_init(&touch->events.motion);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ static void virtual_pointer_frame(struct wl_client *client,
|
|||
/* Deliver pending axis event */
|
||||
wl_signal_emit_mutable(&pointer->pointer.events.axis,
|
||||
&pointer->axis_event[i]);
|
||||
memset(&pointer->axis_event[i], 0, sizeof(pointer->axis_event[i]));
|
||||
pointer->axis_event[i] = (struct wlr_pointer_axis_event){0};
|
||||
pointer->axis_valid[i] = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue