From 842bc00ec620170e987799832912049b5d0e5531 Mon Sep 17 00:00:00 2001 From: Keith94 Date: Sun, 26 Apr 2026 10:46:07 -0600 Subject: [PATCH 1/2] docs: add default mouse actions info --- docs/USER_OPTS.md | 6 ++++++ modernz.conf | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/docs/USER_OPTS.md b/docs/USER_OPTS.md index e519311d..6f278602 100644 --- a/docs/USER_OPTS.md +++ b/docs/USER_OPTS.md @@ -287,6 +287,12 @@ Customize the button function based on mouse actions. | | speed_mbtn_right_command | `osd-msg set speed 1` | | | speed_wheel_down_command | `osd-msg add speed -0.25` | | | speed_wheel_up_command | `osd-msg add speed 0.25` | +| Default actions | default_mbtn_mid_command | `ignore` | +| | default_wheel_up_command | `ignore` | +| | default_wheel_down_command | `ignore` | + +> [!NOTE] +> Commands set as default actions are applied to elements that have no explicit command defined above. ### Auto Profile diff --git a/modernz.conf b/modernz.conf index 6fe19df9..44bac7b9 100644 --- a/modernz.conf +++ b/modernz.conf @@ -442,3 +442,9 @@ speed_mbtn_left_command=osd-msg add speed 1 speed_mbtn_right_command=osd-msg set speed 1 speed_wheel_down_command=osd-msg add speed -0.25 speed_wheel_up_command=osd-msg add speed 0.25 + +# default mouse actions +# applied to elements that have no explicit command defined above +default_mbtn_mid_command=ignore +default_wheel_up_command=ignore +default_wheel_down_command=ignore \ No newline at end of file From 0f3c224c2b5da0b99f66bddaaa8e39bb9b047811 Mon Sep 17 00:00:00 2001 From: Keith94 Date: Sun, 26 Apr 2026 08:55:25 -0600 Subject: [PATCH 2/2] feat: add default mouse commands --- modernz.lua | 56 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/modernz.lua b/modernz.lua index ea058bdd..3206ba37 100644 --- a/modernz.lua +++ b/modernz.lua @@ -302,6 +302,11 @@ local user_opts = { speed_mbtn_right_command = "osd-msg set speed 1", speed_wheel_down_command = "osd-msg add speed -0.25", speed_wheel_up_command = "osd-msg add speed 0.25", + + -- default mouse actions (applied to elements that have no explicit command defined above) + default_mbtn_mid_command = "", + default_wheel_up_command = "", + default_wheel_down_command = "", } local osc_param = { -- calculated by osc_init() @@ -2750,10 +2755,10 @@ local function bind_buttons(element_name, use_down) if command ~= nil and command ~= "" and command ~= "ignore" then elements[element_name].eventresponder["shift+mbtn_left_down"] = function() mp.command(command) end end - for _, button in ipairs({"wheel_up", "wheel_down"}) do - local command = user_opts[element_name .. "_" .. button .. "_command"] + for _, dir in ipairs({"wheel_up", "wheel_down"}) do + local command = user_opts[element_name .. "_" .. dir .. "_command"] if command ~= nil and command ~= "" and command ~= "ignore" then - elements[element_name].eventresponder[button .. "_press"] = function() mp.command(command) end + elements[element_name].eventresponder[dir .. "_press"] = function() mp.command(command) end end end end @@ -2796,6 +2801,20 @@ local function build_cache_seek_ranges() return nranges end +-- dynamically sets the "input" mouse area to only the hovered element +local click_keys = { + "mbtn_left_up", "mbtn_left_down", "mbtn_left_press", + "mbtn_right_up", "mbtn_right_down", "mbtn_right_press", + "wheel_up_press", "wheel_down_press", +} +local function has_click_action(e) + if not e.eventresponder then return false end + for _, k in ipairs(click_keys) do + if e.eventresponder[k] then return true end + end + return false +end + local function osc_init() msg.debug("osc_init") @@ -3353,6 +3372,23 @@ local function osc_init() prepare_elements() update_margins() + + -- apply default mid/wheel commands to every button/slider that has no responder + local default_actions = { + ["shift+mbtn_left_down"] = user_opts.default_mbtn_mid_command, + ["wheel_up_press"] = user_opts.default_wheel_up_command, + ["wheel_down_press"] = user_opts.default_wheel_down_command, + } + for _, element in pairs(elements) do + if (element.type == "button" or element.type == "slider") and element.eventresponder + and has_click_action(element) then + for key, command in pairs(default_actions) do + if not element.eventresponder[key] and command ~= nil and command ~= "" and command ~= "ignore" then + element.eventresponder[key] = function() mp.command(command) end + end + end + end + end end local function show_wc() @@ -3439,20 +3475,6 @@ local function element_has_action(element, action) return element and element.eventresponder and element.eventresponder[action] end --- dynamically sets the "input" mouse area to only the hovered element -local click_keys = { - "mbtn_left_up", "mbtn_left_down", "mbtn_left_press", - "mbtn_right_up", "mbtn_right_down", "mbtn_right_press", - "wheel_up_press", "wheel_down_press", -} -local function has_click_action(e) - if not e.eventresponder then return false end - for _, k in ipairs(click_keys) do - if e.eventresponder[k] then return true end - end - return false -end - local function refresh_input_area() if not state.osc_visible then set_virt_mouse_area(0, 0, 0, 0, "input")