> I've pushed a similar/more complete patch using dmenu-wl[1] here: > > https://gitlab.com/jspricke/surf/-/commit/3787ac989303a316ad08cb4c1a26fc5258ce7926 > > [1] https://github.com/nyyManni/dmenu-wayland > > Cheers Jochen >
Just did a merge of yours and my changes, could simplify things as well with using the define variables in config.def.h for the program. Feel free to use if you want in your patch. I have it working with bemenu using my existing changes. I tried to remove find function but it freaked out during compiling. diff --git a/config.def.h b/config.def.h index 93cfeeb..34dd9dc 100644 --- a/config.def.h +++ b/config.def.h @@ -64,6 +64,9 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | #define PROMPT_GO "Go:" #define PROMPT_FIND "Find:" +/* needs something from stdin to display prompt for dmenu and bemenu */ +#define MENU_GO "$1 | bemenu -i -p Go: -w" +#define MENU_FIND "$1 | bemenu -i -p Find: -w" /* SETPROP(readprop, setprop, prompt)*/ #define SETPROP(r, s, p) { \ @@ -131,10 +134,9 @@ static SiteSpecific certs[] = { */ static Key keys[] = { /* modifier keyval function arg */ - { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, - { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, - { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, - + { MODKEY, GDK_KEY_g, gosh, { 0 } }, + { MODKEY, GDK_KEY_f, findsh, { 0 } }, + { MODKEY, GDK_KEY_slash, findsh, { 0 } }, { 0, GDK_KEY_Escape, stop, { 0 } }, { MODKEY, GDK_KEY_c, stop, { 0 } }, diff --git a/surf.c b/surf.c index 001f776..98fcba7 100644 --- a/surf.c +++ b/surf.c @@ -177,6 +177,7 @@ static void updatewinid(Client *c); static void handleplumb(Client *c, const char *uri); static void newwindow(Client *c, const Arg *a, int noembed); static void spawn(Client *c, const Arg *a); +static void gosh(Client *c, const Arg *a); static void msgext(Client *c, char type, const Arg *a); static void destroyclient(Client *c); static void cleanup(void); @@ -238,6 +239,7 @@ static void togglefullscreen(Client *c, const Arg *a); static void togglecookiepolicy(Client *c, const Arg *a); static void toggleinspector(Client *c, const Arg *a); static void find(Client *c, const Arg *a); +static void findsh(Client *c, const Arg *a); /* Buttons */ static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h); @@ -614,10 +616,13 @@ geturi(Client *c) void setatom(Client *c, int a, const char *v) { + if (GDK_IS_X11_DISPLAY (dpy)) + { XChangeProperty(dpy, c->xid, atoms[a], atoms[AtomUTF8], 8, PropModeReplace, (unsigned char *)v, strlen(v) + 1); XSync(dpy, False); + } } const char * @@ -1068,6 +1073,20 @@ spawn(Client *c, const Arg *a) } } +void +gosh(Client *c, const Arg *a) +{ + char b[BUFSIZ]; + FILE *p; + Arg arg; + if ((p = popen(MENU_GO, "r")) == NULL) + return; + fgets(b, sizeof(b), p); + pclose(p); + arg.v = b; + loaduri(c, &arg); +} + void destroyclient(Client *c) { @@ -1400,7 +1419,12 @@ showview(WebKitWebView *v, Client *c) gtk_widget_grab_focus(GTK_WIDGET(c->view)); gwin = gtk_widget_get_window(GTK_WIDGET(c->win)); + #ifdef GTK_WINDOWING_X11 + if (GTK_IS_X11_DISPLAY (dpy)) + { c->xid = gdk_x11_window_get_xid(gwin); + } + #endif updatewinid(c); if (showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); @@ -1997,6 +2021,30 @@ find(Client *c, const Arg *a) } } +void +findsh(Client *c, const Arg *a) +{ + const char *f; + char b[BUFSIZ]; + FILE *p; + if ((p = popen(MENU_FIND, "r")) == NULL) + return; + fgets(b, sizeof(b), p); + pclose(p); + f = webkit_find_controller_get_search_text(c->finder); + + if (g_strcmp0(f, b) == 0) /* reset search */ + webkit_find_controller_search(c->finder, "", findopts, + G_MAXUINT); + + webkit_find_controller_search(c->finder, b, findopts, + G_MAXUINT); + + printf(f); + if (strcmp(b, "") == 0) + webkit_find_controller_search_finish(c->finder); +} + void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h) {