1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Dmenu] Add a minimum update rate for dmenu reading. (#1681)

This avoid slow loading for some weird slow spaced out input stream.
(one input every 250ms).
Not sure what use-case this fixes.
This fix does cause a noticable slow-down on very large lists.

Issue: #1680
This commit is contained in:
Dave Davenport 2022-08-19 21:35:23 +02:00 committed by GitHub
parent 78d596dc53
commit 89e00ebb32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -256,6 +256,7 @@ static gpointer read_input_thread(gpointer userdata) {
pd->async_queue = g_async_queue_new(); pd->async_queue = g_async_queue_new();
Block *block = NULL; Block *block = NULL;
GTimer *tim = g_timer_new();
int fd = pd->fd; int fd = pd->fd;
while (1) { while (1) {
// Wait for input from the input or from the main thread. // Wait for input from the input or from the main thread.
@ -295,11 +296,15 @@ static gpointer read_input_thread(gpointer userdata) {
memmove(&line[0], &line[i + 1], nread - (i + 1)); memmove(&line[0], &line[i + 1], nread - (i + 1));
nread -= (i + 1); nread -= (i + 1);
i = 0; i = 0;
if (block && block->length == BLOCK_LINES_SIZE) { if (block) {
double elapsed = g_timer_elapsed(tim, NULL);
if ( elapsed >= 0.1 || block->length == BLOCK_LINES_SIZE) {
g_timer_start(tim);
g_async_queue_push(pd->async_queue, block); g_async_queue_push(pd->async_queue, block);
block = NULL; block = NULL;
write(pd->pipefd2[1], "r", 1); write(pd->pipefd2[1], "r", 1);
} }
}
} else { } else {
i++; i++;
} }
@ -311,6 +316,7 @@ static gpointer read_input_thread(gpointer userdata) {
read_add_block(pd, &block, line, nread); read_add_block(pd, &block, line, nread);
} }
if (block) { if (block) {
g_timer_start(tim);
g_async_queue_push(pd->async_queue, block); g_async_queue_push(pd->async_queue, block);
block = NULL; block = NULL;
write(pd->pipefd2[1], "r", 1); write(pd->pipefd2[1], "r", 1);
@ -326,12 +332,14 @@ static gpointer read_input_thread(gpointer userdata) {
nread = 0; nread = 0;
} }
if (block) { if (block) {
g_timer_start(tim);
g_async_queue_push(pd->async_queue, block); g_async_queue_push(pd->async_queue, block);
block = NULL; block = NULL;
write(pd->pipefd2[1], "r", 1); write(pd->pipefd2[1], "r", 1);
} }
} }
} }
g_timer_destroy(tim);
free(line); free(line);
write(pd->pipefd2[1], "q", 1); write(pd->pipefd2[1], "q", 1);
return NULL; return NULL;