diff options
| -rw-r--r-- | st.c | 27 |
1 files changed, 13 insertions, 14 deletions
| @@ -76,7 +76,7 @@ char *argv0; | |||
| 76 | #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) | 76 | #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) |
| 77 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) | 77 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) |
| 78 | #define IS_SET(flag) ((term.mode & (flag)) != 0) | 78 | #define IS_SET(flag) ((term.mode & (flag)) != 0) |
| 79 | #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) | 79 | #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_nsec-t2.tv_nsec)/10E6) |
| 80 | #define CEIL(x) (((x) != (int) (x)) ? (x) + 1 : (x)) | 80 | #define CEIL(x) (((x) != (int) (x)) ? (x) + 1 : (x)) |
| 81 | #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) | 81 | #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) |
| 82 | 82 | ||
| @@ -294,8 +294,8 @@ typedef struct { | |||
| 294 | char *clip; | 294 | char *clip; |
| 295 | Atom xtarget; | 295 | Atom xtarget; |
| 296 | bool alt; | 296 | bool alt; |
| 297 | struct timeval tclick1; | 297 | struct timespec tclick1; |
| 298 | struct timeval tclick2; | 298 | struct timespec tclick2; |
| 299 | } Selection; | 299 | } Selection; |
| 300 | 300 | ||
| 301 | typedef union { | 301 | typedef union { |
| @@ -860,7 +860,7 @@ mousereport(XEvent *e) { | |||
| 860 | 860 | ||
| 861 | void | 861 | void |
| 862 | bpress(XEvent *e) { | 862 | bpress(XEvent *e) { |
| 863 | struct timeval now; | 863 | struct timespec now; |
| 864 | Mousekey *mk; | 864 | Mousekey *mk; |
| 865 | 865 | ||
| 866 | if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { | 866 | if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { |
| @@ -877,7 +877,7 @@ bpress(XEvent *e) { | |||
| 877 | } | 877 | } |
| 878 | 878 | ||
| 879 | if(e->xbutton.button == Button1) { | 879 | if(e->xbutton.button == Button1) { |
| 880 | gettimeofday(&now, NULL); | 880 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 881 | 881 | ||
| 882 | /* Clear previous selection, logically and visually. */ | 882 | /* Clear previous selection, logically and visually. */ |
| 883 | selclear(NULL); | 883 | selclear(NULL); |
| @@ -3709,7 +3709,8 @@ run(void) { | |||
| 3709 | int w = xw.w, h = xw.h; | 3709 | int w = xw.w, h = xw.h; |
| 3710 | fd_set rfd; | 3710 | fd_set rfd; |
| 3711 | int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0; | 3711 | int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0; |
| 3712 | struct timeval drawtimeout, *tv = NULL, now, last, lastblink; | 3712 | struct timespec drawtimeout, *tv = NULL, now, last, lastblink; |
| 3713 | long deltatime; | ||
| 3713 | 3714 | ||
| 3714 | /* Waiting for window mapping */ | 3715 | /* Waiting for window mapping */ |
| 3715 | while(1) { | 3716 | while(1) { |
| @@ -3725,17 +3726,15 @@ run(void) { | |||
| 3725 | ttynew(); | 3726 | ttynew(); |
| 3726 | cresize(w, h); | 3727 | cresize(w, h); |
| 3727 | 3728 | ||
| 3728 | gettimeofday(&last, NULL); | 3729 | clock_gettime(CLOCK_MONOTONIC, &last); |
| 3729 | lastblink = last; | 3730 | lastblink = last; |
| 3730 | 3731 | ||
| 3731 | for(xev = actionfps;;) { | 3732 | for(xev = actionfps;;) { |
| 3732 | long deltatime; | ||
| 3733 | |||
| 3734 | FD_ZERO(&rfd); | 3733 | FD_ZERO(&rfd); |
| 3735 | FD_SET(cmdfd, &rfd); | 3734 | FD_SET(cmdfd, &rfd); |
| 3736 | FD_SET(xfd, &rfd); | 3735 | FD_SET(xfd, &rfd); |
| 3737 | 3736 | ||
| 3738 | if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv) < 0) { | 3737 | if(pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { |
| 3739 | if(errno == EINTR) | 3738 | if(errno == EINTR) |
| 3740 | continue; | 3739 | continue; |
| 3741 | die("select failed: %s\n", strerror(errno)); | 3740 | die("select failed: %s\n", strerror(errno)); |
| @@ -3752,9 +3751,9 @@ run(void) { | |||
| 3752 | if(FD_ISSET(xfd, &rfd)) | 3751 | if(FD_ISSET(xfd, &rfd)) |
| 3753 | xev = actionfps; | 3752 | xev = actionfps; |
| 3754 | 3753 | ||
| 3755 | gettimeofday(&now, NULL); | 3754 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 3756 | drawtimeout.tv_sec = 0; | 3755 | drawtimeout.tv_sec = 0; |
| 3757 | drawtimeout.tv_usec = (1000/xfps) * 1000; | 3756 | drawtimeout.tv_nsec = (1000/xfps) * 10E6; |
| 3758 | tv = &drawtimeout; | 3757 | tv = &drawtimeout; |
| 3759 | 3758 | ||
| 3760 | dodraw = 0; | 3759 | dodraw = 0; |
| @@ -3789,9 +3788,9 @@ run(void) { | |||
| 3789 | if(blinkset) { | 3788 | if(blinkset) { |
| 3790 | if(TIMEDIFF(now, lastblink) \ | 3789 | if(TIMEDIFF(now, lastblink) \ |
| 3791 | > blinktimeout) { | 3790 | > blinktimeout) { |
| 3792 | drawtimeout.tv_usec = 1; | 3791 | drawtimeout.tv_nsec = 1000; |
| 3793 | } else { | 3792 | } else { |
| 3794 | drawtimeout.tv_usec = (1000 * \ | 3793 | drawtimeout.tv_nsec = (10E6 * \ |
| 3795 | (blinktimeout - \ | 3794 | (blinktimeout - \ |
| 3796 | TIMEDIFF(now, | 3795 | TIMEDIFF(now, |
| 3797 | lastblink))); | 3796 | lastblink))); |
