1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2026-02-08 00:32:27 +00:00

Use single instance application to handle multiple windows.

This commit is contained in:
Filippo Scognamiglio
2026-01-04 23:27:43 +01:00
parent 267b39bc9d
commit f58710c76f
12 changed files with 52 additions and 32 deletions

3
.gitmodules vendored
View File

@@ -2,3 +2,6 @@
path = qmltermwidget
url = https://github.com/Swordfish90/qmltermwidget
branch = unstable
[submodule "singleapplication"]
path = singleapplication
url = https://github.com/itay-grudev/SingleApplication.git

View File

@@ -1,13 +1,16 @@
QT += qml quick widgets sql quickcontrols2
DEFINES += QAPPLICATION_CLASS=QApplication
TARGET = cool-retro-term
include(../singleapplication/singleapplication.pri)
DESTDIR = $$OUT_PWD/../
HEADERS += \
fileio.h \
monospacefontmanager.h
SOURCES = main.cpp \
SOURCES += main.cpp \
fileio.cpp \
monospacefontmanager.cpp

View File

@@ -8,6 +8,8 @@
#include <QIcon>
#include <QQuickStyle>
#include <singleapplication.h>
#include <QDebug>
#include <stdlib.h>
@@ -78,9 +80,14 @@ int main(int argc, char *argv[])
return 0;
}
QApplication app(argc, argv);
SingleApplication app(argc, argv, true);
app.setAttribute(Qt::AA_MacDontSwapCtrlAndMeta, true);
if (app.isSecondary()) {
app.sendMessage("new-window");
return 0;
}
QQmlApplicationEngine engine;
FileIO fileIO;
MonospaceFontManager monospaceFontManager;
@@ -135,5 +142,20 @@ int main(int argc, char *argv[])
// Quit the application when the engine closes.
QObject::connect((QObject*) &engine, SIGNAL(quit()), (QObject*) &app, SLOT(quit()));
auto requestNewWindow = [&engine]() {
if (engine.rootObjects().isEmpty())
return;
QObject *rootObject = engine.rootObjects().constFirst();
QMetaObject::invokeMethod(rootObject, "createWindow", Qt::QueuedConnection);
};
QObject::connect(&app, &SingleApplication::receivedMessage, &app,
[&requestNewWindow](quint32 instanceId, QByteArray message) {
Q_UNUSED(instanceId);
if (message.isEmpty() || message == QByteArray("new-window"))
requestNewWindow();
});
return app.exec();
}

View File

@@ -30,7 +30,7 @@ ApplicationWindow {
id: settings_window
title: qsTr("Settings")
width: 640
height: 480
height: 520
Item {
anchors { fill: parent; }

View File

@@ -44,10 +44,6 @@ Item {
}
}
function closeCurrentTab() {
closeTab(tabBar.currentIndex)
}
ListModel {
id: tabsModel
}

View File

@@ -148,12 +148,6 @@ ApplicationWindow {
text: qsTr("New Tab")
onTriggered: terminalTabs.addTab()
}
Action {
id: closeTabAction
text: qsTr("Close Tab")
enabled: terminalTabs.count > 1
onTriggered: terminalTabs.closeCurrentTab()
}
TerminalTabs {
id: terminalTabs
width: parent.width

View File

@@ -32,19 +32,15 @@ Menu {
action: showsettingsAction
}
MenuSeparator {}
Menu {
title: qsTr("Tabs")
title: qsTr("File")
MenuItem {
action: newWindowAction
}
MenuItem {
action: newTabAction
}
MenuItem {
action: closeTabAction
}
}
Menu {
title: qsTr("File")
MenuSeparator {}
MenuItem {
action: quitAction
}

View File

@@ -31,6 +31,12 @@ MenuBar {
shortcut: newWindowAction.shortcut
onTriggered: newWindowAction.trigger()
}
MenuItem {
text: newTabAction.text
shortcut: newTabAction.shortcut
onTriggered: newTabAction.trigger()
}
MenuSeparator {}
MenuItem {
text: quitAction.text
onTriggered: quitAction.trigger()

View File

@@ -28,14 +28,4 @@ Menu {
MenuItem {
action: pasteAction
}
MenuSeparator {}
Menu {
title: qsTr("Tabs")
MenuItem {
action: newTabAction
}
MenuItem {
action: closeTabAction
}
}
}

View File

@@ -29,6 +29,10 @@ MenuBar {
MenuItem {
action: newWindowAction
}
MenuItem {
action: newTabAction
}
MenuSeparator {}
MenuItem {
action: quitAction
}

View File

@@ -9,3 +9,8 @@ StartupNotify=true
Terminal=false
Type=Application
Keywords=shell;prompt;command;commandline;
Actions=NewWindow;
[Desktop Action NewWindow]
Name=New Window
Exec=cool-retro-term

1
singleapplication Submodule

Submodule singleapplication added at a8da87d782