Files
sovereign_browser/src/tab_manager.h
T

223 lines
6.5 KiB
C

/*
* tab_manager.h — multi-tab management for sovereign_browser
*
* Wraps a GtkNotebook and manages per-tab state: each tab has its own
* toolbar (hamburger menu + URL entry) and WebKitWebView. All webviews
* share a single WebKitWebContext so the sovereign:// bridge, security
* settings, and TLS policy apply to every tab.
*/
#ifndef TAB_MANAGER_H
#define TAB_MANAGER_H
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TAB_TITLE_MAX 256
#define TAB_URL_MAX 2048
typedef struct {
WebKitWebView *webview;
GtkWidget *url_entry;
GtkWidget *hamburger;
GtkWidget *page; /* the vertical box (toolbar + webview) */
GtkWidget *tab_label; /* composite label widget for the tab strip */
GtkWidget *title_label; /* child of tab_label */
GtkWidget *favicon; /* favicon image in tab_label */
GtkWidget *refresh_btn; /* toolbar reload/stop button (per-tab) */
gboolean refresh_shows_stop; /* cached visual state, avoids redundant updates */
char current_url[TAB_URL_MAX];
char title[TAB_TITLE_MAX];
} tab_info_t;
/*
* Initialize the tab manager. Creates a GtkNotebook, adds it to parent,
* and stores the shared web context for creating new webviews.
*
* parent: the GtkContainer (typically a GtkBox) to add the notebook to
* ctx: the shared WebKitWebContext for all tabs
* window: the top-level GtkWindow (for menu dialogs, file choosers, etc.)
*/
void tab_manager_init(GtkContainer *parent,
WebKitWebContext *ctx,
GtkWindow *window);
/*
* Create a new tab and load the given URL (or the default new-tab URL
* if url is NULL). Returns the tab index, or -1 on failure (e.g. max
* tabs reached).
*/
int tab_manager_new_tab(const char *url);
/*
* Open the tab at the given index's URL in a new browser window.
* Creates a new top-level GtkWindow with its own notebook and a single
* tab loading the same URL. No-op if the index is out of range.
*/
void tab_manager_open_in_new_window(int index);
/*
* Open a new browser window with a blank tab (or the default new-tab
* URL). Used by the Ctrl+N shortcut.
*/
void tab_manager_new_window_blank(void);
/*
* Close the tab at the given index. If it's the last tab, the window
* destroy handler will fire (caller is responsible for quitting).
*/
void tab_manager_close_tab(int index);
/*
* Close the currently active tab.
*/
void tab_manager_close_active(void);
/*
* Get the index of the currently active tab.
*/
int tab_manager_get_active_index(void);
/*
* Switch to the tab at the given index.
*/
void tab_manager_switch_to(int index);
/*
* Get the tab_info_t for the active tab, or NULL if no tabs exist.
*/
tab_info_t *tab_manager_get_active(void);
/*
* Get the tab_info_t for the tab at the given index, or NULL.
*/
tab_info_t *tab_manager_get(int index);
/*
* Get the number of open tabs.
*/
int tab_manager_count(void);
/*
* Update the title of the tab at the given index. Called from the
* load-changed signal handler when the page title becomes available.
*/
void tab_manager_set_title(int index, const char *title);
/*
* Get the URL of the tab at the given index (for session save).
* Returns NULL if index is out of range.
*/
const char *tab_manager_get_url(int index);
/*
* Cycle to the next tab (wraps around). Used by Ctrl+Tab / Ctrl+PageDown.
*/
void tab_manager_next(void);
/*
* Cycle to the previous tab (wraps around). Used by Ctrl+Shift+Tab /
* Ctrl+PageUp.
*/
void tab_manager_prev(void);
/*
* Close all tabs except the one at the given index.
*/
void tab_manager_close_others(int index);
/*
* Close all tabs to the right of the given index.
*/
void tab_manager_close_to_right(int index);
/*
* Close all open tabs. Closes from the highest index down to 0 so that
* indices remain valid during iteration.
*/
void tab_manager_close_all(void);
/*
* Duplicate the tab at the given index (open a new tab with the same URL).
*/
void tab_manager_duplicate(int index);
/*
* Reload the tab at the given index.
*/
void tab_manager_reload(int index);
/*
* Apply current settings (tab bar position, drag reorder, close buttons).
* Call after settings_change() or at init.
*/
void tab_manager_apply_settings(void);
/*
* Set the user's avatar on the far left of the tab bar. Queries the
* kind 0 profile from SQLite for the picture URL and downloads it
* in a background thread. Falls back to a default icon if no picture
* is available. Call after login (when the pubkey is known).
*
* pubkey_hex — the user's hex pubkey (64 chars, or NULL for default)
*/
void tab_manager_set_avatar(const char *pubkey_hex);
/*
* Toggle the WebKit Web Inspector for the active tab.
* If the inspector is visible, it is closed; otherwise it is shown.
* The inspector's detached window position and size are saved to
* settings and restored on the next show.
*/
void tab_manager_toggle_inspector(void);
/*
* Zoom control for the active tab's webview.
* tab_manager_zoom_in() — multiply zoom by 1.1 (capped at 5.0)
* tab_manager_zoom_out() — multiply zoom by 1/1.1 (floored at 0.25)
* tab_manager_zoom_reset()— set zoom back to 1.0 (100%)
* No-ops if there is no active tab or webview.
*/
void tab_manager_zoom_in(void);
void tab_manager_zoom_out(void);
void tab_manager_zoom_reset(void);
/*
* Toggle the agent chat sidebar for the active window. The sidebar is
* per-window (not per-tab), so it persists across tab switches within a
* window. When showing, if the sidebar webview has not been created yet,
* it is created (sharing the same WebKitWebContext so sovereign:// works)
* and loads sovereign://agents/chat. When hiding, the sidebar container
* is hidden but the webview is kept alive so chat state persists.
*/
void tab_manager_toggle_sidebar(void);
/*
* Returns the main webview (the web page) of the active tab, never the
* sidebar webview. This is used by agent tools so they always operate
* on the web page even when the sidebar is open and focused.
*/
WebKitWebView *tab_manager_get_main_webview(void);
/*
* Returns TRUE if the sidebar is currently visible for the active window.
*/
gboolean tab_manager_sidebar_visible(void);
/*
* Re-hide the sidebar container after gtk_widget_show_all(window).
* Call this in main.c after show_all so the sidebar (which is packed
* in the window-level GtkPaned) doesn't appear on startup.
*/
void tab_manager_hide_sidebar_after_show_all(void);
#ifdef __cplusplus
}
#endif
#endif /* TAB_MANAGER_H */