mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-27 10:00:38 -05:00
Add Window menu for macOS and specify Help menu to AppKit (#12357)
* Add Window menu for macOS and specify Help menu to AppKit * Fix potential NSString dangling pointers of temporary QStrings
This commit is contained in:
parent
9814037fd3
commit
6130a64be5
7 changed files with 65 additions and 2 deletions
|
|
@ -157,6 +157,25 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>AppKit</name>
|
||||||
|
<message>
|
||||||
|
<source>Window</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Minimize</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Zoom</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Bring All to Front</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ApplicationSettingsWidget</name>
|
<name>ApplicationSettingsWidget</name>
|
||||||
<message>
|
<message>
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,10 @@ MainWindow::MainWindow()
|
||||||
|
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
macUtils()->configureWindowAndHelpMenus(this, m_ui->menuHelp);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS)
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS)
|
||||||
new MainWindowAdaptor(this);
|
new MainWindowAdaptor(this);
|
||||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QMainWindow>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
class QWindow;
|
class QWindow;
|
||||||
|
|
@ -45,6 +47,7 @@ public:
|
||||||
bool enableScreenRecording();
|
bool enableScreenRecording();
|
||||||
void toggleForegroundApp(bool foreground);
|
void toggleForegroundApp(bool foreground);
|
||||||
void setWindowSecurity(QWindow* window, bool state);
|
void setWindowSecurity(QWindow* window, bool state);
|
||||||
|
void configureWindowAndHelpMenus(QMainWindow* mainWindow, QMenu* helpMenu);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userSwitched();
|
void userSwitched();
|
||||||
|
|
|
||||||
|
|
@ -42,5 +42,6 @@
|
||||||
- (bool) enableScreenRecording;
|
- (bool) enableScreenRecording;
|
||||||
- (void) toggleForegroundApp:(bool) foreground;
|
- (void) toggleForegroundApp:(bool) foreground;
|
||||||
- (void) setWindowSecurity:(NSWindow*) window state:(bool) state;
|
- (void) setWindowSecurity:(NSWindow*) window state:(bool) state;
|
||||||
|
- (void) configureWindowAndHelpMenus:(QMainWindow*) mainWindow helpMenu:(QMenu*) helpMenu;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#import "AppKitImpl.h"
|
#import "AppKitImpl.h"
|
||||||
#import <QWindow>
|
#import <QWindow>
|
||||||
|
#import <QMenu>
|
||||||
|
#import <QMenuBar>
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#if __clang_major__ >= 13 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_3
|
#if __clang_major__ >= 13 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_3
|
||||||
#import <ScreenCaptureKit/ScreenCaptureKit.h>
|
#import <ScreenCaptureKit/ScreenCaptureKit.h>
|
||||||
|
|
@ -184,7 +186,7 @@
|
||||||
//
|
//
|
||||||
// Check if screen recording is enabled, may show an popup asking for permissions
|
// Check if screen recording is enabled, may show an popup asking for permissions
|
||||||
//
|
//
|
||||||
- (bool) enableScreenRecording
|
- (bool) enableScreenRecording
|
||||||
{
|
{
|
||||||
#if __clang_major__ >= 13 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_3
|
#if __clang_major__ >= 13 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_3
|
||||||
if (@available(macOS 12.3, *)) {
|
if (@available(macOS 12.3, *)) {
|
||||||
|
|
@ -192,7 +194,7 @@
|
||||||
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
|
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
|
||||||
|
|
||||||
// Attempt to use SCShareableContent to check for screen recording permission
|
// Attempt to use SCShareableContent to check for screen recording permission
|
||||||
[SCShareableContent getShareableContentWithCompletionHandler:^(SCShareableContent * _Nullable content,
|
[SCShareableContent getShareableContentWithCompletionHandler:^(SCShareableContent * _Nullable content,
|
||||||
NSError * _Nullable error) {
|
NSError * _Nullable error) {
|
||||||
Q_UNUSED(error);
|
Q_UNUSED(error);
|
||||||
if (content) {
|
if (content) {
|
||||||
|
|
@ -231,8 +233,29 @@
|
||||||
[window setSharingType: state ? NSWindowSharingNone : NSWindowSharingReadOnly];
|
[window setSharingType: state ? NSWindowSharingNone : NSWindowSharingReadOnly];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) configureWindowAndHelpMenus:(QMainWindow*) mainWindow helpMenu:(QMenu*) helpMenu
|
||||||
|
{
|
||||||
|
QMenu *qtWindowMenu = new QMenu(AppKit::tr("Window"));
|
||||||
|
NSMenu *nsWindowMenu = qtWindowMenu->toNSMenu();
|
||||||
|
|
||||||
|
QString minimizeStr = AppKit::tr("Minimize");
|
||||||
|
[nsWindowMenu addItemWithTitle:minimizeStr.toNSString() action:@selector(performMiniaturize:) keyEquivalent:@""];
|
||||||
|
QString zoomStr = AppKit::tr("Zoom");
|
||||||
|
[nsWindowMenu addItemWithTitle:zoomStr.toNSString() action:@selector(performZoom:) keyEquivalent:@""];
|
||||||
|
[nsWindowMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
QString bringAllToFrontStr = AppKit::tr("Bring All to Front");
|
||||||
|
[nsWindowMenu addItemWithTitle:bringAllToFrontStr.toNSString() action:@selector(arrangeInFront:) keyEquivalent:@""];
|
||||||
|
|
||||||
|
NSApp.windowsMenu = nsWindowMenu;
|
||||||
|
|
||||||
|
mainWindow->menuBar()->insertMenu(helpMenu->menuAction(), qtWindowMenu);
|
||||||
|
|
||||||
|
NSApp.helpMenu = helpMenu->toNSMenu();
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// ------------------------- C++ Trampolines -------------------------
|
// ------------------------- C++ Trampolines -------------------------
|
||||||
//
|
//
|
||||||
|
|
@ -312,3 +335,8 @@ void AppKit::setWindowSecurity(QWindow* window, bool state)
|
||||||
auto view = reinterpret_cast<NSView*>(window->winId());
|
auto view = reinterpret_cast<NSView*>(window->winId());
|
||||||
[static_cast<id>(self) setWindowSecurity:view.window state:state];
|
[static_cast<id>(self) setWindowSecurity:view.window state:state];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppKit::configureWindowAndHelpMenus(QMainWindow* window, QMenu* helpMenu)
|
||||||
|
{
|
||||||
|
[static_cast<id>(self) configureWindowAndHelpMenus:window helpMenu:helpMenu];
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
|
||||||
|
|
@ -202,6 +203,11 @@ void MacUtils::registerNativeEventFilter()
|
||||||
::InstallApplicationEventHandler(MacUtils::hotkeyHandler, 1, &eventSpec, this, nullptr);
|
::InstallApplicationEventHandler(MacUtils::hotkeyHandler, 1, &eventSpec, this, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacUtils::configureWindowAndHelpMenus(QMainWindow* mainWindow, QMenu* helpMenu)
|
||||||
|
{
|
||||||
|
return m_appkit->configureWindowAndHelpMenus(mainWindow, helpMenu);
|
||||||
|
}
|
||||||
|
|
||||||
bool MacUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error)
|
bool MacUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error)
|
||||||
{
|
{
|
||||||
auto keycode = qtToNativeKeyCode(key);
|
auto keycode = qtToNativeKeyCode(key);
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ public:
|
||||||
|
|
||||||
void registerNativeEventFilter() override;
|
void registerNativeEventFilter() override;
|
||||||
|
|
||||||
|
void configureWindowAndHelpMenus(QMainWindow* mainWindow, QMenu* helpMenu);
|
||||||
|
|
||||||
bool registerGlobalShortcut(const QString& name,
|
bool registerGlobalShortcut(const QString& name,
|
||||||
Qt::Key key,
|
Qt::Key key,
|
||||||
Qt::KeyboardModifiers modifiers,
|
Qt::KeyboardModifiers modifiers,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue