-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: click areas out of menu would triggers MBTN_LEFT
#23
Comments
I can't find a regular way to resolve it well. Although I can set a flag before menu open, but it's pretty tricky.
|
As a workaround you can include an empty command in the menu, clicking it closes the menu. |
The real problem here is that it blocks the mpv keybinding when the menu is opened, and triggers the event of closing the menu when the left mouse button is clicked; After the menu is closed, it will continue to forward mouse events to trigger the mpv predetermined keybinding function. If we can prevent forwarding left mouse button events when the menu is closed, it will fix this issue. |
I've checked on native windows video players, and the way they handle it is: when menu is open: block player left-click command and bind it to dismiss menu. |
How about replacing MBTN event's command when menu open and reversing it when menu closing? |
Well, it's working now (EDIT: not always working, because script message is async). --- a/lua/dyn_menu.lua
+++ b/lua/dyn_menu.lua
@@ -477,6 +477,14 @@ mp.register_script_message('update', function(keyword, json)
menu_items_dirty = true
end)
+mp.register_script_message('menu-open', function()
+ mp.add_forced_key_binding('MBTN_LEFT', 'click_ignore')
+end)
+
+mp.register_script_message('menu-close', function()
+ mp.remove_key_binding('click_ignore')
+end)
+
-- commit menu items when idle, this reduces the update frequency
mp.register_idle(function()
if menu_items_dirty then
diff --git a/src/menu.c b/src/menu.c
index 8cc553d..665d5df 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -266,8 +266,10 @@ void show_menu(plugin_ctx *ctx, POINT *pt) {
if (!PtInRect(&rc, *pt)) return;
ClientToScreen(ctx->hwnd, pt);
+ mpv_command(ctx->mpv, (const char *[]){"script-message", "menu-open", NULL});
TrackPopupMenuEx(ctx->hmenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, pt->x, pt->y,
ctx->hwnd, NULL);
+ mpv_command(ctx->mpv, (const char *[]){"script-message", "menu-close", NULL});
} |
I think the reason is that the event is deferred. Works fine to me with additional timeout. |
I can confirm that it works. |
I've added the |
ref #19 (comment), #19 (comment)
The text was updated successfully, but these errors were encountered: