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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/*
gui-windows.c : irssi
Copyright (C) 1999-2001 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "module.h"
#include "signals.h"
#include "misc.h"
#include "settings.h"
#include "special-vars.h"
#include "levels.h"
#include "term.h"
#include "gui-entry.h"
#include "gui-windows.h"
#include "gui-printtext.h"
static int window_create_override;
static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window,
MAIN_WINDOW_REC *parent)
{
GUI_WINDOW_REC *gui;
window->width = parent->width;
window->height = MAIN_WINDOW_TEXT_HEIGHT(parent);
gui = g_new0(GUI_WINDOW_REC, 1);
gui->parent = parent;
gui->view = textbuffer_view_create(textbuffer_create(),
window->width, window->height,
settings_get_bool("scroll"),
term_type == TERM_TYPE_UTF8);
textbuffer_view_set_default_indent(gui->view,
settings_get_int("indent"),
!settings_get_bool("indent_always"),
get_default_indent_func());
textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide"));
textbuffer_view_set_hidden_level(gui->view, MSGLEVEL_HIDDEN);
if (parent->active == window)
textbuffer_view_set_window(gui->view, parent->screen_win);
return gui;
}
static void gui_window_deinit(GUI_WINDOW_REC *gui)
{
textbuffer_view_destroy(gui->view);
g_free(gui);
}
static void sig_window_create_override(gpointer tab)
{
window_create_override = GPOINTER_TO_INT(tab);
}
static void gui_window_created(WINDOW_REC *window, void *automatic)
{
MAIN_WINDOW_REC *parent;
int new_parent;
g_return_if_fail(window != NULL);
new_parent = window_create_override == MAIN_WINDOW_TYPE_DEFAULT ||
window_create_override == MAIN_WINDOW_TYPE_SPLIT ||
window_create_override == MAIN_WINDOW_TYPE_RSPLIT ||
active_win == NULL || WINDOW_GUI(active_win) == NULL;
parent = !new_parent ? WINDOW_MAIN(active_win) : mainwindow_create(window_create_override == MAIN_WINDOW_TYPE_RSPLIT);
if (parent == NULL) {
/* not enough space for new window, but we really can't
abort creation of the window anymore, so create hidden
window instead. */
parent = WINDOW_MAIN(active_win);
}
window_create_override = MAIN_WINDOW_TYPE_NONE;
if (parent->active == NULL) parent->active = window;
window->gui_data = gui_window_init(window, parent);
/* set only non-automatic windows sticky so that the windows
irssi creates at startup wont get sticky. */
if (automatic == NULL &&
(parent->sticky_windows ||
(new_parent && settings_get_bool("autostick_split_windows"))))
gui_window_set_sticky(window);
signal_emit("gui window created", 1, window);
}
static void gui_window_destroyed(WINDOW_REC *window)
{
MAIN_WINDOW_REC *parent;
GUI_WINDOW_REC *gui;
g_return_if_fail(window != NULL);
gui = WINDOW_GUI(window);
parent = gui->parent;
gui_window_set_unsticky(window);
signal_emit("gui window destroyed", 1, window);
gui_window_deinit(gui);
window->gui_data = NULL;
if (parent->active == window)
mainwindow_change_active(parent, window);
}
void gui_window_resize(WINDOW_REC *window, int width, int height)
{
GUI_WINDOW_REC *gui;
if (window->width == width && window->height == height)
return;
gui = WINDOW_GUI(window);
irssi_set_dirty();
WINDOW_MAIN(window)->dirty = TRUE;
window->width = width;
window->height = height;
textbuffer_view_resize(gui->view, width, height);
}
void gui_window_scroll(WINDOW_REC *window, int lines)
{
g_return_if_fail(window != NULL);
textbuffer_view_scroll(WINDOW_GUI(window)->view, lines);
signal_emit("gui page scrolled", 1, window);
}
void gui_window_scroll_line(WINDOW_REC *window, LINE_REC *line)
{
g_return_if_fail(window != NULL);
g_return_if_fail(line != NULL);
textbuffer_view_scroll_line(WINDOW_GUI(window)->view, line);
signal_emit("gui page scrolled", 1, window);
}
void gui_window_set_sticky(WINDOW_REC *window)
{
GUI_WINDOW_REC *gui = WINDOW_GUI(window);
if (!gui->sticky) {
gui->sticky = TRUE;
gui->parent->sticky_windows++;
}
}
void gui_window_set_unsticky(WINDOW_REC *window)
{
GUI_WINDOW_REC *gui = WINDOW_GUI(window);
if (gui->sticky) {
gui->sticky = FALSE;
gui->parent->sticky_windows--;
}
}
void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent)
{
MAIN_WINDOW_REC *oldparent;
oldparent = WINDOW_MAIN(window);
if (oldparent == parent)
return;
gui_window_set_unsticky(window);
textbuffer_view_set_window(WINDOW_GUI(window)->view, NULL);
WINDOW_MAIN(window) = parent;
if (parent->sticky_windows)
gui_window_set_sticky(window);
if (MAIN_WINDOW_TEXT_HEIGHT(parent) !=
MAIN_WINDOW_TEXT_HEIGHT(oldparent) ||
parent->width != oldparent->width) {
gui_window_resize(window, parent->width,
MAIN_WINDOW_TEXT_HEIGHT(parent));
}
}
void gui_windows_reset_settings(void)
{
GSList *tmp;
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
WINDOW_REC *rec = tmp->data;
GUI_WINDOW_REC *gui = WINDOW_GUI(rec);
textbuffer_view_set_hidden_level(gui->view, MSGLEVEL_HIDDEN);
textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide"));
textbuffer_view_set_default_indent(gui->view,
settings_get_int("indent"),
!settings_get_bool("indent_always"),
get_default_indent_func());
textbuffer_view_set_scroll(gui->view,
gui->use_scroll ? gui->scroll :
settings_get_bool("scroll"));
}
}
static MAIN_WINDOW_REC *mainwindow_find_unsticky(void)
{
GSList *tmp;
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data;
if (!rec->sticky_windows)
return rec;
}
/* all windows are sticky, fallback to active window */
return active_mainwin;
}
static void signal_window_changed(WINDOW_REC *window)
{
MAIN_WINDOW_REC *parent;
WINDOW_REC *old_window;
g_return_if_fail(window != NULL);
if (quitting) return;
parent = WINDOW_MAIN(window);
if (is_window_visible(window)) {
/* already visible */
active_mainwin = parent;
} else if (active_mainwin == NULL) {
/* no main window set yet */
active_mainwin = parent;
} else if (WINDOW_GUI(window)->sticky) {
/* window is sticky, switch to correct main window */
if (parent != active_mainwin)
active_mainwin = parent;
} else {
/* move window to active main window */
if (active_mainwin->sticky_windows) {
/* active mainwindow is sticky, we'll need to
set the window active somewhere else */
active_mainwin = mainwindow_find_unsticky();
}
gui_window_reparent(window, active_mainwin);
}
old_window = active_mainwin->active;
if (old_window != NULL && old_window != window)
textbuffer_view_set_window(WINDOW_GUI(old_window)->view, NULL);
active_mainwin->active = window;
textbuffer_view_set_window(WINDOW_GUI(window)->view,
active_mainwin->screen_win);
if (WINDOW_GUI(window)->view->dirty)
active_mainwin->dirty = TRUE;
}
static void read_settings(void)
{
gui_windows_reset_settings();
}
void gui_windows_init(void)
{
settings_add_bool("lookandfeel", "autostick_split_windows", FALSE);
settings_add_bool("lookandfeel", "autounstick_windows", TRUE);
settings_add_int("lookandfeel", "indent", 10);
settings_add_bool("lookandfeel", "indent_always", FALSE);
settings_add_bool("lookandfeel", "break_wide", FALSE);
settings_add_bool("lookandfeel", "scroll", TRUE);
window_create_override = MAIN_WINDOW_TYPE_NONE;
read_settings();
signal_add("gui window create override", (SIGNAL_FUNC) sig_window_create_override);
signal_add("window created", (SIGNAL_FUNC) gui_window_created);
signal_add("window destroyed", (SIGNAL_FUNC) gui_window_destroyed);
signal_add_first("window changed", (SIGNAL_FUNC) signal_window_changed);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
}
void gui_windows_deinit(void)
{
while (windows != NULL)
window_destroy(windows->data);
signal_remove("gui window create override", (SIGNAL_FUNC) sig_window_create_override);
signal_remove("window created", (SIGNAL_FUNC) gui_window_created);
signal_remove("window destroyed", (SIGNAL_FUNC) gui_window_destroyed);
signal_remove("window changed", (SIGNAL_FUNC) signal_window_changed);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
}
|