click working, closing disabled

This commit is contained in:
WanderingPenwing 2024-08-05 17:28:00 +02:00
parent 9a0c9b6a90
commit 32a73ad977

72
surf.c
View file

@ -150,7 +150,7 @@ typedef struct Client {
GList *tabs; GList *tabs;
guint selected_tab; guint selected_tab;
GtkWidget *tab_bar; GtkWidget *tab_bar;
int tab_click_pos; int tab_click_index;
} Client; } Client;
typedef struct { typedef struct {
@ -557,49 +557,49 @@ int get_font_size(GtkWidget *widget) {
return size; return size;
} }
void tab_bar_mouse_press(GtkWidget *w, GdkEvent *e, Client *c) { int tab_mouse_pos_index(GdkEvent *e, Client *c) {
if (c->tab_click_pos != -1) {
return;
}
GdkEventButton *event_button = (GdkEventButton *)e; GdkEventButton *event_button = (GdkEventButton *)e;
double x = event_button->x;
if (e->type != GDK_BUTTON_PRESS) { GtkAllocation allocation;
g_print("not a press\n"); gtk_widget_get_allocation(GTK_WIDGET(c->win), &allocation);
int width = allocation.width;
int n_tabs = g_list_length(c->tabs);
int tab_width = width / MAX(n_tabs + 1, min_tab_fraction_size);
return (int)(x / tab_width);
}
void tab_bar_mouse_press(GtkWidget *w, GdkEvent *e, Client *c) {
if (c->tab_click_index != -1) {
return; return;
} }
c->tab_click_pos = event_button->x; c->tab_click_index = tab_mouse_pos_index(e, c);
g_print("press\n"); g_print("press\n");
} }
void tab_bar_mouse_release(GtkWidget *w, GdkEvent *e, Client *c) { void tab_bar_mouse_release(GtkWidget *w, GdkEvent *e, Client *c) {
if (c->tab_click_pos == -1) { if (c->tab_click_index == -1) {
return; return;
} }
GdkEventButton *event_button = (GdkEventButton *)e;
double x = event_button->x; // x position in the widgets coordinates int press_index = tab_mouse_pos_index(e, c);
double y = event_button->y; // y position in the widgets coordinates
g_print("Mouse released at position: (%.0f, %.0f)\n", x, y);
if (event_button->type != GDK_BUTTON_RELEASE) { g_print("%i # %i\n", c->tab_click_index, press_index);
g_print("not a release\n"); if (c->tab_click_index == press_index) {
return;
}
g_print("%i # %i\n", c->tab_click_pos, event_button->x_root);
if (ABS(c->tab_click_pos - x) < 10) {
tab_bar_click(c); tab_bar_click(c);
} }
c->tab_click_pos = -1; c->tab_click_index = -1;
} }
void tab_bar_mouse_move(GtkWidget *w, GdkEvent *e, Client *c) { void tab_bar_mouse_move(GtkWidget *w, GdkEvent *e, Client *c) {
if (c->tab_click_pos == -1) { if (c->tab_click_index == -1) {
return; return;
} }
g_print("move\n"); g_print("move\n");
@ -612,33 +612,27 @@ void tab_bar_click(Client *c) {
g_print("click\n"); g_print("click\n");
GtkAllocation allocation;
gtk_widget_get_allocation(GTK_WIDGET(c->win), &allocation);
int width = allocation.width;
int n_tabs = g_list_length(c->tabs); int n_tabs = g_list_length(c->tabs);
int tab_width = width / MAX(n_tabs + 1, min_tab_fraction_size);
int tab_index = (int)(c->tab_click_pos / tab_width);
if (tab_index >= n_tabs) { if (c->tab_click_index >= n_tabs) {
Arg new_tab_arg = {0}; Arg new_tab_arg = {0};
new_tab(c, &new_tab_arg); new_tab(c, &new_tab_arg);
return; return;
} }
int x_width = MIN(get_font_size(c->tab_bar) * 5 / 2, tab_width / 4); // int x_width = MIN(get_font_size(c->tab_bar) * 5 / 2, tab_width / 4);
//
// if (c->tab_click_pos - tab_index * tab_width > tab_width - x_width) {
// Arg close_arg = {.i = tab_index};
// close_tab(c, &close_arg);
// return;
// }
if (c->tab_click_pos - tab_index * tab_width > tab_width - x_width) { if (c->selected_tab == c->tab_click_index) {
Arg close_arg = {.i = tab_index};
close_tab(c, &close_arg);
return; return;
} }
if (c->selected_tab == tab_index) { c->selected_tab = c->tab_click_index;
return;
}
c->selected_tab = tab_index;
update_tab_bar(c); update_tab_bar(c);
suspend_tab(c); suspend_tab(c);
} }
@ -957,7 +951,7 @@ newclient(Client *rc)
add_tab(c, "about:blank"); add_tab(c, "about:blank");
c->selected_tab = 0; c->selected_tab = 0;
c->tab_click_pos = -1; c->tab_click_index = -1;
create_tab_bar(c); create_tab_bar(c);