Distinguish between hidden and active buffers in Vim

vim

Solution

Use `bufwinnr()` to check if a buffer is open in a window. The result is `-1` if it is not.

Problem

Is there a way to distinguish between hidden and active buffers in Vim? I need to determine if a buffer is active in a window so I can toggle it. Tried `bufloaded`, `bufexists` and `buflisted` but they all return 1 for both active and hidden buffers. (I have `set hidden` and `set bufhidden=hide` in my vimrc)

Original source