Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Fix a potential postponer hangup.
Browse files Browse the repository at this point in the history
  • Loading branch information
kareltucek committed Dec 4, 2024
1 parent 465d52a commit df8d17b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions right/src/event_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@

} event_vector_event_t;

/**
* Notes on EventVector flags:
*
* EventVector_Postponer means that Postponer is active. There may be events in the postponer queue while someone is postponing while sleeping (e.g., macro engine waiting for future events.), and in this case EventVector_Postponer is unset.
* */

// Variables:

extern volatile uint32_t EventScheduler_Vector;
Expand Down
3 changes: 3 additions & 0 deletions right/src/postponer.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ bool PostponerCore_IsActive(void)
return runState.eventsShouldBeQueued;
}

bool PostponerCore_IsNonEmpty(void) {
return bufferSize > 0;
}

void PostponerCore_PrependKeyEvent(key_state_t *keyState, bool active, uint8_t layer)
{
Expand Down
1 change: 1 addition & 0 deletions right/src/postponer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
// Functions (Core hooks):

bool PostponerCore_IsActive(void);
bool PostponerCore_IsNonEmpty(void);
bool PostponerCore_EventsShouldBeQueued(void);
/* void PostponerCore_PostponeNCycles(uint8_t n); */
bool PostponerCore_RunKey(key_state_t* key, bool active);
Expand Down
8 changes: 8 additions & 0 deletions right/src/usb_report_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ static void updateActiveUsbReports(void)
EventVector_Unset(EventVector_ReportsChanged);
InputModifiersPrevious = InputModifiers;
OutputModifiers = 0;
static bool lastSomeonePostponing = false;

PostponerCore_UpdatePostponedTime();

Expand Down Expand Up @@ -646,6 +647,13 @@ static void updateActiveUsbReports(void)
if (EventVector_IsSet(EventVector_MouseController)) {
MouseController_ProcessMouseActions();
}

// If someone was postponing, the postponer has set itself to sleep. Wake it now.
bool currentSomeonePostponing = EventVector_IsSet(EventVector_SomeonePostponing);
if (lastSomeonePostponing && !currentSomeonePostponing && PostponerCore_IsNonEmpty()) {
EventVector_Set(EventVector_Postponer);
}
lastSomeonePostponing = currentSomeonePostponing;
}

void justPreprocessInput(void) {
Expand Down

0 comments on commit df8d17b

Please sign in to comment.