From a2871e63a7eb460095001167ad050f3b4e11415e Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Wed, 16 Jan 2019 18:01:59 +0530 Subject: [PATCH] macOS: Support window management keyboard shortcuts Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/macOS/Application.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WireGuard/WireGuard/UI/macOS/Application.swift b/WireGuard/WireGuard/UI/macOS/Application.swift index fba0ac6..644bbab 100644 --- a/WireGuard/WireGuard/UI/macOS/Application.swift +++ b/WireGuard/WireGuard/UI/macOS/Application.swift @@ -5,13 +5,16 @@ import Cocoa class Application: NSApplication { - private let editorCommands = [ + private let characterKeyCommands = [ "x": #selector(NSText.cut(_:)), "c": #selector(NSText.copy(_:)), "v": #selector(NSText.paste(_:)), "z": #selector(UndoActionRespondable.undo(_:)), "a": #selector(NSResponder.selectAll(_:)), - "Z": #selector(UndoActionRespondable.redo(_:)) + "Z": #selector(UndoActionRespondable.redo(_:)), + "w": #selector(NSWindow.performClose(_:)), + "m": #selector(NSWindow.performMiniaturize(_:)), + "q": #selector(NSApplication.terminate(_:)) ] private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate @@ -33,7 +36,7 @@ class Application: NSApplication { if event.type == .keyDown, (modifierFlags == NSEvent.ModifierFlags.command.rawValue || modifierFlags == NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue), - let selector = editorCommands[event.charactersIgnoringModifiers ?? ""] { + let selector = characterKeyCommands[event.charactersIgnoringModifiers ?? ""] { sendAction(selector, to: nil, from: self) } else { super.sendEvent(event)