-
Notifications
You must be signed in to change notification settings - Fork 74
feat: configurable click behavior to close tabs #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AryanRogye
wants to merge
6
commits into
the-ora:main
Choose a base branch
from
AryanRogye:feature/double_click_exit_fullscreen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78bda0d
Added close active tab while hovering over sidebar
AryanRogye 57123c4
update to return nil
AryanRogye 1670fcf
Fixing lint issues
AryanRogye cffb28f
fixed liniting
AryanRogye f43636f
Updated to only close the tab that is getting hovered on
AryanRogye 3844314
Fix lint
AryanRogye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // | ||
| // ClickDetector.swift | ||
| // ora | ||
| // | ||
| // Created by Aryan Rogye on 3/8/26. | ||
| // | ||
|
|
||
| import AppKit | ||
| import SwiftUI | ||
|
|
||
| enum ClickConfig: String, CaseIterable { | ||
| case none = "None" | ||
| case middleMouse = "Middle Mouse" | ||
| case optionClick = "Option Click" | ||
| } | ||
|
|
||
| struct ClickDetector: NSViewRepresentable { | ||
| var config: ClickConfig | ||
| var onClick: () -> Void | ||
|
|
||
| func makeNSView(context: Context) -> NSView { | ||
| // Uncomment to visualize the click area bounds when debugging. | ||
| // let view = NSView() | ||
| // view.wantsLayer = true | ||
| // view.layer?.borderColor = NSColor.red.cgColor | ||
| // view.layer?.borderWidth = 2 | ||
| // return view | ||
| return NSView() | ||
| } | ||
|
|
||
| func updateNSView(_ nsView: NSView, context: Context) { | ||
| context.coordinator.view = nsView | ||
| context.coordinator.update(config: config, onClick: onClick, view: nsView) | ||
| } | ||
|
|
||
| func makeCoordinator() -> Coordinator { | ||
| Coordinator(config: config, onClick: onClick) | ||
| } | ||
|
|
||
| class Coordinator: NSObject { | ||
| var monitor: Any? | ||
| var lastFired: Date = .distantPast | ||
| let throttleInterval: TimeInterval = 0.5 | ||
| var currentConfig: ClickConfig = .none | ||
| var onClick: (() -> Void)? | ||
| weak var view: NSView? | ||
|
|
||
| init(config: ClickConfig, onClick: @escaping () -> Void) { | ||
| super.init() | ||
| update(config: config, onClick: onClick, view: nil) | ||
| } | ||
|
|
||
| func update(config: ClickConfig, onClick: @escaping () -> Void, view: NSView?) { | ||
| self.view = view | ||
| self.onClick = onClick | ||
| guard currentConfig != config else { return } | ||
| currentConfig = config | ||
| if let monitor { NSEvent.removeMonitor(monitor) } | ||
| monitor = nil | ||
|
|
||
| switch config { | ||
| case .none: | ||
| break | ||
| case .middleMouse: | ||
| monitor = NSEvent.addLocalMonitorForEvents(matching: .otherMouseDown) { [weak self] event in | ||
| guard event.buttonNumber == 2 else { return event } | ||
| guard self?.isOverView(event) == true else { return event } | ||
| self?.fire() | ||
| return nil | ||
| } | ||
| case .optionClick: | ||
| monitor = NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown) { [weak self] event in | ||
| guard event.modifierFlags.contains(.option) else { return event } | ||
| guard self?.isOverView(event) == true else { return event } | ||
| self?.fire() | ||
| return nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func isOverView(_ event: NSEvent) -> Bool { | ||
| guard let view, let window = view.window else { return false } | ||
| let locationInWindow = event.locationInWindow | ||
| let locationInView = view.convert(locationInWindow, from: nil) | ||
| return view.bounds.contains(locationInView) | ||
| } | ||
|
|
||
| private func fire() { | ||
| let now = Date() | ||
| guard now.timeIntervalSince(lastFired) >= throttleInterval else { return } | ||
| lastFired = now | ||
| onClick?() | ||
| } | ||
|
|
||
| deinit { | ||
| if let monitor { NSEvent.removeMonitor(monitor) } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.