summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/ipc-unix.c38
-rw-r--r--input/keycodes.c10
-rw-r--r--input/keycodes.h1
3 files changed, 43 insertions, 6 deletions
diff --git a/input/ipc-unix.c b/input/ipc-unix.c
index e047c30145..cd788e0061 100644
--- a/input/ipc-unix.c
+++ b/input/ipc-unix.c
@@ -18,7 +18,7 @@
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
-
+#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <sys/types.h>
@@ -61,6 +61,7 @@ struct client_arg {
const char *client_name;
int client_fd;
bool close_client_fd;
+ bool quit_on_close;
bool writable;
};
@@ -162,7 +163,7 @@ static void *client_thread(void *p)
}
}
- if (fds[1].revents & (POLLIN | POLLHUP)) {
+ if (fds[1].revents & (POLLIN | POLLHUP | POLLNVAL)) {
while (1) {
char buf[128];
bstr append = { buf, 0 };
@@ -210,8 +211,14 @@ done:
talloc_free(client_msg.start);
if (arg->close_client_fd)
close(arg->client_fd);
- mpv_destroy(arg->client);
+ struct mpv_handle *h = arg->client;
+ bool quit = arg->quit_on_close;
talloc_free(arg);
+ if (quit) {
+ mpv_terminate_destroy(h);
+ } else {
+ mpv_destroy(h);
+ }
return NULL;
}
@@ -248,9 +255,11 @@ static void ipc_start_client_json(struct mp_ipc_ctx *ctx, int id, int fd)
{
struct client_arg *client = talloc_ptrtype(NULL, client);
*client = (struct client_arg){
- .client_name = talloc_asprintf(client, "ipc-%d", id),
- .client_fd = fd,
- .close_client_fd = true,
+ .client_name =
+ id >= 0 ? talloc_asprintf(client, "ipc-%d", id) : "ipc",
+ .client_fd = fd,
+ .close_client_fd = id >= 0,
+ .quit_on_close = id < 0,
.writable = true,
};
@@ -263,6 +272,8 @@ bool mp_ipc_start_anon_client(struct mp_ipc_ctx *ctx, struct mpv_handle *h,
int pair[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair))
return false;
+ mp_set_cloexec(pair[0]);
+ mp_set_cloexec(pair[1]);
struct client_arg *client = talloc_ptrtype(NULL, client);
*client = (struct client_arg){
@@ -384,6 +395,21 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api,
.death_pipe = {-1, -1},
};
+ if (opts->ipc_client && opts->ipc_client[0]) {
+ int fd = -1;
+ if (strncmp(opts->ipc_client, "fd://", 5) == 0) {
+ char *end;
+ unsigned long l = strtoul(opts->ipc_client + 5, &end, 0);
+ if (!end[0] && l <= INT_MAX)
+ fd = l;
+ }
+ if (fd < 0) {
+ MP_ERR(arg, "Invalid IPC client argument: '%s'\n", opts->ipc_client);
+ } else {
+ ipc_start_client_json(arg, -1, fd);
+ }
+ }
+
talloc_free(opts);
if (!arg->path || !arg->path[0])
diff --git a/input/keycodes.c b/input/keycodes.c
index bb92994479..312ffc4893 100644
--- a/input/keycodes.c
+++ b/input/keycodes.c
@@ -322,6 +322,16 @@ void mp_print_key_list(struct mp_log *out)
mp_info(out, "%s\n", key_names[i].name);
}
+char **mp_get_key_list(void)
+{
+ char **list = NULL;
+ int num = 0;
+ for (int i = 0; key_names[i].name != NULL; i++)
+ MP_TARRAY_APPEND(NULL, list, num, talloc_strdup(NULL, key_names[i].name));
+ MP_TARRAY_APPEND(NULL, list, num, NULL);
+ return list;
+}
+
int mp_normalize_keycode(int keycode)
{
if (keycode <= 0)
diff --git a/input/keycodes.h b/input/keycodes.h
index 3a33258031..6373a6e21a 100644
--- a/input/keycodes.h
+++ b/input/keycodes.h
@@ -253,5 +253,6 @@ int mp_input_get_keys_from_string(char *str, int max_num_keys,
struct mp_log;
void mp_print_key_list(struct mp_log *out);
+char **mp_get_key_list(void);
#endif /* MPLAYER_KEYCODES_H */