[hackers] [surf] Add mouse function to play medias in external player || Quentin Rameau

From: <git_AT_suckless.org>
Date: Sat, 21 Nov 2015 19:54:28 +0100 (CET)

commit 954a7181970f61acd54ce82cdff4195e72530db1
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Sat Nov 21 19:53:29 2015 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Sat Nov 21 19:53:29 2015 +0100

    Add mouse function to play medias in external player
    
    Control + left click launches mpv with the target media url.

diff --git a/config.def.h b/config.def.h
index 6d62c98..32ef407 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -65,6 +65,13 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
         } \
 }
 
+/* VIDEOPLAY(URI) */
+#define VIDEOPLAY(u) {\
+ .v = (const char *[]){ "/bin/sh", "-c", \
+ "mpv --really-quiet \"$0\"", u, NULL \
+ } \
+}
+
 /* styles */
 /*
  * The iteration will stop at the first match, beginning at the beginning of
_AT_@ -142,4 +149,5 @@ static Button buttons[] = {
         { OnLink, MODKEY, 1, clicknewwindow, { .b = 1 }, 1 },
         { OnAny, 0, 8, clicknavigate, { .i = -1 }, 1 },
         { OnAny, 0, 9, clicknavigate, { .i = +1 }, 1 },
+ { OnMedia, MODKEY, 1, clickexternplayer, { 0 }, 1 },
 };
diff --git a/surf.c b/surf.c
index 9c9bae7..81ba9a5 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -178,6 +178,7 @@ static void find(Client *c, const Arg *a);
 /* Buttons */
 static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
 static void clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h);
+static void clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h);
 
 static char winid[64];
 static char togglestats[10];
_AT_@ -1462,6 +1463,17 @@ clicknewwindow(Client *c, const Arg *a, WebKitHitTestResult *h)
         newwindow(c, &arg, a->b);
 }
 
+void
+clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h)
+{
+ Arg arg;
+
+ if (webkit_hit_test_result_get_context(h) & OnMedia) {
+ arg = (Arg)VIDEOPLAY(webkit_hit_test_result_get_media_uri(h));
+ spawn(c, &arg);
+ }
+}
+
 int
 main(int argc, char *argv[])
 {
Received on Sat Nov 21 2015 - 19:54:28 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 21 2015 - 20:00:13 CET