mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:42:51 +08:00
apply a workaround for exit
This commit is contained in:
parent
b07ab6d0db
commit
60c9b4a8b9
@ -1,4 +1,4 @@
|
||||
set(PLATFORM_SOURCES 3rdparty/WinCommander.cpp src/sys/windows/guihelper.cpp src/sys/windows/MiniDump.cpp src/sys/windows/cursor.cpp)
|
||||
set(PLATFORM_SOURCES 3rdparty/WinCommander.cpp src/sys/windows/guihelper.cpp src/sys/windows/MiniDump.cpp)
|
||||
set(PLATFORM_LIBRARIES wininet wsock32 ws2_32 user32 rasapi32 iphlpapi)
|
||||
|
||||
include(cmake/windows/generate_product_version.cmake)
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <qpoint.h>
|
||||
|
||||
QPoint GetCursorPosition();
|
||||
@ -151,6 +151,7 @@ private slots:
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QSystemTrayIcon *tray;
|
||||
std::chrono::time_point<std::chrono::steady_clock> trayMenuTime;
|
||||
QShortcut *shortcut_ctrl_f = new QShortcut(QKeySequence("Ctrl+F"), this);
|
||||
QShortcut *shortcut_esc = new QShortcut(QKeySequence("Esc"), this);
|
||||
//
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
#include "include/sys/windows/cursor.h"
|
||||
|
||||
#include <QScreen>
|
||||
#include <string>
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
QPoint GetCursorPosition()
|
||||
{
|
||||
POINT P;
|
||||
if (!GetCursorPos(&P))
|
||||
{
|
||||
qDebug((std::to_string(GetLastError())).c_str());
|
||||
}
|
||||
return {int(P.x), int(P.y)};
|
||||
}
|
||||
@ -22,7 +22,6 @@
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "3rdparty/WinCommander.hpp"
|
||||
#include "include/sys/windows/cursor.h"
|
||||
#else
|
||||
#ifdef Q_OS_LINUX
|
||||
#include "include/sys/linux/LinuxCap.h"
|
||||
@ -273,7 +272,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
|
||||
// Setup Tray
|
||||
tray = new QSystemTrayIcon(nullptr);
|
||||
tray->setIcon(Icon::GetTrayIcon(Icon::NONE));
|
||||
tray->setIcon(GetTrayIcon(Icon::NONE));
|
||||
tray->show();
|
||||
auto *trayMenu = new QMenu();
|
||||
trayMenu->addAction(ui->actionShow_window);
|
||||
@ -287,21 +286,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
trayMenu->addAction(ui->actionRestart_Proxy);
|
||||
trayMenu->addAction(ui->actionRestart_Program);
|
||||
trayMenu->addAction(ui->menu_exit);
|
||||
tray->setContextMenu(trayMenu);
|
||||
connect(tray, &QSystemTrayIcon::activated, qApp, [=](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Context)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
auto pos = GetCursorPosition();
|
||||
MW_show_log(Int2String(pos.x()));
|
||||
MW_show_log(Int2String(pos.y()));
|
||||
auto screen = QGuiApplication::screenAt(QCursor::pos());
|
||||
QPoint finalPos = {int(pos.x() / screen->devicePixelRatio()), int(pos.y() / screen->devicePixelRatio())};
|
||||
MW_show_log(Int2String(finalPos.x()));
|
||||
MW_show_log(Int2String(finalPos.y()));
|
||||
trayMenu->popup(finalPos);
|
||||
#else
|
||||
trayMenu->popup(QCursor::pos());
|
||||
#endif
|
||||
trayMenuTime = std::chrono::steady_clock::now();
|
||||
}
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
if (this->isVisible()) {
|
||||
@ -691,6 +680,11 @@ void MainWindow::on_commitDataRequest() {
|
||||
}
|
||||
|
||||
void MainWindow::on_menu_exit_triggered() {
|
||||
std::chrono::duration<double, std::milli> elapsed_milliseconds = std::chrono::steady_clock::now() - trayMenuTime;
|
||||
if (elapsed_milliseconds.count() < 150)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mu_exit.tryLock()) {
|
||||
NekoGui::dataStore->prepare_exit = true;
|
||||
//
|
||||
|
||||
Loading…
Reference in New Issue
Block a user