Get the pixel size of each screen when connecting multiple monitors

163 views
Skip to first unread message

Danqing

unread,
Mar 3, 2021, 10:49:14 PM3/3/21
to Bonsai Users
Hello,

Hope you are all well.

I want to display the bonsai shader window on the second screen, since some actions are relating to the horizontal resolution of the second screen, I would like to read this value. 
However, after trying to connect two monitors separately to the laptop, I realized that the horizontal resolution of the second screen changes between PCs. On the first trial, the horizontal resolution of the second screen ranges from 0 to 1920. On the second trial, the horizontal resolution of the second screen ranges from 1920 to 3840. Currently, I assume this value ranges from 0 to 1920, but it only works for the first trial, wondering if there is a way to read the horizontal resolution of the second screen regarding different monitors so that we don’t rely on any previous assumption.

Thanks in advance!

Best regards,

Danqing

bruno...@neuro.fchampalimaud.org

unread,
Mar 6, 2021, 11:46:39 AM3/6/21
to Bonsai Users
Hi, 
Can you send your workflow? I think it might have to do no how you are defining your display or how you are passing the resolution argument to downstream nodes. Nevertheless, if you want to normalize across screens, a great way to do this is to use the NormalizeView Node. It transforms pixel coordinates to -1:1 coordinates. You can check in the bonvision examples, some of them use this node (eg https://bonvision.github.io/pages/03-Creating-Basic-Stimuli/#step-2-add-renderframe)
Cheers,
B

Danqing

unread,
Mar 7, 2021, 6:41:15 AM3/7/21
to Bonsai Users
Hi.

Thank you so much for your reply and your suggestions. Yes, I use NormalizeView Node as the coordinate frame, please kindly find the first screenshot. Regarding the second screenshot, I'm trying to rescale the value of the MousCursor to make it compatible with the screen resolution, i.e., Min and Max of Rescale is the range of screen resolution of the second screen, but as I've mentioned in the previous email, this value varies between PCs and I'm struggling to get it.

Best regards,
Danqing

Screenshot 1.png

Screenshot 2.png

bruno...@neuro.fchampalimaud.org

unread,
Mar 7, 2021, 7:15:57 AM3/7/21
to Bonsai Users
Hey!
I am still not sure I fully understand what the problem is exactly. Is it the case that on some computers you want to use the first display and on others, you want to use the second? I think one of these 2 solutions might work for you:

1. Normalize the coordinates of your device using NormalizedDeviceCoordinates. Whenever your mouse is inside the shader's window it will output the coordinates between -1 and 1 for both X and Y. I tend to prefer this solution since I always want to work with the reference of the shader and not the screen. This way, you can move/resize the shader and your code will still generalize.

2.Get the X,Y,Width and Height for each rendered frame (or just the first if you don't touch it afterward)
Right-click on top of RenderFrame and select the "Sender" output. Inside you can output X,Y, Width and Height that pipe those to your rescale node

Hope it helps,
B


Capture2.PNG
Capture.PNG

Danqing

unread,
Mar 9, 2021, 9:03:43 AM3/9/21
to Bonsai Users
Hi,

Thank you so much for your help, I have used the first solution, and it works well now.

Best regards,

Danqing

Reply all
Reply to author
Forward
0 new messages