commit 863053a
Devine Lu Linvega
·
2026-01-08 17:56:27 +0000 UTC
parent 2003304
Use ConnectionNumber instead of XConnectionNumber
1 files changed,
+19,
-12
+19,
-12
1@@ -1279,11 +1279,11 @@ emu_init(void)
2 emu.dpy = XOpenDisplay(NULL);
3 if(!emu.dpy)
4 return !fprintf(stderr, "Display: failed\n");
5+ emu.fd_x11 = ConnectionNumber(emu.dpy);
6 display_center();
7 display_hidecursor();
8 display_floating();
9- emu.fd_x11 = XConnectionNumber(emu.dpy);
10- emu.fd_timer = timerfd_create(CLOCK_MONOTONIC, 0);
11+ emu.fd_timer = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
12 if(emu.fd_timer < 0)
13 return !fprintf(stderr, "timerfd_create: failed\n");
14 timerfd_settime(emu.fd_timer, 0, &screen_tspec, NULL);
15@@ -1297,31 +1297,38 @@ emu_run(void)
16 char expirations[8], coninp[CONINBUFSIZE];
17 struct pollfd fds[3];
18 fds[0].fd = emu.fd_x11;
19+ fds[0].events = POLLIN;
20 fds[1].fd = emu.fd_timer;
21+ fds[1].events = POLLIN;
22 fds[2].fd = STDIN_FILENO;
23- fds[0].events = fds[1].events = fds[2].events = POLLIN;
24+ fds[2].events = POLLIN | POLLHUP;
25+ screen_update();
26 while(!dev[0x0f]) {
27- if(poll(fds, 3, 1000) <= 0)
28+ if(poll(fds, 3, -1) <= 0)
29 continue;
30- if(fds[0].revents & POLLIN)
31+ if(fds[0].revents & POLLIN) {
32 while(XPending(emu.dpy))
33 emu_event();
34+ }
35 if(fds[1].revents & POLLIN) {
36- read(emu.fd_timer, expirations, 8);
37+ read(emu.fd_timer, expirations, sizeof expirations);
38 screen_update();
39 }
40 has_input = fds[2].revents & POLLIN;
41 has_eof = fds[2].revents & POLLHUP;
42-
43 if(has_input || has_eof) {
44 int i, n = read(STDIN_FILENO, coninp, CONINBUFSIZE - 1);
45- for(i = 0; i < n; i++)
46- console_input(coninp[i], CONSOLE_STD), has_sent = 1;
47- if(n == 0 && has_sent)
48- console_input(0, CONSOLE_END), has_sent = 0;
49+ if(n > 0) {
50+ for(i = 0; i < n; i++)
51+ console_input(coninp[i], CONSOLE_STD);
52+ has_sent = 1;
53+ } else if(has_sent) {
54+ console_input(0, CONSOLE_END);
55+ has_sent = 0;
56+ }
57 }
58 }
59- if(emu.fd_timer > 0)
60+ if(emu.fd_timer >= 0)
61 close(emu.fd_timer);
62 if(emu.win)
63 XDestroyWindow(emu.dpy, emu.win);