got title

This commit is contained in:
WanderingPenwing 2024-08-03 17:22:38 +02:00
parent a0884da532
commit bb8e7fae34

42
surf.c
View file

@ -187,7 +187,7 @@ typedef struct {
typedef struct { typedef struct {
char *title; char *title;
char *uri; char *url;
} Tab; } Tab;
/* Surf */ /* Surf */
@ -367,15 +367,15 @@ static ParamName loadfinished[] = {
// Function to free a tab // Function to free a tab
void free_tab(Tab *tab) { void free_tab(Tab *tab) {
g_free(tab->title); g_free(tab->title);
g_free(tab->uri); g_free(tab->url);
g_free(tab); g_free(tab);
} }
// Function to add a tab to the clients tab list // Function to add a tab to the clients tab list
void add_tab(Client *client, const gchar *uri) { void add_tab(Client *client, const gchar *url) {
Tab *tab = g_malloc(sizeof(Tab)); Tab *tab = g_malloc(sizeof(Tab));
tab->title = g_strdup("untitled"); tab->title = g_strdup("untitled");
tab->uri = g_strdup(uri); tab->url = g_strdup(url);
client->tabs = g_list_append(client->tabs, tab); client->tabs = g_list_append(client->tabs, tab);
} }
@ -398,22 +398,42 @@ void free_all_tabs(Client *client) {
} }
void tab_bar_click(GtkWidget *w, GdkEvent *e, Client *c) { void tab_bar_click(GtkWidget *w, GdkEvent *e, Client *c) {
g_print("yay"); g_print("yay\n");
} }
void switch_tab(Client *c, const Arg *a) { void switch_tab(Client *c, const Arg *a) {
g_print("switch %i", a->i); g_print("switch %i\n", a->i);
c->selected_tab = MIN(MAX(c->selected_tab + a->i, 0), g_list_length(c->tabs) - 1); c->selected_tab = MIN(MAX(c->selected_tab + a->i, 0), g_list_length(c->tabs) - 1);
update_tab_bar(c); update_tab_bar(c);
} }
void move_tab(Client *c, const Arg *a) { void move_tab(Client *c, const Arg *a) {
g_print("move"); g_print("move\n");
}
void update_tab_url(Client *c) {
char *url = geturi(c);
g_print("updated tab : %c\n", url);
Tab *selected_tab = g_list_nth_data(c->tabs, c->selected_tab);
selected_tab->url = g_strdup(url);
}
void update_tab_title(Client *c) {
const char *title = c->title ? c->title : "untitled";
Tab *selected_tab = g_list_nth_data(c->tabs, c->selected_tab);
selected_tab->title = g_strdup(title);
//update_tab_url(c);
update_tab_bar(c);
} }
void close_tab(Client *c, const Arg *a) { void close_tab(Client *c, const Arg *a) {
if (g_list_length(c->tabs) == 1) { if (g_list_length(c->tabs) == 1) {
g_print("tried to close last tab"); g_print("tried to close last tab\n");
return; return;
} }
remove_tab(c, g_list_nth_data(c->tabs, c->selected_tab)); remove_tab(c, g_list_nth_data(c->tabs, c->selected_tab));
@ -456,7 +476,6 @@ void fill_tab_bar(Client *c) {
} }
void create_tab_bar(Client *c) { void create_tab_bar(Client *c) {
g_print("hello there\n\n");
GdkRGBA bg_color; GdkRGBA bg_color;
gdk_rgba_parse(&bg_color, tab_bar_color[0]); gdk_rgba_parse(&bg_color, tab_bar_color[0]);
@ -765,6 +784,7 @@ loaduri(Client *c, const Arg *a)
setatom(c, AtomUri, url); setatom(c, AtomUri, url);
g_print("load uri\n");
if (strcmp(url, geturi(c)) == 0) { if (strcmp(url, geturi(c)) == 0) {
reload(c, a); reload(c, a);
} else { } else {
@ -839,6 +859,8 @@ updatetitle(Client *c)
} else { } else {
gtk_window_set_title(GTK_WINDOW(c->win), name); gtk_window_set_title(GTK_WINDOW(c->win), name);
} }
update_tab_title(c);
} }
void void
@ -1258,9 +1280,7 @@ destroyclient(Client *c)
p->next = c->next; p->next = c->next;
else else
clients = c->next; clients = c->next;
free_all_tabs(c); free_all_tabs(c);
free(c); free(c);
} }