Don't get cursor position twice for open with menu

This commit is contained in:
Ilya Fedin 2023-01-20 09:16:51 +04:00 committed by John Preston
parent a65e25b8ae
commit 6f89413c76
7 changed files with 12 additions and 23 deletions

View File

@ -138,9 +138,9 @@ void OpenEmailLink(const QString &email) {
});
}
void OpenWith(const QString &filepath, QPoint menuPosition) {
void OpenWith(const QString &filepath) {
InvokeQueued(QCoreApplication::instance(), [=] {
if (!Platform::File::UnsafeShowOpenWithDropdown(filepath, menuPosition)) {
if (!Platform::File::UnsafeShowOpenWithDropdown(filepath)) {
Ui::PreventDelayedActivation();
if (!Platform::File::UnsafeShowOpenWith(filepath)) {
Platform::File::UnsafeLaunch(filepath);

View File

@ -34,7 +34,7 @@ namespace File {
// Those functions are async wrappers to Platform::File::Unsafe* calls.
void OpenUrl(const QString &url);
void OpenEmailLink(const QString &email);
void OpenWith(const QString &filepath, QPoint menuPosition);
void OpenWith(const QString &filepath);
void Launch(const QString &filepath);
void ShowInFolder(const QString &filepath);

View File

@ -152,7 +152,7 @@ void DocumentOpenWithClickHandler::Open(
data->saveFromDataSilent();
const auto path = data->filepath(true);
if (!path.isEmpty()) {
File::OpenWith(path, QCursor::pos());
File::OpenWith(path);
} else {
DocumentSaveClickHandler::Save(
origin,

View File

@ -16,7 +16,7 @@ inline QString UrlToLocal(const QUrl &url) {
return ::File::internal::UrlToLocalDefault(url);
}
inline bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition) {
inline bool UnsafeShowOpenWithDropdown(const QString &filepath) {
return false;
}

View File

@ -11,9 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "styles/style_window.h"
#include <QtWidgets/QApplication>
#include <QtGui/QScreen>
#include <Cocoa/Cocoa.h>
#include <CoreFoundation/CFURL.h>
@ -68,7 +65,7 @@ QString strNeedToRefresh2() {
}
- (id) init:(NSString *)file;
- (BOOL) popupAtX:(int)x andY:(int)y;
- (BOOL) popupAt:(NSPoint)point;
- (void) itemChosen:(id)sender;
- (void) dealloc;
@ -174,7 +171,7 @@ QString strNeedToRefresh2() {
return self;
}
- (BOOL) popupAtX:(int)x andY:(int)y {
- (BOOL) popupAt:(NSPoint)point {
if (![apps count] && !defName) return NO;
menu = [[NSMenu alloc] initWithTitle:@"Open With"];
@ -197,7 +194,7 @@ QString strNeedToRefresh2() {
NSMenuItem *item = [menu insertItemWithTitle:Q2NSString(tr::lng_mac_choose_program_menu(tr::now)) action:@selector(itemChosen:) keyEquivalent:@"" atIndex:index++];
[item setTarget:self];
[menu popUpMenuPositioningItem:nil atLocation:CGPointMake(x, y) inView:nil];
[menu popUpMenuPositioningItem:nil atLocation:point inView:nil];
return YES;
}
@ -392,20 +389,13 @@ QString UrlToLocal(const QUrl &url) {
return result;
}
bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition) {
bool UnsafeShowOpenWithDropdown(const QString &filepath) {
@autoreleasepool {
NSString *file = Q2NSString(filepath);
@try {
OpenFileWithInterface *menu = [[[OpenFileWithInterface alloc] init:file] autorelease];
const auto screen = QGuiApplication::screenAt(menuPosition);
if (!screen) {
return false;
}
const auto r = screen->geometry();
auto x = menuPosition.x();
auto y = r.y() + r.height() - menuPosition.y();
return !![menu popupAtX:x andY:y];
return !![menu popupAt:[NSEvent mouseLocation]];
}
@catch (NSException *exception) {
}

View File

@ -17,7 +17,7 @@ QString UrlToLocal(const QUrl &url);
// All these functions may enter a nested event loop. Use with caution.
void UnsafeOpenUrl(const QString &url);
void UnsafeOpenEmailLink(const QString &email);
bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition);
bool UnsafeShowOpenWithDropdown(const QString &filepath);
bool UnsafeShowOpenWith(const QString &filepath);
void UnsafeLaunch(const QString &filepath);

View File

@ -142,7 +142,7 @@ void UnsafeOpenEmailLink(const QString &email) {
}
}
bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition) {
bool UnsafeShowOpenWithDropdown(const QString &filepath) {
if (!Dlls::SHAssocEnumHandlers || !Dlls::SHCreateItemFromParsingName) {
return false;
}
@ -230,7 +230,6 @@ bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition) {
menuInfo.dwTypeData = nameArr;
InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &menuInfo);
// menuPosition is incorrect because of devicePixelRatio :(
POINT position;
GetCursorPos(&position);
int sel = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, position.x, position.y, 0, parentHWND, 0);