mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:42:51 +08:00
fix tray context menu on windows
This commit is contained in:
parent
86f84fb5d4
commit
b07ab6d0db
@ -1,4 +1,4 @@
|
||||
set(PLATFORM_SOURCES 3rdparty/WinCommander.cpp src/sys/windows/guihelper.cpp src/sys/windows/MiniDump.cpp)
|
||||
set(PLATFORM_SOURCES 3rdparty/WinCommander.cpp src/sys/windows/guihelper.cpp src/sys/windows/MiniDump.cpp src/sys/windows/cursor.cpp)
|
||||
set(PLATFORM_LIBRARIES wininet wsock32 ws2_32 user32 rasapi32 iphlpapi)
|
||||
|
||||
include(cmake/windows/generate_product_version.cmake)
|
||||
|
||||
5
include/sys/windows/cursor.h
Normal file
5
include/sys/windows/cursor.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <qpoint.h>
|
||||
|
||||
QPoint GetCursorPosition();
|
||||
16
src/sys/windows/cursor.cpp
Normal file
16
src/sys/windows/cursor.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#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,6 +22,7 @@
|
||||
|
||||
#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"
|
||||
@ -289,7 +290,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
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
|
||||
}
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
if (this->isVisible()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user