282 lines
9.1 KiB
C
282 lines
9.1 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) */
|
|
GtkWidget *toolbar; /* #main-toolbar (hamburger + nav + URL) */
|
|
GtkWidget *bookmark_bar; /* bookmarks toolbar (below URL toolbar) */
|
|
GtkWidget *progress_bar; /* thin load-progress bar (below bookmark bar, above webview) */
|
|
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);
|
|
|
|
/*
|
|
* Update the WebKitWebContext that tab_manager_new_tab() and
|
|
* sidebar_create_webview() use to create new webviews. Used during an
|
|
* identity switch: the old context is torn down (after all tabs are
|
|
* closed) and a fresh per-user context is built; this function updates
|
|
* the stored pointer so subsequent new tabs use the new context.
|
|
*
|
|
* The caller MUST have closed all existing tabs and sidebar webviews
|
|
* (which reference the old context) before calling this.
|
|
*/
|
|
void tab_manager_set_context(WebKitWebContext *ctx);
|
|
|
|
/*
|
|
* 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);
|
|
|
|
/*
|
|
* Show the "Open File" dialog and load the chosen local file into the
|
|
* active tab via a file:// URI. The dialog is parented to the focused
|
|
* window. Used by the hamburger-menu "Open File…" item and the Ctrl+O
|
|
* keyboard shortcut. No-op if there is no window or active tab.
|
|
*/
|
|
void tab_manager_open_file(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);
|
|
|
|
/*
|
|
* Destroy the agent chat sidebar webview in every open window (main + aux).
|
|
* The sidebar container itself is kept (it will be re-populated lazily on the
|
|
* next toggle). Used during logout / identity switch so the sidebar — which
|
|
* holds a long-lived WebKitWebView with the previous user's session — does
|
|
* not leak the old identity's sovereign://agents/chat state across users.
|
|
*/
|
|
void tab_manager_destroy_sidebar_webviews(void);
|
|
|
|
/*
|
|
* Temporarily suppress the "last tab closed → quit the app" behavior.
|
|
* Set TRUE before tab_manager_close_all() during an identity switch so
|
|
* the browser does not exit when the previous user's tabs are closed;
|
|
* the caller opens a fresh tab for the new user afterwards. Always
|
|
* reset to FALSE when done so normal quit-on-last-tab-close behavior
|
|
* is restored.
|
|
*/
|
|
void tab_manager_set_suppress_quit_on_last_tab(gboolean suppress);
|
|
|
|
/*
|
|
* 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);
|
|
|
|
/*
|
|
* Toggle visibility of all "menu bars" in the active window: the tab strip
|
|
* (GtkNotebook header), each tab's #main-toolbar, and each tab's bookmark
|
|
* bar. Per-window — only the focused window is affected, mirroring
|
|
* tab_manager_toggle_sidebar(). New tabs opened in a hidden-chrome window
|
|
* inherit the hidden state.
|
|
*/
|
|
void tab_manager_toggle_toolbars(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);
|
|
|
|
/*
|
|
* Returns the main window's GtkNotebook widget. Used by main.c's
|
|
* delete-event handler to identify which tabs belong to the main window
|
|
* (vs auxiliary windows) when closing the main window but keeping aux
|
|
* windows alive.
|
|
*/
|
|
GtkWidget *tab_manager_get_main_notebook(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 */
|