Adapted buttonrelease()

Use the current hit test (c->mousepos) to determine where the mouse
pointer is.
It is possible to link an action to a click and still propagate the
event after that by setting the “stop event” parameter of a Button to 0.
This commit is contained in:
Quentin Rameau 2015-11-19 13:19:27 +01:00
parent 96188f83f0
commit f6a35e5fbf
2 changed files with 22 additions and 23 deletions

View File

@ -129,9 +129,9 @@ static Key keys[] = {
}; };
/* button definitions */ /* button definitions */
/* where can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */ /* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */
static Button buttons[] = { static Button buttons[] = {
/* where event mask button function argument stop event */ /* target event mask button function argument stop event */
{ OnLink, 0, 2, linkopenembed, { 0 }, 1 }, { OnLink, 0, 2, linkopenembed, { 0 }, 1 },
{ OnLink, MODKEY, 2, linkopen, { 0 }, 1 }, { OnLink, MODKEY, 2, linkopen, { 0 }, 1 },
{ OnLink, MODKEY, 1, linkopen, { 0 }, 1 }, { OnLink, MODKEY, 1, linkopen, { 0 }, 1 },

41
surf.c
View File

@ -76,11 +76,12 @@ typedef struct {
} Key; } Key;
typedef struct { typedef struct {
unsigned int click; unsigned int target;
unsigned int mask; unsigned int mask;
guint button; guint button;
void (*func)(Client *c, const Arg *arg); void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
const Arg arg; const Arg arg;
unsigned int stopevent;
} Button; } Button;
typedef struct { typedef struct {
@ -107,7 +108,7 @@ static void beforerequest(WebKitWebView *w, WebKitWebFrame *f,
WebKitNetworkResponse *resp, Client *c); WebKitNetworkResponse *resp, Client *c);
static char *buildfile(const char *path); static char *buildfile(const char *path);
static char *buildpath(const char *path); static char *buildpath(const char *path);
static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c); static gboolean buttonreleased(GtkWidget *w, GdkEventKey *e, Client *c);
static void cleanup(void); static void cleanup(void);
static void clipboard(Client *c, const Arg *arg); static void clipboard(Client *c, const Arg *arg);
@ -308,27 +309,25 @@ buildpath(const char *path)
} }
gboolean gboolean
buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c) buttonreleased(GtkWidget *w, GdkEventKey *e, Client *c)
{ {
WebKitHitTestResultContext context; WebKitHitTestResultContext element;
WebKitHitTestResult *result; GdkEventButton *eb = (GdkEventButton*)e;
Arg arg; int i;
unsigned int i;
result = webkit_web_view_get_hit_test_result(web, e); element = webkit_hit_test_result_get_context(c->mousepos);
g_object_get(result, "context", &context, NULL);
g_object_get(result, "link-uri", &arg.v, NULL); for (i = 0; i < LENGTH(buttons); ++i) {
for (i = 0; i < LENGTH(buttons); i++) { if (element & buttons[i].target &&
if (context & buttons[i].click eb->button == buttons[i].button &&
&& e->button == buttons[i].button CLEANMASK(eb->state) == CLEANMASK(buttons[i].mask) &&
&& CLEANMASK(e->state) == CLEANMASK(buttons[i].mask) buttons[i].func) {
&& buttons[i].func) { buttons[i].func(c, &buttons[i].arg, c->mousepos);
buttons[i].func(c, buttons[i].click == ClkLink return buttons[i].stopevent;
&& buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
return true;
} }
} }
return false;
return FALSE;
} }
void void
@ -1015,7 +1014,7 @@ newview(Client *c, WebKitWebView *rv)
G_CALLBACK(progresschanged), c); G_CALLBACK(progresschanged), c);
g_signal_connect(G_OBJECT(v), g_signal_connect(G_OBJECT(v),
"button-release-event", "button-release-event",
G_CALLBACK(buttonrelease), c); G_CALLBACK(buttonreleased), c);
g_signal_connect(G_OBJECT(v), g_signal_connect(G_OBJECT(v),
"context-menu", "context-menu",
G_CALLBACK(contextmenu), c); G_CALLBACK(contextmenu), c);