applied patch from arg. thanks :)

This commit is contained in:
Enno Boland (tox) 2009-09-17 01:09:00 +02:00
parent d2a4436123
commit 25b9ae3ce4
2 changed files with 57 additions and 67 deletions

View File

@ -4,29 +4,29 @@ static gchar *progress_trust = "#00FF00";
#define MODKEY GDK_CONTROL_MASK #define MODKEY GDK_CONTROL_MASK
static Key keys[] = { static Key keys[] = {
/* modifier keyval function arg Focus */ /* modifier keyval function arg Focus */
{ MODKEY|GDK_SHIFT_MASK,GDK_r, reload, { .b = TRUE }, ALWAYS }, { MODKEY|GDK_SHIFT_MASK,GDK_r, reload, { .b = TRUE }, Any },
{ MODKEY, GDK_r, reload, { .b = FALSE }, ALWAYS }, { MODKEY, GDK_r, reload, { .b = FALSE }, Any },
{ MODKEY, GDK_g, showurl, { 0 }, ALWAYS }, { MODKEY, GDK_g, showurl, { 0 }, Any },
{ MODKEY, GDK_slash, showsearch, { 0 }, ALWAYS }, { MODKEY, GDK_slash, showsearch, { 0 }, Any },
{ 0, GDK_Escape, hidesearch, { 0 }, ALWAYS }, { 0, GDK_Escape, hidesearch, { 0 }, Any },
{ 0, GDK_Escape, hideurl, { 0 }, ALWAYS }, { 0, GDK_Escape, hideurl, { 0 }, Any },
{ MODKEY|GDK_SHIFT_MASK,GDK_p, print, { 0 }, ALWAYS }, { MODKEY|GDK_SHIFT_MASK,GDK_p, print, { 0 }, Any },
{ MODKEY, GDK_p, clipboard, { .b = TRUE }, BROWSER }, { MODKEY, GDK_p, clipboard, { .b = TRUE }, Browser },
{ MODKEY, GDK_y, clipboard, { .b = FALSE }, BROWSER }, { MODKEY, GDK_y, clipboard, { .b = FALSE }, Browser },
{ MODKEY|GDK_SHIFT_MASK,GDK_j, zoom, { .i = -1 }, BROWSER }, { MODKEY|GDK_SHIFT_MASK,GDK_j, zoom, { .i = -1 }, Browser },
{ MODKEY|GDK_SHIFT_MASK,GDK_k, zoom, { .i = +1 }, BROWSER }, { MODKEY|GDK_SHIFT_MASK,GDK_k, zoom, { .i = +1 }, Browser },
{ MODKEY|GDK_SHIFT_MASK,GDK_i, zoom, { .i = 0 }, BROWSER }, { MODKEY|GDK_SHIFT_MASK,GDK_i, zoom, { .i = 0 }, Browser },
{ MODKEY, GDK_l, navigate, { .i = +1 }, BROWSER }, { MODKEY, GDK_l, navigate, { .i = +1 }, Browser },
{ MODKEY, GDK_h, navigate, { .i = -1 }, BROWSER }, { MODKEY, GDK_h, navigate, { .i = -1 }, Browser },
{ MODKEY, GDK_j, scroll, { .i = +1 }, BROWSER }, { MODKEY, GDK_j, scroll, { .i = +1 }, Browser },
{ MODKEY, GDK_k, scroll, { .i = -1 }, BROWSER }, { MODKEY, GDK_k, scroll, { .i = -1 }, Browser },
{ 0, GDK_Escape, stop, { 0 }, BROWSER }, { 0, GDK_Escape, stop, { 0 }, Browser },
{ MODKEY, GDK_o, source, { 0 }, BROWSER }, { MODKEY, GDK_o, source, { 0 }, Browser },
{ MODKEY, GDK_n, searchtext, { .b = TRUE }, BROWSER|SEARCHBAR }, { MODKEY, GDK_n, searchtext, { .b = TRUE }, Browser|SearchBar },
{ MODKEY|GDK_SHIFT_MASK,GDK_n, searchtext, { .b = FALSE }, BROWSER|SEARCHBAR }, { MODKEY|GDK_SHIFT_MASK,GDK_n, searchtext, { .b = FALSE }, Browser|SearchBar },
{ 0, GDK_Return, searchtext, { .b = TRUE }, SEARCHBAR }, { 0, GDK_Return, searchtext, { .b = TRUE }, SearchBar },
{ GDK_SHIFT_MASK, GDK_Return, searchtext, { .b = FALSE }, SEARCHBAR }, { GDK_SHIFT_MASK, GDK_Return, searchtext, { .b = FALSE }, SearchBar },
{ 0, GDK_Return, loaduri, { .v = NULL }, URLBAR }, { 0, GDK_Return, loaduri, { .v = NULL }, UrlBar },
{ 0, GDK_Return, hideurl, { 0 }, URLBAR }, { 0, GDK_Return, hideurl, { 0 }, UrlBar },
}; };

76
surf.c
View File

@ -10,7 +10,6 @@
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <webkit/webkit.h> #include <webkit/webkit.h>
@ -25,7 +24,7 @@ union Arg {
const gboolean b; const gboolean b;
const gint i; const gint i;
const void *v; const void *v;
} ; };
typedef struct Client { typedef struct Client {
GtkWidget *win, *scroll, *vbox, *urlbar, *searchbar, *indicator; GtkWidget *win, *scroll, *vbox, *urlbar, *searchbar, *indicator;
@ -45,10 +44,10 @@ typedef struct Cookie {
} Cookie; } Cookie;
typedef enum { typedef enum {
BROWSER = 0x0001, Browser = 0x0001,
SEARCHBAR = 0x0010, SearchBar = 0x0010,
URLBAR = 0x0100, UrlBar = 0x0100,
ALWAYS = ~0, Any = ~0,
} KeyFocus; } KeyFocus;
typedef struct { typedef struct {
@ -69,8 +68,6 @@ static GdkNativeWindow embed = 0;
static gboolean showxid = FALSE; static gboolean showxid = FALSE;
static gboolean ignore_once = FALSE; static gboolean ignore_once = FALSE;
static gchar *workdir; static gchar *workdir;
extern char *optarg;
extern gint optind;
static void cleanup(void); static void cleanup(void);
static void clipboard(Client *c, const Arg *arg); static void clipboard(Client *c, const Arg *arg);
@ -104,8 +101,7 @@ static void reload(Client *c, const Arg *arg);
static void rereadcookies(void); static void rereadcookies(void);
static void setcookie(char *name, char *val, char *dom, char *path, long exp); static void setcookie(char *name, char *val, char *dom, char *path, long exp);
static void setup(void); static void setup(void);
static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, Client *c);
const gchar* title, Client *c);
static void scroll(Client *c, const Arg *arg); static void scroll(Client *c, const Arg *arg);
static void searchtext(Client *c, const Arg *arg); static void searchtext(Client *c, const Arg *arg);
static void source(Client *c, const Arg *arg); static void source(Client *c, const Arg *arg);
@ -277,11 +273,11 @@ keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
if(ev->type != GDK_KEY_PRESS) if(ev->type != GDK_KEY_PRESS)
return FALSE; return FALSE;
if(GTK_WIDGET_HAS_FOCUS(c->searchbar)) if(GTK_WIDGET_HAS_FOCUS(c->searchbar))
focus = SEARCHBAR; focus = SearchBar;
else if(GTK_WIDGET_HAS_FOCUS(c->urlbar)) else if(GTK_WIDGET_HAS_FOCUS(c->urlbar))
focus = URLBAR; focus = UrlBar;
else else
focus = BROWSER; focus = Browser;
for(i = 0; i < LENGTH(keys); i++) { for(i = 0; i < LENGTH(keys); i++) {
if(focus & keys[i].focus if(focus & keys[i].focus
&& gdk_keyval_to_lower(ev->keyval) == keys[i].keyval && gdk_keyval_to_lower(ev->keyval) == keys[i].keyval
@ -585,6 +581,10 @@ setup(void) {
SoupSession *s; SoupSession *s;
FILE *tmp; FILE *tmp;
gtk_init(NULL, NULL);
if (!g_thread_supported())
g_thread_init(NULL);
dpy = GDK_DISPLAY(); dpy = GDK_DISPLAY();
session = webkit_get_default_session(); session = webkit_get_default_session();
urlprop = XInternAtom(dpy, "_SURF_URL", False); urlprop = XInternAtom(dpy, "_SURF_URL", False);
@ -719,45 +719,35 @@ zoom(Client *c, const Arg *arg) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Client *c; int i;
gint o, a;
Arg arg; Arg arg;
Client *c;
gtk_init(NULL, NULL); /* command line args */
if (!g_thread_supported()) for(i = 1, arg.v = NULL; i < argc; i++) {
g_thread_init(NULL); if(!strcmp(argv[i], "-x"))
while((o = getopt(argc, argv, "vhxe:")) != -1)
switch(o) {
case 'x':
showxid = TRUE; showxid = TRUE;
break; else if(!strcmp(argv[i], "-e")) {
case 'e': if(++i < argc)
if(!(a = atoi(optarg))) embed = atoi(argv[i]);
else
usage(); usage();
embed = a;
break;
case 'v':
die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
break;
default:
usage();
} }
else if(!strcmp(argv[i], "-v"))
die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
else if(argv[i][0] == '-')
usage();
else
arg.v = argv[i];
}
setup(); setup();
if(optind + 1 == argc) { c = newclient();
c = newclient(); if(arg.v) {
arg.v = argv[optind]; if(strchr("./", ((char *)arg.v)[0]) || strcmp("-", (char *)arg.v) == 0)
if(strchr("./", argv[optind][0]) || strcmp("-", argv[optind]) == 0) loadfile(c, (char *)arg.v);
loadfile(c, argv[optind]);
else else
loaduri(c, &arg); loaduri(c, &arg);
} }
else if(optind != argc)
usage();
if(!clients)
newclient();
gtk_main(); gtk_main();
cleanup(); cleanup();
return EXIT_SUCCESS; return EXIT_SUCCESS;