diff options
Diffstat (limited to 'src/uzbl-core.c')
-rw-r--r-- | src/uzbl-core.c | 110 |
1 files changed, 44 insertions, 66 deletions
diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 1e3bed3..770d832 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -246,7 +246,7 @@ expand(const char* s, guint recurse) { void clean_up(void) { if (uzbl.info.pid_str) { - send_event (INSTANCE_EXIT, NULL, TYPE_INT, getpid(), NULL); + send_event (INSTANCE_EXIT, NULL, TYPE_INT, uzbl.info.pid, NULL); g_free(uzbl.info.pid_str); uzbl.info.pid_str = NULL; } @@ -331,11 +331,15 @@ scroll(GtkAdjustment* bar, gchar *amount_str) { if (*end == '%') value += page_size * amount * 0.01; + else if (*end == '!') + value = amount; else value += amount; max_value = gtk_adjustment_get_upper(bar) - page_size; + if (value < 0) + value = 0; /* don't scroll past the beginning of the page */ if (value > max_value) value = max_value; /* don't scroll past the end of the page */ @@ -617,23 +621,16 @@ run_parsed_command(const CommandInfo *c, GArray *a, GString *result) { if(strcmp("set", c->key) && strcmp("event", c->key) && strcmp("request", c->key)) { - GString *param = g_string_new(""); - const gchar *p; - guint i = 0; - while ((p = argv_idx(a, i++))) { - g_string_append (param, " '"); - append_escaped (param, p); - g_string_append_c (param, '\''); - } + Event *event = format_event (COMMAND_EXECUTED, NULL, + TYPE_NAME, c->key, + TYPE_STR_ARRAY, a, + NULL); - /* might be destructive on array a */ + /* might be destructive on array a */ c->function(uzbl.gui.web_view, a, result); - send_event(COMMAND_EXECUTED, NULL, - TYPE_NAME, c->key, - TYPE_FORMATTEDSTR, param->str, - NULL); - g_string_free(param, TRUE); + send_formatted_event (event); + event_free (event); } else c->function(uzbl.gui.web_view, a, result); @@ -729,7 +726,7 @@ update_title(void) { const gchar *title_format = b->title_format_long; /* Update the status bar if shown */ - if (b->show_status) { + if (get_show_status()) { title_format = b->title_format_short; gchar *parsed = expand(b->status_format, 0); @@ -799,7 +796,6 @@ create_window() { GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); - gtk_widget_set_name (window, "Uzbl"); gtk_window_set_title(GTK_WINDOW(window), "Uzbl"); #if GTK_CHECK_VERSION(3,0,0) @@ -912,21 +908,6 @@ void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *au } } -void -retrieve_geometry() { - int w, h, x, y; - GString *buf = g_string_new(""); - - gtk_window_get_size(GTK_WINDOW(uzbl.gui.main_window), &w, &h); - gtk_window_get_position(GTK_WINDOW(uzbl.gui.main_window), &x, &y); - - g_string_printf(buf, "%dx%d+%d+%d", w, h, x, y); - - if(uzbl.gui.geometry) - g_free(uzbl.gui.geometry); - uzbl.gui.geometry = g_string_free(buf, FALSE); -} - /* Set up gtk, gobject, variable defaults and other things that tests and other * external applications need to do anyhow */ void @@ -964,9 +945,10 @@ initialize(int argc, char** argv) { if (uzbl.state.socket_id || uzbl.state.embed) uzbl.state.plug_mode = TRUE; +#if !GLIB_CHECK_VERSION(2, 31, 0) if (!g_thread_supported()) g_thread_init(NULL); - +#endif /* TODO: move the handler setup to event_buffer_timeout and disarm the * handler in empty_event_buffer? */ @@ -1011,7 +993,13 @@ initialize(int argc, char** argv) { create_scrolled_win(); /* pack the window and the status bar */ + +#if GTK_CHECK_VERSION(3,0,0) + uzbl.gui.vbox = gtk_box_new(FALSE, 0); + gtk_orientable_set_orientation(GTK_ORIENTABLE(uzbl.gui.vbox), GTK_ORIENTATION_VERTICAL); +#else uzbl.gui.vbox = gtk_vbox_new(FALSE, 0); +#endif gtk_box_pack_start(GTK_BOX(uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(uzbl.gui.vbox), uzbl.gui.status_bar, FALSE, TRUE, 0); @@ -1022,30 +1010,28 @@ initialize(int argc, char** argv) { /** -- MAIN -- **/ int main (int argc, char* argv[]) { + Window xwin; + initialize(argc, argv); - /* Embedded mode */ if (uzbl.state.plug_mode) { + /* Embedded mode */ uzbl.gui.plug = create_plug(); + gtk_widget_set_name (GTK_WIDGET(uzbl.gui.plug), "Uzbl"); gtk_container_add (GTK_CONTAINER (uzbl.gui.plug), uzbl.gui.vbox); - /* in xembed mode the window has no unique id and thus - * socket/fifo names aren't unique either. - * we use a custom randomizer to create a random id - */ - struct timeval tv; - gettimeofday(&tv, NULL); - srand((unsigned int)tv.tv_sec*tv.tv_usec); - uzbl.xwin = rand(); - } - - /* Windowed mode */ - else { + } else { + /* Windowed mode */ uzbl.gui.main_window = create_window(); + gtk_widget_set_name (uzbl.gui.main_window, "Uzbl"); gtk_container_add (GTK_CONTAINER (uzbl.gui.main_window), uzbl.gui.vbox); + /* We need to ensure there is a window, before we can get XID */ gtk_widget_realize (GTK_WIDGET (uzbl.gui.main_window)); + xwin = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (uzbl.gui.main_window))); - uzbl.xwin = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (uzbl.gui.main_window))); + gchar *xwin_str = g_strdup_printf("%d", (int)xwin); + g_setenv("UZBL_XID", xwin_str, TRUE); + g_free(xwin_str); gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view)); } @@ -1064,17 +1050,14 @@ main (int argc, char* argv[]) { "signal::changed", (GCallback)scroll_horiz_cb, NULL, NULL); - gchar *xwin = g_strdup_printf("%d", (int)uzbl.xwin); - g_setenv("UZBL_XID", xwin, TRUE); + uzbl.info.pid = getpid(); + uzbl.info.pid_str = g_strdup_printf("%d", uzbl.info.pid); + g_setenv("UZBL_PID", uzbl.info.pid_str, TRUE); if(!uzbl.state.instance_name) - uzbl.state.instance_name = g_strdup(xwin); - - g_free(xwin); + uzbl.state.instance_name = uzbl.info.pid_str; - uzbl.info.pid_str = g_strdup_printf("%d", getpid()); - g_setenv("UZBL_PID", uzbl.info.pid_str, TRUE); - send_event(INSTANCE_START, NULL, TYPE_INT, getpid(), NULL); + send_event(INSTANCE_START, NULL, TYPE_INT, uzbl.info.pid, NULL); if (uzbl.state.plug_mode) { send_event(PLUG_CREATED, NULL, TYPE_INT, gtk_plug_get_id (uzbl.gui.plug), NULL); @@ -1084,11 +1067,10 @@ main (int argc, char* argv[]) { builtins(); /* Check uzbl is in window mode before getting/setting geometry */ - if (uzbl.gui.main_window) { - if (uzbl.gui.geometry) - set_geometry(); - else - retrieve_geometry(); + if (uzbl.gui.main_window && uzbl.gui.geometry) { + gchar *geometry = g_strdup(uzbl.gui.geometry); + set_geometry(geometry); + g_free(geometry); } gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL); @@ -1101,10 +1083,7 @@ main (int argc, char* argv[]) { settings_init(); /* Update status bar */ - if (!uzbl.behave.show_status) - gtk_widget_hide(uzbl.gui.status_bar); - else - update_title(); + update_title(); /* WebInspector */ set_up_inspector(); @@ -1131,13 +1110,12 @@ main (int argc, char* argv[]) { if (uzbl.state.socket_id) printf("plug_id %i\n", (int)gtk_plug_get_id(uzbl.gui.plug)); else - printf("window_id %i\n",(int) uzbl.xwin); + printf("window_id %i\n",(int) xwin); printf("pid %i\n", getpid ()); printf("name: %s\n", uzbl.state.instance_name); printf("commit: %s\n", uzbl.info.commit); } - gtk_main(); /* Cleanup and exit*/ |