Skip to content

Commit

Permalink
doc: resolve several issues, refer to the documentation within README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Akazm committed Dec 16, 2024
1 parent cb0030b commit 69f1086
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Then, add `TapGuard` to your target's dependencies:

## Usage

### Create a `HIDEventDispatcher`
### Initialize [`HIDEventDispatcher`](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventdispatcher)

TapGuard provides a convenient way to initialize a `HIDEventDispatcher` with a backing
[CGEventTap](https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate).
Expand Down Expand Up @@ -63,7 +63,9 @@ _install_ the backing CGEventTap.

### Processing events

`HIDEventDispatcher` allows you to register multiple *event receivers*.
`HIDEventDispatcher` allows you to register multiple
[event receivers](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventreceiver). This is also refered
to as 'event processing pipeline.

#### Using an `AsyncStream`:

Expand All @@ -77,6 +79,9 @@ Task {
}
```

For more information, see
[stream(withPriority:)](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventdispatcher/stream(withpriority:))

#### Conformance to `HIDEventReceiver & AnyObject`

```swift
Expand All @@ -100,9 +105,12 @@ class MyReceiver: HIDEventReceiver {
}
}
```
For more information, see [HIDEventReceiver](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventreceiver).

Event processing happens within the closure specified for the defined `HIDEventProcessor`. In the example, the closure
returns a `PostProcessHIDEventInstruction` to specify how to postprocess the event after the closure exited.
Event processing happens within the closure specified for the defined
[HIDEventReceiver](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventreceiver). In the example,
the closure returns a [PostProcessHIDEventInstruction](https://akazm.github.io/osx-tap-guard/documentation/tapguard/postprocesshideventinstruction)
to specify how to postprocess the event after the closure exited.

To enable async event processing, use an `async` processor instead.

Expand All @@ -128,6 +136,7 @@ class MyAsyncReceiver: HIDEventReceiver {
}
}
```
For more information, see [HIDEventProcessor](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventprocessor).

#### Using closures

Expand All @@ -149,6 +158,7 @@ let receiver = dispatcher.addReceiver { event in
return .pass
}
```
For more information, see [`HIDEventDispatcher`](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventdispatcher).

#### Removing receivers

Expand All @@ -163,6 +173,8 @@ let registration = dispatcher.addReceiver(myReceiver)
registration.remove()
```

For more information, see [`DisposableHIDEventReceiver`](https://akazm.github.io/osx-tap-guard/documentation/tapguard/disposablehideventreceiver).

### Enable or disable dispatcher

Manually enable or disable the dispatcher:
Expand All @@ -184,6 +196,9 @@ let suspension = dispatcher.acquireSuspension()
suspension.release()
```

For more information, see
[`acquireSuspension()`](https://akazm.github.io/osx-tap-guard/documentation/tapguard/hideventdispatcher/acquiresuspension())

### Notes on async event processing

Async event processing is supported in order to achieve *formal* thread safety first and foremost, but *not*
Expand All @@ -193,11 +208,11 @@ Doing so nonetheless might result in the following:

1. **MacOS disables a dispatcher's backing event tap ([kCGEventTapDisabledByTimeout](https://developer.apple.com/documentation/coregraphics/cgeventtype/kcgeventtapdisabledbytimeout?language=swift)).**
It will be re-enabled automatically.
2. **MacOS ignores the `PostProcessHIDEventInstruction`**, effectively replacing it with `.bypass` behaviour.
2. **MacOS ignores the `PostProcessHIDEventInstruction`**, effectively replacing it with [.bypass](https://akazm.github.io/osx-tap-guard/documentation/tapguard/postprocesshideventinstruction/bypass) behaviour.

## Documentation

// TODO
See [here](https://akazm.github.io/osx-tap-guard/documentation/tapguard).

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion Sources/TapGuard/HIDEventDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public final class HIDEventDispatcher: Sendable {
}
}

/// Disables ( `false`) or enables (`true`) event processing
/// Disables (`false`) or enables (`true`) event processing
public func setEnabled(_ value: Bool) {
if value == enabledOverride.load(ordering: .sequentiallyConsistent) {
return
Expand Down
2 changes: 1 addition & 1 deletion Sources/TapGuard/HIDEventReceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public extension HIDEventReceiver {
}
}

/// An event receiver that may be removed from a ``HIDEventDispatcher`` by calling ``DisposableHIDEventReceiver/remove``
/// An event receiver that may be removed from a ``HIDEventDispatcher`` by calling ``DisposableHIDEventReceiver/remove``
public protocol DisposableHIDEventReceiver: Sendable {
/// Removes this receiver's registration from the event processing pipeline
var remove: @Sendable () -> Void { get }
Expand Down
2 changes: 1 addition & 1 deletion Sources/TapGuard/PostProcessHIDEventInstruction.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Instructs the ``HIDEventDispatcher``how to postprocess a received event
/// Instructs the ``HIDEventDispatcher`` how to postprocess a received event
public enum PostProcessHIDEventInstruction: Sendable {
/// Instructs the ``HIDEventDispatcher`` to retain an event, preventing it from further processing by the pipeline and the OS
case retain
Expand Down

0 comments on commit 69f1086

Please sign in to comment.