BlankSourceCode / obs-zoom-to-mouse

An OBS lua script to zoom a display-capture source to focus on the mouse
178 stars 15 forks source link

Add provisional Mac and Linux support #16

Closed BlankSourceCode closed 7 months ago

BlankSourceCode commented 7 months ago

This PR adds the FFI defines for Linux and Mac so that the script can now get the mouse position on those platforms.

Inspired by work shown in PR #14 by v0l

Note: I only tested this on Ubuntu 22.04.2 and Mac OS Catalina (I know that's really old but it's the only apple device I have access to). This means it's possible (likely?) that the support won't work on other flavors of Linux or newer versions of Mac.

If anyone is interested in testing it out on other versions and modifying the code, you'll want to look at the FFI defines for each platform near the top of the file and the get_mouse_pos() function. For OSX specifically the get_dc_info() may need updating because the display-capture source for Mac changed between OBS 29.0 and 29.1 and catalina can only install 29.0 :(  

BlankSourceCode commented 7 months ago

related #1

mcnaveen commented 7 months ago

I'm on MacOS Ventura 13.4.1 and it doesn't seem to be working. Pressing the hotkey does nothing.

https://drive.google.com/file/d/19DZp9zg13X_mMrIN4D6qrtDebgBD6oFW/view?usp=sharing

and there is no error in the script log

BlankSourceCode commented 7 months ago

@mcnaveen Thanks for taking a look. I would have thought it would zoom in, just it wouldn't follow the mouse because I didn't change how the hotkeys worked (maybe they work differently on mac - I'll have to investigate somehow).

Did the Zoom Source dropdown show your display capture as an option at least (that was the other part I wasn't sure would work with newer macs)?

Could you try the latest script from main instead and see if it at least toggles the zoom? You'll probably need to enable Allow any zoom source to be able to pick your display capture source.

Thanks!

mcnaveen commented 7 months ago

With the main branch. I'm not getting the Zoom Source. But with the add-mac-linux-support branch I'm getting the select zoom source option.

image

But both aren't actually initiating the Zoom.

P.S: I'll check out this on my Ubuntu 22.04 i3wm. I'm hope it'll work.

mcnaveen commented 7 months ago

Update: It works amazingly well in Ubuntu 22.04 i3wm. I have tried so many Python scripts. This is the only one that works. But the quality isn't good. Anyway this can be fixed?

BlankSourceCode commented 7 months ago

With the main branch. I'm not getting the Zoom Source. But with the add-mac-linux-support branch I'm getting the select zoom source option.

With the main branch, you'll need to scroll down in the settings and check Allow any zoom source to be able to see any display captures in the dropdown (because main doesn't have the code that specifies the new name for the source on mac).

Do any other OBS hotkeys work on your Mac? I had real trouble getting them to work correctly even without my script (they only work when I have OBS in focus)

I haven't updated the hotkey code, so it's odd that it works on Ubuntu and Windows but not Mac.

Update: It works amazingly well in Ubuntu 22.04 i3wm. I have tried so many Python scripts. This is the only one that works. But the quality isn't good. Anyway this can be fixed?

So it does work for you on Ubuntu? Can you tell me what quality issue you are seeing? Mostly the script just animates a Crop/Pad filter with a timer.

BlankSourceCode commented 7 months ago

FYI - I just figured out that to get any hotkeys working in OBS for Mac (even without the script), I needed to enable permissions for OBS in System Preferences -> Security & Privacy -> Privacy Tab. For me, I found OBS listed under Accessibility, but I suspect for later versions of Mac it is under Input Monitoring. Enabling OBS permissions there got hotkeys working correctly.

mcnaveen commented 7 months ago

I have enabled both options. Still, it doesn't work.

BlankSourceCode commented 7 months ago

I modified the code slightly to pick the correct default on OBS for Mac Ventura, and got it tested out on a more modern mac.

Here you can see the script working on 3 different OS's. Ignore the fps of the gifs, in real life it is a lot smoother:

Catalina Ventura Ubuntu

Note: For Ubuntu I installed the loopback package to enable XSHM capture because that one works most like other platform captures. The script also works with a Pipewire capture source but it can't auto calculate the size so you have to enable Allow any zoom source and set the size manually.

BlankSourceCode commented 7 months ago

fixes #1

mcnaveen commented 7 months ago

LGTM 🫡

Tested with OBS v30.0.0 on MacOS Ventura (13.4.1) and Ubuntu 22.02 (i3wm)

p.s: It's not working with a lower version of OBS <v29.x.x

BlankSourceCode commented 7 months ago

I think it was working, just you had to enable "Allow any zoom source". I updated the mac version check to use screen_capture as the default source type for versions > 29.0. Looks like it changed in 29.1.