1 /* Terminal windows stuff. */
10 #include "terminal/event.h"
11 #include "terminal/tab.h"
12 #include "terminal/terminal.h"
13 #include "terminal/window.h"
14 #include "util/error.h"
15 #include "util/memory.h"
19 redraw_from_window(struct window
*win
)
21 struct terminal
*term
= win
->term
;
23 struct window
*end
= (struct window
*) &term
->windows
;
25 if (term
->redrawing
!= TREDRAW_READY
) return;
27 set_redraw_term_event(&ev
, term
->width
, term
->height
);
28 term
->redrawing
= TREDRAW_BUSY
;
29 for (win
= win
->prev
; win
!= end
; win
= win
->prev
) {
30 if (!inactive_tab(win
))
31 win
->handler(win
, &ev
);
33 term
->redrawing
= TREDRAW_READY
;
37 redraw_below_window(struct window
*win
)
39 struct terminal
*term
= win
->term
;
41 struct window
*end
= win
;
42 enum term_redrawing_state saved_redraw_state
= term
->redrawing
;
44 if (term
->redrawing
== TREDRAW_DELAYED
) return;
46 set_redraw_term_event(&ev
, term
->width
, term
->height
);
47 term
->redrawing
= TREDRAW_DELAYED
;
48 for (win
= term
->windows
.prev
; win
!= end
; win
= win
->prev
) {
49 if (!inactive_tab(win
))
50 win
->handler(win
, &ev
);
52 term
->redrawing
= saved_redraw_state
;
56 add_window(struct terminal
*term
, window_handler_T handler
, void *data
)
59 struct window
*win
= mem_calloc(1, sizeof(*win
));
66 win
->handler
= handler
;
67 win
->data
= data
; /* freed later in delete_window() */
69 win
->type
= WINDOW_NORMAL
;
70 add_at_pos((struct window
*) &term
->windows
, win
);
71 set_init_term_event(&ev
, term
->width
, term
->height
);
72 win
->handler(win
, &ev
);
76 delete_window(struct window
*win
)
80 /* Updating the status when destroying tabs needs this before the win
83 set_abort_term_event(&ev
);
84 win
->handler(win
, &ev
);
85 mem_free_if(win
->data
);
86 redraw_terminal(win
->term
);
91 delete_window_ev(struct window
*win
, struct term_event
*ev
)
95 w
= list_has_next(win
->term
->windows
, win
) ? win
->next
: NULL
;
99 if (!ev
|| !w
) return;
101 /* If next is a tab send it to the current tab */
102 if (w
->type
== WINDOW_TAB
) {
103 w
= get_current_tab(w
->term
);
106 if (w
) w
->handler(w
, ev
);
110 get_parent_ptr(struct window
*win
, int *x
, int *y
)
112 struct window
*parent
= win
->next
;
114 if (parent
->type
== WINDOW_TAB
)
115 parent
= get_tab_by_number(win
->term
, win
->term
->current_tab
);
130 unsigned int called_once
:1;
134 empty_window_handler(struct window
*win
, struct term_event
*ev
)
136 struct terminal
*term
= win
->term
;
137 struct ewd
*ewd
= win
->data
;
138 void (*fn
)(void *) = ewd
->fn
;
139 void *data
= ewd
->data
;
141 if (ewd
->called_once
) return;
147 get_parent_ptr(win
, &win
->x
, &win
->y
);
154 /* Silence compiler warnings */
158 ewd
->called_once
= 1;
161 term_send_event(term
, ev
);
165 add_empty_window(struct terminal
*term
, void (*fn
)(void *), void *data
)
167 struct ewd
*ewd
= mem_alloc(sizeof(*ewd
));
172 ewd
->called_once
= 0;
173 add_window(term
, empty_window_handler
, ewd
);
177 /* Check that term->windows are in the documented order. */
179 assert_window_stacking(struct terminal
*term
)
181 enum { WANT_ANY
, WANT_TAB
, WANT_NONE
} want
= WANT_ANY
;
182 const struct window
*win
;
183 const struct window
*main_menu_win
;
185 /* The main menu can be either above or below the tabs. */
186 main_menu_win
= term
->main_menu
? term
->main_menu
->win
: NULL
;
188 foreach (win
, term
->windows
) {
191 if (win
->type
== WINDOW_TAB
)
195 if (win
== main_menu_win
)
198 assert(win
->type
== WINDOW_TAB
);
206 #endif /* CONFIG_DEBUG */