#pragma once #include "browser_client.h" #include "input_handler.h" #include "include/cef_browser.h" #include "include/cef_client.h" #include "include/cef_request_context.h" #include #include // Owns one BrowserClient per tab. The "active" tab is the only one that // renders to /dev/fb0 and receives keyboard/mouse input. main() keeps a // CefRefPtr ref (bound via bindActiveRef) that always points // at the active tab, so the rest of main() is unchanged. class TabManager : public TabController { public: TabManager() = default; ~TabManager() = default; void init(int width, int height, int cell_width, int cell_height, GraphicsBackend backend, int fb_offset_x, int fb_offset_y, CefRefPtr request_context, bool tiled, bool show_logs); // Bind external state that must follow the active tab. void bindActiveRef(CefRefPtr *ref) { active_ref_ = ref; } void bindInputHandler(InputHandler *ih) { input_handler_ = ih; } void createTab(const std::string &url); void closeActiveTab(); void closeAll(); void next(); void prev(); void switchTo(int idx); // TabController implementation (wired to the input handler). void tabNew() override; void tabClose() override; void tabNext() override; void tabPrev() override; void setDefaultUrl(const std::string &u) { default_url_ = u; } BrowserClient *activeClient() const { return (active_ >= 0 && (size_t)active_ < tabs_.size()) ? tabs_[active_].get() : nullptr; } int count() const { return (int)tabs_.size(); } // Called by BrowserClient::OnBeforeClose. void onTabClosed(BrowserClient *client); // Apply a terminal resize to every tab (so switching shows correct sizes). void resizeAll(int width, int height, int cell_width, int cell_height, int fb_offset_x, int fb_offset_y); private: void applyActive(); std::vector> tabs_; int active_ = -1; CefRefPtr *active_ref_ = nullptr; InputHandler *input_handler_ = nullptr; CefRefPtr request_context_; int width_ = 0, height_ = 0, cell_width_ = 0, cell_height_ = 0; GraphicsBackend backend_ = GraphicsBackend::Framebuffer; int fb_offset_x_ = 0, fb_offset_y_ = 0; bool tiled_ = false; bool show_logs_ = false; std::string default_url_; };