Port surf to gtk3

This commit is contained in:
Quentin Rameau 2015-05-11 12:48:40 +02:00
parent 9b1e1873b0
commit 566b452b46
3 changed files with 62 additions and 61 deletions

View file

@ -83,50 +83,50 @@ static SiteStyle styles[] = {
* edit the CLEANMASK() macro. * edit the CLEANMASK() macro.
*/ */
static Key keys[] = { static Key keys[] = {
/* modifier keyval function arg Focus */ /* modifier keyval function arg */
{ MODKEY|GDK_SHIFT_MASK,GDK_r, reload, { .b = TRUE } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_r, reload, { .b = TRUE } },
{ MODKEY, GDK_r, reload, { .b = FALSE } }, { MODKEY, GDK_KEY_r, reload, { .b = FALSE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_p, print, { 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_p, print, { 0 } },
{ MODKEY, GDK_p, clipboard, { .b = TRUE } }, { MODKEY, GDK_KEY_p, clipboard, { .b = TRUE } },
{ MODKEY, GDK_y, clipboard, { .b = FALSE } }, { MODKEY, GDK_KEY_y, clipboard, { .b = FALSE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_j, zoom, { .i = -1 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } },
{ MODKEY|GDK_SHIFT_MASK,GDK_k, zoom, { .i = +1 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } },
{ MODKEY|GDK_SHIFT_MASK,GDK_q, zoom, { .i = 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } },
{ MODKEY, GDK_minus, zoom, { .i = -1 } }, { MODKEY, GDK_KEY_minus, zoom, { .i = -1 } },
{ MODKEY, GDK_plus, zoom, { .i = +1 } }, { MODKEY, GDK_KEY_plus, zoom, { .i = +1 } },
{ MODKEY, GDK_l, navigate, { .i = +1 } }, { MODKEY, GDK_KEY_l, navigate, { .i = +1 } },
{ MODKEY, GDK_h, navigate, { .i = -1 } }, { MODKEY, GDK_KEY_h, navigate, { .i = -1 } },
{ MODKEY, GDK_j, scroll_v, { .i = +1 } }, { MODKEY, GDK_KEY_j, scroll_v, { .i = +1 } },
{ MODKEY, GDK_k, scroll_v, { .i = -1 } }, { MODKEY, GDK_KEY_k, scroll_v, { .i = -1 } },
{ MODKEY, GDK_b, scroll_v, { .i = -10000 } }, { MODKEY, GDK_KEY_b, scroll_v, { .i = -10000 } },
{ MODKEY, GDK_space, scroll_v, { .i = +10000 } }, { MODKEY, GDK_KEY_space, scroll_v, { .i = +10000 } },
{ MODKEY, GDK_i, scroll_h, { .i = +1 } }, { MODKEY, GDK_KEY_i, scroll_h, { .i = +1 } },
{ MODKEY, GDK_u, scroll_h, { .i = -1 } }, { MODKEY, GDK_KEY_u, scroll_h, { .i = -1 } },
{ 0, GDK_F11, fullscreen, { 0 } }, { 0, GDK_KEY_F11, fullscreen, { 0 } },
{ 0, GDK_Escape, stop, { 0 } }, { 0, GDK_KEY_Escape, stop, { 0 } },
{ MODKEY, GDK_o, source, { 0 } }, { MODKEY, GDK_KEY_o, source, { 0 } },
{ MODKEY|GDK_SHIFT_MASK,GDK_o, inspector, { 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_o, inspector, { 0 } },
{ MODKEY, GDK_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") },
{ MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") },
{ MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") },
{ MODKEY, GDK_n, find, { .b = TRUE } }, { MODKEY, GDK_KEY_n, find, { .b = TRUE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_n, find, { .b = FALSE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_c, toggle, { .v = "enable-caret-browsing" } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_c, toggle, { .v = "enable-caret-browsing" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_i, toggle, { .v = "auto-load-images" } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_i, toggle, { .v = "auto-load-images" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_s, toggle, { .v = "enable-scripts" } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_s, toggle, { .v = "enable-scripts" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_v, toggle, { .v = "enable-plugins" } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_v, toggle, { .v = "enable-plugins" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_a, togglecookiepolicy, { 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_a, togglecookiepolicy, { 0 } },
{ MODKEY|GDK_SHIFT_MASK,GDK_m, togglestyle, { 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, togglestyle, { 0 } },
{ MODKEY|GDK_SHIFT_MASK,GDK_b, togglescrollbars, { 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, togglescrollbars, { 0 } },
{ MODKEY|GDK_SHIFT_MASK,GDK_g, togglegeolocation, { 0 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_g, togglegeolocation, { 0 } },
}; };
/* button definitions */ /* button definitions */

View file

@ -10,8 +10,8 @@ MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib X11LIB = /usr/X11R6/lib
GTKINC = `pkg-config --cflags gtk+-2.0 webkit-1.0` GTKINC = `pkg-config --cflags gtk+-3.0 webkitgtk-3.0`
GTKLIB = `pkg-config --libs gtk+-2.0 webkit-1.0` GTKLIB = `pkg-config --libs gtk+-3.0 webkitgtk-3.0`
# includes and libs # includes and libs
INCS = -I. -I/usr/include -I${X11INC} ${GTKINC} INCS = -I. -I/usr/include -I${X11INC} ${GTKINC}

47
surf.c
View file

@ -5,6 +5,7 @@
#include <signal.h> #include <signal.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <gtk/gtkx.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
@ -55,6 +56,7 @@ union Arg {
typedef struct Client { typedef struct Client {
GtkWidget *win, *scroll, *vbox, *pane; GtkWidget *win, *scroll, *vbox, *pane;
Window xid;
WebKitWebView *view; WebKitWebView *view;
WebKitWebInspector *inspector; WebKitWebInspector *inspector;
char *title, *linkhover; char *title, *linkhover;
@ -99,7 +101,7 @@ typedef struct {
static Display *dpy; static Display *dpy;
static Atom atoms[AtomLast]; static Atom atoms[AtomLast];
static Client *clients = NULL; static Client *clients = NULL;
static GdkNativeWindow embed = 0; static Window embed = 0;
static gboolean showxid = FALSE; static gboolean showxid = FALSE;
static char winid[64]; static char winid[64];
static gboolean usingproxy = 0; static gboolean usingproxy = 0;
@ -625,9 +627,9 @@ getatom(Client *c, int a)
unsigned long ldummy; unsigned long ldummy;
unsigned char *p = NULL; unsigned char *p = NULL;
XGetWindowProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), XGetWindowProperty(dpy, c->xid,
atoms[a], 0L, BUFSIZ, False, XA_STRING, atoms[a], 0L, BUFSIZ, False, XA_STRING,
&adummy, &idummy, &ldummy, &ldummy, &p); &adummy, &idummy, &ldummy, &ldummy, &p);
if (p) if (p)
strncpy(buf, (char *)p, LENGTH(buf)-1); strncpy(buf, (char *)p, LENGTH(buf)-1);
else else
@ -870,6 +872,7 @@ newclient(void)
WebKitWebFrame *frame; WebKitWebFrame *frame;
GdkGeometry hints = { 1, 1 }; GdkGeometry hints = { 1, 1 };
GdkScreen *screen; GdkScreen *screen;
GdkWindow *gwin;
gdouble dpi; gdouble dpi;
char *ua; char *ua;
@ -911,10 +914,10 @@ newclient(void)
addaccelgroup(c); addaccelgroup(c);
/* Pane */ /* Pane */
c->pane = gtk_vpaned_new(); c->pane = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
/* VBox */ /* 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); gtk_paned_pack1(GTK_PANED(c->pane), c->vbox, TRUE, TRUE);
/* Webview */ /* Webview */
@ -994,10 +997,12 @@ newclient(void)
gtk_widget_show(c->scroll); gtk_widget_show(c->scroll);
gtk_widget_show(GTK_WIDGET(c->view)); gtk_widget_show(GTK_WIDGET(c->view));
gtk_widget_show(c->win); 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, gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints,
GDK_HINT_MIN_SIZE); GDK_HINT_MIN_SIZE);
gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); gdk_window_add_filter(gwin, processx, c);
webkit_web_view_set_full_content_zoom(c->view, TRUE); webkit_web_view_set_full_content_zoom(c->view, TRUE);
runscript(frame); runscript(frame);
@ -1031,7 +1036,7 @@ newclient(void)
* It is equivalent to firefox's "layout.css.devPixelsPerPx" setting. * It is equivalent to firefox's "layout.css.devPixelsPerPx" setting.
*/ */
if (zoomto96dpi) { if (zoomto96dpi) {
screen = gdk_window_get_screen(GTK_WIDGET(c->win)->window); screen = gdk_window_get_screen(gwin);
dpi = gdk_screen_get_resolution(screen); dpi = gdk_screen_get_resolution(screen);
if (dpi != -1) { if (dpi != -1) {
g_object_set(G_OBJECT(settings), g_object_set(G_OBJECT(settings),
@ -1069,8 +1074,7 @@ newclient(void)
if (showxid) { if (showxid) {
gdk_display_sync(gtk_widget_get_display(c->win)); gdk_display_sync(gtk_widget_get_display(c->win));
printf("%u\n", printf("%lu\n", c->xid);
(guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
fflush(NULL); fflush(NULL);
if (fclose(stdout) != 0) { if (fclose(stdout) != 0) {
die("Error closing stdout"); die("Error closing stdout");
@ -1150,15 +1154,13 @@ menuactivate(GtkMenuItem *item, Client *c)
* context-menu-action-12 stop * context-menu-action-12 stop
*/ */
GtkAction *a = NULL; const gchar *name, *uri;
const char *name, *uri;
GtkClipboard *prisel, *clpbrd; GtkClipboard *prisel, *clpbrd;
a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(item)); name = gtk_actionable_get_action_name(GTK_ACTIONABLE(item));
if (a == NULL) if (name == NULL)
return; return;
name = gtk_action_get_name(a);
if (!g_strcmp0(name, "context-menu-action-3")) { if (!g_strcmp0(name, "context-menu-action-3")) {
prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gtk_clipboard_set_text(prisel, c->linkhover, -1); gtk_clipboard_set_text(prisel, c->linkhover, -1);
@ -1281,9 +1283,9 @@ void
setatom(Client *c, int a, const char *v) setatom(Client *c, int a, const char *v)
{ {
XSync(dpy, False); XSync(dpy, False);
XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), XChangeProperty(dpy, c->xid,
atoms[a], XA_STRING, 8, PropModeReplace, atoms[a], XA_STRING, 8, PropModeReplace,
(unsigned char *)v, strlen(v) + 1); (unsigned char *)v, strlen(v) + 1);
} }
void void
@ -1300,7 +1302,7 @@ setup(void)
sigchld(0); sigchld(0);
gtk_init(NULL, NULL); gtk_init(NULL, NULL);
dpy = GDK_DISPLAY(); dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
/* atoms */ /* atoms */
atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
@ -1618,8 +1620,7 @@ updatetitle(Client *c)
void void
updatewinid(Client *c) updatewinid(Client *c)
{ {
snprintf(winid, LENGTH(winid), "%u", snprintf(winid, LENGTH(winid), "%lu", c->xid);
(int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
} }
void void