Skip to content
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

App stops reacting to shortcuts sometimes #18

Closed
lwouis opened this issue Sep 16, 2019 · 3 comments
Closed

App stops reacting to shortcuts sometimes #18

lwouis opened this issue Sep 16, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@lwouis
Copy link
Owner

lwouis commented Sep 16, 2019

During normal usage, sometimes the app will stop responding to global shortcuts.

I recorded an instance of this where I saw these logs:

"event" 11
"event" 12
"meta down"
"unexpected 1" [2807: 1]
"unexpected 2" [<AXUIElement 0x7ff860f95c40> {pid=2807}]
"event" 12
"meta up"
"event" 12
"event" 12
"event" 11
"event" 12
"meta down"
"unexpected 1" [2807: 1, 13366: 0]
"unexpected 2" [<AXUIElement 0x7ff860f8e3b0> {pid=2807}]
"event" 10
"event" 4294967294

These logs come from this update I made locally in the source code:

func computeOpenWindows() {
        openWindows.removeAll()
        // we rely on the fact that CG and AX APIs arrays follow the same order to match objects from both APIs
        var pidAndCurrentIndex: [pid_t: Int] = [:]
        for cgWindow in cgWindows() {
            let cgId = cgWindow[kCGWindowNumber] as! CGWindowID
            let cgTitle = String(cgWindow[kCGWindowName] as! NSString)
            let cgOwnerPid = cgWindow[kCGWindowOwnerPID] as! pid_t
            let i = pidAndCurrentIndex.index(forKey: cgOwnerPid)
            pidAndCurrentIndex[cgOwnerPid] = (i == nil ? 0 : pidAndCurrentIndex[i!].value + 1)
            let axWindow = axWindows(cgOwnerPid)
            if axWindow.count > pidAndCurrentIndex[cgOwnerPid]! {
                openWindows.append(OpenWindow(target: axWindow[pidAndCurrentIndex[cgOwnerPid]!], ownerPid: cgOwnerPid, cgId: cgId, cgTitle: cgTitle))
            } else {
                debugPrint("unexpected 1", pidAndCurrentIndex)
                debugPrint("unexpected 2", axWindow)
            }
        }
    }

Note that the app isn't crashed. It is ignoring global shortcuts and stdout isn't producing new values

@lwouis lwouis added the bug Something isn't working label Sep 16, 2019
@lwouis
Copy link
Owner Author

lwouis commented Oct 3, 2019

Another case happened:

"event" 10
"event is in somehow"
"event" 11
"event is in somehow"
"event" 12
"event is in somehow"
"event" 12
"event is in somehow"
"event" 4294967294

This is the logging code:

func keyboardHandler(_ cgEvent: CGEvent, _ delegate: Application) -> Unmanaged<CGEvent>? {
    debugPrint("event", cgEvent.type.rawValue)
    if cgEvent.type == .keyDown || cgEvent.type == .keyUp || cgEvent.type == .flagsChanged {
        debugPrint("event is in somehow")
        if let event = NSEvent.init(cgEvent: cgEvent) {

@lwouis
Copy link
Owner Author

lwouis commented Oct 3, 2019

It seems like the event watching loop breaks after receiving these anormal events

@lwouis lwouis closed this as completed in 75db5e9 Oct 4, 2019
lwouis pushed a commit that referenced this issue Oct 4, 2019
## [1.0.11](v1.0.10...v1.0.11) (2019-10-04)

### Bug Fixes

* keyboard events don't stop being listened to (closes [#18](#18)) ([75db5e9](75db5e9))
@lwouis
Copy link
Owner Author

lwouis commented Oct 4, 2019

Note that event.type.rawValue == 4294967294 is the .tapDisabledByTimeout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant