summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
Diffstat (limited to 'clients')
-rw-r--r--clients/desktop-shell.c10
-rw-r--r--clients/nested.c4
-rw-r--r--clients/resizor.c13
-rw-r--r--clients/terminal.c9
-rw-r--r--clients/weston-info.c126
-rw-r--r--clients/window.c2
6 files changed, 138 insertions, 26 deletions
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 4e7a815e..a0c6b6d4 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -21,12 +21,15 @@
* OF THIS SOFTWARE.
*/
+#include "config.h"
+
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#include <math.h>
#include <cairo.h>
#include <sys/wait.h>
@@ -609,7 +612,7 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
launcher = xzalloc(sizeof *launcher);
launcher->icon = load_icon_or_fallback(icon);
- launcher->path = strdup(path);
+ launcher->path = xstrdup(path);
wl_array_init(&launcher->envp);
wl_array_init(&launcher->argv);
@@ -1061,6 +1064,11 @@ background_create(struct desktop *desktop)
weston_config_section_get_string(s, "background-type",
&type, "tile");
+ if (type == NULL) {
+ fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
+ exit(EXIT_FAILURE);
+ }
+
if (strcmp(type, "scale") == 0) {
background->type = BACKGROUND_SCALE;
} else if (strcmp(type, "scale-crop") == 0) {
diff --git a/clients/nested.c b/clients/nested.c
index 74767795..d75e953a 100644
--- a/clients/nested.c
+++ b/clients/nested.c
@@ -844,7 +844,7 @@ static void
blit_surface_init(struct nested_surface *surface)
{
struct nested_blit_surface *blit_surface =
- zalloc(sizeof *blit_surface);
+ xzalloc(sizeof *blit_surface);
glGenTextures(1, &blit_surface->texture);
glBindTexture(GL_TEXTURE_2D, blit_surface->texture);
@@ -967,7 +967,7 @@ ss_surface_init(struct nested_surface *surface)
struct wl_compositor *compositor =
display_get_compositor(nested->display);
struct nested_ss_surface *ss_surface =
- zalloc(sizeof *ss_surface);
+ xzalloc(sizeof *ss_surface);
struct rectangle allocation;
struct wl_region *region;
diff --git a/clients/resizor.c b/clients/resizor.c
index 9cf1a3c6..b5ea55f6 100644
--- a/clients/resizor.c
+++ b/clients/resizor.c
@@ -77,6 +77,14 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time)
assert(!callback || callback == resizor->frame_callback);
+ if (resizor->frame_callback) {
+ wl_callback_destroy(resizor->frame_callback);
+ resizor->frame_callback = NULL;
+ }
+
+ if (window_is_maximized(resizor->window))
+ return;
+
spring_update(&resizor->width);
spring_update(&resizor->height);
@@ -84,11 +92,6 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time)
resizor->width.current + 0.5,
resizor->height.current + 0.5);
- if (resizor->frame_callback) {
- wl_callback_destroy(resizor->frame_callback);
- resizor->frame_callback = NULL;
- }
-
if (!spring_done(&resizor->width) || !spring_done(&resizor->height)) {
resizor->frame_callback =
wl_surface_frame(
diff --git a/clients/terminal.c b/clients/terminal.c
index e2a6236c..f3646fe3 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -848,9 +848,10 @@ resize_handler(struct widget *widget,
width = columns * terminal->average_width + m;
height = rows * terminal->extents.height + m;
widget_set_size(terminal->widget, width, height);
- asprintf(&p, "%s — [%dx%d]", terminal->title, columns, rows);
- window_set_title(terminal->window, p);
- free(p);
+ if (asprintf(&p, "%s — [%dx%d]", terminal->title, columns, rows) > 0) {
+ window_set_title(terminal->window, p);
+ free(p);
+ }
}
terminal_resize_cells(terminal, columns, rows);
@@ -2829,7 +2830,7 @@ terminal_create(struct display *display)
terminal->margin_bottom = -1;
terminal->window = window_create(display);
terminal->widget = window_frame_create(terminal->window, terminal);
- terminal->title = strdup("Wayland Terminal");
+ terminal->title = xstrdup("Wayland Terminal");
window_set_title(terminal->window, terminal->title);
widget_set_transparent(terminal->widget, 0);
diff --git a/clients/weston-info.c b/clients/weston-info.c
index 4cc05723..147dc489 100644
--- a/clients/weston-info.c
+++ b/clients/weston-info.c
@@ -20,6 +20,9 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "config.h"
+
+#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -30,6 +33,7 @@
#include "../shared/os-compatibility.h"
typedef void (*print_info_t)(void *info);
+typedef void (*destroy_info_t)(void *info);
struct global_info {
struct wl_list link;
@@ -39,6 +43,7 @@ struct global_info {
char *interface;
print_info_t print;
+ destroy_info_t destroy;
};
struct output_mode {
@@ -96,18 +101,34 @@ struct weston_info {
};
static void *
-xmalloc(size_t s)
+fail_on_null(void *p)
{
- void *p = malloc(s);
-
if (p == NULL) {
- fprintf(stderr, "out of memory\n");
- exit(1);
+ fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
+ exit(EXIT_FAILURE);
}
return p;
}
+static void *
+xmalloc(size_t s)
+{
+ return fail_on_null(malloc(s));
+}
+
+static void *
+xzalloc(size_t s)
+{
+ return fail_on_null(calloc(1, s));
+}
+
+static char *
+xstrdup(const char *s)
+{
+ return fail_on_null(strdup(s));
+}
+
static void
print_global_info(void *data)
{
@@ -124,7 +145,7 @@ init_global_info(struct weston_info *info,
{
global->id = id;
global->version = version;
- global->interface = strdup(interface);
+ global->interface = xstrdup(interface);
wl_list_insert(info->infos.prev, &global->link);
}
@@ -285,7 +306,7 @@ seat_handle_name(void *data, struct wl_seat *wl_seat,
const char *name)
{
struct seat_info *seat = data;
- seat->name = strdup(name);
+ seat->name = xstrdup(name);
}
static const struct wl_seat_listener seat_listener = {
@@ -294,12 +315,24 @@ static const struct wl_seat_listener seat_listener = {
};
static void
+destroy_seat_info(void *data)
+{
+ struct seat_info *seat = data;
+
+ wl_seat_destroy(seat->seat);
+
+ if (seat->name != NULL)
+ free(seat->name);
+}
+
+static void
add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
{
- struct seat_info *seat = xmalloc(sizeof *seat);
+ struct seat_info *seat = xzalloc(sizeof *seat);
init_global_info(info, &seat->global, id, "wl_seat", version);
seat->global.print = print_seat_info;
+ seat->global.destroy = destroy_seat_info;
seat->seat = wl_registry_bind(info->registry,
id, &wl_seat_interface, 2);
@@ -312,7 +345,7 @@ static void
shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
{
struct shm_info *shm = data;
- struct shm_format *shm_format = xmalloc(sizeof *shm_format);
+ struct shm_format *shm_format = xzalloc(sizeof *shm_format);
wl_list_insert(&shm->formats, &shm_format->link);
shm_format->format = format;
@@ -323,12 +356,28 @@ static const struct wl_shm_listener shm_listener = {
};
static void
+destroy_shm_info(void *data)
+{
+ struct shm_info *shm = data;
+ struct shm_format *format, *tmp;
+
+ wl_list_for_each_safe(format, tmp, &shm->formats, link) {
+ wl_list_remove(&format->link);
+ free(format);
+ }
+
+ wl_shm_destroy(shm->shm);
+}
+
+static void
add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
{
- struct shm_info *shm = xmalloc(sizeof *shm);
+ struct shm_info *shm = xzalloc(sizeof *shm);
init_global_info(info, &shm->global, id, "wl_shm", version);
shm->global.print = print_shm_info;
+ shm->global.destroy = destroy_shm_info;
+
wl_list_init(&shm->formats);
shm->shm = wl_registry_bind(info->registry,
@@ -353,8 +402,8 @@ output_handle_geometry(void *data, struct wl_output *wl_output,
output->geometry.physical_width = physical_width;
output->geometry.physical_height = physical_height;
output->geometry.subpixel = subpixel;
- output->geometry.make = strdup(make);
- output->geometry.model = strdup(model);
+ output->geometry.make = xstrdup(make);
+ output->geometry.model = xstrdup(model);
output->geometry.output_transform = output_transform;
}
@@ -380,12 +429,32 @@ static const struct wl_output_listener output_listener = {
};
static void
+destroy_output_info(void *data)
+{
+ struct output_info *output = data;
+ struct output_mode *mode, *tmp;
+
+ wl_output_destroy(output->output);
+
+ if (output->geometry.make != NULL)
+ free(output->geometry.make);
+ if (output->geometry.model != NULL)
+ free(output->geometry.model);
+
+ wl_list_for_each_safe(mode, tmp, &output->modes, link) {
+ wl_list_remove(&mode->link);
+ free(mode);
+ }
+}
+
+static void
add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
{
- struct output_info *output = xmalloc(sizeof *output);
+ struct output_info *output = xzalloc(sizeof *output);
init_global_info(info, &output->global, id, "wl_output", version);
output->global.print = print_output_info;
+ output->global.destroy = destroy_output_info;
wl_list_init(&output->modes);
@@ -398,13 +467,19 @@ add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
}
static void
+destroy_global_info(void *data)
+{
+}
+
+static void
add_global_info(struct weston_info *info, uint32_t id,
const char *interface, uint32_t version)
{
- struct global_info *global = xmalloc(sizeof *global);
+ struct global_info *global = xzalloc(sizeof *global);
init_global_info(info, global, id, interface, version);
global->print = print_global_info;
+ global->destroy = destroy_global_info;
}
static void
@@ -442,6 +517,25 @@ print_infos(struct wl_list *infos)
info->print(info);
}
+static void
+destroy_info(void *data)
+{
+ struct global_info *global = data;
+
+ global->destroy(data);
+ wl_list_remove(&global->link);
+ free(global->interface);
+ free(data);
+}
+
+static void
+destroy_infos(struct wl_list *infos)
+{
+ struct global_info *info, *tmp;
+ wl_list_for_each_safe(info, tmp, infos, link)
+ destroy_info(info);
+}
+
int
main(int argc, char **argv)
{
@@ -464,6 +558,10 @@ main(int argc, char **argv)
} while (info.roundtrip_needed);
print_infos(&info.infos);
+ destroy_infos(&info.infos);
+
+ wl_registry_destroy(info.registry);
+ wl_display_disconnect(info.display);
return 0;
}
diff --git a/clients/window.c b/clients/window.c
index d59b9c7f..d8d79d04 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -2934,6 +2934,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
if (num_syms == 1)
sym = syms[0];
+
if (sym == XKB_KEY_F5 && input->modifiers == MOD_ALT_MASK) {
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
window_set_maximized(window,
@@ -4593,6 +4594,7 @@ window_show_menu(struct display *display,
window_set_buffer_transform (menu->window, window_get_buffer_transform (parent));
menu->frame = frame_create(window->display->theme, 0, 0,
FRAME_BUTTON_NONE, NULL);
+ fail_on_null(menu->frame);
menu->entries = entries;
menu->count = count;
menu->release_count = 0;