roundabout,
created on Monday, 23 June 2025, 15:08:44 (1750691324),
received on Monday, 23 June 2025, 15:08:46 (1750691326)
Author identity: vlad <vlad.muntoiu@gmail.com>
9871e2a5d58098f4f92113ee1ae76211396746ef
panthera-www.cc
@@ -279,7 +279,6 @@ private:
std::vector<SearchEngine> search_engines;
SearchEngine* default_search_engine;
std::shared_ptr<HistoryManager> history_manager;
HistoryViewer* history_viewer;
Glib::RefPtr<Gio::Menu> main_menu;
std::string new_tab_page;
@@ -309,6 +308,8 @@ class PantheraWindow : public Gtk::ApplicationWindow {
private:
std::shared_ptr<gPanthera::LayoutManager> layout_manager;
Gtk::Entry *url_bar;
HistoryViewer *history_viewer;
gPanthera::ContentPage *controlled_page = nullptr;
public:
friend class PantheraWww;
explicit PantheraWindow(Glib::RefPtr<Gtk::Application> const &application) : Gtk::ApplicationWindow(application) {
@@ -395,13 +396,12 @@ public:
url_bar->set_placeholder_text("Enter URL");
url_bar->set_hexpand(true);
auto load_url_callback = [this, panthera]() {
auto page = panthera->content_manager->get_last_operated_page();
bool has_protocol = url_bar->get_text().find("://") != std::string::npos;
if(!has_protocol) {
url_bar->set_text("http://" + url_bar->get_text());
}
if(page) {
if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) {
if(controlled_page) {
if(auto webview = WEBKIT_WEB_VIEW(controlled_page->get_child()->get_first_child()->gobj())) {
webkit_web_view_load_uri(webview, url_bar->get_text().c_str());
}
}
@@ -417,6 +417,11 @@ public:
if(!page->get_child()->get_first_child()) {
return;
}
if(page->get_root() != this) {
// The page is in some other window
return;
}
controlled_page = page;
url_bar->set_text(webkit_web_view_get_uri(WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())));
guint url_update_handler = g_signal_connect(page->get_child()->get_first_child()->gobj(), "notify", G_CALLBACK(panthera->notify_focused_callback), this);
std::shared_ptr<sigc::connection> control_signal_handler = std::make_shared<sigc::connection>();
@@ -429,9 +434,8 @@ public:
}
});
});
panthera->history_manager = std::make_shared<HistoryManager>("history.db");
panthera->history_viewer = Gtk::make_managed<HistoryViewer>(layout_manager, panthera->history_manager);
panthera->history_viewer->signal_open_url.connect([this, panthera](const std::string &url) {
history_viewer = Gtk::make_managed<HistoryViewer>(layout_manager, panthera->history_manager);
history_viewer->signal_open_url.connect([this, panthera](const std::string &url) {
panthera->on_new_tab(nullptr, url, true);
});
// Back, forward, reload
@@ -445,25 +449,22 @@ public:
reload_button->set_child(*Gtk::make_managed<Gtk::Image>(Gio::Icon::create("view-refresh-symbolic")));
reload_button->set_tooltip_text("Reload");
back_button->signal_clicked().connect([this, panthera]() {
auto page = panthera->content_manager->get_last_operated_page();
if(page) {
if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) {
if(controlled_page) {
if(auto webview = WEBKIT_WEB_VIEW(controlled_page->get_child()->get_first_child()->gobj())) {
webkit_web_view_go_back(webview);
}
}
});
forward_button->signal_clicked().connect([this, panthera]() {
auto page = panthera->content_manager->get_last_operated_page();
if(page) {
if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) {
if(controlled_page) {
if(auto webview = WEBKIT_WEB_VIEW(controlled_page->get_child()->get_first_child()->gobj())) {
webkit_web_view_go_forward(webview);
}
}
});
reload_button->signal_clicked().connect([this, panthera]() {
auto page = panthera->content_manager->get_last_operated_page();
if(page) {
if(auto webview = WEBKIT_WEB_VIEW(page->get_child()->get_first_child()->gobj())) {
if(controlled_page) {
if(auto webview = WEBKIT_WEB_VIEW(controlled_page->get_child()->get_first_child()->gobj())) {
webkit_web_view_reload(webview);
}
}
@@ -529,7 +530,7 @@ public:
layout_file_in.close();
dock_stack_1->add_pane(*pane_1);
dock_stack_1->add_pane(*panthera->history_viewer);
dock_stack_1->add_pane(*history_viewer);
std::ofstream layout_file_out("layout.json");
layout_file_out << layout_manager->get_layout_as_json();
@@ -555,9 +556,7 @@ void PantheraWww::load_change_callback(WebKitWebView *object, WebKitLoadEvent lo
self->history_manager->log_url(webkit_web_view_get_uri(WEBKIT_WEB_VIEW(object)),
webkit_web_view_get_title(WEBKIT_WEB_VIEW(object)));
}
if(self->history_viewer->get_visible()) {
self->history_viewer->reload_history();
}
// TODO: reload visible history viewers
}
}
}
@@ -753,6 +752,7 @@ void PantheraWww::on_startup() {
plugin_file_out << empty_json.dump(4);
plugin_file_out.close();
}
history_manager = std::make_shared<HistoryManager>("history.db");
// Known bug <https://gitlab.gnome.org/GNOME/epiphany/-/issues/2714>:
// JS can't veto the application's accelerators using `preventDefault()`. This is
@@ -780,7 +780,18 @@ void PantheraWww::on_startup() {
add_action(close_tab_action);
set_accels_for_action("app.close_tab", {"<Primary>W"});
file_menu->append("Close tab", "app.close_tab");
// New window
auto new_window_action = Gio::SimpleAction::create("new_window");
new_window_action->signal_activate().connect([this](const Glib::VariantBase&) {
auto window = make_window();
window->present();
});
add_action(new_window_action);
set_accels_for_action("app.new_window", {"<Primary>N"});
file_menu->append("New window", "app.new_window");
main_menu->append_submenu("File", file_menu);
set_menubar(main_menu);
}