Add Signals for closing the App

This commit is contained in:
delia 2025-04-17 16:37:06 +02:00
parent b4b0f56158
commit 0f2489a4c3
2 changed files with 15 additions and 8 deletions

3
.gitignore vendored
View File

@ -3,7 +3,8 @@ cmake-build-debug*
build/
.vscode/
third_party/
compile_commands.json
*-protocol.o
*-protocol.c
*-protocol.h
*-protocol.h

View File

@ -12,6 +12,7 @@
#include <QObject>
#include <iterator>
#include <qboxlayout.h>
#include <qcoreapplication.h>
#include <qglobal.h>
#include <qgridlayout.h>
#include <qlabel.h>
@ -32,12 +33,17 @@
#include "common.h"
WallpaperEngine::Application::CWallpaperApplication* appPointer;
QCoreApplication* globalApp = nullptr;
class UIWindow;
void signalhandler(int sig)
{
if (appPointer == nullptr)
return;
if (appPointer == nullptr) {
if(globalApp != nullptr) {
globalApp->quit();
} else return;
}
appPointer->signal (sig);
}
@ -68,12 +74,12 @@ int main (int argc, char* argv[]) {
wallpaperPaths.push_back(entry.path());
}
for (const std::string s : wallpaperPaths) {
std::cout << s << "\r\n";
}
QApplication qapp(argc, argv);
globalApp = &qapp;
// Signal for properly close the app
std::signal (SIGINT, signalhandler);
std::signal (SIGTERM, signalhandler);
auto* uiWindow = new UIWindow(nullptr, &qapp);