diff options
author | David Walter Seikel | 2014-01-30 16:28:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-01-30 16:28:19 +1000 |
commit | ff70e4a5f44c393f156e2b3e8a86ef45b3261b38 (patch) | |
tree | 477f18dfa6c7fc935886d529a9eee141acead8c3 | |
parent | Minor clean ups. (diff) | |
download | boxes-ff70e4a5f44c393f156e2b3e8a86ef45b3261b38.zip boxes-ff70e4a5f44c393f156e2b3e8a86ef45b3261b38.tar.gz boxes-ff70e4a5f44c393f156e2b3e8a86ef45b3261b38.tar.bz2 boxes-ff70e4a5f44c393f156e2b3e8a86ef45b3261b38.tar.xz |
Move all the SIGWINCH stuff inte handle_keys().
-rw-r--r-- | boxes.c | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -658,7 +658,6 @@ static box *rootBox; // Parent of the rest of the boxes, or the only box. Alway | |||
658 | static box *currentBox; | 658 | static box *currentBox; |
659 | static view *commandLine; | 659 | static view *commandLine; |
660 | static int commandMode; | 660 | static int commandMode; |
661 | static volatile sig_atomic_t sigWinch; | ||
662 | 661 | ||
663 | #define MEM_SIZE 128 // Chunk size for line memory allocation. | 662 | #define MEM_SIZE 128 // Chunk size for line memory allocation. |
664 | 663 | ||
@@ -1858,6 +1857,14 @@ static int handleKeySequence(long extra, char *sequence) | |||
1858 | return 0; | 1857 | return 0; |
1859 | } | 1858 | } |
1860 | 1859 | ||
1860 | |||
1861 | static volatile sig_atomic_t sigWinch; | ||
1862 | |||
1863 | static void handleSignals(int signo) | ||
1864 | { | ||
1865 | sigWinch = 1; | ||
1866 | } | ||
1867 | |||
1861 | // Basically this is the main loop. | 1868 | // Basically this is the main loop. |
1862 | 1869 | ||
1863 | // TODO - Unhandled complications - | 1870 | // TODO - Unhandled complications - |
@@ -1867,12 +1874,19 @@ void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence)) | |||
1867 | { | 1874 | { |
1868 | fd_set selectFds; | 1875 | fd_set selectFds; |
1869 | struct timespec timeout; | 1876 | struct timespec timeout; |
1877 | struct sigaction sigAction, oldSigAction; | ||
1870 | sigset_t signalMask; | 1878 | sigset_t signalMask; |
1871 | char buffer[20], sequence[20]; | 1879 | char buffer[20], sequence[20]; |
1872 | int buffIndex = 0; | 1880 | int buffIndex = 0; |
1873 | 1881 | ||
1874 | buffer[0] = 0; | 1882 | buffer[0] = 0; |
1875 | sequence[0] = 0; | 1883 | sequence[0] = 0; |
1884 | |||
1885 | // Terminals send the SIGWINCH signal when they resize. | ||
1886 | memset(&sigAction, 0, sizeof(sigAction)); | ||
1887 | sigAction.sa_handler = handleSignals; | ||
1888 | sigAction.sa_flags = SA_RESTART;// Useless if we are using poll. | ||
1889 | if (sigaction(SIGWINCH, &sigAction, &oldSigAction)) perror_exit("can't set signal handler SIGWINCH"); | ||
1876 | sigemptyset(&signalMask); | 1890 | sigemptyset(&signalMask); |
1877 | sigaddset(&signalMask, SIGWINCH); | 1891 | sigaddset(&signalMask, SIGWINCH); |
1878 | 1892 | ||
@@ -2079,6 +2093,8 @@ TODO So abort the current CSI and start from scratch. | |||
2079 | } | 2093 | } |
2080 | } | 2094 | } |
2081 | } | 2095 | } |
2096 | |||
2097 | sigaction(SIGWINCH, &oldSigAction, NULL); | ||
2082 | } | 2098 | } |
2083 | 2099 | ||
2084 | 2100 | ||
@@ -2718,18 +2734,12 @@ struct context simpleVi = | |||
2718 | // TODO - have any unrecognised escape key sequence start up a new box (split one) to show the "show keys" content. | 2734 | // TODO - have any unrecognised escape key sequence start up a new box (split one) to show the "show keys" content. |
2719 | // That just adds each "Key is X" to the end of the content, and allows scrolling, as well as switching between other boxes. | 2735 | // That just adds each "Key is X" to the end of the content, and allows scrolling, as well as switching between other boxes. |
2720 | 2736 | ||
2721 | static void handleSignals(int signo) | ||
2722 | { | ||
2723 | sigWinch = 1; | ||
2724 | } | ||
2725 | |||
2726 | void boxes_main(void) | 2737 | void boxes_main(void) |
2727 | { | 2738 | { |
2728 | struct context *context = &simpleMcedit; // The default is mcedit, coz that's what I use. | 2739 | struct context *context = &simpleMcedit; // The default is mcedit, coz that's what I use. |
2729 | struct termios termio, oldtermio; | 2740 | struct termios termio, oldtermio; |
2730 | char *prompt = "Enter a command : "; | 2741 | char *prompt = "Enter a command : "; |
2731 | unsigned W = 80, H = 24; | 2742 | unsigned W = 80, H = 24; |
2732 | struct sigaction sigAction, oldSigActions; | ||
2733 | 2743 | ||
2734 | // For testing purposes, figure out which context we use. When this gets real, the toybox multiplexer will sort this out for us instead. | 2744 | // For testing purposes, figure out which context we use. When this gets real, the toybox multiplexer will sort this out for us instead. |
2735 | if (toys.optflags & FLAG_m) | 2745 | if (toys.optflags & FLAG_m) |
@@ -2810,11 +2820,6 @@ void boxes_main(void) | |||
2810 | termio.c_cc[VMIN]=1; | 2820 | termio.c_cc[VMIN]=1; |
2811 | tcsetattr(0, TCSANOW, &termio); | 2821 | tcsetattr(0, TCSANOW, &termio); |
2812 | 2822 | ||
2813 | // Terminals send the SIGWINCH signal when they resize. | ||
2814 | memset(&sigAction, 0, sizeof(sigAction)); | ||
2815 | sigAction.sa_handler = handleSignals; | ||
2816 | sigAction.sa_flags = SA_RESTART;// Useless if we are using poll. | ||
2817 | if (sigaction(SIGWINCH, &sigAction, &oldSigActions)) perror_exit("can't set signal handler SIGWINCH"); | ||
2818 | terminal_size(&W, &H); | 2823 | terminal_size(&W, &H); |
2819 | if (toys.optflags & FLAG_w) | 2824 | if (toys.optflags & FLAG_w) |
2820 | W = TT.w; | 2825 | W = TT.w; |
@@ -2859,8 +2864,6 @@ void boxes_main(void) | |||
2859 | 2864 | ||
2860 | // TODO - Should remember to turn off mouse reporting when we leave. | 2865 | // TODO - Should remember to turn off mouse reporting when we leave. |
2861 | 2866 | ||
2862 | sigaction(SIGWINCH, &oldSigActions, NULL); | ||
2863 | |||
2864 | // Restore the old terminal settings. | 2867 | // Restore the old terminal settings. |
2865 | tcsetattr(0, TCSANOW, &oldtermio); | 2868 | tcsetattr(0, TCSANOW, &oldtermio); |
2866 | 2869 | ||