#include <JavaScriptCore/JavaScript.h>
+static gboolean button_tablabel(GtkWidget *, GdkEvent *, gpointer);
static void client_destroy(GtkWidget *, gpointer);
-static gboolean client_destroy_request(WebKitWebView *, gpointer);
static WebKitWebView *client_new(const gchar *, WebKitWebView *, gboolean);
static WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction *,
gpointer);
static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
static void keywords_load(void);
static gboolean keywords_try_search(WebKitWebView *, const gchar *);
+static void mainwindow_setup(void);
+static void mainwindow_title(gint);
+static void mainwindow_title_before(GtkNotebook *, GtkWidget *, guint, gpointer);
static gboolean menu_web_view(WebKitWebView *, WebKitContextMenu *, GdkEvent *,
WebKitHitTestResult *, gpointer);
static gboolean quit_if_nothing_active(void);
static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
+static void run_user_scripts(WebKitWebView *);
static void search(gpointer, gint);
static void show_web_view(WebKitWebView *, gpointer);
-static Window tabbed_launch(void);
static void trust_user_certs(WebKitWebContext *);
gchar *hover_uri;
gchar *feed_html;
GtkWidget *location;
+ GtkWidget *tablabel;
GtkWidget *vbox;
GtkWidget *web_view;
- GtkWidget *win;
};
+struct MainWindow
+{
+ GtkWidget *win;
+ GtkWidget *notebook;
+} mw;
+
struct DownloadManager
{
GtkWidget *scroll;
static gboolean cooperative_instances = TRUE;
static int cooperative_pipe_fp = 0;
static gchar *download_dir = "/var/tmp";
-static gboolean enable_webgl = FALSE;
static gboolean enable_console_to_stdout = FALSE;
-static Window embed = 0;
static gchar *fifo_suffix = "main";
static gdouble global_zoom = 1.0;
static gchar *history_file = NULL;
static gboolean initial_wc_setup_done = FALSE;
static GHashTable *keywords = NULL;
static gchar *search_text = NULL;
-static gboolean tabbed_automagic = TRUE;
static gchar *user_agent = NULL;
+gboolean
+button_tablabel(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ if (event->type == GDK_BUTTON_RELEASE)
+ {
+ switch (((GdkEventButton *)event)->button)
+ {
+ case 2:
+ client_destroy(NULL, data);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
void
client_destroy(GtkWidget *widget, gpointer data)
{
struct Client *c = (struct Client *)data;
+ gint idx;
g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
changed_load_progress, c);
+ idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
+ if (idx == -1)
+ fprintf(stderr, __NAME__": Tab index was -1, bamboozled\n");
+ else
+ gtk_notebook_remove_page(GTK_NOTEBOOK(mw.notebook), idx);
+
free(c);
clients--;
quit_if_nothing_active();
}
-gboolean
-client_destroy_request(WebKitWebView *web_view, gpointer data)
-{
- struct Client *c = (struct Client *)data;
-
- gtk_widget_destroy(c->win);
-
- return TRUE;
-}
-
WebKitWebView *
client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show)
{
struct Client *c;
WebKitWebContext *wc;
gchar *f;
+ GtkWidget *evbox;
if (uri != NULL && cooperative_instances && !cooperative_alone)
{
exit(EXIT_FAILURE);
}
- if (embed != 0)
- {
- c->win = gtk_plug_new(embed);
- if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
- {
- fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
- gtk_widget_destroy(c->win);
- c->win = NULL;
- embed = 0;
- }
- }
-
- if (c->win == NULL)
- c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
-
- g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
- gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
-
if (related_wv == NULL)
c->web_view = webkit_web_view_new();
else
g_signal_connect(G_OBJECT(c->web_view), "context-menu",
G_CALLBACK(menu_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "close",
- G_CALLBACK(client_destroy_request), c);
+ G_CALLBACK(client_destroy), c);
g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
G_CALLBACK(decide_policy), NULL);
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
if (enable_console_to_stdout)
webkit_settings_set_enable_write_console_messages_to_stdout(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
- if (enable_webgl)
- webkit_settings_set_enable_webgl(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
+ webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
c->location = gtk_entry_new();
g_signal_connect(G_OBJECT(c->location), "key-press-event",
gtk_box_pack_start(GTK_BOX(c->vbox), c->location, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(c->vbox), c->web_view, TRUE, TRUE, 0);
- gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
+ c->tablabel = gtk_label_new(__NAME__);
+ gtk_label_set_ellipsize(GTK_LABEL(c->tablabel), PANGO_ELLIPSIZE_END);
+ gtk_label_set_width_chars(GTK_LABEL(c->tablabel), 20);
+
+ evbox = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(evbox), c->tablabel);
+ g_signal_connect(G_OBJECT(evbox), "button-release-event",
+ G_CALLBACK(button_tablabel), c);
+
+ /* This only shows the event box and the label inside, nothing else.
+ * Needed because the evbox/label is "internal" to the notebook and
+ * not part of the normal "widget tree" (IIUC). */
+ gtk_widget_show_all(evbox);
+
+ gtk_notebook_append_page(GTK_NOTEBOOK(mw.notebook), c->vbox, evbox);
+ gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(mw.notebook), c->vbox, TRUE);
if (show)
show_web_view(NULL, c);
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
grab_feeds, NULL,
grab_feeds_finished, c);
+
+ run_user_scripts(WEBKIT_WEB_VIEW(c->web_view));
}
gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), p);
}
t = t == NULL ? u : t;
t = t[0] == 0 ? u : t;
- gtk_window_set_title(GTK_WINDOW(c->win), t);
+ gtk_label_set_text(GTK_LABEL(c->tablabel), t);
+ mainwindow_title(-1);
}
void
if (e != NULL)
enable_console_to_stdout = TRUE;
- e = g_getenv(__NAME_UPPERCASE__"_ENABLE_EXPERIMENTAL_WEBGL");
- if (e != NULL)
- enable_webgl = TRUE;
-
e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
if (e != NULL)
fifo_suffix = g_strdup(e);
switch (((GdkEventKey *)event)->keyval)
{
case GDK_KEY_q: /* close window (left hand) */
- gtk_widget_destroy(c->win);
+ client_destroy(NULL, c);
return TRUE;
case GDK_KEY_w: /* home (left hand) */
f = ensure_uri_scheme(home_uri);
return ret;
}
+void
+mainwindow_setup(void)
+{
+ mw.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(mw.win), 800, 600);
+ g_signal_connect(G_OBJECT(mw.win), "destroy", gtk_main_quit, NULL);
+ gtk_window_set_title(GTK_WINDOW(mw.win), __NAME__);
+
+ mw.notebook = gtk_notebook_new();
+ gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
+ gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
+ g_signal_connect(G_OBJECT(mw.notebook), "switch-page",
+ G_CALLBACK(mainwindow_title_before), NULL);
+
+ /* XXX Global hotkeys to change tabs are missing */
+}
+
+void
+mainwindow_title_before(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
+{
+ mainwindow_title(idx);
+}
+
+void
+mainwindow_title(gint idx)
+{
+ GtkWidget *child, *evbox, *label;
+ const gchar *text;
+
+ if (idx == -1)
+ {
+ idx = gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook));
+ if (idx == -1)
+ return;
+ }
+
+ child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(mw.notebook), idx);
+ if (child == NULL)
+ return;
+
+ evbox = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child);
+ label = gtk_bin_get_child(GTK_BIN(evbox));
+ text = gtk_label_get_text(GTK_LABEL(label));
+ gtk_window_set_title(GTK_WINDOW(mw.win), text);
+}
+
gboolean
menu_web_view(WebKitWebView *web_view, WebKitContextMenu *menu, GdkEvent *ev,
WebKitHitTestResult *ht, gpointer data)
return TRUE;
}
+void
+run_user_scripts(WebKitWebView *web_view)
+{
+ gchar *base = NULL, *path = NULL, *contents = NULL;
+ const gchar *entry = NULL;
+ GDir *scriptdir = NULL;
+
+ base = g_build_filename(g_get_user_config_dir(), __NAME__, "user-scripts", NULL);
+ scriptdir = g_dir_open(base, 0, NULL);
+ if (scriptdir != NULL)
+ {
+ while ((entry = g_dir_read_name(scriptdir)) != NULL)
+ {
+ path = g_build_filename(base, entry, NULL);
+ if (g_str_has_suffix(path, ".js"))
+ {
+ if (g_file_get_contents(path, &contents, NULL, NULL))
+ {
+ webkit_web_view_run_javascript(web_view, contents, NULL, NULL, NULL);
+ g_free(contents);
+ }
+ }
+ g_free(path);
+ }
+ g_dir_close(scriptdir);
+ }
+
+ g_free(base);
+}
+
void
search(gpointer data, gint direction)
{
show_web_view(WebKitWebView *web_view, gpointer data)
{
struct Client *c = (struct Client *)data;
+ gint idx;
(void)web_view;
- gtk_widget_grab_focus(c->web_view);
- gtk_widget_show_all(c->win);
-}
+ gtk_widget_show_all(mw.win);
-Window
-tabbed_launch(void)
-{
- gint tabbed_stdout;
- GIOChannel *tabbed_stdout_channel;
- GError *err = NULL;
- gchar *output = NULL;
- char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
- Window plug_into;
+ idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
+ if (idx != -1)
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), idx);
- if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
- NULL, NULL, NULL, &tabbed_stdout, NULL,
- &err))
- {
- fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
- g_error_free(err);
- return 0;
- }
-
- tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
- if (tabbed_stdout_channel == NULL)
- {
- fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
- return 0;
- }
- g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
- g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
- if (output == NULL)
- {
- fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
- return 0;
- }
- g_strstrip(output);
- plug_into = strtol(output, NULL, 16);
- g_free(output);
- if (plug_into == 0)
- fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
- return plug_into;
+ gtk_widget_grab_focus(c->web_view);
}
void
grab_environment_configuration();
- while ((opt = getopt(argc, argv, "e:CT")) != -1)
+ while ((opt = getopt(argc, argv, "C")) != -1)
{
switch (opt)
{
- case 'e':
- embed = atol(optarg);
- tabbed_automagic = FALSE;
- break;
case 'C':
cooperative_instances = FALSE;
break;
- case 'T':
- tabbed_automagic = FALSE;
- break;
default:
fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
exit(EXIT_FAILURE);
cooperation_setup();
downloadmanager_setup();
- if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
- embed = tabbed_launch();
+ mainwindow_setup();
if (!cooperative_instances || cooperative_alone)
{