How to preconfigure default settings for external display?

Is it possible to set default screen resolution, FPS, relative position and whether it is a “main” display for an external screen connected with a dock before connecting it?

I am trying to solve two different problems.

  1. It is annoying to configure everything once again from “Settings” each time I connect the phone to a dock.

    For example, I want an external display to become a “main” display and the phone’s built-in touchscreen should become landscape.

    It becomes annoying squared considering that with the hardware I have (Hoco HB37 hub → HDMI-to-DVI adapter → DVI-D “Single-Link” cable → display) the display frequently turns off while the Librem 5 seems to not notice it. This makes me disconnect everything and connect it back, and then reconfigure it again, and sometimes display immediately turns off after applying new configurations…

    When an external screen turns off the following can be seen in dmesg logs:

    [Jun19 14:57] [drm] hpd irq
    [  +0.201451] [drm] Connector status: 1
    [  +0.000042] [drm] HDMI/DP Cable Plug In
    [  +2.139347] [drm] hpd irq
    [  +0.204617] [drm] Connector status: 1
    [  +0.000030] [drm] HDMI/DP Cable Plug In
    [  +2.136559] [drm] hpd irq
    [  +0.207309] [drm] Connector status: 1
    [  +0.000030] [drm] HDMI/DP Cable Plug In
    [  +5.231905] [drm] hpd irq
    [  +0.204488] [drm] Connector status: 1
    [  +0.000045] [drm] HDMI/DP Cable Plug In
    
  2. With an another cable it seems like the screen is automatically configured in a wrong way, then something fails, the display flashes for a split second with its built-in message about “Not Optimum Mode” (it was almost impossible to read it during that short moment it appeared), turns off, flashes with that message again and so on.

    UPD: It was just a bad connection. I have just unplugged the cable on the screen’s end and pluged it again and it just worked. The question about changing defaults is still valid.

    Details about how the bad connection problem may look like, if you are interested, are under this spoiler.

    The cable is a new HDMI to DVI-D “Dual Link” one I have just bought to rule out the HDMI-to-DVI adapter from the equation in hope that it might make the display not turn off unexpectedly.

    These are the messages in dmesg log I get with this new cable:

    [Jun20 14:32] [drm] hpd irq
    [  +0.201418] [drm] Connector status: 1
    [  +0.000548] [drm] HDMI/DP Cable Plug In
    [  +0.014265] [drm] Connector status: 1
    [  +0.014272] cdns-mhdp-imx 32c00000.hdmi: 0,ff,ff,ff,ff,ff,ff,0
    [  +0.090409] [drm] Mode: 1920x1080p138640
    [  +0.197643] cdns-mhdp-imx 32c00000.hdmi: [drm:cdns_mhdp_set_host_cap [cdns_mhdp_drmcore]] Using 2 lanes
    [  +0.048566] imx-dcss 32e00000.display-controller: Pixel clock set to 138636 kHz instead of 138640 kHz.
    [  +0.000066] cdns-mhdp-imx 32c00000.hdmi: [drm:cdns_mhdp_train_link [cdns_mhdp_drmcore]] Starting link training
    

    wlr-randr shows this:

    $ wlr-randr 
    DSI-1 "<Unknown> <Unknown>  (DSI-1)"
      Physical size: 65x130 mm
      Enabled: yes
      Modes:
        720x1440 px, 63.414001 Hz (preferred, current)
      Position: 0,0
      Transform: normal
      Scale: 2.000000
    DP-1 "Unknown 0x5211 0x00000401 (DP-1)"
      Physical size: 530x300 mm
      Enabled: yes
      Modes:
        1920x1080 px, 49.998001 Hz
        1920x1080 px, 59.993999 Hz (preferred, current)
      Position: 360,0
      Transform: normal
      Scale: 1.000000
    

For reference, i consulted this article to figure out what kind of DVI cable I have.

2 Likes

One answer: UPERFECT X Mini lapdock works with Librem 5 - #96 by tendays (would need to be adapted and note that it is triggering on the appearance of a particular USB device, the lapdock touchscreen device, and you would need to find a device that works for your situation).

2 Likes

Another answer: Display (with Nexdock / ext display) configuration

2 Likes

I asked an AI:

Yes, on a Debian-based distro using Wayland, you can configure predefined display settings for external monitors. While Wayland doesn’t use xrandr (which was common in X11), there are still several ways to achieve this depending on your desktop environment and tools available.


Options for Preconfigured Display Settings on Wayland

1. Desktop Environment Tools

Most modern DEs (like GNOME, KDE Plasma) on Wayland support display profiles:

  • GNOME:
    • Automatically remembers display configurations per monitor.
    • You can manually configure displays via Settings > Displays.
    • Profiles are stored in dconf and can be scripted using gsettings.
  • KDE Plasma:
    • Has built-in support for display profiles.
    • You can save and switch between profiles using KScreen.
    • Profiles are stored in ~/.local/share/kscreen/.

2. udev + systemd + scripts

You can create a udev rule that triggers a script when an external display is connected.

  • udev rule example:
  SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/display-hotplug.sh"
  • Your display-hotplug.sh script could use tools like:
    • wlr-randr (for wlroots-based compositors)
    • swaymsg (for Sway)
    • hyprctl (for Hyprland)
    • gsettings (for GNOME)

Note: The script must be Wayland-aware and use compositor-specific tools.

3. Wayland Compositor-Specific Tools

Depending on your compositor:

  • Sway: Use swaymsg to configure outputs.
  • Hyprland: Use hyprctl to apply monitor settings.
  • Wayfire: Has its own config files.
  • GNOME: Use gsettings or dconf.

4. Manual Script or App Launcher

You can create a script that sets up your preferred layout and bind it to a:

  • Keyboard shortcut
  • Desktop launcher
  • Startup application

Example: Script for Sway

#!/bin/bash
swaymsg output HDMI-A-1 enable pos 1920 0 res 1920x1080

Example: Script for GNOME

gsettings set org.gnome.desktop.wm.preferences auto-raise true
# or use dconf dump/load for full display profile

Maybe those give starting points. It’s not clear to me if any of those are hallucinations or doable with what you know…

1 Like

Thanks! Kanshi seems to be the solution, but…

I have just tried to run kanshi from terminal (with appropriate config) and for some reason profiles are not triggered with display connect/disconnect. Instead they are triggered only once when the daemon is started.

And also each time the display configuration is changed or display itself is connected/disconnected there is a chance that phosh unexpectedly restarts (with all windows closed and displaying login screen). :weary:

Also, is there a command to specify the “main” screen in Phosh so that I can add this command into profile?

2 Likes

I have also configured kanshi to be started as systemd service as suggested in the answer you referred and made display description less specific (DP-1 instead of full display name in double quotes). It did not change anything.

1 Like

Sorry but I don’t myself use kanshi (or udev for this purpose) so don’t have much insight on getting either solution working.

2 Likes

Is this what you are looking for:

If so, it is fixed in a newer phosh than the version shipped with Byzantium.

I originally reported this issue: Display scaling is not persistent over rebooting (#147) · Issues · Librem5 / gnome-control-center · GitLab

3 Likes

Yes, it is possible. Previously I used udev rules to run custom script which configured the main screen using python-dbus binding.

$ cat /etc/udev/rules.d/95-monitor-hotplug.rules
ACTION==“change”, SUBSYSTEM==“drm”, RUN+=“/usr/bin/systemctl start hotplug_monitor.service”

Oh… the path is a little bit longer…

$ cat /etc/systemd/system/hotplug_monitor.service
[Unit]
Description=Monitor hotplug

[Service]
Type=simple
RemainAfterExit=no
User=purism
ExecStart=/usr/local/bin/hotplug_monitor.sh

[Install]
WantedBy=multi-user.target

I do not remember why it is so long (udev->systemd->bash->python->dbus) and I can not check it now as far as my type-c port still a little bit broken. However I believe this solution could be useful for someone.

2 Likes

Yes, this is it!

As I can see, these issues are not yet closed. So, I guess that in Phosh version from Crimson it is also not yet fixed. :disappointed:

At least, it is good to know that the developers are aware of this problem. :slightly_smiling_face:

3 Likes

Thanks! This looks like a solution. I’ll try it once I figure out why Phosh segfaults…

2 Likes