Skip to content

Commit

Permalink
#62 Ability to minimize windows
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Oct 25, 2023
1 parent 9878ccc commit 0c9e3c0
Show file tree
Hide file tree
Showing 29 changed files with 328 additions and 26 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "custom.computermouse.badge.arrow.down.rectangle.fill.svg",
"idiom" : "universal"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "custom.arrow.down.right.and.arrow.up.left.rectangle.svg",
"idiom" : "universal"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"symbols" : [
{
"filename" : "custom.rectangle.inset.filled.slash.svg",
"filename" : "custom.rectangle.slash.svg",
"idiom" : "universal"
}
]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Loop/Extensions/Defaults+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ extension Defaults.Keys {
static let previewPadding = Key<CGFloat>("previewPadding", default: 10)
static let previewBorderThickness = Key<CGFloat>("previewBorderThickness", default: 5)

static let preferMinimizeWithScrollDown = Key<Bool>("preferMinimizeWithScrollDown", default: false)

static let maximizeKeybind = Key<[Set<CGKeyCode>]>(
"maximizeKeybind",
default: [[.kVK_Space]]
Expand All @@ -57,6 +59,10 @@ extension Defaults.Keys {
"hideKeybind",
default: [[.kVK_ANSI_H]]
)
static let minimizeKeybind = Key<[Set<CGKeyCode>]>(
"minimizeKeybind",
default: [[.kVK_ANSI_M]]
)

// Cycle Halves
static let cycleTopKeybind = Key<[Set<CGKeyCode>]>(
Expand Down
20 changes: 15 additions & 5 deletions Loop/Managers/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,22 @@ class LoopManager {
self.scrollEventMonitor = CGEventMonitor(eventMask: [.scrollWheel]) { cgEvent in
if cgEvent.type == .scrollWheel, self.isLoopShown, let event = NSEvent(cgEvent: cgEvent) {

if event.deltaY > 1 && self.currentResizingDirection != .hide {
Notification.Name.directionChanged.post(userInfo: ["direction": WindowDirection.hide])
}
if Defaults[.preferMinimizeWithScrollDown] {
if event.deltaY > 1 && self.currentResizingDirection != .minimize {
Notification.Name.directionChanged.post(userInfo: ["direction": WindowDirection.minimize])
}

if event.deltaY < -1 && self.currentResizingDirection == .hide {
Notification.Name.directionChanged.post(userInfo: ["direction": WindowDirection.noAction])
if event.deltaY < -1 && self.currentResizingDirection == .minimize {
Notification.Name.directionChanged.post(userInfo: ["direction": WindowDirection.noAction])
}
} else {
if event.deltaY > 1 && self.currentResizingDirection != .hide {
Notification.Name.directionChanged.post(userInfo: ["direction": WindowDirection.hide])
}

if event.deltaY < -1 && self.currentResizingDirection == .hide {
Notification.Name.directionChanged.post(userInfo: ["direction": WindowDirection.noAction])
}
}

return nil
Expand Down
28 changes: 27 additions & 1 deletion Loop/Settings/KeybindingsSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct KeybindingsSettingsView: View {
@Default(.triggerDelay) var triggerDelay
@Default(.useSystemAccentColor) var useSystemAccentColor
@Default(.customAccentColor) var customAccentColor
@Default(.preferMinimizeWithScrollDown) var preferMinimizeWithScrollDown

@State var suggestAddingTriggerDelay: Bool = false
@State var suggestDisablingCapsLock: Bool = false
Expand Down Expand Up @@ -190,7 +191,7 @@ struct KeybindingsSettingsView: View {

HStack {
VStack(alignment: .leading) {
Text("Use Z undo window operations:")
Text("Press Z undo window operations:")
}

Spacer()
Expand All @@ -208,6 +209,31 @@ struct KeybindingsSettingsView: View {
}
.foregroundStyle(Color.accentColor)
}

HStack {
VStack(alignment: .leading) {
if self.preferMinimizeWithScrollDown {
Text("Scroll down to minimize a window:")
} else {
Text("Scroll down to hide a window:")
}
}

Spacer()

HStack {
Image(self.triggerKey.keySymbol)
.font(Font.system(size: 30, weight: .regular))

Image(systemName: "plus")
.font(Font.system(size: 15, weight: .bold))

Image(systemName: "arrow.up.and.down.square.fill")
.font(Font.system(size: 30, weight: .regular))
.frame(width: 60)
}
.foregroundStyle(Color.accentColor)
}
}
.symbolRenderingMode(.hierarchical)
}
Expand Down
5 changes: 5 additions & 0 deletions Loop/Settings/MoreSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Defaults
struct MoreSettingsView: View {

@EnvironmentObject var updater: SoftwareUpdater
@Default(.preferMinimizeWithScrollDown) var preferMinimizeWithScrollDown

var body: some View {
Form {
Expand All @@ -36,6 +37,10 @@ struct MoreSettingsView: View {
.foregroundStyle(Color.accentColor)
}
})

Section("Extra Settings") {
Toggle("Prefer scroll down to minimize window", isOn: self.$preferMinimizeWithScrollDown)
}
}
.formStyle(.grouped)
.scrollDisabled(true)
Expand Down
6 changes: 5 additions & 1 deletion Loop/Window Management/WindowDirection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum WindowDirection: CaseIterable, Identifiable {
case center
case initialFrame
case hide
case minimize

// To cycle through directions
case cycleTop
Expand Down Expand Up @@ -119,6 +120,7 @@ enum WindowDirection: CaseIterable, Identifiable {
case .center: "Center"
case .initialFrame: "Initial Frame"
case .hide: "Hide"
case .minimize: "Minimize"

case .cycleTop: "Cycle Top"
case .cycleBottom: "Cycle Bottom"
Expand Down Expand Up @@ -157,6 +159,7 @@ enum WindowDirection: CaseIterable, Identifiable {
case .center: Defaults[.centerKeybind]
case .initialFrame: Defaults[.initialFrameKeybind]
case .hide: Defaults[.hideKeybind]
case .minimize: Defaults[.minimizeKeybind]

case .cycleTop: Defaults[.cycleTopKeybind]
case .cycleRight: Defaults[.cycleRightKeybind]
Expand Down Expand Up @@ -213,7 +216,8 @@ enum WindowDirection: CaseIterable, Identifiable {

var radialMenuImage: Image? {
switch self {
case .hide: Image("custom.rectangle.inset.filled.slash")
case .hide: Image("custom.rectangle.slash")
case .minimize: Image("custom.arrow.down.right.and.arrow.up.left.rectangle")
default: nil
}
}
Expand Down
8 changes: 8 additions & 0 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ struct WindowEngine {
}
}

if direction == .minimize {
if window.isMinimized {
window.setMinimized(false)
} else {
window.setMinimized(true)
}
}

window.setFullscreen(false)

let oldWindowFrame = window.frame
Expand Down

0 comments on commit 0c9e3c0

Please sign in to comment.