mirror of https://github.com/procxx/kepka.git
				
				
				
			Don't show PopupMenu for inactive window on macOS.
This is a fixup for 06bf67c146.
			
			
This commit is contained in:
		
							parent
							
								
									4e0e472f97
								
							
						
					
					
						commit
						c8aa35d23c
					
				|  | @ -47,6 +47,10 @@ bool _psRunCommand(const QByteArray &command) { | |||
| 
 | ||||
| namespace Platform { | ||||
| 
 | ||||
| bool IsApplicationActive() { | ||||
| 	return static_cast<QApplication*>(QApplication::instance())->activeWindow() != nullptr; | ||||
| } | ||||
| 
 | ||||
| QString CurrentExecutablePath(int argc, char *argv[]) { | ||||
| 	constexpr auto kMaxPath = 1024; | ||||
| 	char result[kMaxPath] = { 0 }; | ||||
|  |  | |||
|  | @ -15,6 +15,8 @@ namespace Platform { | |||
| inline void SetWatchingMediaKeys(bool watching) { | ||||
| } | ||||
| 
 | ||||
| bool IsApplicationActive(); | ||||
| 
 | ||||
| inline void StartTranslucentPaint(QPainter &p, QPaintEvent *e) { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,6 +29,8 @@ namespace { | |||
| 
 | ||||
| constexpr auto kIgnoreActivationTimeoutMs = 500; | ||||
| 
 | ||||
| base::optional<bool> ApplicationIsActive; | ||||
| 
 | ||||
| } // namespace | ||||
| 
 | ||||
| using Platform::Q2NSString; | ||||
|  | @ -85,6 +87,7 @@ using Platform::NS2QString; | |||
| - (BOOL) applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag; | ||||
| - (void) applicationDidFinishLaunching:(NSNotification *)aNotification; | ||||
| - (void) applicationDidBecomeActive:(NSNotification *)aNotification; | ||||
| - (void) applicationDidResignActive:(NSNotification *)aNotification; | ||||
| - (void) receiveWakeNote:(NSNotification*)note; | ||||
| 
 | ||||
| - (void) setWatchingMediaKeys:(bool)watching; | ||||
|  | @ -126,6 +129,7 @@ ApplicationDelegate *_sharedDelegate = nil; | |||
| } | ||||
| 
 | ||||
| - (void) applicationDidBecomeActive:(NSNotification *)aNotification { | ||||
| 	ApplicationIsActive = true; | ||||
| 	if (auto messenger = Messenger::InstancePointer()) { | ||||
| 		if (!_ignoreActivation) { | ||||
| 			messenger->handleAppActivated(); | ||||
|  | @ -138,6 +142,10 @@ ApplicationDelegate *_sharedDelegate = nil; | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| - (void) applicationDidResignActive:(NSNotification *)aNotification { | ||||
| 	ApplicationIsActive = false; | ||||
| } | ||||
| 
 | ||||
| - (void) receiveWakeNote:(NSNotification*)aNotification { | ||||
| 	if (auto messenger = Messenger::InstancePointer()) { | ||||
| 		messenger->checkLocalTime(); | ||||
|  | @ -187,6 +195,12 @@ void SetWatchingMediaKeys(bool watching) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| bool IsApplicationActive() { | ||||
| 	return ApplicationIsActive | ||||
| 		? *ApplicationIsActive | ||||
| 		: (static_cast<QApplication*>(QApplication::instance())->activeWindow() != nullptr); | ||||
| } | ||||
| 
 | ||||
| void InitOnTopPanel(QWidget *panel) { | ||||
| 	Expects(!panel->windowHandle()); | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,6 +13,7 @@ void start(); | |||
| void finish(); | ||||
| 
 | ||||
| void SetWatchingMediaKeys(bool watching); | ||||
| bool IsApplicationActive(); | ||||
| bool TranslucentWindowsSupported(QPoint globalPosition); | ||||
| void StartTranslucentPaint(QPainter &p, QPaintEvent *e); | ||||
| void InitOnTopPanel(QWidget *panel); | ||||
|  |  | |||
|  | @ -332,6 +332,10 @@ QString SystemCountry() { | |||
| 	return QString(); | ||||
| } | ||||
| 
 | ||||
| bool IsApplicationActive() { | ||||
| 	return static_cast<QApplication*>(QApplication::instance())->activeWindow() != nullptr; | ||||
| } | ||||
| 
 | ||||
| QString CurrentExecutablePath(int argc, char *argv[]) { | ||||
| 	WCHAR result[MAX_PATH + 1] = { 0 }; | ||||
| 	auto count = GetModuleFileName(nullptr, result, MAX_PATH + 1); | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ namespace Platform { | |||
| inline void SetWatchingMediaKeys(bool watching) { | ||||
| } | ||||
| 
 | ||||
| bool IsApplicationActive(); | ||||
| 
 | ||||
| inline bool TranslucentWindowsSupported(QPoint globalPosition) { | ||||
| 	return true; | ||||
| } | ||||
|  |  | |||
|  | @ -15,6 +15,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| #include "lang/lang_keys.h" | ||||
| 
 | ||||
| namespace Ui { | ||||
| namespace { | ||||
| 
 | ||||
| bool InactiveMacApplication() { | ||||
| 	return (cPlatform() == dbipMac || cPlatform() == dbipMacOld) | ||||
| 		&& !Platform::IsApplicationActive(); | ||||
| } | ||||
| 
 | ||||
| } // namespace
 | ||||
| 
 | ||||
| PopupMenu::PopupMenu(QWidget *parent, const style::PopupMenu &st) | ||||
| : RpWidget(parent) | ||||
|  | @ -423,11 +431,16 @@ void PopupMenu::popup(const QPoint &p) { | |||
| } | ||||
| 
 | ||||
| void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource source) { | ||||
| 	if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) { | ||||
| 		if (!parent && !static_cast<QApplication*>(QApplication::instance())->activeWindow()) { | ||||
| 			crl::on_main(this, [=] { show(); hideFast(); }); | ||||
| 			return; | ||||
| 	if (!parent && InactiveMacApplication()) { | ||||
| 		_hiding = false; | ||||
| 		_a_opacity.finish(); | ||||
| 		_a_show.finish(); | ||||
| 		_cache = QPixmap(); | ||||
| 		hide(); | ||||
| 		if (_deleteOnHide) { | ||||
| 			deleteLater(); | ||||
| 		} | ||||
| 		return; | ||||
| 	} | ||||
| 	_parent = parent; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue