1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

New tabs always open below dialogs, never above.

This fixes the bug that tabs opened with -remote used to hide existing
dialogs, which then became unusable until the new tabs were closed.

src/terminal/tab.c (init_tab): Put the new tab immediately above
existing ones, or if it's the first one, then at the bottom of the stack.
Added assertions.

src/terminal/terminal.h (struct terminal): Redocumented the stacking
order of windows.

src/terminal/window.c [CONFIG_DEBUG] (assert_window_stacking): New function.

src/terminal/window.h (assert_window_stacking): New function or no-op macro.
This commit is contained in:
Kalle Olavi Niemitalo 2006-05-14 14:03:17 +03:00 committed by Kalle Olavi Niemitalo
parent 2fcf33541c
commit 276f723ab7
4 changed files with 61 additions and 4 deletions

View File

@ -30,6 +30,7 @@ struct window *
init_tab(struct terminal *term, void *data, window_handler_T handler) init_tab(struct terminal *term, void *data, window_handler_T handler)
{ {
struct window *win = mem_calloc(1, sizeof(*win)); struct window *win = mem_calloc(1, sizeof(*win));
struct window *pos;
if (!win) return NULL; if (!win) return NULL;
@ -39,7 +40,21 @@ init_tab(struct terminal *term, void *data, window_handler_T handler)
win->type = WINDOW_TAB; win->type = WINDOW_TAB;
win->resize = 1; win->resize = 1;
add_to_list(term->windows, win); /* Insert the new tab immediately above all existing tabs in
* the stack of windows. */
foreach_tab (pos, term->windows) {
pos = pos->prev;
goto found_pos;
}
/* This is a new terminal and there are no tabs yet. If there
* were a main menu already, then we'd have to place the tab
* above it if it were inactive, or below if it were active. */
assert(term->main_menu == NULL);
pos = (struct window *) term->windows.prev;
found_pos:
add_at_pos(pos, win);
assert_window_stacking(term);
return win; return win;
} }

View File

@ -69,13 +69,26 @@ struct terminal {
* are sure what are you doing) to make sure that you don't distribute * are sure what are you doing) to make sure that you don't distribute
* events etc to inactive tabs. * events etc to inactive tabs.
* *
* The stack is top-down, thus .next is the stack's top, the current * The stack is top-down, thus .next is the stack's top, the
* window. .prev is the first tab. * current window; and .prev is the bottom, covered by others.
* - Dialogs or active menus are at the top.
* - Next come all tabs (window.type == WINDOW_TAB). The tab
* created last is at the top, and the tab created first is
* at the bottom; but current_tab controls which tab is
* actually displayed.
* - If the main menu is inactive, then it is at the very bottom,
* hidden under the tabs.
* Call assert_window_stacking to verify this.
* *
* FIXME: Tabs violate the stack nature of this list, they appear there * FIXME: Tabs violate the stack nature of this list, they appear there
* randomly but always in the order in which they were inserted there. * randomly but always in the order in which they were inserted there.
* Eventually, they should all live at the stack bottom, with the * Eventually, they should all live at the stack bottom, with the
* actual tab living on the VERY bottom. --pasky */ * actual tab living on the VERY bottom. --pasky
*
* Keeping the current tab at the very bottom would require storing
* tab numbers explicitly, rather than computing them from the
* stack order as is done now. Also, what should be done with the
* inactive main menu? --KON */
struct list_head windows; /* {struct window} */ struct list_head windows; /* {struct window} */
/* The specification of terminal in terms of terminal options. */ /* The specification of terminal in terms of terminal options. */

View File

@ -6,6 +6,7 @@
#include "elinks.h" #include "elinks.h"
#include "bfu/menu.h"
#include "terminal/event.h" #include "terminal/event.h"
#include "terminal/tab.h" #include "terminal/tab.h"
#include "terminal/terminal.h" #include "terminal/terminal.h"
@ -171,3 +172,25 @@ add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
ewd->called_once = 0; ewd->called_once = 0;
add_window(term, empty_window_handler, ewd); add_window(term, empty_window_handler, ewd);
} }
#if CONFIG_DEBUG
/* Check that term->windows are in the documented order. */
void
assert_window_stacking(struct terminal *term)
{
int prev_type = WINDOW_NORMAL;
const struct window *win;
const struct window *main_menu_win;
/* The main menu can be either above or below the tabs. */
main_menu_win = term->main_menu ? term->main_menu->win : NULL;
foreach (win, term->windows) {
if (win != main_menu_win) {
if (prev_type == WINDOW_TAB)
assert(win->type == WINDOW_TAB);
prev_type = win->type;
}
}
}
#endif /* CONFIG_DEBUG */

View File

@ -56,4 +56,10 @@ void get_parent_ptr(struct window *, int *, int *);
void add_empty_window(struct terminal *, void (*)(void *), void *); void add_empty_window(struct terminal *, void (*)(void *), void *);
#if CONFIG_DEBUG
void assert_window_stacking(struct terminal *);
#else
#define assert_window_stacking(t) ((void) (t))
#endif
#endif #endif