diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-01-24 09:37:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-24 09:37:17 -0500 |
commit | 5941148d4545bc3d45420f31f4408dd06fa54a0e (patch) | |
tree | 3318695da3d7b4ed44e77e996eed2c9cb339483f | |
parent | 4cb0697e576820774013f399c89fe85673e2f338 (diff) | |
parent | 85d84a1a0444bf4ccc7a6a396f2c285540c170ef (diff) |
Merge pull request #1495 from Hjdskes/safe_set_title
backend/x11 & backend/wayland: make set_title NULL-safe
-rw-r--r-- | backend/wayland/output.c | 14 | ||||
-rw-r--r-- | backend/x11/output.c | 13 |
2 files changed, 19 insertions, 8 deletions
diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 1d0c39ef..ba435c25 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -314,10 +314,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) { goto error; } - char title[32]; - if (snprintf(title, sizeof(title), "wlroots - %s", wlr_output->name)) { - xdg_toplevel_set_title(output->xdg_toplevel, title); - } + wlr_wl_output_set_title(wlr_output, NULL); xdg_toplevel_set_app_id(output->xdg_toplevel, "wlroots"); xdg_surface_add_listener(output->xdg_surface, @@ -369,5 +366,14 @@ error: void wlr_wl_output_set_title(struct wlr_output *output, const char *title) { struct wlr_wl_output *wl_output = get_wl_output_from_output(output); + + char wl_title[32]; + if (title == NULL) { + if (snprintf(wl_title, sizeof(wl_title), "wlroots - %s", output->name) <= 0) { + return; + } + title = wl_title; + } + xdg_toplevel_set_title(wl_output->xdg_toplevel, title); } diff --git a/backend/x11/output.c b/backend/x11/output.c index 9c55b154..05df7984 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -185,10 +185,7 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { x11->atoms.wm_protocols, XCB_ATOM_ATOM, 32, 1, &x11->atoms.wm_delete_window); - char title[32]; - if (snprintf(title, sizeof(title), "wlroots - %s", wlr_output->name)) { - wlr_x11_output_set_title(wlr_output, title); - } + wlr_x11_output_set_title(wlr_output, NULL); xcb_map_window(x11->xcb, output->win); xcb_flush(x11->xcb); @@ -236,6 +233,14 @@ bool wlr_output_is_x11(struct wlr_output *wlr_output) { void wlr_x11_output_set_title(struct wlr_output *output, const char *title) { struct wlr_x11_output *x11_output = get_x11_output_from_output(output); + char wl_title[32]; + if (title == NULL) { + if (snprintf(wl_title, sizeof(wl_title), "wlroots - %s", output->name) <= 0) { + return; + } + title = wl_title; + } + xcb_change_property(x11_output->x11->xcb, XCB_PROP_MODE_REPLACE, x11_output->win, x11_output->x11->atoms.net_wm_name, x11_output->x11->atoms.utf8_string, 8, strlen(title), title); |