2000-05-04 06:32:42 -04:00
|
|
|
/*
|
2000-08-12 12:40:39 -04:00
|
|
|
mainwindows.c : irssi
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-08-12 12:40:39 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
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.
|
2000-05-04 06:32:42 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "module-formats.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
|
|
|
#include "levels.h"
|
|
|
|
#include "misc.h"
|
2001-05-18 10:54:02 -04:00
|
|
|
#include "settings.h"
|
2000-10-28 16:14:19 -04:00
|
|
|
#include "printtext.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
#include "term.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "gui-windows.h"
|
|
|
|
|
|
|
|
#define NEW_WINDOW_SIZE (WINDOW_MIN_SIZE + 1)
|
|
|
|
|
|
|
|
GSList *mainwindows;
|
|
|
|
MAIN_WINDOW_REC *active_mainwin;
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
int screen_reserved_top, screen_reserved_bottom;
|
2001-06-01 17:49:07 -04:00
|
|
|
static int old_screen_width, old_screen_height;
|
|
|
|
|
|
|
|
#define mainwindow_create_screen(window) \
|
2001-10-28 06:30:26 -05:00
|
|
|
term_window_create(0, \
|
2001-10-13 12:11:13 -04:00
|
|
|
(window)->first_line + (window)->statusbar_lines_top, \
|
|
|
|
(window)->width, \
|
2001-10-29 13:42:42 -05:00
|
|
|
(window)->height - (window)->statusbar_lines)
|
2001-10-28 06:30:26 -05:00
|
|
|
|
|
|
|
#define mainwindow_set_screen_size(window) \
|
|
|
|
term_window_move((window)->screen_win, 0, \
|
|
|
|
(window)->first_line + (window)->statusbar_lines_top, \
|
|
|
|
(window)->width, \
|
|
|
|
(window)->height - (window)->statusbar_lines);
|
2001-10-13 12:11:13 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
static MAIN_WINDOW_REC *find_window_with_room(void)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *biggest_rec;
|
|
|
|
GSList *tmp;
|
|
|
|
int space, biggest;
|
|
|
|
|
|
|
|
biggest = 0; biggest_rec = NULL;
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
space = MAIN_WINDOW_TEXT_HEIGHT(rec);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (space >= WINDOW_MIN_SIZE+NEW_WINDOW_SIZE && space > biggest) {
|
|
|
|
biggest = space;
|
|
|
|
biggest_rec = rec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return biggest_rec;
|
|
|
|
}
|
|
|
|
|
2001-12-07 18:20:23 -05:00
|
|
|
#define window_size_equals(window, mainwin) \
|
|
|
|
((window)->width == (mainwin)->width && \
|
|
|
|
(window)->height == MAIN_WINDOW_TEXT_HEIGHT(mainwin))
|
|
|
|
|
2001-10-15 16:18:34 -04:00
|
|
|
static void mainwindow_resize_windows(MAIN_WINDOW_REC *window)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
|
|
|
GSList *tmp;
|
2001-12-07 18:20:23 -05:00
|
|
|
int resized;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-29 13:42:42 -05:00
|
|
|
mainwindow_set_screen_size(window);
|
2001-10-20 10:30:20 -04:00
|
|
|
|
2001-12-07 18:20:23 -05:00
|
|
|
resized = FALSE;
|
2000-05-04 06:32:42 -04:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2000-08-10 16:01:32 -04:00
|
|
|
if (rec->gui_data != NULL &&
|
2001-12-07 18:20:23 -05:00
|
|
|
WINDOW_GUI(rec)->parent == window &&
|
|
|
|
!window_size_equals(rec, window)) {
|
|
|
|
resized = TRUE;
|
2001-10-14 06:45:00 -04:00
|
|
|
gui_window_resize(rec, window->width,
|
|
|
|
MAIN_WINDOW_TEXT_HEIGHT(window));
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2001-10-20 10:30:20 -04:00
|
|
|
|
2001-12-07 18:20:23 -05:00
|
|
|
if (resized)
|
|
|
|
signal_emit("mainwindow resized", 1, window);
|
2001-10-15 16:18:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff)
|
|
|
|
{
|
|
|
|
if (quitting || (xdiff == 0 && ydiff == 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->width += xdiff;
|
|
|
|
window->height = window->last_line-window->first_line+1;
|
2001-10-28 13:40:12 -05:00
|
|
|
window->size_dirty = TRUE;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
static GSList *get_sticky_windows_sorted(MAIN_WINDOW_REC *mainwin)
|
|
|
|
{
|
|
|
|
GSList *tmp, *list;
|
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (WINDOW_GUI(rec)->sticky && WINDOW_MAIN(rec) == mainwin) {
|
|
|
|
list = g_slist_insert_sorted(list, rec, (GCompareFunc)
|
|
|
|
window_refnum_cmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2001-08-03 19:39:35 -04:00
|
|
|
void mainwindow_change_active(MAIN_WINDOW_REC *mainwin,
|
|
|
|
WINDOW_REC *skip_window)
|
|
|
|
{
|
2001-12-09 09:03:44 -05:00
|
|
|
WINDOW_REC *window, *other;
|
2001-08-03 19:39:35 -04:00
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
mainwin->active = NULL;
|
2001-08-07 08:41:10 -04:00
|
|
|
if (mainwin->sticky_windows) {
|
2001-08-03 19:39:35 -04:00
|
|
|
/* sticky window */
|
2001-08-07 08:41:10 -04:00
|
|
|
tmp = get_sticky_windows_sorted(mainwin);
|
2001-09-09 08:12:28 -04:00
|
|
|
window = tmp->data;
|
|
|
|
if (window == skip_window) {
|
|
|
|
window = tmp->next == NULL ? NULL :
|
|
|
|
tmp->next->data;
|
|
|
|
}
|
2001-08-07 08:41:10 -04:00
|
|
|
g_slist_free(tmp);
|
2001-09-09 08:12:28 -04:00
|
|
|
|
|
|
|
if (window != NULL) {
|
|
|
|
window_set_active(window);
|
|
|
|
return;
|
|
|
|
}
|
2001-08-03 19:39:35 -04:00
|
|
|
}
|
|
|
|
|
2001-12-09 09:03:44 -05:00
|
|
|
other = NULL;
|
2001-08-03 19:39:35 -04:00
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-12-09 09:03:44 -05:00
|
|
|
if (rec != skip_window) {
|
2003-07-09 17:46:08 -04:00
|
|
|
other = rec;
|
|
|
|
break;
|
2001-08-03 19:39:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-09 09:03:44 -05:00
|
|
|
window_set_active(other);
|
2003-11-17 13:13:17 -05:00
|
|
|
if (mainwindows->next != NULL)
|
|
|
|
mainwindow_destroy(mainwin);
|
2001-08-03 19:39:35 -04:00
|
|
|
}
|
|
|
|
|
2000-08-10 16:01:32 -04:00
|
|
|
void mainwindows_recreate(void)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-06-01 17:49:07 -04:00
|
|
|
rec->screen_win = mainwindow_create_screen(rec);
|
2001-10-28 13:40:12 -05:00
|
|
|
rec->dirty = TRUE;
|
2001-04-14 18:24:56 -04:00
|
|
|
textbuffer_view_set_window(WINDOW_GUI(rec->active)->view,
|
2001-06-01 17:49:07 -04:00
|
|
|
rec->screen_win);
|
2000-08-10 16:01:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
MAIN_WINDOW_REC *mainwindow_create(void)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *rec, *parent;
|
|
|
|
int space;
|
|
|
|
|
|
|
|
rec = g_new0(MAIN_WINDOW_REC, 1);
|
2001-11-19 21:43:43 -05:00
|
|
|
rec->dirty = TRUE;
|
2001-10-28 06:30:26 -05:00
|
|
|
rec->width = term_width;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
if (mainwindows == NULL) {
|
|
|
|
active_mainwin = rec;
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
rec->first_line = screen_reserved_top;
|
2001-10-28 06:30:26 -05:00
|
|
|
rec->last_line = term_height-1 - screen_reserved_bottom;
|
2001-04-14 18:24:56 -04:00
|
|
|
rec->height = rec->last_line-rec->first_line+1;
|
2000-05-04 06:32:42 -04:00
|
|
|
} else {
|
2001-08-07 08:41:10 -04:00
|
|
|
parent = WINDOW_MAIN(active_win);
|
2001-10-20 06:01:29 -04:00
|
|
|
if (MAIN_WINDOW_TEXT_HEIGHT(parent) <
|
|
|
|
WINDOW_MIN_SIZE+NEW_WINDOW_SIZE)
|
2000-05-04 06:32:42 -04:00
|
|
|
parent = find_window_with_room();
|
|
|
|
if (parent == NULL)
|
|
|
|
return NULL; /* not enough space */
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
space = parent->height / 2;
|
2000-05-04 06:32:42 -04:00
|
|
|
rec->first_line = parent->first_line;
|
2001-10-13 12:11:13 -04:00
|
|
|
rec->last_line = rec->first_line + space;
|
2001-04-14 18:24:56 -04:00
|
|
|
rec->height = rec->last_line-rec->first_line+1;
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
parent->first_line = rec->last_line+1;
|
2001-04-14 18:24:56 -04:00
|
|
|
parent->height = parent->last_line-parent->first_line+1;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindow_resize(parent, 0, -space-1);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-06-01 17:49:07 -04:00
|
|
|
rec->screen_win = mainwindow_create_screen(rec);
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh(NULL);
|
2000-08-10 15:13:54 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
mainwindows = g_slist_append(mainwindows, rec);
|
|
|
|
signal_emit("mainwindow created", 1, rec);
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MAIN_WINDOW_REC *mainwindows_find_lower(int line)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *best;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
best = NULL;
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (rec->first_line > line &&
|
|
|
|
(best == NULL || rec->first_line < best->first_line))
|
|
|
|
best = rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MAIN_WINDOW_REC *mainwindows_find_upper(int line)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *best;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
best = NULL;
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (rec->last_line < line &&
|
|
|
|
(best == NULL || rec->last_line > best->last_line))
|
|
|
|
best = rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mainwindows_add_space(int first_line, int last_line)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *rec;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (last_line < first_line)
|
|
|
|
return;
|
|
|
|
|
|
|
|
size = last_line-first_line+1;
|
|
|
|
|
|
|
|
rec = mainwindows_find_lower(last_line);
|
|
|
|
if (rec != NULL) {
|
|
|
|
rec->first_line = first_line;
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindow_resize(rec, 0, size);
|
2000-05-04 06:32:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = mainwindows_find_upper(first_line);
|
|
|
|
if (rec != NULL) {
|
2001-10-13 12:11:13 -04:00
|
|
|
rec->last_line = last_line;
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindow_resize(rec, 0, size);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gui_windows_remove_parent(MAIN_WINDOW_REC *window)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *new_parent;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
new_parent = mainwindows->data;
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
if (rec->gui_data != NULL && WINDOW_MAIN(rec) == window)
|
2000-05-04 06:32:42 -04:00
|
|
|
gui_window_reparent(rec, new_parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mainwindow_destroy(MAIN_WINDOW_REC *window)
|
|
|
|
{
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
2001-06-01 15:12:07 -04:00
|
|
|
mainwindows = g_slist_remove(mainwindows, window);
|
|
|
|
signal_emit("mainwindow destroyed", 1, window);
|
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
term_window_destroy(window->screen_win);
|
2000-07-26 19:29:34 -04:00
|
|
|
|
2003-11-16 19:18:40 -05:00
|
|
|
if (mainwindows != NULL) {
|
2000-05-04 06:32:42 -04:00
|
|
|
gui_windows_remove_parent(window);
|
2003-11-16 19:18:40 -05:00
|
|
|
if (!quitting) {
|
|
|
|
mainwindows_add_space(window->first_line,
|
|
|
|
window->last_line);
|
|
|
|
mainwindows_redraw();
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2001-06-01 15:12:07 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
g_free(window);
|
|
|
|
|
|
|
|
if (active_mainwin == window) active_mainwin = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mainwindows_redraw(void)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
irssi_set_dirty();
|
2000-05-04 06:32:42 -04:00
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
rec->dirty = TRUE;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mainwindows_compare(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2)
|
|
|
|
{
|
|
|
|
return w1->first_line < w2->first_line ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mainwindows_compare_reverse(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2)
|
|
|
|
{
|
|
|
|
return w1->first_line < w2->first_line ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2001-02-10 02:26:54 -05:00
|
|
|
GSList *mainwindows_get_sorted(int reverse)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
|
|
|
GSList *tmp, *list;
|
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
list = g_slist_insert_sorted(list, tmp->data, (GCompareFunc)
|
|
|
|
(reverse ? mainwindows_compare_reverse : mainwindows_compare));
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
static void mainwindows_resize_smaller(int xdiff, int ydiff)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-10-20 06:35:42 -04:00
|
|
|
MAIN_WINDOW_REC *rec;
|
2000-05-04 06:32:42 -04:00
|
|
|
GSList *sorted, *tmp;
|
|
|
|
int space;
|
|
|
|
|
2008-12-06 07:29:51 -05:00
|
|
|
sorted = mainwindows_get_sorted(TRUE);
|
2001-10-20 06:35:42 -04:00
|
|
|
for (;;) {
|
|
|
|
space = 0;
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
rec = tmp->data;
|
|
|
|
space += MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE;
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-20 06:35:42 -04:00
|
|
|
if (space >= -ydiff)
|
|
|
|
break;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-20 06:35:42 -04:00
|
|
|
rec = sorted->data;
|
2008-12-06 07:36:41 -05:00
|
|
|
if (rec == active_mainwin && sorted->next != NULL)
|
|
|
|
rec = sorted->next->data;
|
2001-10-20 06:35:42 -04:00
|
|
|
sorted = g_slist_remove(sorted, rec);
|
|
|
|
|
|
|
|
if (sorted != NULL) {
|
|
|
|
/* terminal is too small - destroy the
|
|
|
|
uppest window and try again */
|
|
|
|
mainwindow_destroy(rec);
|
|
|
|
} else {
|
|
|
|
/* only one window in screen.. just force the resize */
|
|
|
|
rec->last_line += ydiff;
|
|
|
|
mainwindow_resize(rec, xdiff, ydiff);
|
|
|
|
return;
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* resize windows that have space */
|
2001-04-14 18:24:56 -04:00
|
|
|
for (tmp = sorted; tmp != NULL && ydiff < 0; tmp = tmp->next) {
|
2001-10-20 06:35:42 -04:00
|
|
|
rec = tmp->data;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
space = MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE;
|
2000-05-04 06:32:42 -04:00
|
|
|
if (space <= 0) {
|
2002-02-01 14:26:58 -05:00
|
|
|
mainwindow_resize(rec, xdiff, 0);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
rec->first_line += ydiff;
|
|
|
|
rec->last_line += ydiff;
|
2000-05-04 06:32:42 -04:00
|
|
|
signal_emit("mainwindow moved", 1, rec);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (space <= 0) space = 1;
|
2001-04-14 18:24:56 -04:00
|
|
|
if (space > -ydiff) space = -ydiff;
|
|
|
|
rec->last_line += ydiff;
|
|
|
|
ydiff += space;
|
|
|
|
rec->first_line += ydiff;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindow_resize(rec, xdiff, -space);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2002-02-01 14:26:58 -05:00
|
|
|
|
|
|
|
if (xdiff != 0) {
|
|
|
|
while (tmp != NULL) {
|
|
|
|
mainwindow_resize(tmp->data, xdiff, 0);
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
g_slist_free(sorted);
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
static void mainwindows_resize_bigger(int xdiff, int ydiff)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
|
|
|
GSList *sorted, *tmp;
|
|
|
|
int moved, space;
|
|
|
|
|
|
|
|
sorted = mainwindows_get_sorted(FALSE);
|
|
|
|
moved = 0;
|
|
|
|
for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
space = MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE;
|
2001-04-14 18:24:56 -04:00
|
|
|
if (ydiff == 0 || (space >= 0 && tmp->next != NULL)) {
|
2002-02-01 14:26:58 -05:00
|
|
|
mainwindow_resize(rec, xdiff, 0);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (moved > 0) {
|
|
|
|
rec->first_line += moved;
|
|
|
|
rec->last_line += moved;
|
|
|
|
signal_emit("mainwindow moved", 1, rec);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (space < 0 && tmp->next != NULL) {
|
|
|
|
/* space below minimum */
|
|
|
|
space = -space;
|
2001-04-14 18:24:56 -04:00
|
|
|
if (space > ydiff) space = ydiff;
|
2000-05-04 06:32:42 -04:00
|
|
|
} else {
|
|
|
|
/* lowest window - give all the extra space for it */
|
2001-04-14 18:24:56 -04:00
|
|
|
space = ydiff;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
ydiff -= space;
|
2000-05-04 06:32:42 -04:00
|
|
|
rec->first_line += moved;
|
|
|
|
moved += space;
|
|
|
|
rec->last_line += moved;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindow_resize(rec, xdiff, space);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
g_slist_free(sorted);
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
void mainwindows_resize_horiz(int xdiff)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindow_resize(rec, xdiff, 0);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
void mainwindows_resize(int width, int height)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-04-14 18:24:56 -04:00
|
|
|
int xdiff, ydiff;
|
|
|
|
|
2001-06-01 17:49:07 -04:00
|
|
|
xdiff = width-old_screen_width;
|
|
|
|
ydiff = height-old_screen_height;
|
|
|
|
old_screen_width = width;
|
|
|
|
old_screen_height = height;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
if (ydiff < 0)
|
|
|
|
mainwindows_resize_smaller(xdiff, ydiff);
|
|
|
|
else if (ydiff > 0)
|
|
|
|
mainwindows_resize_bigger(xdiff, ydiff);
|
|
|
|
else if (xdiff != 0)
|
|
|
|
mainwindows_resize_horiz(xdiff);
|
2001-10-14 06:45:00 -04:00
|
|
|
|
|
|
|
signal_emit("terminal resized", 0);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
irssi_redraw();
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
int mainwindows_reserve_lines(int top, int bottom)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *window;
|
|
|
|
int ret;
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
ret = -1;
|
|
|
|
if (top != 0) {
|
2001-10-20 06:01:29 -04:00
|
|
|
g_return_val_if_fail(top > 0 || screen_reserved_top > top, -1);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
ret = screen_reserved_top;
|
|
|
|
screen_reserved_top += top;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
window = mainwindows_find_lower(-1);
|
2001-10-13 12:11:13 -04:00
|
|
|
if (window != NULL) {
|
|
|
|
window->first_line += top;
|
|
|
|
mainwindow_resize(window, 0, -top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom != 0) {
|
2001-10-20 06:01:29 -04:00
|
|
|
g_return_val_if_fail(bottom > 0 || screen_reserved_bottom > bottom, -1);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
ret = screen_reserved_bottom;
|
|
|
|
screen_reserved_bottom += bottom;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
window = mainwindows_find_upper(term_height);
|
2001-10-13 12:11:13 -04:00
|
|
|
if (window != NULL) {
|
|
|
|
window->last_line -= bottom;
|
|
|
|
mainwindow_resize(window, 0, -bottom);
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
int mainwindow_set_statusbar_lines(MAIN_WINDOW_REC *window,
|
|
|
|
int top, int bottom)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
if (top != 0) {
|
|
|
|
ret = window->statusbar_lines_top;
|
|
|
|
window->statusbar_lines_top += top;
|
|
|
|
window->statusbar_lines += top;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom != 0) {
|
|
|
|
ret = window->statusbar_lines_bottom;
|
|
|
|
window->statusbar_lines_bottom += bottom;
|
|
|
|
window->statusbar_lines += bottom;
|
|
|
|
}
|
|
|
|
|
2001-10-20 10:30:20 -04:00
|
|
|
if (top+bottom != 0)
|
2001-10-28 13:40:12 -05:00
|
|
|
window->size_dirty = TRUE;
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-08-10 15:13:54 -04:00
|
|
|
static void mainwindows_resize_two(MAIN_WINDOW_REC *grow_win,
|
|
|
|
MAIN_WINDOW_REC *shrink_win, int count)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-10-28 13:40:12 -05:00
|
|
|
irssi_set_dirty();
|
|
|
|
|
2001-04-14 19:24:19 -04:00
|
|
|
mainwindow_resize(grow_win, 0, count);
|
|
|
|
mainwindow_resize(shrink_win, 0, -count);
|
2001-10-28 13:40:12 -05:00
|
|
|
grow_win->dirty = TRUE;
|
|
|
|
shrink_win->dirty = TRUE;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
static int try_shrink_lower(MAIN_WINDOW_REC *window, int count)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-02-10 02:26:54 -05:00
|
|
|
MAIN_WINDOW_REC *shrink_win;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
shrink_win = mainwindows_find_lower(window->last_line);
|
2001-10-20 06:01:29 -04:00
|
|
|
if (shrink_win != NULL &&
|
|
|
|
MAIN_WINDOW_TEXT_HEIGHT(shrink_win)-count >= WINDOW_MIN_SIZE) {
|
2000-05-04 06:32:42 -04:00
|
|
|
window->last_line += count;
|
|
|
|
shrink_win->first_line += count;
|
2001-10-20 06:01:29 -04:00
|
|
|
mainwindows_resize_two(window, shrink_win, count);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-02-10 02:26:54 -05:00
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
static int try_shrink_upper(MAIN_WINDOW_REC *window, int count)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *shrink_win;
|
|
|
|
|
|
|
|
shrink_win = mainwindows_find_upper(window->first_line);
|
|
|
|
if (shrink_win != NULL &&
|
|
|
|
MAIN_WINDOW_TEXT_HEIGHT(shrink_win)-count >= WINDOW_MIN_SIZE) {
|
2001-02-10 02:26:54 -05:00
|
|
|
window->first_line -= count;
|
|
|
|
shrink_win->last_line -= count;
|
2001-10-20 06:01:29 -04:00
|
|
|
mainwindows_resize_two(window, shrink_win, count);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mainwindow_grow(MAIN_WINDOW_REC *window, int count,
|
|
|
|
int resize_lower)
|
|
|
|
{
|
|
|
|
if (!resize_lower || !try_shrink_lower(window, count)) {
|
|
|
|
if (!try_shrink_upper(window, count)) {
|
|
|
|
if (resize_lower || !try_shrink_lower(window, count))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-02-10 02:26:54 -05:00
|
|
|
return TRUE;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
static int try_grow_lower(MAIN_WINDOW_REC *window, int count)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-02-10 02:26:54 -05:00
|
|
|
MAIN_WINDOW_REC *grow_win;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
grow_win = mainwindows_find_lower(window->last_line);
|
|
|
|
if (grow_win != NULL) {
|
|
|
|
window->last_line -= count;
|
|
|
|
grow_win->first_line -= count;
|
2001-10-20 06:01:29 -04:00
|
|
|
mainwindows_resize_two(grow_win, window, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return grow_win != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int try_grow_upper(MAIN_WINDOW_REC *window, int count)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *grow_win;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
grow_win = mainwindows_find_upper(window->first_line);
|
|
|
|
if (grow_win != NULL) {
|
2000-05-04 06:32:42 -04:00
|
|
|
window->first_line += count;
|
|
|
|
grow_win->last_line += count;
|
2001-10-20 06:01:29 -04:00
|
|
|
mainwindows_resize_two(grow_win, window, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return grow_win != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count, int resize_lower)
|
|
|
|
{
|
|
|
|
if (MAIN_WINDOW_TEXT_HEIGHT(window)-count < WINDOW_MIN_SIZE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!resize_lower || !try_grow_lower(window, count)) {
|
|
|
|
if (!try_grow_upper(window, count)) {
|
|
|
|
if (resize_lower || !try_grow_lower(window, count))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-02-10 02:26:54 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
/* Change the window height - the height includes the lines needed for
|
|
|
|
statusbars. If resize_lower is TRUE, the lower window is first tried
|
|
|
|
to be resized instead of upper window. */
|
|
|
|
void mainwindow_set_size(MAIN_WINDOW_REC *window, int height, int resize_lower)
|
2001-02-10 02:26:54 -05:00
|
|
|
{
|
2001-10-20 06:01:29 -04:00
|
|
|
height -= window->height;
|
|
|
|
if (height < 0)
|
|
|
|
mainwindow_shrink(window, -height, resize_lower);
|
2001-02-10 02:26:54 -05:00
|
|
|
else
|
2001-10-20 06:01:29 -04:00
|
|
|
mainwindow_grow(window, height, resize_lower);
|
2001-02-10 02:26:54 -05:00
|
|
|
}
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
void mainwindows_redraw_dirty(void)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (rec->size_dirty) {
|
|
|
|
rec->size_dirty = FALSE;
|
|
|
|
mainwindow_resize_windows(rec);
|
|
|
|
}
|
|
|
|
if (rec->dirty) {
|
|
|
|
rec->dirty = FALSE;
|
|
|
|
gui_window_redraw(rec->active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-10 02:26:54 -05:00
|
|
|
/* SYNTAX: WINDOW GROW [<lines>] */
|
|
|
|
static void cmd_window_grow(const char *data)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *window;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = *data == '\0' ? 1 : atoi(data);
|
2001-08-07 08:41:10 -04:00
|
|
|
window = WINDOW_MAIN(active_win);
|
2001-02-10 02:26:54 -05:00
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
if (!mainwindow_grow(window, count, FALSE)) {
|
2001-02-10 02:26:54 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_TOO_SMALL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SYNTAX: WINDOW SHRINK [<lines>] */
|
|
|
|
static void cmd_window_shrink(const char *data)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = *data == '\0' ? 1 : atoi(data);
|
2001-10-20 06:01:29 -04:00
|
|
|
if (!mainwindow_shrink(WINDOW_MAIN(active_win), count, FALSE)) {
|
2001-02-10 02:26:54 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_TOO_SMALL);
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW SIZE <lines> */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_window_size(const char *data)
|
|
|
|
{
|
|
|
|
char sizestr[MAX_INT_STRLEN];
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (!is_numeric(data, 0)) return;
|
|
|
|
size = atoi(data);
|
|
|
|
|
2001-10-20 06:01:29 -04:00
|
|
|
size -= WINDOW_MAIN(active_win)->height -
|
|
|
|
WINDOW_MAIN(active_win)->statusbar_lines;
|
2000-05-04 06:32:42 -04:00
|
|
|
if (size == 0) return;
|
|
|
|
|
|
|
|
ltoa(sizestr, size < 0 ? -size : size);
|
|
|
|
if (size < 0)
|
|
|
|
cmd_window_shrink(sizestr);
|
|
|
|
else
|
|
|
|
cmd_window_grow(sizestr);
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW BALANCE */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_window_balance(void)
|
|
|
|
{
|
|
|
|
GSList *sorted, *tmp;
|
|
|
|
int avail_size, unit_size, bigger_units;
|
|
|
|
int windows, last_line, old_size;
|
|
|
|
|
|
|
|
windows = g_slist_length(mainwindows);
|
|
|
|
if (windows == 1) return;
|
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
avail_size = term_height - screen_reserved_top-screen_reserved_bottom;
|
2000-05-04 06:32:42 -04:00
|
|
|
unit_size = avail_size/windows;
|
|
|
|
bigger_units = avail_size%windows;
|
|
|
|
|
|
|
|
sorted = mainwindows_get_sorted(FALSE);
|
2001-10-20 06:01:29 -04:00
|
|
|
last_line = screen_reserved_top;
|
2000-05-04 06:32:42 -04:00
|
|
|
for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
|
|
|
|
MAIN_WINDOW_REC *rec = tmp->data;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
old_size = rec->height;
|
2001-08-08 10:43:14 -04:00
|
|
|
rec->first_line = last_line;
|
2001-10-13 12:11:13 -04:00
|
|
|
rec->last_line = rec->first_line + unit_size-1;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
if (bigger_units > 0) {
|
|
|
|
rec->last_line++;
|
|
|
|
bigger_units--;
|
|
|
|
}
|
2001-11-12 08:53:58 -05:00
|
|
|
|
|
|
|
rec->height = rec->last_line-rec->first_line+1;
|
2001-10-13 12:11:13 -04:00
|
|
|
last_line = rec->last_line+1;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-04-14 19:24:19 -04:00
|
|
|
mainwindow_resize(rec, 0, rec->height-old_size);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
g_slist_free(sorted);
|
|
|
|
|
|
|
|
mainwindows_redraw();
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW HIDE [<number>|<name>] */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_window_hide(const char *data)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
if (mainwindows->next == NULL) {
|
2001-02-09 23:43:21 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_CANT_HIDE_LAST);
|
2000-05-04 06:32:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*data == '\0')
|
|
|
|
window = active_win;
|
2001-02-09 23:43:21 -05:00
|
|
|
else if (is_numeric(data, 0)) {
|
2000-05-04 06:32:42 -04:00
|
|
|
window = window_find_refnum(atoi(data));
|
2001-02-09 23:43:21 -05:00
|
|
|
if (window == NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_REFNUM_NOT_FOUND, data);
|
|
|
|
}
|
|
|
|
} else {
|
2000-12-02 14:08:21 -05:00
|
|
|
window = window_find_item(active_win->active_server, data);
|
2001-02-09 23:43:21 -05:00
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-02-09 23:43:21 -05:00
|
|
|
if (window == NULL || !is_window_visible(window))
|
|
|
|
return;
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
if (WINDOW_MAIN(window)->sticky_windows) {
|
2001-02-09 23:43:21 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_CANT_HIDE_STICKY_WINDOWS);
|
|
|
|
return;
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
mainwindow_destroy(WINDOW_MAIN(window));
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
if (active_mainwin == NULL) {
|
2001-08-07 08:41:10 -04:00
|
|
|
active_mainwin = WINDOW_MAIN(active_win);
|
2000-05-04 06:32:42 -04:00
|
|
|
window_set_active(active_mainwin->active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW SHOW <number>|<name> */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_window_show(const char *data)
|
|
|
|
{
|
2001-03-03 21:26:35 -05:00
|
|
|
MAIN_WINDOW_REC *parent;
|
2000-05-04 06:32:42 -04:00
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
2001-02-09 23:43:21 -05:00
|
|
|
if (is_numeric(data, '\0')) {
|
|
|
|
window = window_find_refnum(atoi(data));
|
|
|
|
if (window == NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_REFNUM_NOT_FOUND, data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window = window_find_item(active_win->active_server, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window == NULL || is_window_visible(window))
|
|
|
|
return;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2007-04-05 14:25:29 -04:00
|
|
|
if (WINDOW_GUI(window)->sticky) {
|
2001-02-09 23:43:21 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_CANT_SHOW_STICKY_WINDOWS);
|
|
|
|
return;
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-03-03 21:26:35 -05:00
|
|
|
parent = mainwindow_create();
|
2001-08-07 08:41:10 -04:00
|
|
|
parent->active = window;
|
2001-03-03 21:26:35 -05:00
|
|
|
gui_window_reparent(window, parent);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
if (settings_get_bool("autostick_split_windows"))
|
|
|
|
gui_window_set_sticky(window);
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
active_mainwin = NULL;
|
|
|
|
window_set_active(window);
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW UP */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_window_up(void)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *rec;
|
|
|
|
|
|
|
|
rec = mainwindows_find_upper(active_mainwin->first_line);
|
2001-11-15 15:49:12 -05:00
|
|
|
if (rec == NULL)
|
|
|
|
rec = mainwindows_find_upper(term_height);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (rec != NULL)
|
|
|
|
window_set_active(rec->active);
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW DOWN */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_window_down(void)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *rec;
|
|
|
|
|
|
|
|
rec = mainwindows_find_lower(active_mainwin->last_line);
|
2001-11-15 15:49:12 -05:00
|
|
|
if (rec == NULL)
|
|
|
|
rec = mainwindows_find_lower(-1);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (rec != NULL)
|
|
|
|
window_set_active(rec->active);
|
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
#define WINDOW_STICKY_MATCH(window, sticky_parent) \
|
|
|
|
((!WINDOW_GUI(window)->sticky && (sticky_parent) == NULL) || \
|
|
|
|
(WINDOW_GUI(window)->sticky && \
|
|
|
|
WINDOW_MAIN(window) == (sticky_parent)))
|
|
|
|
|
|
|
|
static int window_refnum_left(int refnum, int wrap)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *find_sticky;
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
window = window_find_refnum(refnum);
|
|
|
|
g_return_val_if_fail(window != NULL, -1);
|
|
|
|
|
|
|
|
find_sticky = WINDOW_MAIN(window)->sticky_windows ?
|
|
|
|
WINDOW_MAIN(window) : NULL;
|
|
|
|
|
|
|
|
do {
|
|
|
|
refnum = window_refnum_prev(refnum, wrap);
|
|
|
|
if (refnum < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
window = window_find_refnum(refnum);
|
|
|
|
} while (!WINDOW_STICKY_MATCH(window, find_sticky));
|
|
|
|
|
|
|
|
return refnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int window_refnum_right(int refnum, int wrap)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *find_sticky;
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
window = window_find_refnum(refnum);
|
|
|
|
g_return_val_if_fail(window != NULL, -1);
|
|
|
|
|
|
|
|
find_sticky = WINDOW_MAIN(window)->sticky_windows ?
|
|
|
|
WINDOW_MAIN(window) : NULL;
|
|
|
|
|
|
|
|
do {
|
|
|
|
refnum = window_refnum_next(refnum, wrap);
|
|
|
|
if (refnum < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
window = window_find_refnum(refnum);
|
|
|
|
} while (!WINDOW_STICKY_MATCH(window, find_sticky));
|
|
|
|
|
|
|
|
return refnum;
|
|
|
|
}
|
|
|
|
|
2001-02-09 23:43:21 -05:00
|
|
|
/* SYNTAX: WINDOW LEFT */
|
|
|
|
static void cmd_window_left(const char *data, SERVER_REC *server, void *item)
|
|
|
|
{
|
2001-08-07 08:41:10 -04:00
|
|
|
int refnum;
|
2001-02-09 23:43:21 -05:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
refnum = window_refnum_left(active_win->refnum, TRUE);
|
|
|
|
if (refnum != -1)
|
|
|
|
window_set_active(window_find_refnum(refnum));
|
2001-02-09 23:43:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SYNTAX: WINDOW RIGHT */
|
|
|
|
static void cmd_window_right(void)
|
|
|
|
{
|
2001-08-07 08:41:10 -04:00
|
|
|
int refnum;
|
|
|
|
|
|
|
|
refnum = window_refnum_right(active_win->refnum, TRUE);
|
|
|
|
if (refnum != -1)
|
|
|
|
window_set_active(window_find_refnum(refnum));
|
|
|
|
}
|
2001-02-09 23:43:21 -05:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
static void window_reparent(WINDOW_REC *win, MAIN_WINDOW_REC *mainwin)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *old_mainwin;
|
|
|
|
|
|
|
|
old_mainwin = WINDOW_MAIN(win);
|
|
|
|
|
|
|
|
if (old_mainwin != mainwin) {
|
2001-09-09 08:12:28 -04:00
|
|
|
gui_window_set_unsticky(win);
|
2001-08-07 08:41:10 -04:00
|
|
|
|
2001-09-09 08:12:28 -04:00
|
|
|
if (old_mainwin->active == win) {
|
2001-08-07 08:41:10 -04:00
|
|
|
mainwindow_change_active(old_mainwin, win);
|
2001-09-09 08:12:28 -04:00
|
|
|
if (active_mainwin == NULL) {
|
|
|
|
active_mainwin = mainwin;
|
|
|
|
window_set_active(mainwin->active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_window_reparent(win, mainwin);
|
|
|
|
window_set_active(win);
|
2001-08-07 08:41:10 -04:00
|
|
|
}
|
2001-02-09 23:43:21 -05:00
|
|
|
}
|
|
|
|
|
2001-08-03 19:39:35 -04:00
|
|
|
/* SYNTAX: WINDOW STICK [<ref#>] [ON|OFF] */
|
2001-02-09 23:43:21 -05:00
|
|
|
static void cmd_window_stick(const char *data)
|
|
|
|
{
|
2001-08-03 19:39:35 -04:00
|
|
|
MAIN_WINDOW_REC *mainwin;
|
|
|
|
WINDOW_REC *win;
|
|
|
|
|
|
|
|
mainwin = active_mainwin;
|
|
|
|
win = active_mainwin->active;
|
2001-02-09 23:43:21 -05:00
|
|
|
|
2001-11-19 22:38:53 -05:00
|
|
|
if (is_numeric(data, ' ')) {
|
2001-08-03 19:39:35 -04:00
|
|
|
/* ref# specified */
|
|
|
|
win = window_find_refnum(atoi(data));
|
2001-02-09 23:43:21 -05:00
|
|
|
if (win == NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_REFNUM_NOT_FOUND, data);
|
|
|
|
return;
|
|
|
|
}
|
2001-08-03 19:39:35 -04:00
|
|
|
|
|
|
|
while (*data != ' ' && *data != '\0') data++;
|
|
|
|
while (*data == ' ') data++;
|
2001-02-09 23:43:21 -05:00
|
|
|
}
|
|
|
|
|
2008-03-09 08:17:55 -04:00
|
|
|
if (g_ascii_strncasecmp(data, "OF", 2) == 0 || i_toupper(*data) == 'N') {
|
2001-02-09 23:43:21 -05:00
|
|
|
/* unset sticky */
|
2001-08-07 08:41:10 -04:00
|
|
|
if (!WINDOW_GUI(win)->sticky) {
|
2001-08-03 19:39:35 -04:00
|
|
|
printformat_window(win, MSGLEVEL_CLIENTERROR,
|
2001-02-09 23:43:21 -05:00
|
|
|
TXT_WINDOW_NOT_STICKY);
|
|
|
|
} else {
|
2001-08-07 08:41:10 -04:00
|
|
|
gui_window_set_unsticky(win);
|
2001-08-03 19:39:35 -04:00
|
|
|
printformat_window(win, MSGLEVEL_CLIENTNOTICE,
|
2001-02-09 23:43:21 -05:00
|
|
|
TXT_WINDOW_UNSET_STICKY);
|
|
|
|
}
|
|
|
|
} else {
|
2001-08-03 19:39:35 -04:00
|
|
|
/* set sticky */
|
2001-08-07 08:41:10 -04:00
|
|
|
window_reparent(win, mainwin);
|
|
|
|
gui_window_set_sticky(win);
|
2001-02-09 23:43:21 -05:00
|
|
|
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_SET_STICKY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
/* SYNTAX: WINDOW MOVE LEFT */
|
|
|
|
static void cmd_window_move_left(void)
|
2001-08-03 18:54:08 -04:00
|
|
|
{
|
2001-08-07 08:41:10 -04:00
|
|
|
int refnum;
|
2001-08-03 18:54:08 -04:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
refnum = window_refnum_left(active_win->refnum, TRUE);
|
|
|
|
if (refnum != -1)
|
|
|
|
window_set_refnum(active_win, refnum);
|
|
|
|
}
|
2001-08-03 18:54:08 -04:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
/* SYNTAX: WINDOW MOVE RIGHT */
|
|
|
|
static void cmd_window_move_right(void)
|
|
|
|
{
|
|
|
|
int refnum;
|
|
|
|
|
|
|
|
refnum = window_refnum_right(active_win->refnum, TRUE);
|
|
|
|
if (refnum != -1)
|
|
|
|
window_set_refnum(active_win, refnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SYNTAX: WINDOW MOVE UP */
|
|
|
|
static void cmd_window_move_up(void)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *rec;
|
|
|
|
|
|
|
|
rec = mainwindows_find_upper(active_mainwin->first_line);
|
2001-09-09 08:12:28 -04:00
|
|
|
if (rec != NULL)
|
2001-08-07 08:41:10 -04:00
|
|
|
window_reparent(active_win, rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SYNTAX: WINDOW MOVE DOWN */
|
|
|
|
static void cmd_window_move_down(void)
|
|
|
|
{
|
|
|
|
MAIN_WINDOW_REC *rec;
|
|
|
|
|
|
|
|
rec = mainwindows_find_lower(active_mainwin->last_line);
|
|
|
|
if (rec != NULL)
|
|
|
|
window_reparent(active_win, rec);
|
|
|
|
}
|
|
|
|
|
2002-02-22 08:12:33 -05:00
|
|
|
static void windows_print_sticky(WINDOW_REC *win)
|
2001-08-07 08:41:10 -04:00
|
|
|
{
|
2002-02-22 08:12:33 -05:00
|
|
|
MAIN_WINDOW_REC *mainwin;
|
2001-08-07 08:41:10 -04:00
|
|
|
GSList *tmp, *list;
|
|
|
|
GString *str;
|
2001-08-03 18:54:08 -04:00
|
|
|
|
2002-02-22 08:12:33 -05:00
|
|
|
mainwin = WINDOW_MAIN(win);
|
|
|
|
|
2001-08-03 18:54:08 -04:00
|
|
|
/* convert to string */
|
2001-08-07 08:41:10 -04:00
|
|
|
str = g_string_new(NULL);
|
2002-02-22 08:12:33 -05:00
|
|
|
list = get_sticky_windows_sorted(mainwin);
|
2001-08-07 08:41:10 -04:00
|
|
|
for (tmp = list; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
2001-08-03 18:54:08 -04:00
|
|
|
|
|
|
|
g_string_sprintfa(str, "#%d, ", rec->refnum);
|
|
|
|
}
|
|
|
|
g_string_truncate(str, str->len-2);
|
2001-08-07 08:41:10 -04:00
|
|
|
g_slist_free(list);
|
2001-08-03 18:54:08 -04:00
|
|
|
|
2002-02-22 08:12:33 -05:00
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
2001-08-03 18:54:08 -04:00
|
|
|
TXT_WINDOW_INFO_STICKY, str->str);
|
|
|
|
g_string_free(str, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_window_print_info(WINDOW_REC *win)
|
|
|
|
{
|
2002-02-22 08:12:33 -05:00
|
|
|
GUI_WINDOW_REC *gui;
|
|
|
|
|
|
|
|
gui = WINDOW_GUI(win);
|
|
|
|
if (gui->use_scroll) {
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_SCROLL,
|
|
|
|
gui->scroll ? "yes" : "no");
|
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
if (WINDOW_MAIN(win)->sticky_windows)
|
2002-02-22 08:12:33 -05:00
|
|
|
windows_print_sticky(win);
|
2001-08-03 18:54:08 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void mainwindows_init(void)
|
|
|
|
{
|
2001-10-28 06:30:26 -05:00
|
|
|
old_screen_width = term_width;
|
|
|
|
old_screen_height = term_height;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
mainwindows = NULL;
|
|
|
|
active_mainwin = NULL;
|
2001-10-20 06:01:29 -04:00
|
|
|
screen_reserved_top = screen_reserved_bottom = 0;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
command_bind("window grow", NULL, (SIGNAL_FUNC) cmd_window_grow);
|
|
|
|
command_bind("window shrink", NULL, (SIGNAL_FUNC) cmd_window_shrink);
|
|
|
|
command_bind("window size", NULL, (SIGNAL_FUNC) cmd_window_size);
|
|
|
|
command_bind("window balance", NULL, (SIGNAL_FUNC) cmd_window_balance);
|
|
|
|
command_bind("window hide", NULL, (SIGNAL_FUNC) cmd_window_hide);
|
|
|
|
command_bind("window show", NULL, (SIGNAL_FUNC) cmd_window_show);
|
|
|
|
command_bind("window up", NULL, (SIGNAL_FUNC) cmd_window_up);
|
|
|
|
command_bind("window down", NULL, (SIGNAL_FUNC) cmd_window_down);
|
2001-02-09 23:43:21 -05:00
|
|
|
command_bind("window left", NULL, (SIGNAL_FUNC) cmd_window_left);
|
|
|
|
command_bind("window right", NULL, (SIGNAL_FUNC) cmd_window_right);
|
|
|
|
command_bind("window stick", NULL, (SIGNAL_FUNC) cmd_window_stick);
|
2001-08-07 08:41:10 -04:00
|
|
|
command_bind("window move left", NULL, (SIGNAL_FUNC) cmd_window_move_left);
|
|
|
|
command_bind("window move right", NULL, (SIGNAL_FUNC) cmd_window_move_right);
|
|
|
|
command_bind("window move up", NULL, (SIGNAL_FUNC) cmd_window_move_up);
|
|
|
|
command_bind("window move down", NULL, (SIGNAL_FUNC) cmd_window_move_down);
|
2001-08-03 18:54:08 -04:00
|
|
|
signal_add("window print info", (SIGNAL_FUNC) sig_window_print_info);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void mainwindows_deinit(void)
|
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
while (mainwindows != NULL)
|
|
|
|
mainwindow_destroy(mainwindows->data);
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
command_unbind("window grow", (SIGNAL_FUNC) cmd_window_grow);
|
|
|
|
command_unbind("window shrink", (SIGNAL_FUNC) cmd_window_shrink);
|
|
|
|
command_unbind("window size", (SIGNAL_FUNC) cmd_window_size);
|
|
|
|
command_unbind("window balance", (SIGNAL_FUNC) cmd_window_balance);
|
|
|
|
command_unbind("window hide", (SIGNAL_FUNC) cmd_window_hide);
|
|
|
|
command_unbind("window show", (SIGNAL_FUNC) cmd_window_show);
|
|
|
|
command_unbind("window up", (SIGNAL_FUNC) cmd_window_up);
|
|
|
|
command_unbind("window down", (SIGNAL_FUNC) cmd_window_down);
|
2001-02-09 23:43:21 -05:00
|
|
|
command_unbind("window left", (SIGNAL_FUNC) cmd_window_left);
|
|
|
|
command_unbind("window right", (SIGNAL_FUNC) cmd_window_right);
|
|
|
|
command_unbind("window stick", (SIGNAL_FUNC) cmd_window_stick);
|
2001-08-07 08:41:10 -04:00
|
|
|
command_unbind("window move left", (SIGNAL_FUNC) cmd_window_move_left);
|
|
|
|
command_unbind("window move right", (SIGNAL_FUNC) cmd_window_move_right);
|
|
|
|
command_unbind("window move up", (SIGNAL_FUNC) cmd_window_move_up);
|
|
|
|
command_unbind("window move down", (SIGNAL_FUNC) cmd_window_move_down);
|
2001-08-03 18:54:08 -04:00
|
|
|
signal_remove("window print info", (SIGNAL_FUNC) sig_window_print_info);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|