Files
qbz/crates/qbz-qt/cxx/app_lifecycle.cpp
T
vicrodh 2fc03d325d fix(qt): restore window lifecycle and improve grid artwork
Restore tray-aware close and quit confirmation, circular label covers, and missing label artist portraits. Publish artwork progressively, preload two grid rows, and skip redundant motion reports while preserving data refreshes.

Include regression tests and isolated artwork benchmarks. Verified Linux build, QML checks, and scrolling smoke tests.

cx
2026-09-09 21:58:25 -06:00

46 lines
1.5 KiB
C++

#include <QtCore/QCoreApplication>
#include <QtCore/QEvent>
#include <QtCore/QObject>
#include <QtGui/QKeyEvent>
namespace {
// Lifecycle commands are reserved even while a text field or mini window
// owns focus. Qt maps ControlModifier to Command on macOS.
class LifecycleFilter final : public QObject {
public:
LifecycleFilter(QObject *parent, void (*request)(bool))
: QObject(parent), request_(request) {}
protected:
bool eventFilter(QObject *receiver, QEvent *event) override {
if (receiver == QCoreApplication::instance() && event->type() == QEvent::Quit) {
event->ignore(); // termination is pending until QML confirms
request_(true);
return true;
}
if (event->type() != QEvent::KeyPress && event->type() != QEvent::ShortcutOverride)
return false;
auto *key = static_cast<QKeyEvent *>(event);
if (key->modifiers() != Qt::ControlModifier
|| (key->key() != Qt::Key_Q && key->key() != Qt::Key_W))
return false;
event->accept();
if (event->type() == QEvent::KeyPress && !key->isAutoRepeat())
request_(key->key() == Qt::Key_Q);
return true;
}
private:
void (*request_)(bool);
};
}
extern "C" void qbz_install_lifecycle_filter(void (*request)(bool)) {
static LifecycleFilter *filter = nullptr;
auto *app = QCoreApplication::instance();
if (!filter && app) {
filter = new LifecycleFilter(app, request);
app->installEventFilter(filter);
}
}