Position tab bar as per new margin options

Also mouse clicking anywhere in the tab bar margins should be the same
as clicking in the tab bar, for ease of use.
This commit is contained in:
Kovid Goyal 2021-06-05 08:43:20 +05:30
parent f3977da8f3
commit caa44b3d4a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 26 additions and 9 deletions

View File

@ -516,7 +516,7 @@ static inline Window*
window_for_event(unsigned int *window_idx, bool *in_tab_bar) {
Region central, tab_bar;
os_window_regions(global_state.callback_os_window, &central, &tab_bar);
*in_tab_bar = mouse_in_region(&tab_bar);
*in_tab_bar = !mouse_in_region(&central);
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++) {

View File

@ -61,12 +61,19 @@ GlobalState global_state = {{0}};
if (wp->id == cb_window_id && cb_window_id) global_state.callback_os_window = wp; \
}}
static inline double
static double
dpi_for_os_window(OSWindow *os_window) {
double dpi = (os_window->logical_dpi_x + os_window->logical_dpi_y) / 2.;
if (dpi == 0) dpi = (global_state.default_dpi.x + global_state.default_dpi.y) / 2.;
return dpi;
}
static double
dpi_for_os_window_id(id_type os_window_id) {
double dpi = 0;
if (os_window_id) {
WITH_OS_WINDOW(os_window_id)
dpi = (os_window->logical_dpi_x + os_window->logical_dpi_y) / 2.;
dpi = dpi_for_os_window(os_window);
END_WITH_OS_WINDOW
}
if (dpi == 0) {
@ -75,6 +82,11 @@ dpi_for_os_window_id(id_type os_window_id) {
return dpi;
}
static long
pt_to_px_for_os_window(double pt, OSWindow *w) {
const double dpi = dpi_for_os_window(w);
return ((long)round((pt * (dpi / 72.0))));
}
static long
pt_to_px(double pt, id_type os_window_id) {
@ -469,20 +481,25 @@ 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 (!OPT(tab_bar_hidden) && os_window->num_tabs >= OPT(tab_bar_min_tabs)) {
long margin_outer = pt_to_px_for_os_window(OPT(tab_bar_margin_height.outer), os_window);
long margin_inner = pt_to_px_for_os_window(OPT(tab_bar_margin_height.inner), os_window);
switch(OPT(tab_bar_edge)) {
case TOP_EDGE:
central->left = 0; central->top = os_window->fonts_data->cell_height; central->right = os_window->viewport_width - 1;
central->left = 0; central->right = os_window->viewport_width - 1;
central->top = os_window->fonts_data->cell_height + margin_inner + margin_outer;
central->bottom = os_window->viewport_height - 1;
tab_bar->left = central->left; tab_bar->right = central->right; tab_bar->top = 0;
tab_bar->bottom = central->top - 1;
central->top = MIN(central->top, central->bottom);
tab_bar->top = margin_outer;
break;
default:
central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1;
central->bottom = os_window->viewport_height - os_window->fonts_data->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;
long bottom = os_window->viewport_height - os_window->fonts_data->cell_height - 1 - margin_inner - margin_outer;
central->bottom = MAX(0, bottom);
tab_bar->top = central->bottom + 1 + margin_inner;
break;
}
tab_bar->left = central->left; tab_bar->right = central->right;
tab_bar->bottom = tab_bar->top + os_window->fonts_data->cell_height - 1;
} else {
zero_at_ptr(tab_bar);
central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1;