Is there a way to detect option change for a specific window?

OptionSet autocmd can be used to detect change for an option. But there is no way to narrow it down for a specific window, or know for which window that option was changed.

Is there any other possible way to do this?

For example: Let’s say I want a function to be called whenever the winhighlight option changes for a specific floating window.

Would something like this work? (replacing local win=... and 'number' with desired):

local win=vim.api.nvim_get_current_win()


    if CACHE~=vim.api.nvim_win_get_option(win,'number') then
        --add wanted command here

Hmm… Yeah, that would get the work done.

But it’s a bit wasteful, it will get triggered whenever number is changed, doesn’t matter for which window.

I wish autocmds had more fine grained control.