Skip to content

Commit

Permalink
Merge pull request #832 from ianyh/0.14.0
Browse files Browse the repository at this point in the history
0.14.0 to master
  • Loading branch information
ianyh authored Jun 1, 2019
2 parents b3f29cd + 55fd05f commit 5bfe46d
Show file tree
Hide file tree
Showing 45 changed files with 2,834 additions and 1,965 deletions.
2 changes: 1 addition & 1 deletion .hound.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
swift:
swiftlint:
config_file: .swiftlint.yml
5 changes: 3 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ disabled_rules:
- statement_position
- force_cast
- force_try
- variable_name_min_length
included:
- Amethyst
- AmethystTests
line_length: 200
line_length:
warning: 200
ignores_comments: true
file_length: 500
type_body_length: 400
cyclomatic_complexity: 15
Expand Down
126 changes: 75 additions & 51 deletions Amethyst.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Amethyst/Amethyst-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.13.0</string>
<string>0.14.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>70</string>
<string>72</string>
<key>Fabric</key>
<dict>
<key>Kits</key>
Expand Down
5 changes: 3 additions & 2 deletions Amethyst/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import Foundation
import LoginServiceKit
import RxCocoa
import RxSwift
import Silica
import Sparkle
import SwiftyBeaver

final class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var preferencesWindowController: PreferencesWindowController?

fileprivate var windowManager: WindowManager?
private var hotKeyManager: HotKeyManager?
fileprivate var windowManager: WindowManager<SIApplication>?
private var hotKeyManager: HotKeyManager<SIApplication>?

fileprivate var statusItem: NSStatusItem?
@IBOutlet var statusItemMenu: NSMenu?
Expand Down
44 changes: 42 additions & 2 deletions Amethyst/Categories/NSScreen+Amethyst.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SwiftyJSON

extension NSScreen {
static func screenDescriptions() -> [JSON]? {
guard let cfScreenDescriptions = CGSCopyManagedDisplaySpaces(_CGSDefaultConnection())?.takeRetainedValue() else {
guard let cfScreenDescriptions = CGSCopyManagedDisplaySpaces(CGSMainConnectionID())?.takeRetainedValue() else {
return nil
}
guard let screenDescriptions = cfScreenDescriptions as NSArray as? [[String: AnyObject]] else {
Expand All @@ -30,7 +30,7 @@ extension NSScreen {
}

func screenIdentifier() -> String? {
guard let managedDisplay = CGSCopyBestManagedDisplayForRect(_CGSDefaultConnection(), frameIncludingDockAndMenu()) else {
guard let managedDisplay = CGSCopyBestManagedDisplayForRect(CGSMainConnectionID(), frameIncludingDockAndMenu()) else {
return nil
}
return String(managedDisplay.takeRetainedValue())
Expand All @@ -43,4 +43,44 @@ extension NSScreen {
mouseMoveEvent?.flags = CGEventFlags(rawValue: 0)
mouseMoveEvent?.post(tap: .cghidEventTap)
}

func adjustedFrame() -> CGRect {
var frame = UserConfiguration.shared.ignoreMenuBar() ? frameIncludingDockAndMenu() : frameWithoutDockOrMenu()

if UserConfiguration.shared.windowMargins() {
/* Inset for producing half of the full padding around screen as collapse only adds half of it to all windows */
let padding = floor(UserConfiguration.shared.windowMarginSize() / 2)

frame.origin.x += padding
frame.origin.y += padding
frame.size.width -= 2 * padding
frame.size.height -= 2 * padding
}

let windowMinimumWidth = UserConfiguration.shared.windowMinimumWidth()
let windowMinimumHeight = UserConfiguration.shared.windowMinimumHeight()

if windowMinimumWidth > frame.size.width {
frame.origin.x -= (windowMinimumWidth - frame.size.width) / 2
frame.size.width = windowMinimumWidth
}

if windowMinimumHeight > frame.size.height {
frame.origin.y -= (windowMinimumHeight - frame.size.height) / 2
frame.size.height = windowMinimumHeight
}

let paddingTop = UserConfiguration.shared.screenPaddingTop()
let paddingBottom = UserConfiguration.shared.screenPaddingBottom()
let paddingLeft = UserConfiguration.shared.screenPaddingLeft()
let paddingRight = UserConfiguration.shared.screenPaddingRight()
frame.origin.y += paddingTop
frame.origin.x += paddingLeft
// subtract the right padding, and also any amount that we pushed the frame to the left with the left padding
frame.size.width -= (paddingRight + paddingLeft)
// subtract the bottom padding, and also any amount that we pushed the frame down with the top padding
frame.size.height -= (paddingBottom + paddingTop)

return frame
}
}
2 changes: 0 additions & 2 deletions Amethyst/Categories/NSTableView+Amethyst.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
import Cocoa

extension NSTableView {

static let noRowSelectedIndex = -1

}
56 changes: 32 additions & 24 deletions Amethyst/Events/HotKeyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import MASShortcut
import Silica

// Type for defining key code.
typealias AMKeyCode = Int
Expand All @@ -21,7 +22,7 @@ private let AMKeyCodeInvalid: AMKeyCode = 0xFF

typealias HotKeyHandler = () -> Void

final class HotKeyManager: NSObject {
final class HotKeyManager<Application: ApplicationType>: NSObject {
private let userConfiguration: UserConfiguration

private(set) lazy var stringToKeyCodes: [String: [AMKeyCode]] = {
Expand Down Expand Up @@ -68,77 +69,83 @@ final class HotKeyManager: NSObject {
}
}

func setUpWithWindowManager(_ windowManager: WindowManager, configuration: UserConfiguration) {
func setUpWithWindowManager(_ windowManager: WindowManager<Application>, configuration: UserConfiguration) {
constructCommandWithCommandKey(CommandKey.cycleLayoutForward.rawValue) {
windowManager.focusedScreenManager()?.cycleLayoutForward()
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.cycleLayoutForward()
}

constructCommandWithCommandKey(CommandKey.cycleLayoutBackward.rawValue) {
windowManager.focusedScreenManager()?.cycleLayoutBackward()
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.cycleLayoutBackward()
}

constructCommandWithCommandKey(CommandKey.shrinkMain.rawValue) {
windowManager.focusedScreenManager()?.updateCurrentLayout { layout in
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.updateCurrentLayout { layout in
if let panedLayout = layout as? PanedLayout {
panedLayout.shrinkMainPane()
}
}
}

constructCommandWithCommandKey(CommandKey.expandMain.rawValue) {
windowManager.focusedScreenManager()?.updateCurrentLayout { layout in
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.updateCurrentLayout { layout in
if let panedLayout = layout as? PanedLayout {
panedLayout.expandMainPane()
}
}
}

constructCommandWithCommandKey(CommandKey.increaseMain.rawValue) {
windowManager.focusedScreenManager()?.updateCurrentLayout { layout in
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.updateCurrentLayout { layout in
if let panedLayout = layout as? PanedLayout {
panedLayout.increaseMainPaneCount()
}
}
}

constructCommandWithCommandKey(CommandKey.decreaseMain.rawValue) {
windowManager.focusedScreenManager()?.updateCurrentLayout { layout in
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.updateCurrentLayout { layout in
if let panedLayout = layout as? PanedLayout {
panedLayout.decreaseMainPaneCount()
}
}
}

constructCommandWithCommandKey(CommandKey.focusCCW.rawValue) {
windowManager.moveFocusCounterClockwise()
windowManager.focusTransitionCoordinator.moveFocusCounterClockwise()
}

constructCommandWithCommandKey(CommandKey.focusCW.rawValue) {
windowManager.moveFocusClockwise()
windowManager.focusTransitionCoordinator.moveFocusClockwise()
}

constructCommandWithCommandKey(CommandKey.focusMain.rawValue) {
windowManager.moveFocusToMain()
windowManager.focusTransitionCoordinator.moveFocusToMain()
}

constructCommandWithCommandKey(CommandKey.swapScreenCCW.rawValue) {
windowManager.swapFocusedWindowScreenCounterClockwise()
windowManager.windowTransitionCoordinator.swapFocusedWindowScreenCounterClockwise()
}

constructCommandWithCommandKey(CommandKey.swapScreenCW.rawValue) {
windowManager.swapFocusedWindowScreenClockwise()
windowManager.windowTransitionCoordinator.swapFocusedWindowScreenClockwise()
}

constructCommandWithCommandKey(CommandKey.swapCCW.rawValue) {
windowManager.swapFocusedWindowCounterClockwise()
windowManager.windowTransitionCoordinator.swapFocusedWindowCounterClockwise()
}

constructCommandWithCommandKey(CommandKey.swapCW.rawValue) {
windowManager.swapFocusedWindowClockwise()
windowManager.windowTransitionCoordinator.swapFocusedWindowClockwise()
}

constructCommandWithCommandKey(CommandKey.swapMain.rawValue) {
windowManager.swapFocusedWindowToMain()
windowManager.windowTransitionCoordinator.swapFocusedWindowToMain()
}

constructCommandWithCommandKey(CommandKey.displayCurrentLayout.rawValue) {
Expand All @@ -150,28 +157,28 @@ final class HotKeyManager: NSObject {
let throwCommandKey = "\(CommandKey.throwScreenPrefix.rawValue)-\(screenNumber)"

self.constructCommandWithCommandKey(focusCommandKey) {
windowManager.focusScreen(at: screenNumber - 1)
windowManager.focusTransitionCoordinator.focusScreen(at: screenNumber - 1)
}

self.constructCommandWithCommandKey(throwCommandKey) {
windowManager.throwToScreenAtIndex(screenNumber - 1)
windowManager.windowTransitionCoordinator.throwToScreenAtIndex(screenNumber - 1)
}
}

(1...10).forEach { spaceNumber in
let commandKey = "\(CommandKey.throwSpacePrefix.rawValue)-\(spaceNumber)"

self.constructCommandWithCommandKey(commandKey) {
windowManager.pushFocusedWindowToSpace(UInt(spaceNumber))
windowManager.windowTransitionCoordinator.pushFocusedWindowToSpace(spaceNumber - 1)
}
}

constructCommandWithCommandKey(CommandKey.throwSpaceLeft.rawValue) {
windowManager.pushFocusedWindowToSpaceLeft()
windowManager.windowTransitionCoordinator.pushFocusedWindowToSpaceLeft()
}

constructCommandWithCommandKey(CommandKey.throwSpaceRight.rawValue) {
windowManager.pushFocusedWindowToSpaceRight()
windowManager.windowTransitionCoordinator.pushFocusedWindowToSpaceRight()
}

constructCommandWithCommandKey(CommandKey.toggleFloat.rawValue) {
Expand All @@ -191,9 +198,10 @@ final class HotKeyManager: NSObject {
self.userConfiguration.toggleFocusFollowsMouse()
}

LayoutManager.availableLayoutStrings().forEach { (layoutKey, _) in
LayoutManager<Application.Window>.availableLayoutStrings().forEach { (layoutKey, _) in
self.constructCommandWithCommandKey(UserConfiguration.constructLayoutKeyString(layoutKey)) {
windowManager.focusedScreenManager()?.selectLayout(layoutKey)
let screenManager: ScreenManager<Application.Window>? = windowManager.focusedScreenManager()
screenManager?.selectLayout(layoutKey)
}
}
}
Expand Down Expand Up @@ -341,7 +349,7 @@ final class HotKeyManager: NSObject {
hotKeyNameToDefaultsKey.append(["Display current layout", CommandKey.displayCurrentLayout.rawValue])
hotKeyNameToDefaultsKey.append(["Toggle global tiling", CommandKey.toggleTiling.rawValue])

for (layoutKey, layoutName) in LayoutManager.availableLayoutStrings() {
for (layoutKey, layoutName) in LayoutManager<Application.Window>.availableLayoutStrings() {
let commandName = "Select \(layoutName) layout"
let commandKey = "select-\(layoutKey)-layout"
hotKeyNameToDefaultsKey.append([commandName, commandKey])
Expand Down
29 changes: 0 additions & 29 deletions Amethyst/Layout/FloatingLayout.swift

This file was deleted.

45 changes: 0 additions & 45 deletions Amethyst/Layout/FullscreenLayout.swift

This file was deleted.

Loading

0 comments on commit 5bfe46d

Please sign in to comment.