Skip to content

Commit

Permalink
解决 wayland 下标题栏没图标的问题!
Browse files Browse the repository at this point in the history
  • Loading branch information
microcai committed Oct 7, 2024
1 parent 809926f commit 1b71449
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@

#include <QApplication>
#include "mainwindow.hpp"
#include <QDebug>

static const char desktop_file_content[] = R"ss([Desktop Entry]
Categories=Development;Electronics;
Comment=免费、强大、易用的PCB设计辅助工具
Icon=edatool
Name=JLC EDA Tool
Type=Application
StartupWMClass=edatool
)ss";

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

if (app.platformName() == "wayland")
{
// 解决 wayland 下 没 icon 的问题
QFile iconfile(QDir::homePath() + "/.local/share/icons/edatool.png");
QFile resiconfile(":/images/res/logo.png");
resiconfile.open(QIODeviceBase::ReadOnly);
iconfile.open(QIODeviceBase::ReadWrite);

iconfile.write(resiconfile.readAll());
resiconfile.close(); iconfile.close();

QFile desktopfile(QDir::homePath() + "/.local/share/applications/edatool.desktop");
if (desktopfile.open(QIODeviceBase::ReadWrite))
{
desktopfile.write(desktop_file_content, sizeof (desktop_file_content) - 1);
desktopfile.write(QString("Exec=%1\n").arg(app.applicationFilePath()).toUtf8());
}
desktopfile.close();
}

QIcon ico(":/images/res/logo.png");
app.setWindowIcon(ico);
app.setDesktopFileName("edatool.desktop");

MainWindow mywin;

Expand Down

0 comments on commit 1b71449

Please sign in to comment.