Move window region calculations into one place
This commit is contained in:
parent
b9a14e0e4a
commit
b6188bf436
@ -320,9 +320,19 @@ handle_tab_bar_mouse(int button, int UNUSED modifiers) {
|
||||
call_boss(activate_tab_at, "Kd", global_state.callback_os_window->id, global_state.callback_os_window->mouse_x);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
mouse_in_region(Region *r) {
|
||||
if (r->left == r->right) return false;
|
||||
if (global_state.callback_os_window->mouse_y < r->top || global_state.callback_os_window->mouse_y > r->bottom) return false;
|
||||
if (global_state.callback_os_window->mouse_x < r->left || global_state.callback_os_window->mouse_x > r->right) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline Window*
|
||||
window_for_event(unsigned int *window_idx, bool *in_tab_bar) {
|
||||
*in_tab_bar = global_state.callback_os_window->num_tabs > 1 && global_state.callback_os_window->mouse_y >= global_state.callback_os_window->viewport_height - global_state.cell_height;
|
||||
Region central, tab_bar;
|
||||
os_window_regions(global_state.callback_os_window, ¢ral, &tab_bar);
|
||||
*in_tab_bar = mouse_in_region(&tab_bar);
|
||||
if (!*in_tab_bar && global_state.callback_os_window->num_tabs > 0) {
|
||||
Tab *t = global_state.callback_os_window->tabs + global_state.callback_os_window->active_tab;
|
||||
for (unsigned int i = 0; i < t->num_windows; i++) {
|
||||
|
||||
@ -242,6 +242,21 @@ add_borders_rect(id_type os_window_id, id_type tab_id, uint32_t left, uint32_t t
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
os_window_regions(OSWindow *os_window, Region *central, Region *tab_bar) {
|
||||
if (os_window->num_tabs > 1) {
|
||||
central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1;
|
||||
central->bottom = os_window->viewport_height - global_state.cell_height - 1;
|
||||
tab_bar->left = central->left; tab_bar->right = central->right; tab_bar->top = central->bottom + 1;
|
||||
tab_bar->bottom = os_window->viewport_height - 1;
|
||||
} else {
|
||||
memset(tab_bar, 0, sizeof(Region));
|
||||
central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1;
|
||||
central->bottom = os_window->viewport_height - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Python API {{{
|
||||
#define PYWRAP0(name) static PyObject* py##name(PyObject UNUSED *self)
|
||||
#define PYWRAP1(name) static PyObject* py##name(PyObject UNUSED *self, PyObject *args)
|
||||
|
||||
@ -160,6 +160,7 @@ void set_os_window_title(OSWindow *w, const char *title);
|
||||
OSWindow* os_window_for_kitty_window(id_type);
|
||||
OSWindow* add_os_window();
|
||||
OSWindow* current_os_window();
|
||||
void os_window_regions(OSWindow*, Region *main, Region *tab_bar);
|
||||
bool drag_scroll(Window *, OSWindow*);
|
||||
void draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_buf, bool rect_data_is_dirty, uint32_t viewport_width, uint32_t viewport_height);
|
||||
ssize_t create_cell_vao();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user