-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize.c
184 lines (159 loc) · 5.29 KB
/
resize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright (c) 1993-Present, Jason W. Bacon, Acadix Software Systems
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <twintk.h>
#include <xtend/string.h>
#include "edit.h"
#include "protos.h"
file_t *File;
int *Aw;
opt_t *Options;
buff_t *Cut_buff;
win_t *File_list;
extern int Shelled_out;
int Resized = 0;
void
win_resize (void)
{
extern win_t *Swin, *Bar_win;
extern term_t *Terminal;
static volatile int too_small = 0;
int c, min_lines=24, min_cols=80;
static char msg[]="APE: Resize your terminal to at least %d x %d...";
sigset_t signals;
#if ! defined(__sun__)
int signal_received;
#endif
/*
* Linux signal() function is old-fashioned, and needs to be reset
* sun causes char deletions and termination!
*/
#if defined(linux) || defined(__sun__)
signal(SIGWINCH,(sig_t)win_resize);
#endif
/*
* If a resize occurs while running a subprocess, we don't want to
* redraw the APE screen immediately. This will be done when the
* subprocess exits anyway.
*/
if ( Shelled_out )
return;
Resized = 1;
/* Reopen terminal in resized window */
del_image(&Terminal->image,0);
resize_terminal(Terminal);
/* Check screen size */
if ( File_list != NULL )
{
min_lines = TW_LINES(File_list)+4;
min_cols = TW_COLS(File_list)+1;
}
too_small = (Terminal->lines < min_lines) || (Terminal->columns < min_cols);
if ( too_small )
{
/* Display pause message */
tclear_screen(Terminal);
tmove_to(Terminal,TLINES(Terminal)/2-1,MAX(0,
(int)(TCOLS(Terminal)-sizeof(msg))/2));
tprintf(Terminal,msg,min_cols, min_lines);
TFLUSH_OUT(Terminal);
/* Wait for resize signal */
// FIXME: sigpause() is deprecated. Test replacement with sigwait().
// sigpause(SIGWINCH);
sigemptyset(&signals);
if (sigaddset(&signals, SIGWINCH) == -1 )
sprintw(2, 50, "Warning: Sigaddset error");
#if defined(__sun__)
sigwait(&signals);
#else
sigwait(&signals, &signal_received);
#endif
return;
}
/* Resize all file windows, menu bar, status window, and terminal */
tw_del_win(&Swin);
tw_del_win(&Bar_win);
/* Re-create global windows */
global_wins(Options);
/*
* Unlist basic windows like menus, file text, etc. so that they
* don't get redrawn again by tw_redraw_all(), which is used to redraw
* non-standard windows like popups, file browsers, etc.
*/
tw_unlist_win(Swin);
tw_unlist_win(Bar_win);
/* Re-create all file windows */
for (c=0; c<Options->max_files; ++c)
{
if ( File[c].window != NULL )
{
tw_del_win(&File[c].text);
if ( Options->scroll_bars )
{
tw_del_win(&File[c].hscroll_bar);
tw_del_win(&File[c].vscroll_bar);
}
tw_del_win(&File[c].window);
create_edit_win(File+c,Options);
tw_unlist_win(File[c].window);
tw_unlist_win(File[c].text);
if ( Options->scroll_bars )
{
tw_unlist_win(File[c].hscroll_bar);
tw_unlist_win(File[c].vscroll_bar);
}
if ( c != *Aw ) /* Do aw later so it's the last drawn */
{
edit_border(File+c,Options);
// Why was this here? Is there a reason to redraw
// file windows that aren't active?
//update_win(File+c,Options,Cut_buff);
}
}
}
/* Redraw screen */
edit_border(File+*Aw,Options);
update_win(File+*Aw,Options,Cut_buff);
/*
* Redraw any windows marked for redraw. FIXME: This is inefficient
* and annoying terminal I/O since some functions above redraw
* individual windows.
*/
tw_redraw_all(Terminal);
if ( File_list != NULL )
TW_SYNC_CURSOR(File_list);
TFLUSH_OUT(Terminal);
/* FIXME: Re-list windows in case tw_redraw_all() is used elsewhere */
}
void
setup_resize (file_t file[], int *aw, opt_t *options, buff_t *cut_buff)
{
File = file;
Aw = aw;
Options = options;
Cut_buff = cut_buff;
}