X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=uzbl.c;h=c224f09f2206c525d493a5e55542704e85ab28c0;hb=f5ce2e1ee873036f1c4ff034c8d4dcb9f68c6f6e;hp=5449ee683e20fd88f443146fbe20f9e2f48e0ef5;hpb=3d7c01cb4997f6d08ab01d831f5536582d35f0c1;p=uzbl-mobile diff --git a/uzbl.c b/uzbl.c index 5449ee6..c224f09 100644 --- a/uzbl.c +++ b/uzbl.c @@ -29,11 +29,11 @@ */ -#define LENGTH(x) (sizeof x / sizeof x[0]) -#define GDK_Escape 0xff1b +#define LENGTH(x) (sizeof x / sizeof x[0]) #include #include +#include #include #include #include @@ -51,7 +51,6 @@ static WebKitWebView* web_view; static gchar* main_title; static gchar selected_url[500]; static gint load_progress; -static guint status_context_id; static Window xwin = 0; static char fifopath[64]; @@ -69,10 +68,9 @@ static gboolean show_status = FALSE; static gboolean insert_mode = FALSE; static gboolean status_top = FALSE; static gchar* modkey = NULL; +static guint modmask = 0; - -typedef struct -{ +typedef struct { const char *binding; const char *action; } Binding; @@ -91,7 +89,7 @@ static GOptionEntry entries[] = { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", NULL }, - { NULL } + { NULL, 0, 0, 0, NULL, NULL, NULL } }; /* for internal list of commands */ @@ -99,7 +97,7 @@ typedef struct { const char *command; void (*func_1_param)(WebKitWebView*); - void (*func_2_params)(WebKitWebView*, char *); + void (*func_2_params)(WebKitWebView*, const gchar *); } Command; @@ -112,17 +110,20 @@ run_command(const char *command, const char *args); /* --- CALLBACKS --- */ static void -go_back_cb (GtkWidget* widget, gpointer data) { +go_back_cb (WebKitWebView* page) { + (void) page; webkit_web_view_go_back (web_view); } static void -go_forward_cb (GtkWidget* widget, gpointer data) { +go_forward_cb (WebKitWebView* page) { + (void) page; webkit_web_view_go_forward (web_view); } static void -toggle_status_cb() { +toggle_status_cb (WebKitWebView* page) { + (void) page; if (show_status) { gtk_widget_hide(mainbar); } else { @@ -134,12 +135,9 @@ toggle_status_cb() { static void link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) { - /* underflow is allowed */ - //gtk_statusbar_pop (main_statusbar, status_context_id); - //if (link) - // gtk_statusbar_push (main_statusbar, status_context_id, link); - //TODO implementation roadmap pending.. - + (void) page; + (void) title; + (void) data; //ADD HOVER URL TO WINDOW TITLE selected_url[0] = '\0'; if (link) { @@ -150,6 +148,9 @@ link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpoin static void title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data) { + (void) web_view; + (void) web_frame; + (void) data; if (main_title) g_free (main_title); main_title = g_strdup (title); @@ -158,17 +159,23 @@ title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar static void progress_change_cb (WebKitWebView* page, gint progress, gpointer data) { + (void) page; + (void) data; load_progress = progress; update_title (GTK_WINDOW (main_window)); } static void load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { + (void) page; + (void) data; strcpy (uri, webkit_web_frame_get_uri (frame)); } static void destroy_cb (GtkWidget* widget, gpointer data) { + (void) widget; + (void) data; gtk_main_quit (); } @@ -222,17 +229,19 @@ run_command(const char *command, const char *args) { GString* to_execute = g_string_new (""); gboolean result; g_string_printf (to_execute, "%s '%s' '%i' '%i' '%s' %s", command, config_file, (int) getpid() , (int) xwin, "/tmp/uzbl_25165827", args); - result = system(to_execute->str); + result = g_spawn_command_line_async (to_execute->str, NULL); printf("Called %s. Result: %s\n", to_execute->str, (result ? "FALSE" : "TRUE" )); return result; } static void -parse_command(const char *command) { - int i; +parse_command(const char *cmd) { + unsigned int i; Command *c = NULL; - char * command_name = strtok (command, " "); - char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work + char buffer[200]; + strcpy(buffer,cmd); + char * command_name = strtok (buffer, " "); + char * command_param = strtok (NULL, " ,"); Command *c_tmp = NULL; for (i = 0; i < LENGTH (commands); i++) { @@ -259,7 +268,7 @@ parse_command(const char *command) { c->func_1_param (web_view); } } else { - fprintf (stderr, "command \"%s\" not understood. ignoring.\n", command); + fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd); } } @@ -325,7 +334,7 @@ update_title (GtkWindow* window) { if (show_status) { gtk_window_set_title (window, title_short); - gtk_label_set_text(mainbar_label, title_long); + gtk_label_set_text(GTK_LABEL(mainbar_label), title_long); } else { gtk_window_set_title (window, title_long); } @@ -337,34 +346,39 @@ update_title (GtkWindow* window) { static gboolean key_press_cb (WebKitWebView* page, GdkEventKey* event) { + (void) page; int i; gboolean result=FALSE; //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further. if (event->type != GDK_KEY_PRESS) return result; - //TURN OFF INSERT MODE - if (insert_mode && (event->keyval == GDK_Escape)) { - insert_mode = FALSE; + //TURN OFF/ON INSERT MODE + if (!always_insert_mode && ((insert_mode && (event->keyval == GDK_Escape)) || (!insert_mode && (event->string[0] == 'i')))) { + insert_mode = !insert_mode; update_title (GTK_WINDOW (main_window)); return TRUE; } - //TURN ON INSERT MODE - if (!insert_mode && (event->string[0] == 'i')) { - insert_mode = TRUE; - update_title (GTK_WINDOW (main_window)); - return TRUE; + //INTERNAL BINDINGS + for (i = 0; i < num_internal_bindings; i++) { + if (strcmp(event->string, internal_bindings[i].binding) == 0) { + if (!insert_mode || (event->state == modmask)) { + parse_command (internal_bindings[i].action); + result = TRUE; + } + } } - //INTERNAL KEYS - if (always_insert_mode || !insert_mode) { - for (i = 0; i < num_internal_bindings; i++) { - if (event->string[0] == internal_bindings[i].binding[0]) { - parse_command (internal_bindings[i].action); + //EXTERNAL BINDINGS + for (i = 0; i < num_external_bindings; i++) { + if (strcmp(event->string, external_bindings[i].binding) == 0) { + if (!insert_mode || (event->state == modmask)) { + run_command(external_bindings[i].action, NULL); result = TRUE; - } - } + } + } } + if (!result) result = (insert_mode ? FALSE : TRUE); @@ -393,8 +407,8 @@ static GtkWidget* create_mainbar () { mainbar = gtk_hbox_new (FALSE, 0); mainbar_label = gtk_label_new (""); - gtk_misc_set_alignment (mainbar_label, 0, 0); - gtk_misc_set_padding (mainbar_label, 2, 2); + gtk_misc_set_alignment (GTK_MISC(mainbar_label), 0, 0); + gtk_misc_set_padding (GTK_MISC(mainbar_label), 2, 2); gtk_box_pack_start (GTK_BOX (mainbar), mainbar_label, TRUE, TRUE, 0); return mainbar; } @@ -437,7 +451,7 @@ settings_init () { strcat (conf, "/uzbl"); if (file_exists (conf)) { printf ("Config file %s found.\n", conf); - config_file = &conf; + config_file = &conf[0]; } } } @@ -494,8 +508,28 @@ settings_init () { if (modkey) { printf ("Modkey: %s\n", modkey); } else { - printf ("Modkey disabled\n"); + printf ("Modkey disabled\n"); + modkey = ""; } + //POSSIBLE MODKEY VALUES (COMBINATIONS CAN BE USED) + gchar* modkeyup = g_utf8_strup(modkey, -1); + if (g_strrstr(modkeyup,"SHIFT") != NULL) modmask |= GDK_SHIFT_MASK; //the Shift key. + if (g_strrstr(modkeyup,"LOCK") != NULL) modmask |= GDK_LOCK_MASK; //a Lock key (depending on the modifier mapping of the X server this may either be CapsLock or ShiftLock). + if (g_strrstr(modkeyup,"CONTROL") != NULL) modmask |= GDK_CONTROL_MASK; //the Control key. + if (g_strrstr(modkeyup,"MOD1") != NULL) modmask |= GDK_MOD1_MASK; //the fourth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier, but normally it is the Alt key). + if (g_strrstr(modkeyup,"MOD2") != NULL) modmask |= GDK_MOD2_MASK; //the fifth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"MOD3") != NULL) modmask |= GDK_MOD3_MASK; //the sixth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"MOD4") != NULL) modmask |= GDK_MOD4_MASK; //the seventh modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"MOD5") != NULL) modmask |= GDK_MOD5_MASK; //the eighth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"BUTTON1") != NULL) modmask |= GDK_BUTTON1_MASK; //the first mouse button. + if (g_strrstr(modkeyup,"BUTTON2") != NULL) modmask |= GDK_BUTTON2_MASK; //the second mouse button. + if (g_strrstr(modkeyup,"BUTTON3") != NULL) modmask |= GDK_BUTTON3_MASK; //the third mouse button. + if (g_strrstr(modkeyup,"BUTTON4") != NULL) modmask |= GDK_BUTTON4_MASK; //the fourth mouse button. + if (g_strrstr(modkeyup,"BUTTON5") != NULL) modmask |= GDK_BUTTON5_MASK; //the fifth mouse button. + if (g_strrstr(modkeyup,"SUPER") != NULL) modmask |= GDK_SUPER_MASK; //the Super modifier. Since 2.10 + if (g_strrstr(modkeyup,"HYPER") != NULL) modmask |= GDK_HYPER_MASK; //the Hyper modifier. Since 2.10 + if (g_strrstr(modkeyup,"META") != NULL) modmask |= GDK_META_MASK; //the Meta modifier. Since 2.10 */ + free (modkeyup); if (keysi) { int i = 0;