mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-27 22:06:58 +08:00
player: kill associated OSD and key bindings when removing a script
The former was done already for Lua scripts, but move it to the generic code.
This commit is contained in:
+23
-1
@@ -73,6 +73,7 @@ struct cmd_bind {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_bind_section {
|
struct cmd_bind_section {
|
||||||
|
char *owner;
|
||||||
struct cmd_bind *binds;
|
struct cmd_bind *binds;
|
||||||
int num_binds;
|
int num_binds;
|
||||||
char *section;
|
char *section;
|
||||||
@@ -1009,13 +1010,19 @@ static void remove_binds(struct cmd_bind_section *bs, bool builtin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mp_input_define_section(struct input_ctx *ictx, char *name, char *location,
|
void mp_input_define_section(struct input_ctx *ictx, char *name, char *location,
|
||||||
char *contents, bool builtin)
|
char *contents, bool builtin, char *owner)
|
||||||
{
|
{
|
||||||
if (!name || !name[0])
|
if (!name || !name[0])
|
||||||
return; // parse_config() changes semantics with restrict_section==empty
|
return; // parse_config() changes semantics with restrict_section==empty
|
||||||
input_lock(ictx);
|
input_lock(ictx);
|
||||||
// Delete:
|
// Delete:
|
||||||
struct cmd_bind_section *bs = get_bind_section(ictx, bstr0(name));
|
struct cmd_bind_section *bs = get_bind_section(ictx, bstr0(name));
|
||||||
|
if ((!bs->owner || (owner && strcmp(bs->owner, owner) != 0)) &&
|
||||||
|
strcmp(bs->section, "default") != 0)
|
||||||
|
{
|
||||||
|
talloc_free(bs->owner);
|
||||||
|
bs->owner = talloc_strdup(bs, owner);
|
||||||
|
}
|
||||||
remove_binds(bs, builtin);
|
remove_binds(bs, builtin);
|
||||||
if (contents && contents[0]) {
|
if (contents && contents[0]) {
|
||||||
// Redefine:
|
// Redefine:
|
||||||
@@ -1027,6 +1034,21 @@ void mp_input_define_section(struct input_ctx *ictx, char *name, char *location,
|
|||||||
input_unlock(ictx);
|
input_unlock(ictx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mp_input_remove_sections_by_owner(struct input_ctx *ictx, char *owner)
|
||||||
|
{
|
||||||
|
input_lock(ictx);
|
||||||
|
struct cmd_bind_section *bs = ictx->cmd_bind_sections;
|
||||||
|
while (bs) {
|
||||||
|
if (bs->owner && owner && strcmp(bs->owner, owner) == 0) {
|
||||||
|
mp_input_disable_section(ictx, bs->section);
|
||||||
|
remove_binds(bs, false);
|
||||||
|
remove_binds(bs, true);
|
||||||
|
}
|
||||||
|
bs = bs->next;
|
||||||
|
}
|
||||||
|
input_unlock(ictx);
|
||||||
|
}
|
||||||
|
|
||||||
static bool bind_matches_key(struct cmd_bind *bind, int num_keys, const int *keys)
|
static bool bind_matches_key(struct cmd_bind *bind, int num_keys, const int *keys)
|
||||||
{
|
{
|
||||||
if (bind->num_keys != num_keys)
|
if (bind->num_keys != num_keys)
|
||||||
|
|||||||
+5
-1
@@ -196,9 +196,13 @@ void mp_input_disable_all_sections(struct input_ctx *ictx);
|
|||||||
// builtin: create as builtin section; this means if the user defines bindings
|
// builtin: create as builtin section; this means if the user defines bindings
|
||||||
// using "{name}", they won't be ignored or overwritten - instead,
|
// using "{name}", they won't be ignored or overwritten - instead,
|
||||||
// they are preferred to the bindings defined with this call
|
// they are preferred to the bindings defined with this call
|
||||||
|
// owner: string ID of the client which defined this, or NULL
|
||||||
// If the section already exists, its bindings are removed and replaced.
|
// If the section already exists, its bindings are removed and replaced.
|
||||||
void mp_input_define_section(struct input_ctx *ictx, char *name, char *location,
|
void mp_input_define_section(struct input_ctx *ictx, char *name, char *location,
|
||||||
char *contents, bool builtin);
|
char *contents, bool builtin, char *owner);
|
||||||
|
|
||||||
|
// Remove all sections that have been defined by the given owner.
|
||||||
|
void mp_input_remove_sections_by_owner(struct input_ctx *ictx, char *owner);
|
||||||
|
|
||||||
// Define where on the screen the named input section should receive.
|
// Define where on the screen the named input section should receive.
|
||||||
// Setting a rectangle of size 0 unsets the mouse area.
|
// Setting a rectangle of size 0 unsets the mouse area.
|
||||||
|
|||||||
@@ -416,6 +416,8 @@ void mpv_detach_destroy(mpv_handle *ctx)
|
|||||||
ctx->num_events--;
|
ctx->num_events--;
|
||||||
}
|
}
|
||||||
mp_msg_log_buffer_destroy(ctx->messages);
|
mp_msg_log_buffer_destroy(ctx->messages);
|
||||||
|
osd_set_external(ctx->mpctx->osd, ctx, 0, 0, NULL);
|
||||||
|
mp_input_remove_sections_by_owner(ctx->mpctx->input, ctx->name);
|
||||||
pthread_cond_destroy(&ctx->wakeup);
|
pthread_cond_destroy(&ctx->wakeup);
|
||||||
pthread_mutex_destroy(&ctx->wakeup_lock);
|
pthread_mutex_destroy(&ctx->wakeup_lock);
|
||||||
pthread_mutex_destroy(&ctx->lock);
|
pthread_mutex_destroy(&ctx->lock);
|
||||||
@@ -759,6 +761,9 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout)
|
|||||||
{
|
{
|
||||||
mpv_event *event = ctx->cur_event;
|
mpv_event *event = ctx->cur_event;
|
||||||
|
|
||||||
|
if (!ctx->mpctx->initialized)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
pthread_mutex_lock(&ctx->lock);
|
pthread_mutex_lock(&ctx->lock);
|
||||||
|
|
||||||
if (!ctx->fuzzy_initialized)
|
if (!ctx->fuzzy_initialized)
|
||||||
|
|||||||
+2
-1
@@ -5282,7 +5282,8 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
|
|||||||
|
|
||||||
case MP_CMD_DEFINE_INPUT_SECTION:
|
case MP_CMD_DEFINE_INPUT_SECTION:
|
||||||
mp_input_define_section(mpctx->input, cmd->args[0].v.s, "<api>",
|
mp_input_define_section(mpctx->input, cmd->args[0].v.s, "<api>",
|
||||||
cmd->args[1].v.s, !!cmd->args[2].v.i);
|
cmd->args[1].v.s, !!cmd->args[2].v.i,
|
||||||
|
cmd->sender);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_CMD_AB_LOOP: {
|
case MP_CMD_AB_LOOP: {
|
||||||
|
|||||||
@@ -391,7 +391,6 @@ static int load_lua(struct mpv_handle *client, const char *fname)
|
|||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
error_out:
|
error_out:
|
||||||
osd_set_external(ctx->mpctx->osd, client, 0, 0, NULL); // remove overlay
|
|
||||||
mp_resume_all(client);
|
mp_resume_all(client);
|
||||||
if (ctx->state)
|
if (ctx->state)
|
||||||
lua_close(ctx->state);
|
lua_close(ctx->state);
|
||||||
|
|||||||
Reference in New Issue
Block a user