Skip to content

Commit

Permalink
Simplify TitleBarBackgroundEventFilter QObject pointer casting
Browse files Browse the repository at this point in the history
It can't really be QWindow
  • Loading branch information
equeim committed Sep 7, 2024
1 parent c5f4360 commit c0ed16a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ui/darkthemeapplier_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ namespace tremotesf {
bool eventFilter(QObject* watched, QEvent* event) override {
switch (event->type()) {
case QEvent::WinIdChange: {
auto window = qobject_cast<QWindow*>(watched);
if (!window) {
if (auto widget = qobject_cast<QWidget*>(watched); widget) {
window = widget->windowHandle();
}
// Using QWindow::winId instead of QWidget::winId directly because
// QWidget::winId may create native window prematurely which we don't want
// QWidget::windowHandle will return nullptr if native window doesn't exist yet so we check for that
QWindow* window{};
if (auto widget = qobject_cast<QWidget*>(watched); widget) {
window = widget->windowHandle();
}
if (window) {
switch (window->type()) {
Expand Down

0 comments on commit c0ed16a

Please sign in to comment.