LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   How to get monitor number in multi display configuration (https://www.linuxquestions.org/questions/linux-desktop-74/how-to-get-monitor-number-in-multi-display-configuration-4175636261/)

DAFlippers 08-13-2018 05:59 AM

How to get monitor number in multi display configuration
 
When you configure a multi display setup in Linux you can place the monitors as you wish and a single desktop canvas is created. In a very simple example I could place two monitors, each 1920x1200, side by side to create a 3840x1200 desktop.

The problem I have is that I could have placed:

Monitor 1 Monitor 2

or

Monitor 2 Monitor 1

I know the desktop size and I can use XRRGetMonitors() to get the position of each monitor but not the number that is used in the configuration tool and I need the id number for my application. I am sure it is simple but I haven't found a way thus far.

It appears the monitor data is stored from top left to bottom right in files like monitors.xml however the display id number is not held in any file I have found so far. Xrandr also outputs screens top left to bottom right but does not give display id number. I need the id number of the display shown in the Display arrangement in the Screen Display GUI as I need to sync this with external applications.

Can someone enlighten me please?

ferrari 08-25-2018 09:22 PM

I don't have a definitive answer here, but from an xrandr perspective it's the display interface that's relevant (rather than some arbitrary number). For example...

Code:

xrandr --auto --output HDMI1 --primary --left-of VGA1

DAFlippers 08-26-2018 02:36 AM

Unfortunately the screen layouts are set up by users using the system GUI and that is why I need the internal numeric IDs for the screens. I am amazed that no-one knows how to obtain these IDs.

David

ferrari 08-26-2018 03:48 AM

Quote:

Unfortunately the screen layouts are set up by users using the system GUI and that is why I need the internal numeric IDs for the screens. I am amazed that no-one knows how to obtain these IDs.
You haven't mentioned the GUI in question. KDE's "Display and Monitor" utility shows the layout with interface labels. These are consistent with those reported by xrandr. I can't see the need for any other arbitrarily-assigned ID.

DAFlippers 08-26-2018 04:47 AM

Quote:

KDE's "Display and Monitor" utility shows the layout with interface labels. These are consistent with those reported by xrandr.
In Ubuntu Settings::Devices::Screen Display I can arrange the Screens and they are shown with numeric IDs in the GUI and on each screen when GUI has focus. The GUI shows monitor name however all monitors are the same type so I can't use name to determine screen. xrandr output below. I can see port but not the ID. In the below Screen ID 1 is above (with slight offset to right) of screen ID 2.

david@david-desktop:~$ xrandr
Screen 0: minimum 320 x 200, current 2772 x 2160, maximum 8192 x 8192
VGA-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 connected primary 1920x1080+0+1080 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+
1600x1200 60.00
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1152x864 75.00
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
640x480 75.00 72.81 66.67 59.94
720x400 70.08
HDMI-3 connected 1920x1080+852+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+ 50.00 59.94 59.99
1920x1080i 60.00 50.00 59.94
1600x1200 60.00
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1366x768 59.79
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
720x576 50.00
720x480 60.00 59.94
640x480 75.00 72.81 66.67 60.00 59.94
720x400 70.08
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
DP-1-4 disconnected (normal left inverted right x axis y axis)
DP-1-5 disconnected (normal left inverted right x axis y axis)
DP-1-6 disconnected (normal left inverted right x axis y axis)
DP-1-7 disconnected (normal left inverted right x axis y axis)
david@david-desktop:~$


Now I have changed ports and the GUI shows Screen 2 to the left of Screen 1. xrandr reports:


david@david-desktop:~$ xrandr
Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 8192 x 8192
VGA-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+
1600x1200 60.00
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1152x864 75.00
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
640x480 75.00 72.81 66.67 59.94
720x400 70.08
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
HDMI-3 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+ 50.00 59.94 59.99
1920x1080i 60.00 50.00 59.94
1600x1200 60.00
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1366x768 59.79
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
720x576 50.00
720x480 60.00 59.94
640x480 75.00 72.81 66.67 60.00 59.94
720x400 70.08
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
DP-1-4 disconnected (normal left inverted right x axis y axis)
DP-1-5 disconnected (normal left inverted right x axis y axis)
DP-1-6 disconnected (normal left inverted right x axis y axis)
DP-1-7 disconnected (normal left inverted right x axis y axis)
david@david-desktop:~$



I now move Screen 2 to right of Screen 1 in the GUI and xrandr reports:


david@david-desktop:~$ xrandr
Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 8192 x 8192
VGA-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 connected primary 1920x1080+1920+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+
1600x1200 60.00
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1152x864 75.00
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
640x480 75.00 72.81 66.67 59.94
720x400 70.08
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
HDMI-3 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+ 50.00 59.94 59.99
1920x1080i 60.00 50.00 59.94
1600x1200 60.00
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1366x768 59.79
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
720x576 50.00
720x480 60.00 59.94
640x480 75.00 72.81 66.67 60.00 59.94
720x400 70.08
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
DP-1-4 disconnected (normal left inverted right x axis y axis)
DP-1-5 disconnected (normal left inverted right x axis y axis)
DP-1-6 disconnected (normal left inverted right x axis y axis)
DP-1-7 disconnected (normal left inverted right x axis y axis)
david@david-desktop:~$


So xrandr reports in port order but does not provide the ID I need.


Or am I missing something obvious?

ferrari 08-26-2018 05:16 AM

I'm not 100% certain, but from what you've posted the xrandr interface order seems to be significant. In the examples you gave, the last connected interface seems to be mapped to screen ID 1, with screen ID 2 being the next prior connected display interface.

So 'HDMI-1 connected' and 'HDMI-3 connected' would appear to be associated with screen ID 2 and screen ID 1 respectively. Likewise, for the case with 'HDMI-2 connected' and 'HDMI-3 connected' would perhaps correspond with screen ID 2 and screen ID 1 respectively. Does that make sense?

DAFlippers 08-26-2018 05:29 AM

Quote:

So 'HDMI-1 connected' and 'HDMI-3 connected' would appear to be associated with screen ID 2 and screen ID 1 respectively. Likewise, for the case with 'HDMI-2 connected' and 'HDMI-3 connected' would perhaps correspond with screen ID 2 and screen ID 1 respectively. Does that make sense?
In the above example yes however the ID in the GUI depends on the order that you plug in the screens - if I plug in HDMI 3 only then that will be ID 1 and then I plug in HDMI 1 that will become ID 2 but if I started with HDMI 1 then that would be ID 1 etc.. See the problem?

ferrari 08-26-2018 05:37 AM

I'm not sure. You might need to test that scenario perhaps. I'm not a Gnome user unfortunately.

DAFlippers 08-26-2018 05:43 AM

That is the case which is why I want to get the ID used in the GUI....

Thanks for your suggestions, though.


All times are GMT -5. The time now is 09:23 PM.