Can gestures trigger different actions based on what app/window the cursor is over?

I want my three finger down swipe to close the window my cursor is over, and if it's over safari, just close the tab. Sending command + W to the app the cursor doesn't work in mission control, won't always target the window I'm mousing over if multiple windows of the same app are open, and just doesn't work on some applications. If I set it to use the "Close window under cursor" action globally and send command + W only in safari, it chooses based on which app I'm focused on and not which app the cursor is over, still preventing it from working in mission control if safari is focused. Is there a way around this?