Skip to content

Commit

Permalink
Merge pull request #3789 from pqrs-org/remove-device-observer
Browse files Browse the repository at this point in the history
Remove karabiner_observer
  • Loading branch information
tekezo committed Apr 23, 2024
2 parents 41c3b1c + ea94352 commit 3cb961b
Show file tree
Hide file tree
Showing 64 changed files with 554 additions and 1,033 deletions.
24 changes: 4 additions & 20 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ cd src/core/grabber
make install
```

### Replace `karabiner_observer`

```shell
cd src/core/observer
make install
```

### Replace `karabiner_session_monitor`

```shell
Expand All @@ -35,10 +28,6 @@ make install
- `karabiner_grabber`
- Run with root privilege.
- Seize the input devices and modify events then post events using `Karabiner-DriverKit-VirtualHIDDevice`.
- `karabiner_observer`
- Run with root privilege.
- Observe input devices and manage the grabbable state.
- Tell the grabbable state to `karabiner_grabber`.
- `karabiner_session_monitor`
- Run with root privilege.
- (Opened by console user privilege in order to use CoreGraphics session API.
Expand All @@ -63,11 +52,6 @@ make install
3. `karabiner_grabber` opens grabber server Unix domain socket.
4. When a window server session state is changed, `karabiner_grabber` changes the Unix domain socket owner to console user.

`karabiner_observer`

1. Run `karabiner_observer`.
2. `karabiner_observer` observes devices and send the input events to `karabiner_grabber`.

`karabiner_session_monitor`

1. Run `karabiner_session_monitor`.
Expand Down Expand Up @@ -293,8 +277,8 @@ The caps lock is quite different from the normal modifier.
- Send the event via virtual hid keyboard.
- macOS update the caps lock LED of virtual hid keyboard.
- Virtual hid keyboard sends the LED updated event.
- karabiner_observer receives the LED updated event and tells it karabiner_grabber.
- karabiner_grabber makes `event::type::caps_lock_state_changed` event and processes it.
- karabiner_grabber observes events from the virtual hid keyboard.
When an event {usage_page::leds, usage::led::caps_lock} is detected, karabiner_grabber generates an `event::type::caps_lock_state_changed` and adds it to the queue.
- The state of `modifier_flag_manager` is changed by `event::type::caps_lock_state_changed`.

### modifier state holders
Expand Down Expand Up @@ -332,7 +316,7 @@ Example:
- `key_event_dispatcher` is updated.
- `pressed_keys_.insert(caps_lock)`
- macOS update the caps lock LED state (on).
- `event::type::caps_lock_state_changed (on)` is sent via `karabiner_observer`.
- `event::type::caps_lock_state_changed (on)` is sent via `krbn::event_queue::utility::make_queue` in `karabiner_grabber`.
- `modifier_flag_manager increase_led_lock (caps_lock)`
- `key_event_dispatcher` is updated.
- `pressed_modifier_flags_.insert(caps_lock)`
Expand All @@ -350,7 +334,7 @@ Example:
- `sticky_modifier caps_lock true` is sent by `modifiers.mandatory`.
- `modifier_flag_manager increase_sticky (caps_lock)`
- macOS update the caps lock LED state (off).
- `event::type::caps_lock_state_changed (off)` is sent via `karabiner_observer`.
- `event::type::caps_lock_state_changed (off)` is sent via `krbn::event_queue::utility::make_queue` in `karabiner_grabber`.
- `modifier_flag_manager decrease_led_lock (caps_lock)`
- Note: led_lock will be ignored while other counter is active in modifier_flag_manager.
- Release `down_arrow` key.
Expand Down
4 changes: 3 additions & 1 deletion docs/images/processes.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

18 changes: 0 additions & 18 deletions files/LaunchDaemons/org.pqrs.karabiner.karabiner_observer.plist

This file was deleted.

1 change: 0 additions & 1 deletion make-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ mkdir -p "$basedir"
cp src/bin/cli/build/Release/karabiner_cli "$basedir"
cp src/core/console_user_server/build/Release/karabiner_console_user_server "$basedir"
cp src/core/grabber/build/Release/karabiner_grabber "$basedir"
cp src/core/observer/build/Release/karabiner_observer "$basedir"
cp src/core/session_monitor/build/Release/karabiner_session_monitor "$basedir"

mkdir -p "pkgroot/Library"
Expand Down
6 changes: 0 additions & 6 deletions pkginfo/Scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ chmod 4755 '/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabin
# ------------------------------------------------------------
# Relaunch karabiner processes

killall karabiner_kextd
killall karabiner_grabber
killall karabiner_observer
killall karabiner_session_monitor
killall karabiner_console_user_server
killall Karabiner-NotificationWindow
Expand All @@ -31,8 +29,4 @@ launchctl enable system/org.pqrs.karabiner.karabiner_grabber
launchctl bootstrap system /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_grabber.plist
launchctl enable system/org.pqrs.karabiner.karabiner_grabber

launchctl enable system/org.pqrs.karabiner.karabiner_observer
launchctl bootstrap system /Library/LaunchDaemons/org.pqrs.karabiner.karabiner_observer.plist
launchctl enable system/org.pqrs.karabiner.karabiner_observer

exit 0
2 changes: 0 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ all:
$(MAKE) -C bin/cli
$(MAKE) -C core/console_user_server
$(MAKE) -C core/grabber
$(MAKE) -C core/observer
$(MAKE) -C core/session_monitor
$(MAKE) -C lib/libkrbn

Expand All @@ -22,6 +21,5 @@ clean:
$(MAKE) -C bin/cli clean
$(MAKE) -C core/console_user_server clean
$(MAKE) -C core/grabber clean
$(MAKE) -C core/observer clean
$(MAKE) -C core/session_monitor clean
$(MAKE) -C lib/libkrbn clean
24 changes: 4 additions & 20 deletions src/apps/SettingsWindow/src/StateJsonMonitor.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import Foundation

private func grabberStateJsonFileUpdatedCallback() {
private func callback() {
Task { @MainActor in
StateJsonMonitor.shared.update(StateJsonMonitor.shared.grabberStateJsonFilePath)
}
}

private func observerStateJsonFileUpdatedCallback() {
Task { @MainActor in
StateJsonMonitor.shared.update(StateJsonMonitor.shared.observerStateJsonFilePath)
}
}

private struct State: Codable {
var driverActivated: Bool?
var driverVersionMismatched: Bool?
Expand All @@ -22,7 +16,6 @@ public class StateJsonMonitor {
static let shared = StateJsonMonitor()

let grabberStateJsonFilePath = LibKrbn.grabberStateJsonFilePath()
let observerStateJsonFilePath = LibKrbn.observerStateJsonFilePath()

private var states: [String: State] = [:]

Expand All @@ -34,23 +27,14 @@ public class StateJsonMonitor {

libkrbn_register_file_updated_callback(
grabberStateJsonFilePath.cString(using: .utf8),
grabberStateJsonFileUpdatedCallback)
libkrbn_enqueue_callback(grabberStateJsonFileUpdatedCallback)

libkrbn_register_file_updated_callback(
observerStateJsonFilePath.cString(using: .utf8),
observerStateJsonFileUpdatedCallback)
libkrbn_enqueue_callback(observerStateJsonFileUpdatedCallback)
callback)
libkrbn_enqueue_callback(callback)
}

public func stop() {
libkrbn_unregister_file_updated_callback(
grabberStateJsonFilePath.cString(using: .utf8),
grabberStateJsonFileUpdatedCallback)

libkrbn_unregister_file_updated_callback(
observerStateJsonFilePath.cString(using: .utf8),
observerStateJsonFileUpdatedCallback)
callback)

// We don't call `libkrbn_disable_file_monitors` because the file monitors may be used elsewhere.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ struct DevicesGamePadSettingsView_Previews: PreviewProvider {
isBuiltInKeyboard: false,
isBuiltInTrackpad: false,
isBuiltInTouchBar: false,
isAppleDevice: false
isAppleDevice: false,
isKarabinerVirtualHidDevice: false
)
@State static var showing = true

Expand Down
25 changes: 15 additions & 10 deletions src/apps/SettingsWindow/src/View/DevicesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ struct DevicesView: View {
ForEach(connectedDevices.connectedDevices) { connectedDevice in
VStack(alignment: .leading, spacing: 0.0) {
DeviceName(connectedDevice: connectedDevice)
.if(connectedDevice.isKarabinerVirtualHidDevice) {
$0.foregroundColor(Color(NSColor.placeholderTextColor))
}

VStack(alignment: .leading, spacing: 0.0) {
ModifyEventsSetting(connectedDevice: connectedDevice)
if !connectedDevice.isKarabinerVirtualHidDevice {
VStack(alignment: .leading, spacing: 0.0) {
ModifyEventsSetting(connectedDevice: connectedDevice)

VStack(alignment: .leading, spacing: 12.0) {
KeyboardSettings(connectedDevice: connectedDevice)
VStack(alignment: .leading, spacing: 12.0) {
KeyboardSettings(connectedDevice: connectedDevice)

MouseSettings(connectedDevice: connectedDevice)
MouseSettings(connectedDevice: connectedDevice)

GamePadSettings(connectedDevice: connectedDevice)
GamePadSettings(connectedDevice: connectedDevice)
}
.padding(.leading, 20.0)
.padding(.top, 8.0)
}
.padding(.leading, 20.0)
.padding(.top, 8.0)
.padding(.leading, 62.0)
.padding(.top, 20.0)
}
.padding(.leading, 62.0)
.padding(.top, 20.0)
}
.padding(.vertical, 12.0)
.padding(.trailing, 12.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct InputMonitoringPermissionsAlertView: View {
.font(.system(size: 24))

Text(
"karabiner_grabber and karabiner_observer require Input Monitoring permission.\nPlease allow them on Privacy & Security System Settings."
"karabiner_grabber requires Input Monitoring permission.\nPlease allow them on Privacy & Security System Settings."
)
.fixedSize(horizontal: false, vertical: true)

Expand Down
3 changes: 2 additions & 1 deletion src/apps/share/swift/LibKrbn/ConnectedDevices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ extension LibKrbn {
isBuiltInKeyboard: libkrbn_connected_devices_get_is_built_in_keyboard(i),
isBuiltInTrackpad: libkrbn_connected_devices_get_is_built_in_trackpad(i),
isBuiltInTouchBar: libkrbn_connected_devices_get_is_built_in_touch_bar(i),
isAppleDevice: libkrbn_connected_devices_is_apple(i)
isAppleDevice: libkrbn_connected_devices_is_apple(i),
isKarabinerVirtualHidDevice: libkrbn_connected_devices_is_karabiner_virtual_hid_device(i)
)

newConnectedDevices.append(connectedDevice)
Expand Down
6 changes: 0 additions & 6 deletions src/apps/share/swift/LibKrbn/LibKrbn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@ public struct LibKrbn {
libkrbn_get_notification_message_json_file_path(&buffer, buffer.count)
return String(cString: buffer)
}

public static func observerStateJsonFilePath() -> String {
var buffer = [Int8](repeating: 0, count: 1024)
libkrbn_get_observer_state_json_file_path(&buffer, buffer.count)
return String(cString: buffer)
}
}
5 changes: 4 additions & 1 deletion src/apps/share/swift/LibKrbn/Models/ConnectedDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension LibKrbn {
let isBuiltInTrackpad: Bool
let isBuiltInTouchBar: Bool
let isAppleDevice: Bool
let isKarabinerVirtualHidDevice: Bool

let libkrbnDeviceIdentifiers: UnsafeMutablePointer<libkrbn_device_identifiers>

Expand All @@ -34,7 +35,8 @@ extension LibKrbn {
isBuiltInKeyboard: Bool,
isBuiltInTrackpad: Bool,
isBuiltInTouchBar: Bool,
isAppleDevice: Bool
isAppleDevice: Bool,
isKarabinerVirtualHidDevice: Bool
) {
self.index = index
self.manufacturerName = manufacturerName
Expand All @@ -50,6 +52,7 @@ extension LibKrbn {
self.isBuiltInTrackpad = isBuiltInTrackpad
self.isBuiltInTouchBar = isBuiltInTouchBar
self.isAppleDevice = isAppleDevice
self.isKarabinerVirtualHidDevice = isKarabinerVirtualHidDevice

libkrbnDeviceIdentifiers = UnsafeMutablePointer<libkrbn_device_identifiers>.allocate(
capacity: 1)
Expand Down
1 change: 0 additions & 1 deletion src/core/console_user_server/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ int main(int argc, const char* argv[]) {
krbn::launchctl_utility::manage_session_monitor();
krbn::launchctl_utility::manage_console_user_server(true);
krbn::launchctl_utility::manage_notification_window(true);
krbn::launchctl_utility::manage_observer_agent();
krbn::launchctl_utility::manage_grabber_agent();

//
Expand Down

0 comments on commit 3cb961b

Please sign in to comment.