Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-07-31 10:37:24

Pindakoe
Member
From: NL
Registered: 2003-11-26
Posts: 116

How can I find out which monitor(s) are connected to my PC

I have an (home-grown) script to cycle through a list of wallpapers or create a new backdrop by tiling some of my own photo's. This stopped functioning this morning when replacing the cable to my monitor (needed a longer one and thus moved from HDMI to DP). This made me realise again that Xfce codes the display differently by port/connection which shows in the displays.xml and xfce4-desktop.xml files in .config/xfce4/xfconf/xfce-perchannel-xml/:

selected lines from displays.xml
<channel name="displays" version="1.0">
  <property name="Default" type="empty">
    <property name="HDMI-2" type="string" value="1. Dell Inc. 24&quot;">
      <property name="Active" type="bool" value="true"/>

...

    <property name="HDMI-1" type="string" value="Dell Inc. 24&quot;">
      <property name="Active" type="bool" value="true"/>

...

    <property name="DP-1" type="string" value="Dell Inc. 24&quot;">
      <property name="Active" type="bool" value="true"/>

Note the differerent properyt-names HDMI-1, HDMI-2 en DP-1...
This also shows in xfce4-desktop.xml, see below selected lines:

<channel name="xfce4-desktop" version="1.0">
  <property name="backdrop" type="empty">
    <property name="screen0" type="empty">
      <property name="monitorHDMI-1" type="empty">

... and lower down..

      <property name="monitorDP-1" type="empty">
        <property name="workspace0" type="empty">

The important part to realise here is that I only have one monitor which historically was connected using HDMI en is now switched to DP.

My script sets the image on workspace0 to display a wallpaper and obviously needs to know which port it should use. Currently all are listed as active and other fields under display or desktop all have mostly same info).

Last edited by Pindakoe (2021-07-31 10:41:09)

Offline

#2 2021-07-31 11:35:27

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,023

Re: How can I find out which monitor(s) are connected to my PC

How can I find out which monitor(s) are connected to my PC

Not sure if its helpful, but here is a small C program that will show the screen and monitor names of active monitors connected to your computer:

#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>

int
main (int argc, char **argv)
{
    GdkDisplay *display;
    int i, n;

    gboolean ok = gtk_init_check(&argc, &argv);
   
    if (!ok) {
        return -1;
    }

    display = gdk_display_get_default ();
    if (display == NULL) {
        return -1;
    }

    n = gdk_display_get_n_monitors(display);

    for (i = 0; i < n; i++) {
        GdkMonitor *moni = gdk_display_get_monitor(display, i);
        const char *model = gdk_monitor_get_model(moni);

        g_print("screen%d monitor%s\n", i, model);
    }
    return 0;
}

Compile it with:

gcc xfmonitor.c -o xfmonitor `pkg-config --cflags --libs gtk+-3.0`

...naturally, you will need the build packages and gtk/gdk dev libraries installed.

If you are looking to script something, you could use the output of this program to identify the xfce4-desktop screen and monitor names.

Sample Output:

$ ./xfmonitor 
screen0 monitorLVDS-1
screen1 monitorHDMI-3

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2021-08-01 10:12:44

Jerry3904
Member
Registered: 2013-11-09
Posts: 853

Re: How can I find out which monitor(s) are connected to my PC

Being simple-minded, I would use arandr or one of the other *randr apps.

<But maybe you meant from within a script...>

Last edited by Jerry3904 (2021-08-01 10:41:53)


MX-23 (based on Debian Stable) with our flagship Xfce 4.18.

Offline

Board footer

Powered by FluxBB