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 <pq@iki.fi>
Signed-off-by: Maniraj Devadoss <Maniraj.Devadoss@in.bosch.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
dev
Pekka Paalanen 7 years ago committed by Daniel Stone
parent 0a3ef9902a
commit b3b0065598
  1. 39
      xwayland/selection.c
  2. 67
      xwayland/window-manager.c
  3. 3
      xwayland/xwayland.h

@ -34,6 +34,12 @@
#include "xwayland.h" #include "xwayland.h"
#include "shared/helpers.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 static int
writable_callback(int fd, uint32_t mask, void *data) 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_cookie_t cookie;
xcb_get_property_reply_t *reply; xcb_get_property_reply_t *reply;
FILE *fp;
char *logstr;
size_t logsize;
cookie = xcb_get_property(wm->conn, cookie = xcb_get_property(wm->conn,
0, /* delete */ 0, /* delete */
@ -115,7 +124,13 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
if (reply == NULL) if (reply == NULL)
return; 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) { if (xcb_get_property_value_length(reply) > 0) {
/* reply's ownership is transferred to wm, which is responsible /* 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; xcb_atom_t *value;
char **p; char **p;
uint32_t i; uint32_t i;
FILE *fp;
char *logstr;
size_t logsize;
cookie = xcb_get_property(wm->conn, cookie = xcb_get_property(wm->conn,
1, /* delete */ 1, /* delete */
@ -191,7 +209,13 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
if (reply == NULL) if (reply == NULL)
return; 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) { if (reply->type != XCB_ATOM_ATOM) {
free(reply); free(reply);
@ -232,6 +256,9 @@ weston_wm_get_selection_data(struct weston_wm *wm)
{ {
xcb_get_property_cookie_t cookie; xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply; xcb_get_property_reply_t *reply;
FILE *fp;
char *logstr;
size_t logsize;
cookie = xcb_get_property(wm->conn, cookie = xcb_get_property(wm->conn,
1, /* delete */ 1, /* delete */
@ -243,7 +270,13 @@ weston_wm_get_selection_data(struct weston_wm *wm)
reply = xcb_get_property_reply(wm->conn, cookie, NULL); 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) { if (reply == NULL) {
return; return;

@ -210,23 +210,6 @@ wm_log(const char *fmt, ...)
#endif #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 static void
weston_output_weak_ref_init(struct weston_output_weak_ref *ref) 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 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) xcb_atom_t property, xcb_get_property_reply_t *reply)
{ {
int32_t *incr_value; int32_t *incr_value;
@ -439,18 +422,11 @@ dump_property(struct weston_wm *wm,
xcb_window_t *window_value; xcb_window_t *window_value;
int width, len; int width, len;
uint32_t i; 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)); width = fprintf(fp, "%s: ", get_atom_name(wm->conn, property));
if (reply == NULL) { if (reply == NULL) {
fprintf(fp, "(no reply)\n"); fprintf(fp, "(no reply)\n");
goto out; return;
} }
width += fprintf(fp, "%s/%d, length %d (value_len %d): ", width += fprintf(fp, "%s/%d, length %d (value_len %d): ",
@ -492,15 +468,10 @@ dump_property(struct weston_wm *wm,
} else { } else {
fprintf(fp, "huh?\n"); fprintf(fp, "huh?\n");
} }
out:
if (fclose(fp) == 0)
wm_log_continue("%s", logstr);
free(logstr);
} }
static void 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_window_t window, xcb_atom_t property)
{ {
xcb_get_property_reply_t *reply; xcb_get_property_reply_t *reply;
@ -510,7 +481,7 @@ read_and_dump_property(struct weston_wm *wm,
property, XCB_ATOM_ANY, 0, 2048); property, XCB_ATOM_ANY, 0, 2048);
reply = xcb_get_property_reply(wm->conn, cookie, NULL); reply = xcb_get_property_reply(wm->conn, cookie, NULL);
dump_property(wm, property, reply); dump_property(fp, wm, property, reply);
free(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 *property_notify =
(xcb_property_notify_event_t *) event; (xcb_property_notify_event_t *) event;
struct weston_wm_window *window; struct weston_wm_window *window;
FILE *fp;
char *logstr;
size_t logsize;
if (!wm_lookup_window(wm, property_notify->window, &window)) if (!wm_lookup_window(wm, property_notify->window, &window))
return; return;
window->properties_dirty = 1; window->properties_dirty = 1;
wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window); fp = open_memstream(&logstr, &logsize);
if (property_notify->state == XCB_PROPERTY_DELETE) if (fp) {
wm_log_continue("deleted %s\n", fprintf(fp, "XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
get_atom_name(wm->conn, property_notify->atom)); if (property_notify->state == XCB_PROPERTY_DELETE)
else fprintf(fp, "deleted %s\n",
read_and_dump_property(wm, property_notify->window, get_atom_name(wm->conn, property_notify->atom));
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 || if (property_notify->atom == wm->atom.net_wm_name ||
property_notify->atom == XCB_ATOM_WM_NAME) property_notify->atom == XCB_ATOM_WM_NAME)

@ -23,6 +23,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <stdio.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xfixes.h> #include <xcb/xfixes.h>
@ -159,7 +160,7 @@ struct weston_wm {
}; };
void 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); xcb_get_property_reply_t *reply);
const char * const char *

Loading…
Cancel
Save