Use struct initializers instead of memset()

This is a bit more type-safe.
master
Simon Ser 1 year ago
parent 4966857f21
commit 7a9f8d8d6b

@ -197,8 +197,8 @@ Functions that are responsible for constructing objects should take one of the
two following forms: two following forms:
* `init`: for functions which accept a pointer to a pre-allocated object (e.g. * `init`: for functions which accept a pointer to a pre-allocated object (e.g.
a member of a struct) and initialize it. Such functions must call `memset()` a member of a struct) and initialize it. Such functions must zero out the
to zero out the memory before initializing it to avoid leaving unset fields. memory before initializing it to avoid leaving unset fields.
* `create`: for functions which allocate the memory for an object, initialize * `create`: for functions which allocate the memory for an object, initialize
it, and return a pointer. Such functions should allocate the memory with it, and return a pointer. Such functions should allocate the memory with
`calloc()` to avoid leaving unset fields. `calloc()` to avoid leaving unset fields.

@ -40,8 +40,9 @@
void wlr_backend_init(struct wlr_backend *backend, void wlr_backend_init(struct wlr_backend *backend,
const struct wlr_backend_impl *impl) { const struct wlr_backend_impl *impl) {
memset(backend, 0, sizeof(*backend)); *backend = (struct wlr_backend){
backend->impl = impl; .impl = impl,
};
wl_signal_init(&backend->events.destroy); wl_signal_init(&backend->events.destroy);
wl_signal_init(&backend->events.new_input); wl_signal_init(&backend->events.new_input);
wl_signal_init(&backend->events.new_output); wl_signal_init(&backend->events.new_output);

@ -50,7 +50,7 @@ struct atomic {
}; };
static void atomic_begin(struct atomic *atom) { static void atomic_begin(struct atomic *atom) {
memset(atom, 0, sizeof(*atom)); *atom = (struct atomic){0};
atom->req = drmModeAtomicAlloc(); atom->req = drmModeAtomicAlloc();
if (!atom->req) { if (!atom->req) {

@ -445,11 +445,12 @@ static bool drm_crtc_commit(struct wlr_drm_connector *conn,
static void drm_connector_state_init(struct wlr_drm_connector_state *state, static void drm_connector_state_init(struct wlr_drm_connector_state *state,
struct wlr_drm_connector *conn, struct wlr_drm_connector *conn,
const struct wlr_output_state *base) { const struct wlr_output_state *base) {
memset(state, 0, sizeof(*state)); *state = (struct wlr_drm_connector_state){
state->base = base; .base = base,
state->modeset = base->allow_artifacts; .modeset = base->allow_artifacts,
state->active = (base->committed & WLR_OUTPUT_STATE_ENABLED) ? .active = (base->committed & WLR_OUTPUT_STATE_ENABLED) ?
base->enabled : conn->output.enabled; base->enabled : conn->output.enabled,
};
if (base->committed & WLR_OUTPUT_STATE_MODE) { if (base->committed & WLR_OUTPUT_STATE_MODE) {
switch (base->mode_type) { switch (base->mode_type) {
@ -1028,7 +1029,7 @@ static void drm_connector_destroy_output(struct wlr_output *output) {
free(mode); free(mode);
} }
memset(&conn->output, 0, sizeof(struct wlr_output)); conn->output = (struct wlr_output){0};
} }
static const struct wlr_drm_format_set *drm_connector_get_cursor_formats( static const struct wlr_drm_format_set *drm_connector_get_cursor_formats(

@ -55,7 +55,7 @@ static void finish_drm_surface(struct wlr_drm_surface *surf) {
wlr_swapchain_destroy(surf->swapchain); wlr_swapchain_destroy(surf->swapchain);
memset(surf, 0, sizeof(*surf)); *surf = (struct wlr_drm_surface){0};
} }
bool init_drm_surface(struct wlr_drm_surface *surf, bool init_drm_surface(struct wlr_drm_surface *surf,

@ -22,9 +22,10 @@
void wlr_allocator_init(struct wlr_allocator *alloc, void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl, uint32_t buffer_caps) { const struct wlr_allocator_interface *impl, uint32_t buffer_caps) {
assert(impl && impl->destroy && impl->create_buffer); assert(impl && impl->destroy && impl->create_buffer);
memset(alloc, 0, sizeof(*alloc)); *alloc = (struct wlr_allocator){
alloc->impl = impl; .impl = impl,
alloc->buffer_caps = buffer_caps; .buffer_caps = buffer_caps,
};
wl_signal_init(&alloc->events.destroy); wl_signal_init(&alloc->events.destroy);
} }

@ -86,8 +86,9 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
} }
void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format) { void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format) {
memset(fmt, 0, sizeof(*fmt)); *fmt = (struct wlr_drm_format){
fmt->format = format; .format = format,
};
} }
bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) { bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) {

@ -373,8 +373,9 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture, void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture,
struct wlr_gles2_texture_attribs *attribs) { struct wlr_gles2_texture_attribs *attribs) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
memset(attribs, 0, sizeof(*attribs)); *attribs = (struct wlr_gles2_texture_attribs){
attribs->target = texture->target; .target = texture->target,
attribs->tex = texture->tex; .tex = texture->tex,
attribs->has_alpha = texture->has_alpha; .has_alpha = texture->has_alpha,
};
} }

@ -15,8 +15,9 @@ struct wlr_render_pass_legacy {
void wlr_render_pass_init(struct wlr_render_pass *render_pass, void wlr_render_pass_init(struct wlr_render_pass *render_pass,
const struct wlr_render_pass_impl *impl) { const struct wlr_render_pass_impl *impl) {
assert(impl->submit && impl->add_texture && impl->add_rect); assert(impl->submit && impl->add_texture && impl->add_rect);
memset(render_pass, 0, sizeof(*render_pass)); *render_pass = (struct wlr_render_pass){
render_pass->impl = impl; .impl = impl,
};
} }
bool wlr_render_pass_submit(struct wlr_render_pass *render_pass) { bool wlr_render_pass_submit(struct wlr_render_pass *render_pass) {

@ -42,7 +42,7 @@ static void slot_reset(struct wlr_swapchain_slot *slot) {
wl_list_remove(&slot->release.link); wl_list_remove(&slot->release.link);
} }
wlr_buffer_drop(slot->buffer); wlr_buffer_drop(slot->buffer);
memset(slot, 0, sizeof(*slot)); *slot = (struct wlr_swapchain_slot){0};
} }
void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) { void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) {

@ -44,8 +44,9 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
assert(impl->get_shm_texture_formats); assert(impl->get_shm_texture_formats);
assert(impl->get_render_buffer_caps); assert(impl->get_render_buffer_caps);
memset(renderer, 0, sizeof(*renderer)); *renderer = (struct wlr_renderer){
renderer->impl = impl; .impl = impl,
};
wl_signal_init(&renderer->events.destroy); wl_signal_init(&renderer->events.destroy);
wl_signal_init(&renderer->events.lost); wl_signal_init(&renderer->events.lost);

@ -10,11 +10,12 @@ void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *renderer
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) { const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
assert(renderer); assert(renderer);
memset(texture, 0, sizeof(*texture)); *texture = (struct wlr_texture){
texture->renderer = renderer; .renderer = renderer,
texture->impl = impl; .impl = impl,
texture->width = width; .width = width,
texture->height = height; .height = height,
};
} }
void wlr_texture_destroy(struct wlr_texture *texture) { void wlr_texture_destroy(struct wlr_texture *texture) {

@ -11,10 +11,11 @@ void wlr_buffer_init(struct wlr_buffer *buffer,
assert(impl->begin_data_ptr_access && impl->end_data_ptr_access); assert(impl->begin_data_ptr_access && impl->end_data_ptr_access);
} }
memset(buffer, 0, sizeof(*buffer)); *buffer = (struct wlr_buffer){
buffer->impl = impl; .impl = impl,
buffer->width = width; .width = width,
buffer->height = height; .height = height,
};
wl_signal_init(&buffer->events.destroy); wl_signal_init(&buffer->events.destroy);
wl_signal_init(&buffer->events.release); wl_signal_init(&buffer->events.release);
wlr_addon_set_init(&buffer->addons); 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)) { if (!wlr_dmabuf_attributes_copy(&saved_dmabuf, &buffer->dmabuf)) {
wlr_log(WLR_ERROR, "Failed to save DMA-BUF"); wlr_log(WLR_ERROR, "Failed to save DMA-BUF");
ok = false; ok = false;
memset(&buffer->dmabuf, 0, sizeof(buffer->dmabuf)); buffer->dmabuf = (struct wlr_dmabuf_attributes){0};
} else { } else {
buffer->dmabuf = saved_dmabuf; buffer->dmabuf = saved_dmabuf;
buffer->saved = true; buffer->saved = true;

@ -14,11 +14,12 @@ void wlr_data_source_init(struct wlr_data_source *source,
const struct wlr_data_source_impl *impl) { const struct wlr_data_source_impl *impl) {
assert(impl->send); assert(impl->send);
memset(source, 0, sizeof(*source)); *source = (struct wlr_data_source){
source->impl = impl; .impl = impl,
.actions = -1,
};
wl_array_init(&source->mime_types); wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy); wl_signal_init(&source->events.destroy);
source->actions = -1;
} }
void wlr_data_source_send(struct wlr_data_source *source, const char *mime_type, 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); assert(impl->set_cursor && impl->move_cursor);
} }
memset(output, 0, sizeof(*output)); *output = (struct wlr_output){
output->backend = backend; .backend = backend,
output->impl = impl; .impl = impl,
output->display = display; .display = display,
.render_format = DRM_FORMAT_XRGB8888,
.transform = WL_OUTPUT_TRANSFORM_NORMAL,
.scale = 1,
.commit_seq = 0,
};
wl_list_init(&output->modes); 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->cursors);
wl_list_init(&output->layers); wl_list_init(&output->layers);
wl_list_init(&output->resources); 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, static void scene_node_init(struct wlr_scene_node *node,
enum wlr_scene_node_type type, struct wlr_scene_tree *parent) { enum wlr_scene_node_type type, struct wlr_scene_tree *parent) {
memset(node, 0, sizeof(*node)); *node = (struct wlr_scene_node){
node->type = type; .type = type,
node->parent = parent; .parent = parent,
node->enabled = true; .enabled = true,
};
wl_list_init(&node->link); 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, static void scene_tree_init(struct wlr_scene_tree *tree,
struct wlr_scene_tree *parent) { 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); scene_node_init(&tree->node, WLR_SCENE_NODE_TREE, parent);
wl_list_init(&tree->children); 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) { if (old_primary_output != scene_buffer->primary_output) {
memset(&scene_buffer->prev_feedback_options, 0, scene_buffer->prev_feedback_options =
sizeof(scene_buffer->prev_feedback_options)); (struct wlr_linux_dmabuf_feedback_v1_init_options){0};
} }
uint64_t old_active = scene_buffer->active_outputs; 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) { static void surface_state_init(struct wlr_surface_state *state) {
memset(state, 0, sizeof(*state)); *state = (struct wlr_surface_state){
.scale = 1,
state->scale = 1; .transform = WL_OUTPUT_TRANSFORM_NORMAL,
state->transform = WL_OUTPUT_TRANSFORM_NORMAL; };
wl_list_init(&state->subsurfaces_above); wl_list_init(&state->subsurfaces_above);
wl_list_init(&state->subsurfaces_below); 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) { struct wlr_input_device *dev, struct wlr_box *box) {
assert(cur->state->layout); 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); struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
if (c_device) { 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, void wlr_cursor_map_to_region(struct wlr_cursor *cur,
const struct wlr_box *box) { 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 (box) {
if (wlr_box_empty(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, void wlr_cursor_map_input_to_region(struct wlr_cursor *cur,
struct wlr_input_device *dev, const struct wlr_box *box) { 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); struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
if (!c_device) { if (!c_device) {

@ -8,10 +8,10 @@
#define WLR_DAMAGE_RING_MAX_RECTS 20 #define WLR_DAMAGE_RING_MAX_RECTS 20
void wlr_damage_ring_init(struct wlr_damage_ring *ring) { void wlr_damage_ring_init(struct wlr_damage_ring *ring) {
memset(ring, 0, sizeof(*ring)); *ring = (struct wlr_damage_ring){
.width = INT_MAX,
ring->width = INT_MAX; .height = INT_MAX,
ring->height = INT_MAX; };
pixman_region32_init(&ring->current); pixman_region32_init(&ring->current);
for (size_t i = 0; i < WLR_DAMAGE_RING_PREVIOUS_LEN; ++i) { 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, void wlr_input_device_init(struct wlr_input_device *dev,
enum wlr_input_device_type type, const char *name) { enum wlr_input_device_type type, const char *name) {
memset(dev, 0, sizeof(*dev)); *dev = (struct wlr_input_device){
dev->type = type; .type = type,
dev->name = strdup(name); .name = strdup(name),
dev->vendor = 0; };
dev->product = 0;
wl_signal_init(&dev->events.destroy); 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, void wlr_keyboard_init(struct wlr_keyboard *kb,
const struct wlr_keyboard_impl *impl, const char *name) { 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); 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.key);
wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.modifiers);
wl_signal_init(&kb->events.keymap); wl_signal_init(&kb->events.keymap);
wl_signal_init(&kb->events.repeat_info); 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) { 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"); wlr_log_errno(WLR_ERROR, "Allocation failed");
return NULL; return NULL;
} }
memset(tranche, 0, sizeof(*tranche)); *tranche = (struct wlr_linux_dmabuf_feedback_v1_tranche){0};
return tranche; 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 || assert(options->scanout_primary_output == NULL ||
options->output_layer_feedback_event == 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); int renderer_drm_fd = wlr_renderer_get_drm_fd(options->main_renderer);
if (renderer_drm_fd < 0) { 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, void wlr_output_layout_get_box(struct wlr_output_layout *layout,
struct wlr_output *reference, struct wlr_box *dest_box) { 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; struct wlr_output_layout_output *l_output;
if (reference) { if (reference) {

@ -15,10 +15,11 @@ struct wlr_pointer *wlr_pointer_from_input_device(
void wlr_pointer_init(struct wlr_pointer *pointer, void wlr_pointer_init(struct wlr_pointer *pointer,
const struct wlr_pointer_impl *impl, const char *name) { 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); 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);
wl_signal_init(&pointer->events.motion_absolute); wl_signal_init(&pointer->events.motion_absolute);
wl_signal_init(&pointer->events.button); 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, void wlr_presentation_event_from_output(struct wlr_presentation_event *event,
const struct wlr_output_event_present *output_event) { const struct wlr_output_event_present *output_event) {
memset(event, 0, sizeof(*event)); *event = (struct wlr_presentation_event){
event->output = output_event->output; .output = output_event->output,
event->tv_sec = (uint64_t)output_event->when->tv_sec; .tv_sec = (uint64_t)output_event->when->tv_sec,
event->tv_nsec = (uint32_t)output_event->when->tv_nsec; .tv_nsec = (uint32_t)output_event->when->tv_nsec,
event->refresh = (uint32_t)output_event->refresh; .refresh = (uint32_t)output_event->refresh,
event->seq = (uint64_t)output_event->seq; .seq = (uint64_t)output_event->seq,
event->flags = output_event->flags; .flags = output_event->flags,
};
} }
static void feedback_unset_output(struct wlr_presentation_feedback *feedback) { 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, struct wlr_primary_selection_source *source,
const struct wlr_primary_selection_source_impl *impl) { const struct wlr_primary_selection_source_impl *impl) {
assert(impl->send); assert(impl->send);
memset(source, 0, sizeof(*source)); *source = (struct wlr_primary_selection_source){
.impl = impl,
};
wl_array_init(&source->mime_types); wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy); wl_signal_init(&source->events.destroy);
source->impl = impl;
} }
void wlr_primary_selection_source_destroy( 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, void wlr_switch_init(struct wlr_switch *switch_device,
const struct wlr_switch_impl *impl, const char *name) { 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); wlr_input_device_init(&switch_device->base, WLR_INPUT_DEVICE_SWITCH, name);
switch_device->impl = impl;
wl_signal_init(&switch_device->events.toggle); 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, void wlr_tablet_pad_init(struct wlr_tablet_pad *pad,
const struct wlr_tablet_pad_impl *impl, const char *name) { 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); 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.button);
wl_signal_init(&pad->events.ring); wl_signal_init(&pad->events.ring);
wl_signal_init(&pad->events.strip); 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, void wlr_tablet_init(struct wlr_tablet *tablet,
const struct wlr_tablet_impl *impl, const char *name) { 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); 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.axis);
wl_signal_init(&tablet->events.proximity); wl_signal_init(&tablet->events.proximity);
wl_signal_init(&tablet->events.tip); 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, void wlr_touch_init(struct wlr_touch *touch,
const struct wlr_touch_impl *impl, const char *name) { 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); 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.down);
wl_signal_init(&touch->events.up); wl_signal_init(&touch->events.up);
wl_signal_init(&touch->events.motion); wl_signal_init(&touch->events.motion);

@ -113,7 +113,7 @@ static void virtual_pointer_frame(struct wl_client *client,
/* Deliver pending axis event */ /* Deliver pending axis event */
wl_signal_emit_mutable(&pointer->pointer.events.axis, wl_signal_emit_mutable(&pointer->pointer.events.axis,
&pointer->axis_event[i]); &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; pointer->axis_valid[i] = false;
} }
} }

@ -6,7 +6,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
void wlr_addon_set_init(struct wlr_addon_set *set) { void wlr_addon_set_init(struct wlr_addon_set *set) {
memset(set, 0, sizeof(*set)); *set = (struct wlr_addon_set){0};
wl_list_init(&set->addons); wl_list_init(&set->addons);
} }
@ -26,7 +26,10 @@ void wlr_addon_set_finish(struct wlr_addon_set *set) {
void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set, void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,
const void *owner, const struct wlr_addon_interface *impl) { const void *owner, const struct wlr_addon_interface *impl) {
assert(impl); assert(impl);
memset(addon, 0, sizeof(*addon)); *addon = (struct wlr_addon){
.impl = impl,
.owner = owner,
};
struct wlr_addon *iter; struct wlr_addon *iter;
wl_list_for_each(iter, &set->addons, link) { wl_list_for_each(iter, &set->addons, link) {
if (iter->owner == addon->owner && iter->impl == addon->impl) { if (iter->owner == addon->owner && iter->impl == addon->impl) {
@ -34,8 +37,6 @@ void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,
} }
} }
wl_list_insert(&set->addons, &addon->link); wl_list_insert(&set->addons, &addon->link);
addon->owner = owner;
addon->impl = impl;
} }
void wlr_addon_finish(struct wlr_addon *addon) { void wlr_addon_finish(struct wlr_addon *addon) {

@ -34,9 +34,10 @@ void xwm_selection_transfer_destroy_property_reply(
void xwm_selection_transfer_init(struct wlr_xwm_selection_transfer *transfer, void xwm_selection_transfer_init(struct wlr_xwm_selection_transfer *transfer,
struct wlr_xwm_selection *selection) { struct wlr_xwm_selection *selection) {
memset(transfer, 0, sizeof(*transfer)); *transfer = (struct wlr_xwm_selection_transfer){
transfer->selection = selection; .selection = selection,
transfer->wl_client_fd = -1; .wl_client_fd = -1,
};
} }
void xwm_selection_transfer_destroy( void xwm_selection_transfer_destroy(
@ -175,14 +176,14 @@ int xwm_handle_selection_event(struct wlr_xwm *xwm,
void xwm_selection_init(struct wlr_xwm_selection *selection, void xwm_selection_init(struct wlr_xwm_selection *selection,
struct wlr_xwm *xwm, xcb_atom_t atom) { struct wlr_xwm *xwm, xcb_atom_t atom) {
memset(selection, 0, sizeof(*selection)); *selection = (struct wlr_xwm_selection){
.xwm = xwm,
.atom = atom,
.window = xcb_generate_id(xwm->xcb_conn),
};
wl_list_init(&selection->incoming); wl_list_init(&selection->incoming);
wl_list_init(&selection->outgoing); wl_list_init(&selection->outgoing);
selection->xwm = xwm;
selection->atom = atom;
selection->window = xcb_generate_id(xwm->xcb_conn);
if (atom == xwm->atoms[DND_SELECTION]) { if (atom == xwm->atoms[DND_SELECTION]) {
xcb_create_window( xcb_create_window(
xwm->xcb_conn, xwm->xcb_conn,

Loading…
Cancel
Save