event: use log levels, not ifdefs

And some general clean up.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-03-17 14:15:17 +00:00
parent 17c96eb9ba
commit e414fee91f
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 27 additions and 44 deletions

View File

@ -4,6 +4,7 @@
#include <X11/Xlibint.h> #include <X11/Xlibint.h>
#include <X11/extensions/sync.h> #include <X11/extensions/sync.h>
#include "compiler.h"
#include "common.h" #include "common.h"
#include "compton.h" #include "compton.h"
#include "event.h" #include "event.h"
@ -40,30 +41,32 @@
/** /**
* Get a window's name from window ID. * Get a window's name from window ID.
*/ */
static inline void attr_unused ev_window_name(session_t *ps, xcb_window_t wid, char **name) { static inline const char *ev_window_name(session_t *ps, xcb_window_t wid) {
*name = ""; char *name = "";
if (wid) { if (wid) {
*name = "(Failed to get title)"; name = "(Failed to get title)";
if (ps->root == wid) if (ps->root == wid) {
*name = "(Root window)"; name = "(Root window)";
else if (ps->overlay == wid) } else if (ps->overlay == wid) {
*name = "(Overlay)"; name = "(Overlay)";
else { } else {
win *w = find_win(ps, wid); win *w = find_win(ps, wid);
if (!w) if (!w) {
w = find_toplevel(ps, wid); w = find_toplevel(ps, wid);
}
if (w) if (w) {
win_get_name(ps, w); win_get_name(ps, w);
if (w && w->name) if (w->name) {
*name = w->name; name = w->name;
else
*name = "unknown";
} }
} }
} }
}
return name;
}
static inline xcb_window_t attr_unused ev_window(session_t *ps, xcb_generic_event_t *ev) { static inline xcb_window_t attr_pure ev_window(session_t *ps, xcb_generic_event_t *ev) {
switch (ev->response_type) { switch (ev->response_type) {
case FocusIn: case FocusIn:
case FocusOut: return ((xcb_focus_in_event_t *)ev)->event; case FocusOut: return ((xcb_focus_in_event_t *)ev)->event;
@ -90,11 +93,7 @@ static inline xcb_window_t attr_unused ev_window(session_t *ps, xcb_generic_even
} }
} }
static inline int attr_unused ev_serial(xcb_generic_event_t *ev) { static inline const char * ev_name(session_t *ps, xcb_generic_event_t *ev) {
return ev->full_sequence;
}
static inline const char *attr_unused ev_name(session_t *ps, xcb_generic_event_t *ev) {
static char buf[128]; static char buf[128];
switch (ev->response_type & 0x7f) { switch (ev->response_type & 0x7f) {
CASESTRRET(FocusIn); CASESTRRET(FocusIn);
@ -130,7 +129,7 @@ static inline const char *attr_unused ev_name(session_t *ps, xcb_generic_event_t
return buf; return buf;
} }
static inline const char *ev_focus_mode_name(xcb_focus_in_event_t *ev) { static inline const char *attr_pure ev_focus_mode_name(xcb_focus_in_event_t *ev) {
switch (ev->mode) { switch (ev->mode) {
CASESTRRET(NotifyNormal); CASESTRRET(NotifyNormal);
CASESTRRET(NotifyWhileGrabbed); CASESTRRET(NotifyWhileGrabbed);
@ -141,7 +140,7 @@ static inline const char *ev_focus_mode_name(xcb_focus_in_event_t *ev) {
return "Unknown"; return "Unknown";
} }
static inline const char *ev_focus_detail_name(xcb_focus_in_event_t *ev) { static inline const char *attr_pure ev_focus_detail_name(xcb_focus_in_event_t *ev) {
switch (ev->detail) { switch (ev->detail) {
CASESTRRET(NotifyAncestor); CASESTRRET(NotifyAncestor);
CASESTRRET(NotifyVirtual); CASESTRRET(NotifyVirtual);
@ -156,24 +155,15 @@ static inline const char *ev_focus_detail_name(xcb_focus_in_event_t *ev) {
return "Unknown"; return "Unknown";
} }
static inline void attr_unused ev_focus_report(xcb_focus_in_event_t *ev) { static inline void ev_focus_in(session_t *ps, xcb_focus_in_event_t *ev) {
log_trace("{ mode: %s, detail: %s }\n", ev_focus_mode_name(ev), log_trace("{ mode: %s, detail: %s }\n", ev_focus_mode_name(ev),
ev_focus_detail_name(ev)); ev_focus_detail_name(ev));
}
static inline void ev_focus_in(session_t *ps, xcb_focus_in_event_t *ev) {
#ifdef DEBUG_EVENTS
ev_focus_report(ev);
#endif
recheck_focus(ps); recheck_focus(ps);
} }
static inline void ev_focus_out(session_t *ps, xcb_focus_out_event_t *ev) { static inline void ev_focus_out(session_t *ps, xcb_focus_out_event_t *ev) {
#ifdef DEBUG_EVENTS log_trace("{ mode: %s, detail: %s }\n", ev_focus_mode_name(ev),
ev_focus_report(ev); ev_focus_detail_name(ev));
#endif
recheck_focus(ps); recheck_focus(ps);
} }
@ -299,8 +289,7 @@ static inline void ev_expose(session_t *ps, xcb_expose_event_t *ev) {
} }
static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) { static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) {
#ifdef DEBUG_EVENTS if (unlikely(log_get_level_tls() <= LOG_LEVEL_TRACE)) {
{
// Print out changed atom // Print out changed atom
xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply_t *reply =
xcb_get_atom_name_reply(ps->c, xcb_get_atom_name(ps->c, ev->atom), NULL); xcb_get_atom_name_reply(ps->c, xcb_get_atom_name(ps->c, ev->atom), NULL);
@ -314,7 +303,6 @@ static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t
log_trace("{ atom = %.*s }", name_len, name); log_trace("{ atom = %.*s }", name_len, name);
free(reply); free(reply);
} }
#endif
if (ps->root == ev->window) { if (ps->root == ev->window) {
if (ps->o.track_focus && ps->o.use_ewmh_active_win && if (ps->o.track_focus && ps->o.use_ewmh_active_win &&
@ -549,16 +537,11 @@ void ev_handle(session_t *ps, xcb_generic_event_t *ev) {
discard_ignore(ps, ev->full_sequence); discard_ignore(ps, ev->full_sequence);
} }
#ifdef DEBUG_EVENTS
if (ev->response_type != ps->damage_event + XCB_DAMAGE_NOTIFY) { if (ev->response_type != ps->damage_event + XCB_DAMAGE_NOTIFY) {
xcb_window_t wid = ev_window(ps, ev); xcb_window_t wid = ev_window(ps, ev);
char *window_name = NULL; log_trace("event %10.10s serial %#010x window %#010x \"%s\"",
ev_window_name(ps, wid, &window_name); ev_name(ps, ev), ev->full_sequence, wid, ev_window_name(ps, wid));
log_trace("event %10.10s serial %#010x window %#010lx \"%s\"",
ev_name(ps, ev), ev_serial(ev), wid, window_name);
} }
#endif
// Check if a custom XEvent constructor was registered in xlib for this event // Check if a custom XEvent constructor was registered in xlib for this event
// type, and call it discarding the constructed XEvent if any. XESetWireToEvent // type, and call it discarding the constructed XEvent if any. XESetWireToEvent