summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/quiwindow.mm
blob: 7c910b6d9edebdb0e453b43fd08c2882a2609637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "quiwindow.h"

#include "qiostheme.h"

#include <QtCore/qscopedvaluerollback.h>

#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformtheme.h>

#include <UIKit/UIKit.h>

@implementation QUIWindow

- (instancetype)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame]))
        self->_sendingEvent = NO;

    return self;
}

- (void)sendEvent:(UIEvent *)event
{
    QScopedValueRollback<BOOL> sendingEvent(self->_sendingEvent, YES);
    [super sendEvent:event];
}

#if !defined(Q_OS_VISIONOS)
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
    [super traitCollectionDidChange:previousTraitCollection];

    if (!qGuiApp)
        return;

    Qt::ColorScheme colorScheme = self.traitCollection.userInterfaceStyle
                              == UIUserInterfaceStyleDark
                              ? Qt::ColorScheme::Dark
                              : Qt::ColorScheme::Light;

    if (self.screen == UIScreen.mainScreen) {
        // Check if the current userInterfaceStyle reports a different appearance than
        // the platformTheme's appearance. We might have set that one based on the UIScreen
        if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle
            || QGuiApplicationPrivate::platformTheme()->colorScheme() != colorScheme) {
            QIOSTheme::initializeSystemPalette();
            QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
        }
    }
}
#endif

@end