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

Remove released keys from queue. #74

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ static void send_mapped_key(int code, int value)
}
emit(EV_KEY, output.sequence[i], value);
}
if (value == 0)
{
removeKeyFromQueue(code);
}
}

/**
Expand All @@ -68,6 +72,10 @@ static void send_remapped_key(int code, int value)
code = remap[code];
}
emit(EV_KEY, code, value);
if (value == 0)
{
removeKeyFromQueue(code);
}
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void clearQueue()
{
store[i] = 0;
}
head = tail = 0;
}

/**
Expand Down Expand Up @@ -74,3 +75,32 @@ int peek()
}
return store[head];
}

/**
* Remove key from the queue.
* */
void removeKeyFromQueue(int value)
{
for (int i = head; i != tail; i = (i + 1) % length)
{
if (store[i] == value)
{
if (i == head)
{
head = (head + 1) % length;
}
else
{
if (i != tail)
{
for (int j = (i + 1) % length; j != tail; j = (j + 1) % length, i++)
{
store[i] = store[j];
}
}
tail = (length + tail - 1) % length;
}
return;
}
}
}
5 changes: 5 additions & 0 deletions src/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ int dequeue();
* */
int peek();

/**
* Remove key from the queue.
* */
void removeKeyFromQueue(int value);

#endif
Loading