Restoring layout for split windows works betters now. Some sticky window

changes/fixes. Renamed /WINDOW MOVE LEFT|RIGHT -> PREV|NEXT, added commands
/WINDOW MOVE UP|DOWN|LEFT|RIGHT. The new LEFT|RIGHT now moves the window
only inside split windows. mainwindows-save.c -> mainwindows-layout.c


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1710 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-08-07 12:41:10 +00:00 committed by cras
commit 45bb5c3cee
11 changed files with 415 additions and 366 deletions

View file

@ -458,70 +458,85 @@ static void cmd_window_name(const char *data)
/* we're moving the first window to last - move the first contiguous block
of refnums to left. Like if there's windows 1..5 and 7..10, move 1 to
11, 2..5 to 1..4 and leave 7..10 alone */
static void windows_move_left(WINDOW_REC *move_window)
11, 2..5 to 1..4 and leave 7..10 alone */
static void window_refnums_move_left(WINDOW_REC *move_window)
{
WINDOW_REC *window;
int refnum;
int refnum, new_refnum;
window_set_refnum(move_window, windows_refnum_last()+1);
for (refnum = 2;; refnum++) {
new_refnum = windows_refnum_last();
for (refnum = move_window->refnum+1; refnum <= new_refnum; refnum++) {
window = window_find_refnum(refnum);
if (window == NULL) break;
if (window == NULL) {
new_refnum++;
break;
}
window_set_refnum(window, refnum-1);
}
window_set_refnum(move_window, new_refnum);
}
/* we're moving the last window to first - make some space so we can use the
refnum 1 */
static void windows_move_right(WINDOW_REC *move_window)
static void window_refnums_move_right(WINDOW_REC *move_window)
{
WINDOW_REC *window;
int refnum;
int refnum, new_refnum;
new_refnum = 1;
if (window_find_refnum(new_refnum) == NULL) {
window_set_refnum(move_window, new_refnum);
return;
}
/* find the first unused refnum, like if there's windows
1..5 and 7..10, we only need to move 1..5 to 2..6 */
refnum = 1;
while (window_find_refnum(refnum) != NULL) refnum++;
refnum = new_refnum;
while (move_window->refnum == refnum ||
window_find_refnum(refnum) != NULL) refnum++;
refnum--;
while (refnum > 0) {
while (refnum >= new_refnum) {
window = window_find_refnum(refnum);
g_return_if_fail(window != NULL);
window_set_refnum(window, window == move_window ? 1 : refnum+1);
window_set_refnum(window, refnum+1);
refnum--;
}
window_set_refnum(move_window, new_refnum);
}
static void cmd_window_move_left(void)
/* SYNTAX: WINDOW MOVE PREV */
static void cmd_window_move_prev(void)
{
int refnum;
refnum = window_refnum_prev(active_win->refnum, TRUE);
refnum = window_refnum_prev(active_win->refnum, FALSE);
if (refnum != -1) {
window_set_refnum(active_win, refnum);
return;
}
windows_move_left(active_win);
window_refnums_move_left(active_win);
}
static void cmd_window_move_right(void)
/* SYNTAX: WINDOW MOVE NEXT */
static void cmd_window_move_next(void)
{
int refnum;
refnum = window_refnum_next(active_win->refnum, TRUE);
refnum = window_refnum_next(active_win->refnum, FALSE);
if (refnum != -1) {
window_set_refnum(active_win, refnum);
return;
}
windows_move_right(active_win);
window_refnums_move_right(active_win);
}
/* SYNTAX: WINDOW MOVE <number>|left|right */
/* SYNTAX: WINDOW MOVE <number>|<direction> */
static void cmd_window_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
int new_refnum, refnum;
@ -666,8 +681,8 @@ void window_commands_init(void)
command_bind("window number", NULL, (SIGNAL_FUNC) cmd_window_number);
command_bind("window name", NULL, (SIGNAL_FUNC) cmd_window_name);
command_bind("window move", NULL, (SIGNAL_FUNC) cmd_window_move);
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 prev", NULL, (SIGNAL_FUNC) cmd_window_move_prev);
command_bind("window move next", NULL, (SIGNAL_FUNC) cmd_window_move_next);
command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
command_bind("layout", NULL, (SIGNAL_FUNC) cmd_layout);
@ -703,8 +718,8 @@ void window_commands_deinit(void)
command_unbind("window number", (SIGNAL_FUNC) cmd_window_number);
command_unbind("window name", (SIGNAL_FUNC) cmd_window_name);
command_unbind("window move", (SIGNAL_FUNC) cmd_window_move);
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 prev", (SIGNAL_FUNC) cmd_window_move_prev);
command_unbind("window move next", (SIGNAL_FUNC) cmd_window_move_next);
command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
command_unbind("layout", (SIGNAL_FUNC) cmd_layout);

View file

@ -93,6 +93,11 @@ static void window_add_items(WINDOW_REC *window, CONFIG_NODE *node)
}
void windows_layout_restore(void)
{
signal_emit("windows restored", 0);
}
static void sig_windows_restored(void)
{
WINDOW_REC *window;
CONFIG_NODE *node;
@ -104,7 +109,10 @@ void windows_layout_restore(void)
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
CONFIG_NODE *node = tmp->data;
window = window_create(NULL, TRUE);
window = window_find_refnum(atoi(node->key));
if (window == NULL)
window = window_create(NULL, TRUE);
window_set_refnum(window, atoi(node->key));
window->sticky_refnum = config_node_get_bool(node, "sticky_refnum", FALSE);
window_set_name(window, config_node_get_str(node, "name", NULL));
@ -118,8 +126,6 @@ void windows_layout_restore(void)
window_add_items(window, config_node_section(node, "items", -1));
signal_emit("window restore", 2, window, node);
}
signal_emit("windows restored", 0);
}
static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
@ -204,9 +210,11 @@ void windows_layout_reset(void)
void windows_layout_init(void)
{
signal_add("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
signal_add("windows restored", (SIGNAL_FUNC) sig_windows_restored);
}
void windows_layout_deinit(void)
{
signal_remove("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
signal_remove("windows restored", (SIGNAL_FUNC) sig_windows_restored);
}