mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
common: Add additional memory utilities (xzalloc() etc.)
This commit is contained in:
parent
b89f7bfc0d
commit
cb40cdc36c
35 changed files with 193 additions and 167 deletions
40
include/common/mem.h
Normal file
40
include/common/mem.h
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
#ifndef __LABWC_MEM_H
|
||||||
|
#define __LABWC_MEM_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As defined in busybox, weston, etc.
|
||||||
|
* Allocates zero-filled memory; calls exit() on error.
|
||||||
|
* Returns NULL only if (size == 0).
|
||||||
|
*/
|
||||||
|
void *xzalloc(size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As defined in FreeBSD.
|
||||||
|
* Like realloc(), but calls exit() on error.
|
||||||
|
* Returns NULL only if (size == 0).
|
||||||
|
* Does NOT zero-fill memory.
|
||||||
|
*/
|
||||||
|
void *xrealloc(void *ptr, size_t size);
|
||||||
|
|
||||||
|
/* malloc() is a specific case of realloc() */
|
||||||
|
#define xmalloc(size) xrealloc(NULL, (size))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As defined in FreeBSD.
|
||||||
|
* Allocates a copy of <str>; calls exit() on error.
|
||||||
|
* Requires (str != NULL) and never returns NULL.
|
||||||
|
*/
|
||||||
|
char *xstrdup(const char *str);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Frees memory pointed to by <ptr> and sets <ptr> to NULL.
|
||||||
|
* Does nothing if <ptr> is already NULL.
|
||||||
|
*/
|
||||||
|
#define zfree(ptr) do { \
|
||||||
|
free(ptr); (ptr) = NULL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif /* __LABWC_MEM_H */
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
||||||
#ifndef __LABWC_ZFREE_H
|
|
||||||
#define __LABWC_ZFREE_H
|
|
||||||
|
|
||||||
void __zfree(void **ptr);
|
|
||||||
|
|
||||||
#define zfree(ptr) __zfree((void **)&(ptr))
|
|
||||||
|
|
||||||
#endif /* __LABWC_ZFREE_H */
|
|
||||||
10
src/action.c
10
src/action.c
|
|
@ -6,8 +6,8 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
#include "common/zfree.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
|
|
@ -105,7 +105,7 @@ action_create(const char *action_name)
|
||||||
wlr_log(WLR_ERROR, "action name not specified");
|
wlr_log(WLR_ERROR, "action name not specified");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
struct action *action = calloc(1, sizeof(struct action));
|
struct action *action = xzalloc(sizeof(struct action));
|
||||||
action->type = action_type_from_str(action_name);
|
action->type = action_type_from_str(action_name);
|
||||||
wl_list_init(&action->args);
|
wl_list_init(&action->args);
|
||||||
return action;
|
return action;
|
||||||
|
|
@ -372,11 +372,11 @@ void
|
||||||
action_arg_add_str(struct action *action, char *key, const char *value)
|
action_arg_add_str(struct action *action, char *key, const char *value)
|
||||||
{
|
{
|
||||||
assert(value && "Tried to add NULL action string argument");
|
assert(value && "Tried to add NULL action string argument");
|
||||||
struct action_arg_str *arg = calloc(1, sizeof(*arg));
|
struct action_arg_str *arg = xzalloc(sizeof(*arg));
|
||||||
arg->base.type = LAB_ACTION_ARG_STR;
|
arg->base.type = LAB_ACTION_ARG_STR;
|
||||||
if (key) {
|
if (key) {
|
||||||
arg->base.key = strdup(key);
|
arg->base.key = xstrdup(key);
|
||||||
}
|
}
|
||||||
arg->value = strdup(value);
|
arg->value = xstrdup(value);
|
||||||
wl_list_insert(action->args.prev, &arg->base.link);
|
wl_list_insert(action->args.prev, &arg->base.link);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/buffer.c
12
src/buffer.c
|
|
@ -24,12 +24,12 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <drm_fourcc.h>
|
#include <drm_fourcc.h>
|
||||||
#include <wlr/interfaces/wlr_buffer.h>
|
#include <wlr/interfaces/wlr_buffer.h>
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include "common/mem.h"
|
||||||
|
|
||||||
static const struct wlr_buffer_impl data_buffer_impl;
|
static const struct wlr_buffer_impl data_buffer_impl;
|
||||||
|
|
||||||
|
|
@ -88,10 +88,7 @@ struct lab_data_buffer *
|
||||||
buffer_create_cairo(uint32_t width, uint32_t height, float scale,
|
buffer_create_cairo(uint32_t width, uint32_t height, float scale,
|
||||||
bool free_on_destroy)
|
bool free_on_destroy)
|
||||||
{
|
{
|
||||||
struct lab_data_buffer *buffer = calloc(1, sizeof(*buffer));
|
struct lab_data_buffer *buffer = xzalloc(sizeof(*buffer));
|
||||||
if (!buffer) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
buffer->unscaled_width = width;
|
buffer->unscaled_width = width;
|
||||||
buffer->unscaled_height = height;
|
buffer->unscaled_height = height;
|
||||||
width *= scale;
|
width *= scale;
|
||||||
|
|
@ -130,10 +127,7 @@ struct lab_data_buffer *
|
||||||
buffer_create_wrap(void *pixel_data, uint32_t width, uint32_t height,
|
buffer_create_wrap(void *pixel_data, uint32_t width, uint32_t height,
|
||||||
uint32_t stride, bool free_on_destroy)
|
uint32_t stride, bool free_on_destroy)
|
||||||
{
|
{
|
||||||
struct lab_data_buffer *buffer = calloc(1, sizeof(*buffer));
|
struct lab_data_buffer *buffer = xzalloc(sizeof(*buffer));
|
||||||
if (!buffer) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
wlr_buffer_init(&buffer->base, &data_buffer_impl, width, height);
|
wlr_buffer_init(&buffer->base, &data_buffer_impl, width, height);
|
||||||
buffer->data = pixel_data;
|
buffer->data = pixel_data;
|
||||||
buffer->format = DRM_FORMAT_ARGB8888;
|
buffer->format = DRM_FORMAT_ARGB8888;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
|
#include "common/mem.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
strip_curly_braces(char *s)
|
strip_curly_braces(char *s)
|
||||||
|
|
@ -45,7 +46,7 @@ buf_expand_shell_variables(struct buf *s)
|
||||||
/* just add one character at a time */
|
/* just add one character at a time */
|
||||||
if (new.alloc <= new.len + 1) {
|
if (new.alloc <= new.len + 1) {
|
||||||
new.alloc = new.alloc * 3 / 2 + 16;
|
new.alloc = new.alloc * 3 / 2 + 16;
|
||||||
new.buf = realloc(new.buf, new.alloc);
|
new.buf = xrealloc(new.buf, new.alloc);
|
||||||
}
|
}
|
||||||
new.buf[new.len++] = s->buf[i];
|
new.buf[new.len++] = s->buf[i];
|
||||||
new.buf[new.len] = '\0';
|
new.buf[new.len] = '\0';
|
||||||
|
|
@ -60,7 +61,7 @@ void
|
||||||
buf_init(struct buf *s)
|
buf_init(struct buf *s)
|
||||||
{
|
{
|
||||||
s->alloc = 256;
|
s->alloc = 256;
|
||||||
s->buf = malloc(s->alloc);
|
s->buf = xmalloc(s->alloc);
|
||||||
s->buf[0] = '\0';
|
s->buf[0] = '\0';
|
||||||
s->len = 0;
|
s->len = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +75,7 @@ buf_add(struct buf *s, const char *data)
|
||||||
int len = strlen(data);
|
int len = strlen(data);
|
||||||
if (s->alloc <= s->len + len + 1) {
|
if (s->alloc <= s->len + len + 1) {
|
||||||
s->alloc = s->alloc + len;
|
s->alloc = s->alloc + len;
|
||||||
s->buf = realloc(s->buf, s->alloc);
|
s->buf = xrealloc(s->buf, s->alloc);
|
||||||
}
|
}
|
||||||
memcpy(s->buf + s->len, data, len);
|
memcpy(s->buf + s->len, data, len);
|
||||||
s->len += len;
|
s->len += len;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wlr/types/wlr_scene.h>
|
#include <wlr/types/wlr_scene.h>
|
||||||
#include "common/graphic-helpers.h"
|
#include "common/graphic-helpers.h"
|
||||||
|
#include "common/mem.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
multi_rect_destroy_notify(struct wl_listener *listener, void *data)
|
multi_rect_destroy_notify(struct wl_listener *listener, void *data)
|
||||||
|
|
@ -16,7 +17,7 @@ multi_rect_destroy_notify(struct wl_listener *listener, void *data)
|
||||||
struct multi_rect *
|
struct multi_rect *
|
||||||
multi_rect_create(struct wlr_scene_tree *parent, float *colors[3], int line_width)
|
multi_rect_create(struct wlr_scene_tree *parent, float *colors[3], int line_width)
|
||||||
{
|
{
|
||||||
struct multi_rect *rect = calloc(1, sizeof(*rect));
|
struct multi_rect *rect = xzalloc(sizeof(*rect));
|
||||||
rect->line_width = line_width;
|
rect->line_width = line_width;
|
||||||
rect->tree = wlr_scene_tree_create(parent);
|
rect->tree = wlr_scene_tree_create(parent);
|
||||||
rect->destroy.notify = multi_rect_destroy_notify;
|
rect->destroy.notify = multi_rect_destroy_notify;
|
||||||
|
|
|
||||||
47
src/common/mem.c
Normal file
47
src/common/mem.c
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "common/mem.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
die_if_null(void *ptr)
|
||||||
|
{
|
||||||
|
if (!ptr) {
|
||||||
|
perror("Failed to allocate memory");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
xzalloc(size_t size)
|
||||||
|
{
|
||||||
|
if (!size) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
void *ptr = calloc(1, size);
|
||||||
|
die_if_null(ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
xrealloc(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
if (!size) {
|
||||||
|
free(ptr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ptr = realloc(ptr, size);
|
||||||
|
die_if_null(ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
xstrdup(const char *str)
|
||||||
|
{
|
||||||
|
assert(str);
|
||||||
|
char *copy = strdup(str);
|
||||||
|
die_if_null(copy);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
@ -5,11 +5,11 @@ labwc_sources += files(
|
||||||
'font.c',
|
'font.c',
|
||||||
'grab-file.c',
|
'grab-file.c',
|
||||||
'graphic-helpers.c',
|
'graphic-helpers.c',
|
||||||
|
'mem.c',
|
||||||
'nodename.c',
|
'nodename.c',
|
||||||
'scaled_font_buffer.c',
|
'scaled_font_buffer.c',
|
||||||
'scaled_scene_buffer.c',
|
'scaled_scene_buffer.c',
|
||||||
'scene-helpers.c',
|
'scene-helpers.c',
|
||||||
'spawn.c',
|
'spawn.c',
|
||||||
'string-helpers.c',
|
'string-helpers.c',
|
||||||
'zfree.c',
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/scaled_scene_buffer.h"
|
#include "common/scaled_scene_buffer.h"
|
||||||
#include "common/scaled_font_buffer.h"
|
#include "common/scaled_font_buffer.h"
|
||||||
#include "common/zfree.h"
|
|
||||||
|
|
||||||
static struct lab_data_buffer *
|
static struct lab_data_buffer *
|
||||||
_create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
|
_create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
|
||||||
|
|
@ -46,10 +46,7 @@ struct scaled_font_buffer *
|
||||||
scaled_font_buffer_create(struct wlr_scene_tree *parent)
|
scaled_font_buffer_create(struct wlr_scene_tree *parent)
|
||||||
{
|
{
|
||||||
assert(parent);
|
assert(parent);
|
||||||
struct scaled_font_buffer *self = calloc(1, sizeof(*self));
|
struct scaled_font_buffer *self = xzalloc(sizeof(*self));
|
||||||
if (!self) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct scaled_scene_buffer *scaled_buffer
|
struct scaled_scene_buffer *scaled_buffer
|
||||||
= scaled_scene_buffer_create(parent, &impl);
|
= scaled_scene_buffer_create(parent, &impl);
|
||||||
|
|
@ -80,16 +77,16 @@ scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
||||||
zfree(self->arrow);
|
zfree(self->arrow);
|
||||||
|
|
||||||
/* Update internal state */
|
/* Update internal state */
|
||||||
self->text = strdup(text);
|
self->text = xstrdup(text);
|
||||||
self->max_width = max_width;
|
self->max_width = max_width;
|
||||||
if (font->name) {
|
if (font->name) {
|
||||||
self->font.name = strdup(font->name);
|
self->font.name = xstrdup(font->name);
|
||||||
}
|
}
|
||||||
self->font.size = font->size;
|
self->font.size = font->size;
|
||||||
self->font.slant = font->slant;
|
self->font.slant = font->slant;
|
||||||
self->font.weight = font->weight;
|
self->font.weight = font->weight;
|
||||||
memcpy(self->color, color, sizeof(self->color));
|
memcpy(self->color, color, sizeof(self->color));
|
||||||
self->arrow = arrow ? strdup(arrow) : NULL;
|
self->arrow = arrow ? xstrdup(arrow) : NULL;
|
||||||
|
|
||||||
/* Invalidate cache and force a new render */
|
/* Invalidate cache and force a new render */
|
||||||
scaled_scene_buffer_invalidate_cache(self->scaled_buffer);
|
scaled_scene_buffer_invalidate_cache(self->scaled_buffer);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <wlr/types/wlr_scene.h>
|
#include <wlr/types/wlr_scene.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/scaled_scene_buffer.h"
|
#include "common/scaled_scene_buffer.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,7 +68,7 @@ _update_buffer(struct scaled_scene_buffer *self, double scale)
|
||||||
|
|
||||||
/* Create or reuse cache entry */
|
/* Create or reuse cache entry */
|
||||||
if (wl_list_length(&self->cache) < LAB_SCALED_BUFFER_MAX_CACHE) {
|
if (wl_list_length(&self->cache) < LAB_SCALED_BUFFER_MAX_CACHE) {
|
||||||
cache_entry = calloc(1, sizeof(*cache_entry));
|
cache_entry = xzalloc(sizeof(*cache_entry));
|
||||||
} else {
|
} else {
|
||||||
cache_entry = wl_container_of(self->cache.prev, cache_entry, link);
|
cache_entry = wl_container_of(self->cache.prev, cache_entry, link);
|
||||||
if (cache_entry->buffer) {
|
if (cache_entry->buffer) {
|
||||||
|
|
@ -150,10 +151,7 @@ scaled_scene_buffer_create(struct wlr_scene_tree *parent,
|
||||||
assert(impl);
|
assert(impl);
|
||||||
assert(impl->create_buffer);
|
assert(impl->create_buffer);
|
||||||
|
|
||||||
struct scaled_scene_buffer *self = calloc(1, sizeof(*self));
|
struct scaled_scene_buffer *self = xzalloc(sizeof(*self));
|
||||||
if (!self) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->scene_buffer = wlr_scene_buffer_create(parent, NULL);
|
self->scene_buffer = wlr_scene_buffer_create(parent, NULL);
|
||||||
if (!self->scene_buffer) {
|
if (!self->scene_buffer) {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "common/zfree.h"
|
|
||||||
|
|
||||||
void __zfree(void **ptr)
|
|
||||||
{
|
|
||||||
if (!ptr || !*ptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free(*ptr);
|
|
||||||
*ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "config/keybind.h"
|
#include "config/keybind.h"
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
|
|
||||||
|
|
@ -27,7 +28,7 @@ parse_modifier(const char *symname)
|
||||||
struct keybind *
|
struct keybind *
|
||||||
keybind_create(const char *keybind)
|
keybind_create(const char *keybind)
|
||||||
{
|
{
|
||||||
struct keybind *k = calloc(1, sizeof(struct keybind));
|
struct keybind *k = xzalloc(sizeof(struct keybind));
|
||||||
xkb_keysym_t keysyms[MAX_KEYSYMS];
|
xkb_keysym_t keysyms[MAX_KEYSYMS];
|
||||||
gchar **symnames = g_strsplit(keybind, "-", -1);
|
gchar **symnames = g_strsplit(keybind, "-", -1);
|
||||||
for (int i = 0; symnames[i]; i++) {
|
for (int i = 0; symnames[i]; i++) {
|
||||||
|
|
@ -60,7 +61,7 @@ keybind_create(const char *keybind)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wl_list_insert(rc.keybinds.prev, &k->link);
|
wl_list_insert(rc.keybinds.prev, &k->link);
|
||||||
k->keysyms = malloc(k->keysyms_len * sizeof(xkb_keysym_t));
|
k->keysyms = xmalloc(k->keysyms_len * sizeof(xkb_keysym_t));
|
||||||
memcpy(k->keysyms, keysyms, k->keysyms_len * sizeof(xkb_keysym_t));
|
memcpy(k->keysyms, keysyms, k->keysyms_len * sizeof(xkb_keysym_t));
|
||||||
wl_list_init(&k->actions);
|
wl_list_init(&k->actions);
|
||||||
return k;
|
return k;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include "common/mem.h"
|
||||||
#include "config/libinput.h"
|
#include "config/libinput.h"
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
libinput_category_init(struct libinput_category *l)
|
libinput_category_init(struct libinput_category *l)
|
||||||
{
|
{
|
||||||
|
|
@ -36,10 +38,7 @@ get_device_type(const char *s)
|
||||||
struct libinput_category *
|
struct libinput_category *
|
||||||
libinput_category_create(void)
|
libinput_category_create(void)
|
||||||
{
|
{
|
||||||
struct libinput_category *l = calloc(1, sizeof(struct libinput_category));
|
struct libinput_category *l = xzalloc(sizeof(struct libinput_category));
|
||||||
if (!l) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
libinput_category_init(l);
|
libinput_category_init(l);
|
||||||
wl_list_insert(&rc.libinput_categories, &l->link);
|
wl_list_insert(&rc.libinput_categories, &l->link);
|
||||||
return l;
|
return l;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "config/mousebind.h"
|
#include "config/mousebind.h"
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
|
|
||||||
|
|
@ -108,7 +109,7 @@ mousebind_create(const char *context)
|
||||||
wlr_log(WLR_ERROR, "mousebind context not specified");
|
wlr_log(WLR_ERROR, "mousebind context not specified");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
struct mousebind *m = calloc(1, sizeof(struct mousebind));
|
struct mousebind *m = xzalloc(sizeof(struct mousebind));
|
||||||
m->context = context_from_str(context);
|
m->context = context_from_str(context);
|
||||||
if (m->context != LAB_SSD_NONE) {
|
if (m->context != LAB_SSD_NONE) {
|
||||||
wl_list_insert(rc.mousebinds.prev, &m->link);
|
wl_list_insert(rc.mousebinds.prev, &m->link);
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/nodename.h"
|
#include "common/nodename.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
#include "common/zfree.h"
|
|
||||||
#include "config/keybind.h"
|
#include "config/keybind.h"
|
||||||
#include "config/libinput.h"
|
#include "config/libinput.h"
|
||||||
#include "config/mousebind.h"
|
#include "config/mousebind.h"
|
||||||
|
|
@ -194,7 +194,7 @@ fill_libinput_category(char *nodename, char *content)
|
||||||
|| !strcmp(content, "default")) {
|
|| !strcmp(content, "default")) {
|
||||||
current_libinput_category->type = get_device_type(content);
|
current_libinput_category->type = get_device_type(content);
|
||||||
} else {
|
} else {
|
||||||
current_libinput_category->name = strdup(content);
|
current_libinput_category->name = xstrdup(content);
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp(nodename, "naturalScroll")) {
|
} else if (!strcasecmp(nodename, "naturalScroll")) {
|
||||||
current_libinput_category->natural_scroll =
|
current_libinput_category->natural_scroll =
|
||||||
|
|
@ -241,7 +241,7 @@ set_font_attr(struct font *font, const char *nodename, const char *content)
|
||||||
{
|
{
|
||||||
if (!strcmp(nodename, "name")) {
|
if (!strcmp(nodename, "name")) {
|
||||||
zfree(font->name);
|
zfree(font->name);
|
||||||
font->name = strdup(content);
|
font->name = xstrdup(content);
|
||||||
} else if (!strcmp(nodename, "size")) {
|
} else if (!strcmp(nodename, "size")) {
|
||||||
font->size = atoi(content);
|
font->size = atoi(content);
|
||||||
} else if (!strcmp(nodename, "slant")) {
|
} else if (!strcmp(nodename, "slant")) {
|
||||||
|
|
@ -361,7 +361,7 @@ entry(xmlNode *node, char *nodename, char *content)
|
||||||
} else if (!strcasecmp(nodename, "adaptiveSync.core")) {
|
} else if (!strcasecmp(nodename, "adaptiveSync.core")) {
|
||||||
rc.adaptive_sync = get_bool(content);
|
rc.adaptive_sync = get_bool(content);
|
||||||
} else if (!strcmp(nodename, "name.theme")) {
|
} else if (!strcmp(nodename, "name.theme")) {
|
||||||
rc.theme_name = strdup(content);
|
rc.theme_name = xstrdup(content);
|
||||||
} else if (!strcmp(nodename, "cornerradius.theme")) {
|
} else if (!strcmp(nodename, "cornerradius.theme")) {
|
||||||
rc.corner_radius = atoi(content);
|
rc.corner_radius = atoi(content);
|
||||||
} else if (!strcmp(nodename, "name.font.theme")) {
|
} else if (!strcmp(nodename, "name.font.theme")) {
|
||||||
|
|
@ -401,8 +401,8 @@ entry(xmlNode *node, char *nodename, char *content)
|
||||||
} else if (!strcasecmp(nodename, "cycleViewOutlines.core")) {
|
} else if (!strcasecmp(nodename, "cycleViewOutlines.core")) {
|
||||||
rc.cycle_preview_outlines = get_bool(content);
|
rc.cycle_preview_outlines = get_bool(content);
|
||||||
} else if (!strcasecmp(nodename, "name.names.desktops")) {
|
} else if (!strcasecmp(nodename, "name.names.desktops")) {
|
||||||
struct workspace *workspace = calloc(1, sizeof(struct workspace));
|
struct workspace *workspace = xzalloc(sizeof(struct workspace));
|
||||||
workspace->name = strdup(content);
|
workspace->name = xstrdup(content);
|
||||||
wl_list_insert(rc.workspace_config.workspaces.prev, &workspace->link);
|
wl_list_insert(rc.workspace_config.workspaces.prev, &workspace->link);
|
||||||
} else if (!strcasecmp(nodename, "popupTime.desktops")) {
|
} else if (!strcasecmp(nodename, "popupTime.desktops")) {
|
||||||
rc.workspace_config.popuptime = atoi(content);
|
rc.workspace_config.popuptime = atoi(content);
|
||||||
|
|
@ -671,13 +671,13 @@ post_processing(void)
|
||||||
merge_mouse_bindings();
|
merge_mouse_bindings();
|
||||||
|
|
||||||
if (!rc.font_activewindow.name) {
|
if (!rc.font_activewindow.name) {
|
||||||
rc.font_activewindow.name = strdup("sans");
|
rc.font_activewindow.name = xstrdup("sans");
|
||||||
}
|
}
|
||||||
if (!rc.font_menuitem.name) {
|
if (!rc.font_menuitem.name) {
|
||||||
rc.font_menuitem.name = strdup("sans");
|
rc.font_menuitem.name = xstrdup("sans");
|
||||||
}
|
}
|
||||||
if (!rc.font_osd.name) {
|
if (!rc.font_osd.name) {
|
||||||
rc.font_osd.name = strdup("sans");
|
rc.font_osd.name = xstrdup("sans");
|
||||||
}
|
}
|
||||||
if (!wl_list_length(&rc.libinput_categories)) {
|
if (!wl_list_length(&rc.libinput_categories)) {
|
||||||
/* So we still allow tap to click by default */
|
/* So we still allow tap to click by default */
|
||||||
|
|
@ -685,8 +685,8 @@ post_processing(void)
|
||||||
l->type = DEFAULT_DEVICE;
|
l->type = DEFAULT_DEVICE;
|
||||||
}
|
}
|
||||||
if (!wl_list_length(&rc.workspace_config.workspaces)) {
|
if (!wl_list_length(&rc.workspace_config.workspaces)) {
|
||||||
struct workspace *workspace = calloc(1, sizeof(struct workspace));
|
struct workspace *workspace = xzalloc(sizeof(struct workspace));
|
||||||
workspace->name = strdup("Default");
|
workspace->name = xstrdup("Default");
|
||||||
wl_list_insert(rc.workspace_config.workspaces.prev, &workspace->link);
|
wl_list_insert(rc.workspace_config.workspaces.prev, &workspace->link);
|
||||||
}
|
}
|
||||||
if (rc.workspace_config.popuptime == INT_MIN) {
|
if (rc.workspace_config.popuptime == INT_MIN) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
|
|
||||||
|
|
@ -78,10 +79,7 @@ build_path(const char *dir, const char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int len = strlen(dir) + strlen(filename) + 2;
|
int len = strlen(dir) + strlen(filename) + 2;
|
||||||
char *buffer = calloc(1, len);
|
char *buffer = xzalloc(len);
|
||||||
if (!buffer) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcat(buffer, dir);
|
strcat(buffer, dir);
|
||||||
strcat(buffer, "/");
|
strcat(buffer, "/");
|
||||||
strcat(buffer, filename);
|
strcat(buffer, filename);
|
||||||
|
|
@ -103,25 +101,17 @@ update_activation_env(const char *env_keys)
|
||||||
const char *dbus = "dbus-update-activation-environment ";
|
const char *dbus = "dbus-update-activation-environment ";
|
||||||
const char *systemd = "systemctl --user import-environment ";
|
const char *systemd = "systemctl --user import-environment ";
|
||||||
|
|
||||||
cmd = calloc(1, strlen(dbus) + strlen(env_keys) + 1);
|
cmd = xzalloc(strlen(dbus) + strlen(env_keys) + 1);
|
||||||
if (!cmd) {
|
strcat(cmd, dbus);
|
||||||
wlr_log(WLR_ERROR, "Failed to allocate memory for dbus env update");
|
strcat(cmd, env_keys);
|
||||||
} else {
|
spawn_async_no_shell(cmd);
|
||||||
strcat(cmd, dbus);
|
free(cmd);
|
||||||
strcat(cmd, env_keys);
|
|
||||||
spawn_async_no_shell(cmd);
|
|
||||||
free(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = calloc(1, strlen(systemd) + strlen(env_keys) + 1);
|
cmd = xzalloc(strlen(systemd) + strlen(env_keys) + 1);
|
||||||
if (!cmd) {
|
strcat(cmd, systemd);
|
||||||
wlr_log(WLR_ERROR, "Failed to allocate memory for systemd env update");
|
strcat(cmd, env_keys);
|
||||||
} else {
|
spawn_async_no_shell(cmd);
|
||||||
strcat(cmd, systemd);
|
free(cmd);
|
||||||
strcat(cmd, env_keys);
|
|
||||||
spawn_async_no_shell(cmd);
|
|
||||||
free(cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -158,11 +148,7 @@ session_autostart_init(const char *dir)
|
||||||
}
|
}
|
||||||
wlr_log(WLR_INFO, "run autostart file %s", autostart);
|
wlr_log(WLR_INFO, "run autostart file %s", autostart);
|
||||||
int len = strlen(autostart) + 4;
|
int len = strlen(autostart) + 4;
|
||||||
char *cmd = calloc(1, len);
|
char *cmd = xzalloc(len);
|
||||||
if (!cmd) {
|
|
||||||
wlr_log(WLR_ERROR, "Failed to allocate memory for autostart command");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
strcat(cmd, "sh ");
|
strcat(cmd, "sh ");
|
||||||
strcat(cmd, autostart);
|
strcat(cmd, autostart);
|
||||||
spawn_async_no_shell(cmd);
|
spawn_async_no_shell(cmd);
|
||||||
|
|
|
||||||
10
src/cursor.c
10
src/cursor.c
|
|
@ -6,12 +6,13 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <wlr/types/wlr_primary_selection.h>
|
#include <wlr/types/wlr_primary_selection.h>
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
|
#include "common/mem.h"
|
||||||
|
#include "common/scene-helpers.h"
|
||||||
|
#include "config/mousebind.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "resistance.h"
|
#include "resistance.h"
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
#include "config/mousebind.h"
|
|
||||||
#include "common/scene-helpers.h"
|
|
||||||
|
|
||||||
static const char **cursor_names = NULL;
|
static const char **cursor_names = NULL;
|
||||||
|
|
||||||
|
|
@ -531,15 +532,14 @@ create_constraint(struct wl_listener *listener, void *data)
|
||||||
struct wlr_pointer_constraint_v1 *wlr_constraint = data;
|
struct wlr_pointer_constraint_v1 *wlr_constraint = data;
|
||||||
struct server *server = wl_container_of(listener, server,
|
struct server *server = wl_container_of(listener, server,
|
||||||
new_constraint);
|
new_constraint);
|
||||||
struct view *view;
|
struct constraint *constraint = xzalloc(sizeof(struct constraint));
|
||||||
struct constraint *constraint = calloc(1, sizeof(struct constraint));
|
|
||||||
|
|
||||||
constraint->constraint = wlr_constraint;
|
constraint->constraint = wlr_constraint;
|
||||||
constraint->seat = &server->seat;
|
constraint->seat = &server->seat;
|
||||||
constraint->destroy.notify = destroy_constraint;
|
constraint->destroy.notify = destroy_constraint;
|
||||||
wl_signal_add(&wlr_constraint->events.destroy, &constraint->destroy);
|
wl_signal_add(&wlr_constraint->events.destroy, &constraint->destroy);
|
||||||
|
|
||||||
view = desktop_focused_view(server);
|
struct view *view = desktop_focused_view(server);
|
||||||
if (view && view->surface == wlr_constraint->surface) {
|
if (view && view->surface == wlr_constraint->surface) {
|
||||||
constrain_cursor(server, wlr_constraint);
|
constrain_cursor(server, wlr_constraint);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/layers.c
11
src/layers.c
|
|
@ -14,6 +14,7 @@
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/types/wlr_layer_shell_v1.h>
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "layers.h"
|
#include "layers.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
@ -202,10 +203,7 @@ create_popup(struct wlr_xdg_popup *wlr_popup, struct wlr_scene_tree *parent,
|
||||||
struct wlr_box *output_toplevel_sx_box)
|
struct wlr_box *output_toplevel_sx_box)
|
||||||
{
|
{
|
||||||
struct lab_layer_popup *popup =
|
struct lab_layer_popup *popup =
|
||||||
calloc(1, sizeof(struct lab_layer_popup));
|
xzalloc(sizeof(struct lab_layer_popup));
|
||||||
if (!popup) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
popup->wlr_popup = wlr_popup;
|
popup->wlr_popup = wlr_popup;
|
||||||
popup->scene_tree =
|
popup->scene_tree =
|
||||||
|
|
@ -325,10 +323,7 @@ new_layer_surface_notify(struct wl_listener *listener, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lab_layer_surface *surface =
|
struct lab_layer_surface *surface =
|
||||||
calloc(1, sizeof(struct lab_layer_surface));
|
xzalloc(sizeof(struct lab_layer_surface));
|
||||||
if (!surface) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
surface->surface_commit.notify = surface_commit_notify;
|
surface->surface_commit.notify = surface_commit_notify;
|
||||||
wl_signal_add(&layer_surface->surface->events.commit,
|
wl_signal_add(&layer_surface->surface->events.commit,
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "common/dir.h"
|
#include "common/dir.h"
|
||||||
|
#include "common/fd_util.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
#include "config/session.h"
|
#include "config/session.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "xbm/xbm.h"
|
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "common/fd_util.h"
|
|
||||||
|
|
||||||
struct rcxml rc = { 0 };
|
struct rcxml rc = { 0 };
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ main(int argc, char *argv[])
|
||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
rc.config_dir = strdup(optarg);
|
rc.config_dir = xstrdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
verbosity = WLR_DEBUG;
|
verbosity = WLR_DEBUG;
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,14 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/nodename.h"
|
#include "common/nodename.h"
|
||||||
#include "common/scaled_font_buffer.h"
|
#include "common/scaled_font_buffer.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
#include "common/zfree.h"
|
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "buffer.h"
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#define MENUWIDTH (110)
|
#define MENUWIDTH (110)
|
||||||
|
|
@ -44,14 +43,14 @@ menu_create(struct server *server, const char *id, const char *label)
|
||||||
{
|
{
|
||||||
if (nr_menus == alloc_menus) {
|
if (nr_menus == alloc_menus) {
|
||||||
alloc_menus = (alloc_menus + 16) * 2;
|
alloc_menus = (alloc_menus + 16) * 2;
|
||||||
menus = realloc(menus, alloc_menus * sizeof(struct menu));
|
menus = xrealloc(menus, alloc_menus * sizeof(struct menu));
|
||||||
}
|
}
|
||||||
struct menu *menu = menus + nr_menus;
|
struct menu *menu = menus + nr_menus;
|
||||||
memset(menu, 0, sizeof(*menu));
|
memset(menu, 0, sizeof(*menu));
|
||||||
nr_menus++;
|
nr_menus++;
|
||||||
wl_list_init(&menu->menuitems);
|
wl_list_init(&menu->menuitems);
|
||||||
menu->id = strdup(id);
|
menu->id = xstrdup(id);
|
||||||
menu->label = label ? strdup(label) : strdup(id);
|
menu->label = xstrdup(label ? label : id);
|
||||||
menu->parent = current_menu;
|
menu->parent = current_menu;
|
||||||
menu->server = server;
|
menu->server = server;
|
||||||
menu->size.width = MENUWIDTH;
|
menu->size.width = MENUWIDTH;
|
||||||
|
|
@ -80,10 +79,7 @@ menu_get_by_id(const char *id)
|
||||||
static struct menuitem *
|
static struct menuitem *
|
||||||
item_create(struct menu *menu, const char *text, bool show_arrow)
|
item_create(struct menu *menu, const char *text, bool show_arrow)
|
||||||
{
|
{
|
||||||
struct menuitem *menuitem = calloc(1, sizeof(struct menuitem));
|
struct menuitem *menuitem = xzalloc(sizeof(struct menuitem));
|
||||||
if (!menuitem) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
menuitem->parent = menu;
|
menuitem->parent = menu;
|
||||||
menuitem->selectable = true;
|
menuitem->selectable = true;
|
||||||
struct server *server = menu->server;
|
struct server *server = menu->server;
|
||||||
|
|
@ -164,10 +160,7 @@ item_create(struct menu *menu, const char *text, bool show_arrow)
|
||||||
static struct menuitem *
|
static struct menuitem *
|
||||||
separator_create(struct menu *menu, const char *label)
|
separator_create(struct menu *menu, const char *label)
|
||||||
{
|
{
|
||||||
struct menuitem *menuitem = calloc(1, sizeof(struct menuitem));
|
struct menuitem *menuitem = xzalloc(sizeof(struct menuitem));
|
||||||
if (!menuitem) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
menuitem->parent = menu;
|
menuitem->parent = menu;
|
||||||
menuitem->selectable = false;
|
menuitem->selectable = false;
|
||||||
struct server *server = menu->server;
|
struct server *server = menu->server;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -26,10 +27,7 @@ node_descriptor_create(struct wlr_scene_node *scene_node,
|
||||||
enum node_descriptor_type type, void *data)
|
enum node_descriptor_type type, void *data)
|
||||||
{
|
{
|
||||||
struct node_descriptor *node_descriptor =
|
struct node_descriptor *node_descriptor =
|
||||||
calloc(1, sizeof(struct node_descriptor));
|
xzalloc(sizeof(struct node_descriptor));
|
||||||
if (!node_descriptor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
node_descriptor->type = type;
|
node_descriptor->type = type;
|
||||||
node_descriptor->data = data;
|
node_descriptor->data = data;
|
||||||
node_descriptor->destroy.notify = destroy_notify;
|
node_descriptor->destroy.notify = destroy_notify;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include "config.h"
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <wlr/types/wlr_buffer.h>
|
#include <wlr/types/wlr_buffer.h>
|
||||||
#include <wlr/types/wlr_drm_lease_v1.h>
|
#include <wlr/types/wlr_drm_lease_v1.h>
|
||||||
|
|
@ -16,13 +15,10 @@
|
||||||
#include <wlr/types/wlr_scene.h>
|
#include <wlr/types/wlr_scene.h>
|
||||||
#include <wlr/util/region.h>
|
#include <wlr/util/region.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "buffer.h"
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "layers.h"
|
#include "layers.h"
|
||||||
#include "menu/menu.h"
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "ssd.h"
|
|
||||||
#include "theme.h"
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
output_frame_notify(struct wl_listener *listener, void *data)
|
output_frame_notify(struct wl_listener *listener, void *data)
|
||||||
|
|
@ -129,7 +125,7 @@ new_output_notify(struct wl_listener *listener, void *data)
|
||||||
|
|
||||||
wlr_output_commit(wlr_output);
|
wlr_output_commit(wlr_output);
|
||||||
|
|
||||||
struct output *output = calloc(1, sizeof(struct output));
|
struct output *output = xzalloc(sizeof(struct output));
|
||||||
output->wlr_output = wlr_output;
|
output->wlr_output = wlr_output;
|
||||||
wlr_output->data = output;
|
wlr_output->data = output;
|
||||||
output->server = server;
|
output->server = server;
|
||||||
|
|
|
||||||
10
src/seat.c
10
src/seat.c
|
|
@ -8,6 +8,7 @@
|
||||||
#include <wlr/types/wlr_pointer.h>
|
#include <wlr/types/wlr_pointer.h>
|
||||||
#include <wlr/types/wlr_touch.h>
|
#include <wlr/types/wlr_touch.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -201,7 +202,7 @@ new_input_notify(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct seat *seat = wl_container_of(listener, seat, new_input);
|
struct seat *seat = wl_container_of(listener, seat, new_input);
|
||||||
struct wlr_input_device *device = data;
|
struct wlr_input_device *device = data;
|
||||||
struct input *input = calloc(1, sizeof(struct input));
|
struct input *input = xzalloc(sizeof(struct input));
|
||||||
input->wlr_input_device = device;
|
input->wlr_input_device = device;
|
||||||
input->seat = seat;
|
input->seat = seat;
|
||||||
|
|
||||||
|
|
@ -262,11 +263,8 @@ new_idle_inhibitor(struct wl_listener *listener, void *data)
|
||||||
struct seat *seat = wl_container_of(listener, seat,
|
struct seat *seat = wl_container_of(listener, seat,
|
||||||
idle_inhibitor_create);
|
idle_inhibitor_create);
|
||||||
|
|
||||||
struct idle_inhibitor *inhibitor = calloc(1,
|
struct idle_inhibitor *inhibitor =
|
||||||
sizeof(struct idle_inhibitor));
|
xzalloc(sizeof(struct idle_inhibitor));
|
||||||
if (!inhibitor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
inhibitor->seat = seat;
|
inhibitor->seat = seat;
|
||||||
inhibitor->wlr_inhibitor = wlr_inhibitor;
|
inhibitor->wlr_inhibitor = wlr_inhibitor;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/scene-helpers.h"
|
#include "common/scene-helpers.h"
|
||||||
|
|
||||||
static struct ssd_part *
|
static struct ssd_part *
|
||||||
|
|
@ -18,7 +19,7 @@ add_extent(struct wl_list *part_list, enum ssd_part_type type,
|
||||||
* part->geometry will get free'd automatically in ssd_destroy_parts().
|
* part->geometry will get free'd automatically in ssd_destroy_parts().
|
||||||
*/
|
*/
|
||||||
part->node = &wlr_scene_rect_create(parent, 0, 0, invisible)->node;
|
part->node = &wlr_scene_rect_create(parent, 0, 0, invisible)->node;
|
||||||
part->geometry = calloc(1, sizeof(struct wlr_box));
|
part->geometry = xzalloc(sizeof(struct wlr_box));
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "common/font.h"
|
|
||||||
|
|
||||||
/* Internal helpers */
|
/* Internal helpers */
|
||||||
static void
|
static void
|
||||||
|
|
@ -24,7 +24,7 @@ static struct ssd_button *
|
||||||
ssd_button_descriptor_create(struct wlr_scene_node *node)
|
ssd_button_descriptor_create(struct wlr_scene_node *node)
|
||||||
{
|
{
|
||||||
/* Create new ssd_button */
|
/* Create new ssd_button */
|
||||||
struct ssd_button *button = calloc(1, sizeof(struct ssd_button));
|
struct ssd_button *button = xzalloc(sizeof(struct ssd_button));
|
||||||
|
|
||||||
/* Let it destroy automatically when the scene node destroys */
|
/* Let it destroy automatically when the scene node destroys */
|
||||||
button->destroy.notify = ssd_button_destroy_notify;
|
button->destroy.notify = ssd_button_destroy_notify;
|
||||||
|
|
@ -39,7 +39,7 @@ ssd_button_descriptor_create(struct wlr_scene_node *node)
|
||||||
struct ssd_part *
|
struct ssd_part *
|
||||||
add_scene_part(struct wl_list *part_list, enum ssd_part_type type)
|
add_scene_part(struct wl_list *part_list, enum ssd_part_type type)
|
||||||
{
|
{
|
||||||
struct ssd_part *part = calloc(1, sizeof(struct ssd_part));
|
struct ssd_part *part = xzalloc(sizeof(struct ssd_part));
|
||||||
part->type = type;
|
part->type = type;
|
||||||
wl_list_insert(part_list->prev, &part->link);
|
wl_list_insert(part_list->prev, &part->link);
|
||||||
return part;
|
return part;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
|
#include "common/mem.h"
|
||||||
#include "common/scaled_font_buffer.h"
|
#include "common/scaled_font_buffer.h"
|
||||||
#include "common/scene-helpers.h"
|
#include "common/scene-helpers.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
@ -271,7 +272,7 @@ ssd_update_title(struct view *view)
|
||||||
if (state->text) {
|
if (state->text) {
|
||||||
free(state->text);
|
free(state->text);
|
||||||
}
|
}
|
||||||
state->text = strdup(title);
|
state->text = xstrdup(title);
|
||||||
}
|
}
|
||||||
ssd_update_title_positions(view);
|
ssd_update_title_positions(view);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
#include "common/graphic-helpers.h"
|
#include "common/graphic-helpers.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
#include "common/zfree.h"
|
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "xbm/xbm.h"
|
#include "xbm/xbm.h"
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
#include "common/graphic-helpers.h"
|
#include "common/graphic-helpers.h"
|
||||||
#include "common/zfree.h"
|
#include "common/mem.h"
|
||||||
#include "workspaces.h"
|
#include "workspaces.h"
|
||||||
|
|
||||||
/* Internal helpers */
|
/* Internal helpers */
|
||||||
|
|
@ -154,9 +154,9 @@ _osd_update(struct server *server)
|
||||||
static void
|
static void
|
||||||
add_workspace(struct server *server, const char *name)
|
add_workspace(struct server *server, const char *name)
|
||||||
{
|
{
|
||||||
struct workspace *workspace = calloc(1, sizeof(struct workspace));
|
struct workspace *workspace = xzalloc(sizeof(struct workspace));
|
||||||
workspace->server = server;
|
workspace->server = server;
|
||||||
workspace->name = strdup(name);
|
workspace->name = xstrdup(name);
|
||||||
workspace->tree = wlr_scene_tree_create(server->view_tree);
|
workspace->tree = wlr_scene_tree_create(server->view_tree);
|
||||||
wl_list_insert(server->workspaces.prev, &workspace->link);
|
wl_list_insert(server->workspaces.prev, &workspace->link);
|
||||||
if (!server->workspace_current) {
|
if (!server->workspace_current) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "common/mem.h"
|
||||||
#include "xbm/parse.h"
|
#include "xbm/parse.h"
|
||||||
|
|
||||||
static uint32_t color;
|
static uint32_t color;
|
||||||
|
|
@ -37,8 +38,8 @@ parse_set_color(float *rgba)
|
||||||
static void
|
static void
|
||||||
process_bytes(struct pixmap *pixmap, struct token *tokens)
|
process_bytes(struct pixmap *pixmap, struct token *tokens)
|
||||||
{
|
{
|
||||||
pixmap->data = (uint32_t *)calloc(pixmap->width * pixmap->height,
|
pixmap->data = (uint32_t *)xzalloc(
|
||||||
sizeof(uint32_t));
|
pixmap->width * pixmap->height * sizeof(uint32_t));
|
||||||
struct token *t = tokens;
|
struct token *t = tokens;
|
||||||
for (int row = 0; row < pixmap->height; row++) {
|
for (int row = 0; row < pixmap->height; row++) {
|
||||||
int byte = 1;
|
int byte = 1;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "common/mem.h"
|
||||||
#include "xbm/tokenize.h"
|
#include "xbm/tokenize.h"
|
||||||
|
|
||||||
static char *current_buffer_position;
|
static char *current_buffer_position;
|
||||||
|
|
@ -20,7 +21,7 @@ add_token(enum token_type token_type)
|
||||||
{
|
{
|
||||||
if (nr_tokens == alloc_tokens) {
|
if (nr_tokens == alloc_tokens) {
|
||||||
alloc_tokens = (alloc_tokens + 16) * 2;
|
alloc_tokens = (alloc_tokens + 16) * 2;
|
||||||
tokens = realloc(tokens, alloc_tokens * sizeof(struct token));
|
tokens = xrealloc(tokens, alloc_tokens * sizeof(struct token));
|
||||||
}
|
}
|
||||||
struct token *token = tokens + nr_tokens;
|
struct token *token = tokens + nr_tokens;
|
||||||
memset(token, 0, sizeof(*token));
|
memset(token, 0, sizeof(*token));
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
|
||||||
struct xdg_deco {
|
struct xdg_deco {
|
||||||
|
|
@ -43,10 +44,7 @@ xdg_toplevel_decoration(struct wl_listener *listener, void *data)
|
||||||
struct server *server =
|
struct server *server =
|
||||||
wl_container_of(listener, server, xdg_toplevel_decoration);
|
wl_container_of(listener, server, xdg_toplevel_decoration);
|
||||||
struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data;
|
struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data;
|
||||||
struct xdg_deco *xdg_deco = calloc(1, sizeof(struct xdg_deco));
|
struct xdg_deco *xdg_deco = xzalloc(sizeof(struct xdg_deco));
|
||||||
if (!xdg_deco) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xdg_deco->wlr_decoration = wlr_decoration;
|
xdg_deco->wlr_decoration = wlr_decoration;
|
||||||
xdg_deco->server = server;
|
xdg_deco->server = server;
|
||||||
xdg_deco->view = wlr_decoration->surface->data;
|
xdg_deco->view = wlr_decoration->surface->data;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
* - keeping non-layer-shell xdg-popups outside the layers.c code
|
* - keeping non-layer-shell xdg-popups outside the layers.c code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
|
|
@ -67,10 +68,7 @@ xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xdg_popup *popup = calloc(1, sizeof(struct xdg_popup));
|
struct xdg_popup *popup = xzalloc(sizeof(struct xdg_popup));
|
||||||
if (!popup) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
popup->parent_view = view;
|
popup->parent_view = view;
|
||||||
popup->wlr_popup = wlr_popup;
|
popup->wlr_popup = wlr_popup;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
|
|
@ -374,7 +375,7 @@ xdg_surface_new(struct wl_listener *listener, void *data)
|
||||||
|
|
||||||
wlr_xdg_surface_ping(xdg_surface);
|
wlr_xdg_surface_ping(xdg_surface);
|
||||||
|
|
||||||
struct view *view = calloc(1, sizeof(struct view));
|
struct view *view = xzalloc(sizeof(struct view));
|
||||||
view->server = server;
|
view->server = server;
|
||||||
view->type = LAB_XDG_SHELL_VIEW;
|
view->type = LAB_XDG_SHELL_VIEW;
|
||||||
view->impl = &xdg_toplevel_view_impl;
|
view->impl = &xdg_toplevel_view_impl;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -139,8 +140,8 @@ struct xwayland_unmanaged *
|
||||||
xwayland_unmanaged_create(struct server *server,
|
xwayland_unmanaged_create(struct server *server,
|
||||||
struct wlr_xwayland_surface *xsurface)
|
struct wlr_xwayland_surface *xsurface)
|
||||||
{
|
{
|
||||||
struct xwayland_unmanaged *unmanaged;
|
struct xwayland_unmanaged *unmanaged =
|
||||||
unmanaged = calloc(1, sizeof(struct xwayland_unmanaged));
|
xzalloc(sizeof(struct xwayland_unmanaged));
|
||||||
unmanaged->server = server;
|
unmanaged->server = server;
|
||||||
unmanaged->xwayland_surface = xsurface;
|
unmanaged->xwayland_surface = xsurface;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include "common/mem.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
|
|
@ -483,7 +484,7 @@ xwayland_surface_new(struct wl_listener *listener, void *data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct view *view = calloc(1, sizeof(struct view));
|
struct view *view = xzalloc(sizeof(struct view));
|
||||||
view->server = server;
|
view->server = server;
|
||||||
view->type = LAB_XWAYLAND_VIEW;
|
view->type = LAB_XWAYLAND_VIEW;
|
||||||
view->impl = &xwl_view_impl;
|
view->impl = &xwl_view_impl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue