Commit b3b00655 authored by Pekka Paalanen's avatar Pekka Paalanen Committed by Daniel Stone

xwm: move FILE to the callers of dump_property()

This is preparation for using the weston-debug infrastructure for
WM_DEBUG. dump_property() may be called from different debugging
contexts and often needs to be prefixed with more information.

An alternative to this patch would be to pass in the weston_debug_scope
as an argument to dump_property(), but then all callers would need to be
converted to weston-debug infra in a single commit.

Therefore require the callers to provide the FILE* to print to.
Signed-off-by: Pekka Paalanen's avatarPekka Paalanen <pq@iki.fi>
Signed-off-by: default avatarManiraj Devadoss <Maniraj.Devadoss@in.bosch.com>
Reviewed-by: Pekka Paalanen's avatarPekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone's avatarDaniel Stone <daniels@collabora.com>
parent 0a3ef990
......@@ -34,6 +34,12 @@
#include "xwayland.h"
#include "shared/helpers.h"
#ifdef WM_DEBUG
#define wm_log(...) weston_log(__VA_ARGS__)
#else
#define wm_log(...) do {} while (0)
#endif
static int
writable_callback(int fd, uint32_t mask, void *data)
{
......@@ -102,6 +108,9 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
{
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply;
FILE *fp;
char *logstr;
size_t logsize;
cookie = xcb_get_property(wm->conn,
0, /* delete */
......@@ -115,7 +124,13 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
if (reply == NULL)
return;
dump_property(wm, wm->atom.wl_selection, reply);
fp = open_memstream(&logstr, &logsize);
if (fp) {
dump_property(fp, wm, wm->atom.wl_selection, reply);
if (fclose(fp) == 0)
wm_log("%s", logstr);
free(logstr);
}
if (xcb_get_property_value_length(reply) > 0) {
/* reply's ownership is transferred to wm, which is responsible
......@@ -178,6 +193,9 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
xcb_atom_t *value;
char **p;
uint32_t i;
FILE *fp;
char *logstr;
size_t logsize;
cookie = xcb_get_property(wm->conn,
1, /* delete */
......@@ -191,7 +209,13 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
if (reply == NULL)
return;
dump_property(wm, wm->atom.wl_selection, reply);
fp = open_memstream(&logstr, &logsize);
if (fp) {
dump_property(fp, wm, wm->atom.wl_selection, reply);
if (fclose(fp) == 0)
wm_log("%s", logstr);
free(logstr);
}
if (reply->type != XCB_ATOM_ATOM) {
free(reply);
......@@ -232,6 +256,9 @@ weston_wm_get_selection_data(struct weston_wm *wm)
{
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply;
FILE *fp;
char *logstr;
size_t logsize;
cookie = xcb_get_property(wm->conn,
1, /* delete */
......@@ -243,7 +270,13 @@ weston_wm_get_selection_data(struct weston_wm *wm)
reply = xcb_get_property_reply(wm->conn, cookie, NULL);
dump_property(wm, wm->atom.wl_selection, reply);
fp = open_memstream(&logstr, &logsize);
if (fp) {
dump_property(fp, wm, wm->atom.wl_selection, reply);
if (fclose(fp) == 0)
wm_log("%s", logstr);
free(logstr);
}
if (reply == NULL) {
return;
......
......@@ -210,23 +210,6 @@ wm_log(const char *fmt, ...)
#endif
}
static int __attribute__ ((format (printf, 1, 2)))
wm_log_continue(const char *fmt, ...)
{
#ifdef WM_DEBUG
int l;
va_list argp;
va_start(argp, fmt);
l = weston_vlog_continue(fmt, argp);
va_end(argp);
return l;
#else
return 0;
#endif
}
static void
weston_output_weak_ref_init(struct weston_output_weak_ref *ref)
{
......@@ -430,7 +413,7 @@ dump_cardinal_array(FILE *fp, xcb_get_property_reply_t *reply)
}
void
dump_property(struct weston_wm *wm,
dump_property(FILE *fp, struct weston_wm *wm,
xcb_atom_t property, xcb_get_property_reply_t *reply)
{
int32_t *incr_value;
......@@ -439,18 +422,11 @@ dump_property(struct weston_wm *wm,
xcb_window_t *window_value;
int width, len;
uint32_t i;
FILE *fp;
char *logstr;
size_t logsize;
fp = open_memstream(&logstr, &logsize);
if (!fp)
return;
width = fprintf(fp, "%s: ", get_atom_name(wm->conn, property));
if (reply == NULL) {
fprintf(fp, "(no reply)\n");
goto out;
return;
}
width += fprintf(fp, "%s/%d, length %d (value_len %d): ",
......@@ -492,15 +468,10 @@ dump_property(struct weston_wm *wm,
} else {
fprintf(fp, "huh?\n");
}
out:
if (fclose(fp) == 0)
wm_log_continue("%s", logstr);
free(logstr);
}
static void
read_and_dump_property(struct weston_wm *wm,
read_and_dump_property(FILE *fp, struct weston_wm *wm,
xcb_window_t window, xcb_atom_t property)
{
xcb_get_property_reply_t *reply;
......@@ -510,7 +481,7 @@ read_and_dump_property(struct weston_wm *wm,
property, XCB_ATOM_ANY, 0, 2048);
reply = xcb_get_property_reply(wm->conn, cookie, NULL);
dump_property(wm, property, reply);
dump_property(fp, wm, property, reply);
free(reply);
}
......@@ -1389,19 +1360,35 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even
xcb_property_notify_event_t *property_notify =
(xcb_property_notify_event_t *) event;
struct weston_wm_window *window;
FILE *fp;
char *logstr;
size_t logsize;
if (!wm_lookup_window(wm, property_notify->window, &window))
return;
window->properties_dirty = 1;
wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
if (property_notify->state == XCB_PROPERTY_DELETE)
wm_log_continue("deleted %s\n",
get_atom_name(wm->conn, property_notify->atom));
else
read_and_dump_property(wm, property_notify->window,
property_notify->atom);
fp = open_memstream(&logstr, &logsize);
if (fp) {
fprintf(fp, "XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
if (property_notify->state == XCB_PROPERTY_DELETE)
fprintf(fp, "deleted %s\n",
get_atom_name(wm->conn, property_notify->atom));
else
read_and_dump_property(fp, wm, property_notify->window,
property_notify->atom);
if (fclose(fp) == 0)
wm_log("%s", logstr);
free(logstr);
} else {
/* read_and_dump_property() is a X11 roundtrip.
* Mimic it to maintain ordering semantics between debug
* and non-debug paths.
*/
get_atom_name(wm->conn, property_notify->atom);
}
if (property_notify->atom == wm->atom.net_wm_name ||
property_notify->atom == XCB_ATOM_WM_NAME)
......
......@@ -23,6 +23,7 @@
* SOFTWARE.
*/
#include <stdio.h>
#include <wayland-server.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
......@@ -159,7 +160,7 @@ struct weston_wm {
};
void
dump_property(struct weston_wm *wm, xcb_atom_t property,
dump_property(FILE *fp, struct weston_wm *wm, xcb_atom_t property,
xcb_get_property_reply_t *reply);
const char *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment