Skip to content

Commit

Permalink
🔀 Merge pull request #559 from MrKai77/mrkai77/improve-keybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Sep 15, 2024
2 parents e39d201 + 0be86ea commit bcf20bd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 46 deletions.
21 changes: 11 additions & 10 deletions Loop/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
await Defaults.iCloud.waitForSyncCompletion()
}

// Check & ask for accessibility access
AccessibilityManager.requestAccess()
UNUserNotificationCenter.current().delegate = self

AppDelegate.requestNotificationAuthorization()

IconManager.refreshCurrentAppIcon()
AppDelegate.loopManager.start()
AppDelegate.windowDragManager.addObservers()

if !launchedAsLoginItem {
LuminareManager.open()
} else {
Expand All @@ -45,6 +35,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.setActivationPolicy(.accessory)
}
}

IconManager.refreshCurrentAppIcon()
AppDelegate.loopManager.start()
AppDelegate.windowDragManager.addObservers()

UNUserNotificationCenter.current().delegate = self
AppDelegate.requestNotificationAuthorization()

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
AccessibilityManager.requestAccess()
}
}

func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ struct CustomActionConfigurationView: View {
}

var body: some View {
ScreenView {
ScreenView(blurred: .constant(action.sizeMode != .custom)) {
GeometryReader { geo in
let frame = action.getFrame(window: nil, bounds: CGRect(origin: .zero, size: geo.size), disablePadding: true)
let _ = print(frame)
ZStack {
if action.sizeMode == .custom {
let frame = action.getFrame(window: nil, bounds: CGRect(origin: .zero, size: geo.size), disablePadding: true)

blurredWindow()
.frame(width: frame.width, height: frame.height)
.offset(x: frame.origin.x, y: frame.origin.y)
.animation(LuminareSettingsWindow.animation, value: frame)
}
}
.frame(width: geo.size.width, height: geo.size.height, alignment: .topLeading)
.animation(LuminareSettingsWindow.animation, value: frame)
}
}
.onChange(of: action) { windowAction = $0 }
Expand Down Expand Up @@ -303,9 +303,9 @@ struct CustomActionConfigurationView: View {
@ViewBuilder private func blurredWindow() -> some View {
VisualEffectView(material: .hudWindow, blendingMode: .withinWindow)
.overlay {
RoundedRectangle(cornerRadius: 5)
.strokeBorder(.white.opacity(0.1), lineWidth: 2)
RoundedRectangle(cornerRadius: 12 - 5)
.strokeBorder(Color.getLoopAccent(tone: .normal), lineWidth: 2)
}
.clipShape(RoundedRectangle(cornerRadius: 5))
.clipShape(RoundedRectangle(cornerRadius: 12 - 5))
}
}
74 changes: 57 additions & 17 deletions Loop/Luminare/Settings/Keybindings/KeybindingItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ struct KeybindingItemView: View {
}
.help("Customize what this keybind cycles through.")
}

if isHovering {
directionPicker()
.help("Customize this keybind's action.")
}
}
.font(.title3)
.foregroundStyle(isHovering ? .primary : .secondary)
Expand Down Expand Up @@ -137,6 +132,7 @@ struct KeybindingItemView: View {
.fixedSize()
}
}
.animation(LuminareSettingsWindow.animation, value: keybind)
.padding(.horizontal, 12)
.onAppear {
computeSearchResults()
Expand All @@ -163,21 +159,26 @@ struct KeybindingItemView: View {
}

func label() -> some View {
HStack(spacing: 0) {
HStack(spacing: 8) {
IconView(action: $keybind)

Text(keybind.getName())
.lineLimit(1)
.contentTransition(.numericText())
.animation(LuminareSettingsWindow.animation, value: keybind)
}
Button {
isPresented.toggle()
} label: {
HStack(spacing: 0) {
HStack(spacing: 8) {
IconView(action: $keybind)

Text(keybind.getName())
.lineLimit(1)
.contentTransition(.numericText())
}

if let info = keybind.direction.infoView {
info
if let info = keybind.direction.infoView {
info
}
}
.fixedSize(horizontal: false, vertical: true)
}
.fixedSize(horizontal: false, vertical: true)
.buttonStyle(CompactButtonStyle())
.help("Customize this keybind's action.")
}

func directionPicker() -> some View {
Expand Down Expand Up @@ -225,3 +226,42 @@ struct KeybindingItemView: View {
}
}
}

private struct CompactButtonStyle: ButtonStyle {
@Environment(\.hoveringOverLuminareItem) var hoveringOverLuminareItem
@Environment(\.isEnabled) private var isEnabled: Bool
let elementMinHeight: CGFloat = 25
@State var isHovering: Bool = false
let cornerRadius: CGFloat = 6

public func makeBody(configuration: Configuration) -> some View {
configuration.label
.background {
if configuration.isPressed || isHovering || hoveringOverLuminareItem {
backgroundForState(isPressed: configuration.isPressed)
.background {
RoundedRectangle(cornerRadius: cornerRadius)
.strokeBorder(.quaternary, lineWidth: 1)
}
.clipShape(.rect(cornerRadius: cornerRadius))
.padding(-4)
}
}
.onHover { isHovering = $0 }
.animation(LuminareSettingsWindow.fastAnimation, value: [isHovering, hoveringOverLuminareItem])
.frame(minHeight: elementMinHeight)
.opacity(isEnabled ? 1 : 0.5)
}

private func backgroundForState(isPressed: Bool) -> some View {
Group {
if isPressed {
Rectangle().foregroundStyle(.quaternary)
} else if isHovering {
Rectangle().foregroundStyle(.quaternary.opacity(0.6))
} else {
Rectangle().foregroundStyle(.quinary.opacity(0.5))
}
}
}
}
10 changes: 0 additions & 10 deletions Loop/Window Management/WindowAction+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ struct IconView: View {
.font(.system(size: 8))
.fontWeight(.bold)
.frame(width: size.width, height: size.height)
} else if action.direction == .cycle, action.cycle?.first == nil {
Image(._18PxRepeat4)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: size.width, height: size.height)
} else if action.direction == .custom, frame == .zero {
Image(._18PxSliders)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: size.width, height: size.height)
} else {
ZStack {
RoundedRectangle(cornerRadius: outerCornerRadius - inset)
Expand Down
4 changes: 2 additions & 2 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ enum WindowEngine {
let animate = Defaults[.animateWindowResizes] && !enhancedUI
WindowRecords.record(window, action)

if window.nsRunningApplication == NSRunningApplication.current,
let window = NSApp.keyWindow {
if window.nsRunningApplication?.bundleIdentifier == Bundle.main.bundleIdentifier,
let window = NSApp.keyWindow ?? NSApp.windows.first {
var newFrame = targetFrame
newFrame.size = window.frame.size

Expand Down

0 comments on commit bcf20bd

Please sign in to comment.