surf

My custom build of surf web browser
Log | Files | Refs | README | LICENSE

commit 566b452b46a171a4426256cdb02704ae8351a2b3
parent 9b1e1873b0929ff397abf5ba523390c9f01f807f
Author: Quentin Rameau <quinq@fifth.space>
Date:   Mon, 11 May 2015 12:48:40 +0200

Port surf to gtk3

Diffstat:
Mconfig.def.h | 88++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mconfig.mk | 4++--
Msurf.c | 47++++++++++++++++++++++++-----------------------
3 files changed, 70 insertions(+), 69 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -83,50 +83,50 @@ static SiteStyle styles[] = { * edit the CLEANMASK() macro. */ static Key keys[] = { - /* modifier keyval function arg Focus */ - { MODKEY|GDK_SHIFT_MASK,GDK_r, reload, { .b = TRUE } }, - { MODKEY, GDK_r, reload, { .b = FALSE } }, - { MODKEY|GDK_SHIFT_MASK,GDK_p, print, { 0 } }, - - { MODKEY, GDK_p, clipboard, { .b = TRUE } }, - { MODKEY, GDK_y, clipboard, { .b = FALSE } }, - - { MODKEY|GDK_SHIFT_MASK,GDK_j, zoom, { .i = -1 } }, - { MODKEY|GDK_SHIFT_MASK,GDK_k, zoom, { .i = +1 } }, - { MODKEY|GDK_SHIFT_MASK,GDK_q, zoom, { .i = 0 } }, - { MODKEY, GDK_minus, zoom, { .i = -1 } }, - { MODKEY, GDK_plus, zoom, { .i = +1 } }, - - { MODKEY, GDK_l, navigate, { .i = +1 } }, - { MODKEY, GDK_h, navigate, { .i = -1 } }, - - { MODKEY, GDK_j, scroll_v, { .i = +1 } }, - { MODKEY, GDK_k, scroll_v, { .i = -1 } }, - { MODKEY, GDK_b, scroll_v, { .i = -10000 } }, - { MODKEY, GDK_space, scroll_v, { .i = +10000 } }, - { MODKEY, GDK_i, scroll_h, { .i = +1 } }, - { MODKEY, GDK_u, scroll_h, { .i = -1 } }, - - { 0, GDK_F11, fullscreen, { 0 } }, - { 0, GDK_Escape, stop, { 0 } }, - { MODKEY, GDK_o, source, { 0 } }, - { MODKEY|GDK_SHIFT_MASK,GDK_o, inspector, { 0 } }, - - { MODKEY, GDK_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, - { MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, - { MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, - - { MODKEY, GDK_n, find, { .b = TRUE } }, - { MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } }, - - { MODKEY|GDK_SHIFT_MASK,GDK_c, toggle, { .v = "enable-caret-browsing" } }, - { MODKEY|GDK_SHIFT_MASK,GDK_i, toggle, { .v = "auto-load-images" } }, - { MODKEY|GDK_SHIFT_MASK,GDK_s, toggle, { .v = "enable-scripts" } }, - { MODKEY|GDK_SHIFT_MASK,GDK_v, toggle, { .v = "enable-plugins" } }, - { MODKEY|GDK_SHIFT_MASK,GDK_a, togglecookiepolicy, { 0 } }, - { MODKEY|GDK_SHIFT_MASK,GDK_m, togglestyle, { 0 } }, - { MODKEY|GDK_SHIFT_MASK,GDK_b, togglescrollbars, { 0 } }, - { MODKEY|GDK_SHIFT_MASK,GDK_g, togglegeolocation, { 0 } }, + /* modifier keyval function arg */ + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_r, reload, { .b = TRUE } }, + { MODKEY, GDK_KEY_r, reload, { .b = FALSE } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_p, print, { 0 } }, + + { MODKEY, GDK_KEY_p, clipboard, { .b = TRUE } }, + { MODKEY, GDK_KEY_y, clipboard, { .b = FALSE } }, + + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, + { MODKEY, GDK_KEY_minus, zoom, { .i = -1 } }, + { MODKEY, GDK_KEY_plus, zoom, { .i = +1 } }, + + { MODKEY, GDK_KEY_l, navigate, { .i = +1 } }, + { MODKEY, GDK_KEY_h, navigate, { .i = -1 } }, + + { MODKEY, GDK_KEY_j, scroll_v, { .i = +1 } }, + { MODKEY, GDK_KEY_k, scroll_v, { .i = -1 } }, + { MODKEY, GDK_KEY_b, scroll_v, { .i = -10000 } }, + { MODKEY, GDK_KEY_space, scroll_v, { .i = +10000 } }, + { MODKEY, GDK_KEY_i, scroll_h, { .i = +1 } }, + { MODKEY, GDK_KEY_u, scroll_h, { .i = -1 } }, + + { 0, GDK_KEY_F11, fullscreen, { 0 } }, + { 0, GDK_KEY_Escape, stop, { 0 } }, + { MODKEY, GDK_KEY_o, source, { 0 } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_o, inspector, { 0 } }, + + { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, + { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, + { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, + + { MODKEY, GDK_KEY_n, find, { .b = TRUE } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_n, find, { .b = FALSE } }, + + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_c, toggle, { .v = "enable-caret-browsing" } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_i, toggle, { .v = "auto-load-images" } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_s, toggle, { .v = "enable-scripts" } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_v, toggle, { .v = "enable-plugins" } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_a, togglecookiepolicy, { 0 } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, togglestyle, { 0 } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, togglescrollbars, { 0 } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_g, togglegeolocation, { 0 } }, }; /* button definitions */ diff --git a/config.mk b/config.mk @@ -10,8 +10,8 @@ MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib -GTKINC = `pkg-config --cflags gtk+-2.0 webkit-1.0` -GTKLIB = `pkg-config --libs gtk+-2.0 webkit-1.0` +GTKINC = `pkg-config --cflags gtk+-3.0 webkitgtk-3.0` +GTKLIB = `pkg-config --libs gtk+-3.0 webkitgtk-3.0` # includes and libs INCS = -I. -I/usr/include -I${X11INC} ${GTKINC} diff --git a/surf.c b/surf.c @@ -5,6 +5,7 @@ #include <signal.h> #include <X11/X.h> #include <X11/Xatom.h> +#include <gtk/gtkx.h> #include <gtk/gtk.h> #include <gdk/gdkx.h> #include <gdk/gdk.h> @@ -55,6 +56,7 @@ union Arg { typedef struct Client { GtkWidget *win, *scroll, *vbox, *pane; + Window xid; WebKitWebView *view; WebKitWebInspector *inspector; char *title, *linkhover; @@ -99,7 +101,7 @@ typedef struct { static Display *dpy; static Atom atoms[AtomLast]; static Client *clients = NULL; -static GdkNativeWindow embed = 0; +static Window embed = 0; static gboolean showxid = FALSE; static char winid[64]; static gboolean usingproxy = 0; @@ -625,9 +627,9 @@ getatom(Client *c, int a) unsigned long ldummy; unsigned char *p = NULL; - XGetWindowProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), - atoms[a], 0L, BUFSIZ, False, XA_STRING, - &adummy, &idummy, &ldummy, &ldummy, &p); + XGetWindowProperty(dpy, c->xid, + atoms[a], 0L, BUFSIZ, False, XA_STRING, + &adummy, &idummy, &ldummy, &ldummy, &p); if (p) strncpy(buf, (char *)p, LENGTH(buf)-1); else @@ -870,6 +872,7 @@ newclient(void) WebKitWebFrame *frame; GdkGeometry hints = { 1, 1 }; GdkScreen *screen; + GdkWindow *gwin; gdouble dpi; char *ua; @@ -911,10 +914,10 @@ newclient(void) addaccelgroup(c); /* Pane */ - c->pane = gtk_vpaned_new(); + c->pane = gtk_paned_new(GTK_ORIENTATION_VERTICAL); /* VBox */ - c->vbox = gtk_vbox_new(FALSE, 0); + c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_paned_pack1(GTK_PANED(c->pane), c->vbox, TRUE, TRUE); /* Webview */ @@ -994,10 +997,12 @@ newclient(void) gtk_widget_show(c->scroll); gtk_widget_show(GTK_WIDGET(c->view)); gtk_widget_show(c->win); + gwin = gtk_widget_get_window(GTK_WIDGET(c->win)); + c->xid = gdk_x11_window_get_xid(gwin); gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, - GDK_HINT_MIN_SIZE); - gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); - gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); + GDK_HINT_MIN_SIZE); + gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK); + gdk_window_add_filter(gwin, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); runscript(frame); @@ -1031,7 +1036,7 @@ newclient(void) * It is equivalent to firefox's "layout.css.devPixelsPerPx" setting. */ if (zoomto96dpi) { - screen = gdk_window_get_screen(GTK_WIDGET(c->win)->window); + screen = gdk_window_get_screen(gwin); dpi = gdk_screen_get_resolution(screen); if (dpi != -1) { g_object_set(G_OBJECT(settings), @@ -1069,8 +1074,7 @@ newclient(void) if (showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); - printf("%u\n", - (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); + printf("%lu\n", c->xid); fflush(NULL); if (fclose(stdout) != 0) { die("Error closing stdout"); @@ -1150,15 +1154,13 @@ menuactivate(GtkMenuItem *item, Client *c) * context-menu-action-12 stop */ - GtkAction *a = NULL; - const char *name, *uri; + const gchar *name, *uri; GtkClipboard *prisel, *clpbrd; - a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(item)); - if (a == NULL) + name = gtk_actionable_get_action_name(GTK_ACTIONABLE(item)); + if (name == NULL) return; - name = gtk_action_get_name(a); if (!g_strcmp0(name, "context-menu-action-3")) { prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); gtk_clipboard_set_text(prisel, c->linkhover, -1); @@ -1281,9 +1283,9 @@ void setatom(Client *c, int a, const char *v) { XSync(dpy, False); - XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), - atoms[a], XA_STRING, 8, PropModeReplace, - (unsigned char *)v, strlen(v) + 1); + XChangeProperty(dpy, c->xid, + atoms[a], XA_STRING, 8, PropModeReplace, + (unsigned char *)v, strlen(v) + 1); } void @@ -1300,7 +1302,7 @@ setup(void) sigchld(0); gtk_init(NULL, NULL); - dpy = GDK_DISPLAY(); + dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); /* atoms */ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); @@ -1618,8 +1620,7 @@ updatetitle(Client *c) void updatewinid(Client *c) { - snprintf(winid, LENGTH(winid), "%u", - (int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); + snprintf(winid, LENGTH(winid), "%lu", c->xid); } void