Using Brainstorm on two screens under Linux

Dear Brainstorm-Team,
I am currently trying to use brainstorm from a linux computer and I somehow run into troubles using two joined screens. When launching brainstorm I receive the following error:

Index in position 1 exceeds array bounds (must not exceed 1).

Error in gui_layout>GetScreenClientArea (line 237)
MaxWin = [MonitorPositions(i,1) + jInsets.left, ...

Error in gui_layout (line 33)
eval(macro_method);

Error in bst_startup (line 330)
GlobalData.Program.ScreenDef = gui_layout('GetScreenClientArea');

Error in brainstorm (line 138)
bst_startup(BrainstormHomeDir, 1, BrainstormDbDir);

When deactivating the second screen, everything works fine.
Is there any solution to this problem? :slight_smile:

Best,
Yvonne

Hi Yvonne,

It seems that Matlab is returning incorrect values for MonitorPosition (link)

Please execute code lines below in Matlab and post the result in this thread, alongside with your Matlab version, Linux distribution and desktop environment.

ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
NScreensJava = length(ge.getScreenDevices())
MonitorPositions = get(0, 'MonitorPositions')

Best,
Raymundo

Dear Raymundo,

Thank you for your reply! I ran the command and obtained:
NScreensJava =

 2

MonitorPositions =

       1           1        3840        1200

For the other information: I am using Matlab R2021a, Ubuntu 20.04 focal and GNOME 3.36.5!

Best,
Yvonne

This is odd, the number of screens reported with Java functions (2) doesn't match the number of screens registered in Matlab (1).

For the moment, I proposed a fix that would prevent the code from crashing, but may not work any better than disabling the second screen from the Brainstorm interface (in the display options menu, top-right part of the Brainstorm window - have you tried this btw?)
Update Brainstorm if you want to try this: https://github.com/brainstorm-tools/brainstorm3/commit/1a6df44494c4cf91c43666a17509c02bd7facc91

Maybe Raymundo will be able to reproduce the error on an Ubuntu 20 system and will be able to provide a better workaround?

Dear Francois,

Thank you for this proposed fix! I tried the update, but unfortunately it is also not working, I get the same error!
With regard to change the display options, I can't change them, because brainstorm wouldn't even start - I get the above mentioned error right in the beginning when calling the brainstorm.m script and don't get to the brainstorm interface. So the only way to get brainstorm running for me is to really unplug or deactivate the second screen completely from my computer!

I doubt that this is the same error. Please open function gui_layout.m at line 184, and check that this is a comment line that says % Fix discrepancies. If it does not, please try again updating Brainstorm.
If Brainstorm has been correctly updated, please copy-paste the full text of the error.

With regard to change the display options, I can't change them, because brainstorm wouldn't even start - I get the above mentioned error right in the beginning when calling the brainstorm.m script and don't get to the brainstorm interface.

Please copy paste the full error message you get at startup when you select the option One screen instead of two screens.

If you run into trouble to start Brainstorm, you can change the option back by executing in your command window:
bst_set('Layout', 'DoubleScreen', 1)
or
bst_set('Layout', 'DoubleScreen', 0)

Can you also please confirm that the dimensions in MonitorPositions (3840 x 1200) represent your two monitors horizontally extended?

Don't you have other options to set up your multiple screens in Ubuntu?

Thank you for this proposed fix! I tried the update, but unfortunately it is also not working, I get the same error!

Oops, I made a mistake in the fix... this is re-fixed here: Bugfix: Mismatch Matlab/Java in number of screens · brainstorm-tools/brainstorm3@1a6df44 · GitHub
Please try downloading Brainstorm once more...

Okay, I again updated brainstorm, but the comparison still seems to be in the wrong direction. However, if I manually change line 185 of gui_layout.m (in the way discussed in the github), it works! Thank you!

I aligned the resolutions of the screens to be exactly the same, so that now it is 1920 x 1080 each (before one of them was 1920 x 1200) and hence MonitorPositions (3840 x 1080) represents the horizontally extended monitors, as you assumed.

Now that you have the same resolution in both monitors, does
MonitorPositions = get(0, 'MonitorPositions')
returns only one monitor?

No, it still says 2 monitors:

ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
NScreensJava = length(ge.getScreenDevices())
MonitorPositions = get(0, 'MonitorPositions')

NScreensJava =

 2

MonitorPositions =

       1           1        3840        1080

Okay, I again updated brainstorm, but the comparison still seems to be in the wrong direction.

I had committed it but the push had failed for some reason... Here it is:
Bugfix: Mismatch Matlab/Java in number of screens (fix) · brainstorm-tools/brainstorm3@1d49449 · GitHub

It's good if you can work with Brainstorm now, but I still would like to check on the other options that you complained about. Can you please check the display option "One screen" vs. "Two screens"?
If you get any error message, please post the full stack trace here - thanks

Dear Francois,

Sure no problem!
I updated again, but the comparison sign is somehow still inversed in line 185.

In the manually corrected version I can run the commands bst_set('Layout', 'DoubleScreen', 1) (or 0) without any errors and the settings then change from "one screen" to "two screens" in the settings found in the upper right corner.

However, I do not see that it changes anything in the arrangements of the figures. They are mainly on the first screen and then spanned halfway across the second screen, no matter which settings I use.

I updated again, but the comparison sign is somehow still inversed in line 185.

The file is correctly updated online and I rebuilt the .zip packages, so if you don't see a ">", there was something wrong with the update process.

However, I do not see that it changes anything in the arrangements of the figures. They are mainly on the first screen and then spanned halfway across the second screen, no matter which settings I use.

Yes, this is what is expected...
For Matlab, you have only one screen with a width of 3840 pixels...
You can try changing the window manager, or changing the multi-screen configuration of Gnome, maybe some combinations of parameters will lead Matlab to get more information.

Note that if you do change the display parameters, you need to restart Matlab after, as otherwise the changes might not be taken into account.