Add more tracing options to debug UI messages

Added REPORT_MOUSE/PAINT/TIMER_MESSAGES macros, and change _EVENTS to
_MESSAGES to avoid confusion with the current terminology.

The output string for each message was also simplified.
This commit is contained in:
David Capello 2024-10-17 19:23:52 -03:00
parent 71f6dbad28
commit a7799b76fc
2 changed files with 46 additions and 22 deletions

View File

@ -63,4 +63,5 @@ target_link_libraries(ui-lib
laf-os
laf-gfx
laf-base
obs)
obs
fmt)

View File

@ -5,11 +5,14 @@
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
// #define REPORT_EVENTS
// #define REPORT_FOCUS_MOVEMENT
// #define DEBUG_PAINT_EVENTS
// #define LIMIT_DISPATCH_TIME
#define GARBAGE_TRACE(...)
// #define REPORT_MESSAGES 1
// #define REPORT_MOUSE_MESSAGES 1
// #define REPORT_PAINT_MESSAGES 1
// #define REPORT_TIMER_MESSAGES 1
// #define REPORT_FOCUS_MOVEMENT 1
// #define DEBUG_PAINT_MESSAGES 1
// #define LIMIT_DISPATCH_TIME 1
#define GARBAGE_TRACE(...) // TRACE(__VA_ARGS__)
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -21,6 +24,7 @@
#include "base/scoped_value.h"
#include "base/thread.h"
#include "base/time.h"
#include "fmt/format.h"
#include "os/event.h"
#include "os/event_queue.h"
#include "os/surface.h"
@ -38,7 +42,7 @@
#include <utility>
#include <vector>
#if defined(_WIN32) && defined(DEBUG_PAINT_EVENTS)
#if defined(_WIN32) && defined(DEBUG_PAINT_MESSAGES)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef min
@ -989,7 +993,7 @@ void Manager::setFocus(Widget* widget)
void Manager::setMouse(Widget* widget)
{
#ifdef REPORT_EVENTS
#if REPORT_MOUSE_MESSAGES
TRACEARGS("Manager::setMouse ",
(widget ? typeid(*widget).name(): "null"),
(widget ? widget->id(): ""));
@ -1812,13 +1816,13 @@ int Manager::pumpQueue()
{
ASSERT(manager_thread == std::this_thread::get_id());
#ifdef LIMIT_DISPATCH_TIME
#if LIMIT_DISPATCH_TIME
base::tick_t t = base::current_tick();
#endif
int count = 0; // Number of processed messages
while (!msg_queue.empty()) {
#ifdef LIMIT_DISPATCH_TIME
#if LIMIT_DISPATCH_TIME
if (base::current_tick()-t > 250)
break;
#endif
@ -1887,7 +1891,7 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
if (!widget)
return false;
#ifdef REPORT_EVENTS
#if REPORT_MESSAGES
{
static const char* msg_name[] = {
"kOpenMessage",
@ -1918,15 +1922,38 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
static_assert(kOpenMessage == 0 &&
kCallbackMessage == sizeof(msg_name)/sizeof(const char*)-1,
"MessageType enum has changed");
const char* string =
const char* messageStr =
(msg->type() >= 0 &&
msg->type() < sizeof(msg_name)/sizeof(const char*)) ?
msg_name[msg->type()]: "Unknown";
TRACEARGS("Event", msg->type(), "(", string, ")",
"for", ((void*)widget),
typeid(*widget).name(),
widget->id().empty());
if (
#if !REPORT_MOUSE_MESSAGES
(msg->type() < kMouseDownMessage ||
msg->type() > kTouchMagnifyMessage) &&
#endif
#if !REPORT_PAINT_MESSAGES
(msg->type() != kPaintMessage) &&
#endif
#if !REPORT_TIMER_MESSAGES
(msg->type() != kTimerMessage) &&
#endif
true)
{
TRACEARGS(fmt::format(
"-- {} ({}) for {} {}{}{} --",
messageStr,
(int)msg->type(),
((void*)widget),
typeid(*widget).name(),
!widget->id().empty() ? " " + widget->id() : "",
#if REPORT_PAINT_MESSAGES
(msg->type() == kPaintMessage) ?
" clipRect=" +
base_args_to_string(static_cast<PaintMessage*>(msg)->rect()) :
#endif
""));
}
}
#endif
@ -1953,11 +1980,7 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
surface->saveClip();
if (surface->clipRect(paintMsg->rect())) {
#ifdef REPORT_EVENTS
TRACEARGS(" - clipRect ", paintMsg->rect());
#endif
#ifdef DEBUG_PAINT_EVENTS
#if DEBUG_PAINT_MESSAGES
{
os::SurfaceLock lock(surface.get());
os::Paint p;
@ -2280,7 +2303,7 @@ bool Manager::processFocusMovementMessage(Message* msg)
}
}
#ifdef REPORT_FOCUS_MOVEMENT
#if REPORT_FOCUS_MOVEMENT
// Print list of widgets
for (int i=c; i<count-1; ++i) {
TRACE("list[%d] = %d (%s)\n",