Add Mac system button area interfaces
| | |
| | | return true; |
| | | } |
| | | |
| | | #ifdef Q_OS_MAC |
| | | void AbstractWindowContext::setSystemButtonArea(const QRect &rect) { |
| | | m_systemButtonArea = rect; |
| | | virtual_hook(SystemButtonAreaChangedHook, nullptr); |
| | | } |
| | | #endif |
| | | |
| | | bool AbstractWindowContext::isInSystemButtons(const QPoint &pos, |
| | | WindowAgentBase::SystemButton *button) const { |
| | | *button = WindowAgentBase::Unknown; |
| | |
| | | inline QObject *titleBar() const; |
| | | bool setTitleBar(QObject *obj); |
| | | |
| | | #ifdef Q_OS_MAC |
| | | inline QRect systemButtonArea() const; |
| | | void setSystemButtonArea(const QRect &rect); |
| | | #endif |
| | | |
| | | bool isInSystemButtons(const QPoint &pos, WindowAgentBase::SystemButton *button) const; |
| | | bool isInTitleBarDraggableArea(const QPoint &pos) const; |
| | | |
| | |
| | | CentralizeHook = 1, |
| | | ShowSystemMenuHook, |
| | | DefaultColorsHook, |
| | | DrawWindows10BorderHook, // Only works on Windows 10 |
| | | DrawWindows10BorderHook, // Only works on Windows 10 |
| | | SystemButtonAreaChangedHook, // Only works on Mac |
| | | }; |
| | | virtual void virtual_hook(int id, void *data); |
| | | |
| | |
| | | QWindow *m_windowHandle{}; |
| | | |
| | | QSet<const QObject *> m_hitTestVisibleItems; |
| | | #ifdef Q_OS_MAC |
| | | QRect m_systemButtonArea; |
| | | #endif |
| | | |
| | | QObject *m_titleBar{}; |
| | | std::array<QObject *, WindowAgentBase::NumSystemButton> m_systemButtons{}; |
| | |
| | | return m_titleBar; |
| | | } |
| | | |
| | | #ifdef Q_OS_MAC |
| | | inline QRect AbstractWindowContext::systemButtonArea() const { |
| | | return m_systemButtonArea; |
| | | } |
| | | #endif |
| | | |
| | | } |
| | | |
| | | #endif // ABSTRACTWINDOWCONTEXT_P_H |
| | |
| | | nswindow.showsToolbarButton = NO; |
| | | nswindow.movableByWindowBackground = NO; |
| | | nswindow.movable = NO; // This line causes the window in the wrong position when |
| | | // become fullscreen. |
| | | // become fullscreen. |
| | | // For some unknown reason, we don't need the following hack in Qt versions below or |
| | | // equal to 6.2.4. |
| | | #if (QT_VERSION > QT_VERSION_CHECK(6, 2, 4)) |
| | |
| | | } |
| | | |
| | | void CocoaWindowContext::virtual_hook(int id, void *data) { |
| | | switch (id) { |
| | | case ShowSystemMenuHook: |
| | | // TODO: mac system menu |
| | | return; |
| | | case SystemButtonAreaChangedHook: |
| | | // TODO: mac system button rect updated |
| | | return; |
| | | default: |
| | | break; |
| | | } |
| | | AbstractWindowContext::virtual_hook(id, data); |
| | | } |
| | | |
| | | bool CocoaWindowContext::setupHost() { |
| | |
| | | |
| | | if(WIN32) |
| | | list(APPEND _src widgetwindowagent_win.cpp) |
| | | elseif(APPLE) |
| | | list(APPEND _src widgetwindowagent_mac.cpp) |
| | | endif() |
| | | |
| | | qwk_add_library(${PROJECT_NAME} AUTOGEN |
| | |
| | | QWidget *systemButton(SystemButton button) const; |
| | | void setSystemButton(SystemButton button, QWidget *w); |
| | | |
| | | #ifdef Q_OS_MAC |
| | | QWidget *systemButtonArea() const; |
| | | void setSystemButtonArea(QWidget *widget); |
| | | #endif |
| | | |
| | | bool isHitTestVisible(const QWidget *w) const; |
| | | void setHitTestVisible(const QWidget *w, bool visible = true); |
| | | |
New file |
| | |
| | | #include "widgetwindowagent_p.h" |
| | | |
| | | #include <QtGui/QtEvents> |
| | | |
| | | namespace QWK { |
| | | |
| | | class SystemButtonAreaWidgetEventFilter : public QObject { |
| | | public: |
| | | SystemButtonAreaWidgetEventFilter(QWidget *widget, AbstractWindowContext *ctx, |
| | | QObject *parent = nullptr) |
| | | : QObject(parent), widget(widget), ctx(ctx) { |
| | | widget->installEventFilter(this); |
| | | } |
| | | ~SystemButtonAreaWidgetEventFilter() = default; |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *obj, QEvent *event) override { |
| | | switch (event->type()) { |
| | | case QEvent::Move: |
| | | case QEvent::Resize: { |
| | | ctx->setSystemButtonArea(widget->geometry()); |
| | | break; |
| | | } |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | return QObject::eventFilter(obj, event); |
| | | } |
| | | |
| | | protected: |
| | | QWidget *widget; |
| | | AbstractWindowContext *ctx; |
| | | }; |
| | | |
| | | QWidget *WidgetWindowAgent::systemButtonArea() const { |
| | | Q_D(const WidgetWindowAgent); |
| | | return d->systemButtonAreaWidget; |
| | | } |
| | | |
| | | void WidgetWindowAgent::setSystemButtonArea(QWidget *widget) { |
| | | Q_D(WidgetWindowAgent); |
| | | d->systemButtonAreaWidget = widget; |
| | | if (!widget) { |
| | | systemButtonAreaWidgetEventFilter.reset(); |
| | | d->context->setSystemButtonArea({}); |
| | | return; |
| | | } |
| | | systemButtonAreaWidgetEventFilter = |
| | | std::make_unique<SystemButtonAreaWidgetEventFilter>(widget, d->context); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | // Host |
| | | QWidget *hostWidget{}; |
| | | #ifdef Q_OS_MAC |
| | | QWidget *systemButtonAreaWidget{}; |
| | | std::unique_ptr<QObject> systemButtonAreaWidgetEventFilter; |
| | | #endif |
| | | |
| | | #ifdef Q_OS_WINDOWS |
| | | void setupWindows10BorderWorkaround(); |