fix(xdrawer,dwm,dmenu): remove top bar gap and eliminate softkey menu latency
This commit is contained in:
+49
-27
@@ -956,9 +956,37 @@ query_softkeys_down(void)
|
||||
return mask;
|
||||
}
|
||||
|
||||
static void
|
||||
read_softkey_state(int *mask_out, long long *ms_out)
|
||||
{
|
||||
char buf[64];
|
||||
int fd = open("/tmp/sxmo_softkey_state", O_RDONLY | O_CLOEXEC);
|
||||
*mask_out = 0;
|
||||
*ms_out = 0;
|
||||
if (fd >= 0) {
|
||||
ssize_t n = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if (n > 0) {
|
||||
buf[n] = '\0';
|
||||
sscanf(buf, "%d %lld", mask_out, ms_out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clear_softkey_state(void)
|
||||
{
|
||||
int fd = open("/tmp/sxmo_softkey_state", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if (fd >= 0) {
|
||||
(void)write(fd, "0 0\n", 4);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
spawn_xdrawer_and_exit(void)
|
||||
{
|
||||
clear_softkey_state();
|
||||
write_softkey_suppress(dmenu_now_ms() + 500);
|
||||
cleanup();
|
||||
if (fork() == 0) {
|
||||
@@ -984,12 +1012,15 @@ run(void)
|
||||
{
|
||||
XEvent ev;
|
||||
int soft_pending = 0;
|
||||
long long soft_first_ms = 0;
|
||||
long long soft_deadline = 0;
|
||||
long long start_ignore = dmenu_now_ms() + 40;
|
||||
int initial_released = (query_softkeys_down() == 0);
|
||||
int init_soft_mask = 0;
|
||||
long long init_soft_ms = 0;
|
||||
int xfd = ConnectionNumber(dpy);
|
||||
|
||||
read_softkey_state(&init_soft_mask, &init_soft_ms);
|
||||
|
||||
for (;;) {
|
||||
if (!initial_released && query_softkeys_down() == 0)
|
||||
initial_released = 1;
|
||||
@@ -1004,28 +1035,23 @@ run(void)
|
||||
int is_right = (ks == XF86XK_Back || ks == XF86XK_KbdLcdMenu2 || ev.xkey.keycode == 166);
|
||||
if (is_left || is_right) {
|
||||
long long now = dmenu_now_ms();
|
||||
int which = (is_left ? 1 : 0) | (is_right ? 2 : 0);
|
||||
if (ev.type == KeyPress && init_soft_mask != 0 &&
|
||||
(init_soft_mask | which) == 3 &&
|
||||
(now - init_soft_ms) <= 320) {
|
||||
spawn_xdrawer_and_exit();
|
||||
}
|
||||
if (ev.type == KeyRelease) {
|
||||
initial_released = 1;
|
||||
if (soft_pending != 0 && soft_pending != 3) {
|
||||
long long grace = now + 65;
|
||||
if (grace > soft_deadline)
|
||||
soft_deadline = grace;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!initial_released || now < start_ignore)
|
||||
continue;
|
||||
if (is_left)
|
||||
soft_pending |= 1;
|
||||
if (is_right)
|
||||
soft_pending |= 2;
|
||||
soft_pending |= query_softkeys_down();
|
||||
soft_pending |= which | query_softkeys_down();
|
||||
if (soft_pending == 3)
|
||||
spawn_xdrawer_and_exit();
|
||||
if (soft_deadline == 0) {
|
||||
soft_first_ms = now;
|
||||
soft_deadline = now + 200;
|
||||
}
|
||||
if (soft_deadline == 0)
|
||||
soft_deadline = now + 30;
|
||||
continue;
|
||||
}
|
||||
if (!issoftkey(ev.xkey.keycode)) {
|
||||
@@ -1077,19 +1103,15 @@ run(void)
|
||||
spawn_xdrawer_and_exit();
|
||||
long long rem = soft_deadline - now;
|
||||
if (rem <= 0) {
|
||||
if (hw_down != 0 && (now - soft_first_ms) < 480) {
|
||||
soft_deadline = now + 25;
|
||||
rem = 25;
|
||||
clear_softkey_state();
|
||||
write_softkey_suppress(now + 250);
|
||||
if (soft_pending == 1) {
|
||||
puts((sel) ? sel->text : text);
|
||||
cleanup();
|
||||
exit(0);
|
||||
} else {
|
||||
write_softkey_suppress(now + 400);
|
||||
if (soft_pending == 1) {
|
||||
puts((sel) ? sel->text : text);
|
||||
cleanup();
|
||||
exit(0);
|
||||
} else {
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
struct pollfd pfd = { xfd, POLLIN, 0 };
|
||||
|
||||
Reference in New Issue
Block a user