Necessary updates applied to make it work on mac

This commit is contained in:
Sale Djenic 2022-07-21 11:04:07 +02:00 committed by Michał Cieślak
parent a50296046d
commit 2d92be0bfa
4 changed files with 72 additions and 61 deletions

View File

@ -7,27 +7,32 @@ find_package(
file(GLOB_RECURSE QML_FILES "../*.qml")
file(GLOB_RECURSE JS_FILES "../*.js")
file(GLOB_RECURSE HEADERS *.h)
if(APPLE)
file(GLOB_RECURSE SOURCES *.cpp *.mm)
else()
file(GLOB_RECURSE SOURCES *.cpp)
endif()
qt5_add_big_resources(QRC_FILES qml.qrc ../src/statusq.qrc ../src/assets.qrc)
add_executable(
${PROJECT_NAME}
main.cpp
handler.cpp
sandboxapp.cpp
spellchecker.cpp
${HEADERS}
${SOURCES}
${QRC_FILES}
${QML_FILES}
${JS_FILES})
if(APPLE)
target_sources(${PROJECT_NAME} PRIVATE statuswindow_mac.mm)
else()
target_sources(${PROJECT_NAME} PRIVATE statuswindow.cpp)
endif()
target_compile_definitions(${PROJECT_NAME}
PRIVATE SRC_DIR="${CMAKE_CURRENT_LIST_DIR}")
target_link_libraries(
${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2
SortFilterProxyModel)
if (APPLE)
find_library(AppKit AppKit)
find_library(Foundation Foundation)
target_link_libraries(${PROJECT_NAME} PRIVATE ${AppKit} ${Foundation})
endif()

View File

@ -1,5 +1,33 @@
#include "statuswindow.h"
StatusWindow::StatusWindow(QQuickWindow *parent)
: QQuickWindow(parent)
, m_isFullScreen(false)
{
removeTitleBar();
connect(this, &QQuickWindow::windowStateChanged, [&](Qt::WindowState windowState) {
if (windowState == Qt::WindowNoState) {
removeTitleBar();
m_isFullScreen = false;
emit isFullScreenChanged();
} else if (windowState == Qt::WindowFullScreen) {
m_isFullScreen = true;
emit isFullScreenChanged();
showTitleBar();
}
});
}
void StatusWindow::updatePosition()
{
auto point = QPoint(screen()->geometry().center().x() - geometry().width() / 2,
screen()->geometry().center().y() - geometry().height() / 2);
if (point != this->position()) {
this->setPosition(point);
}
}
void StatusWindow::toggleFullScreen()
{
if (m_isFullScreen) {
@ -16,10 +44,26 @@ bool StatusWindow::isFullScreen() const
void StatusWindow::removeTitleBar()
{
#ifdef Q_OS_WIN
removeTitleBarWin();
#elif defined Q_OS_MACOS
removeTitleBarMac();
#endif
}
void StatusWindow::showTitleBar()
{
#ifdef Q_OS_WIN
showTitleBarWin();
#elif defined Q_OS_MACOS
showTitleBarMac();
#endif
}
#ifdef Q_OS_WIN
void StatusWindow::removeTitleBarWin()
{}
void StatusWindow::showTitleBarWin()
{}
#endif

View File

@ -11,40 +11,11 @@ class StatusWindow: public QQuickWindow
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
public:
struct EventCallbacks {
std::function<void()> onResize;
std::function<void()> willExitFullScreen;
std::function<void()> didExitFullScreen;
};
explicit StatusWindow(QWindow *parent = nullptr)
: QQuickWindow(parent),
m_isFullScreen(false)
{
removeTitleBar();
connect(this, &QQuickWindow::windowStateChanged, [&](Qt::WindowState windowState) {
if (windowState == Qt::WindowNoState) {
removeTitleBar();
m_isFullScreen = false;
emit isFullScreenChanged();
} else if (windowState == Qt::WindowFullScreen) {
m_isFullScreen = true;
emit isFullScreenChanged();
showTitleBar();
}
});
}
explicit StatusWindow(QQuickWindow *parent = nullptr);
Q_INVOKABLE void toggleFullScreen();
Q_INVOKABLE void updatePosition() {
auto point = QPoint(screen()->geometry().center().x() - geometry().width() / 2, screen()->geometry().center().y() - geometry().height() / 2);
if (point != this->position()) {
this->setPosition(point);
}
}
Q_INVOKABLE void updatePosition();
bool isFullScreen() const;
@ -54,10 +25,15 @@ signals:
private:
void removeTitleBar();
void showTitleBar();
void initCallbacks();
#ifdef Q_OS_WIN
void removeTitleBarWin();
void showTitleBarWin();
#elif defined Q_OS_MACOS
void removeTitleBarMac();
void showTitleBarMac();
#endif
private:
EventCallbacks m_callbacks;
bool m_isFullScreen;
};

View File

@ -12,21 +12,7 @@
#include <AppKit/NSButton.h>
#include <AppKit/AppKit.h>
void StatusWindow::toggleFullScreen()
{
if (m_isFullScreen) {
showNormal();
} else {
showFullScreen();
}
}
bool StatusWindow::isFullScreen() const
{
return m_isFullScreen;
}
void StatusWindow::removeTitleBar()
void StatusWindow::removeTitleBarMac()
{
NSView *nsView = reinterpret_cast<NSView*>(this->winId());
NSWindow *window = [nsView window];
@ -39,7 +25,7 @@ void StatusWindow::removeTitleBar()
[titleBarContainerView setHidden:YES];
}
void StatusWindow::showTitleBar()
void StatusWindow::showTitleBarMac()
{
NSView *nsView = reinterpret_cast<NSView*>(this->winId());
NSWindow *window = [nsView window];