-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcm-event.c
More file actions
49 lines (36 loc) · 1.08 KB
/
cm-event.c
File metadata and controls
49 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdlib.h>
#include "cm-event.h"
#include "cm-util.h"
#include "ringbuffer.h"
ringBuffer_typedef(unsigned long, IgnoreErrRingbuf);
static IgnoreErrRingbuf ignore_ringbuf;
static IgnoreErrRingbuf* p_ignore_ringbuf = &ignore_ringbuf;
void set_ignore(Display *dpy, unsigned long sequence) {
if(unlikely(isBufferFull(p_ignore_ringbuf))) {
bufferIncrease(p_ignore_ringbuf, p_ignore_ringbuf->size*2);
}
bufferWrite(p_ignore_ringbuf, sequence);
}
int should_ignore(Display *dpy, unsigned long sequence) {
unsigned long buf_seq;
discard_ignore(dpy, sequence);
if(isBufferEmpty(p_ignore_ringbuf)) return False;
buf_seq = bufferReadPeek(p_ignore_ringbuf);
return buf_seq == sequence;
}
void discard_ignore(Display *dpy, unsigned long sequence) {
while(! isBufferEmpty(p_ignore_ringbuf)){
unsigned long buf_seq;
buf_seq = bufferReadPeek(p_ignore_ringbuf);
if ((long) (sequence - buf_seq) > 0) {
bufferReadSkip(p_ignore_ringbuf);
} else {
break;
}
}
}
bool event_init()
{
bufferInit(ignore_ringbuf, 2048, unsigned long);
return true;
}