How to restore/rebuild/recreate X11 .conf files for NVidia Optimus card and dual screens?

I own a laptop with a Nvidia Optimus system (switchable Intel and NVidia graphics) with a second screen attached via a HDMI cable.
In some state of madness I deleted my nvidia.conf, intel.conf and possibly another .conf from /etc/X11/xorg.conf.d some time ago. Since then hardware seems to be autodetected on each startup but there are some quirks, especially with the dual monitor setup. Manjaro does not save the dual monitor configuration and I have to reconfigure it on each startup for my needs, which is kind of annoying.
Is there no way to force an autodetection with proper hardware-recognition and creation of new .conf files? I already tried nvidia-xconfig and built a new xorg.conf but only the hdmi-attached screen and the nvidia card were recognized.
Those files are created during system installation so there should be a way to re-do it afterwards!? Any ideas on that or do I have to reinstall the whole system?

provide formated output from:
inxi -Fazy
mhwd -l && mhwd -li
find /etc/X11/ -name "*.conf"

❯ inxi -Fazy
System:
  Kernel: 5.17.9-1-MANJARO arch: x86_64 bits: 64 compiler: gcc v: 12.1.0
    parameters: BOOT_IMAGE=/boot/vmlinuz-5.17-x86_64
    root=UUID=9e744c1a-ec40-4c90-b092-da43ca14110d rw quiet
    cryptdevice=UUID=3352fb98-8855-4902-9528-db429256c07d:luks-3352fb98-8855-4902-9528-db429256c07d
    root=/dev/mapper/luks-3352fb98-8855-4902-9528-db429256c07d
    resume=/dev/mapper/luks-3352fb98-8855-4902-9528-db429256c07d apparmor=1
    security=apparmor udev.log_priority=3
  Desktop: Xfce v: 4.16.0 tk: Gtk v: 3.24.29 info: xfce4-panel wm: xfwm
    v: 4.16.1 vt: 7 dm: LightDM v: 1.30.0 Distro: Manjaro Linux base: Arch Linux
Machine:
  Type: Laptop System: Micro-Star product: GE73 Raider RGB 8RF v: REV:1.0
    serial: <superuser required> Chassis: type: 10 serial: <superuser required>
  Mobo: Micro-Star model: MS-17C5 v: REV:1.0 serial: <superuser required>
    UEFI: American Megatrends v: E17C5IMS.10F date: 05/20/2019
Battery:
  ID-1: BAT1 charge: 38.3 Wh (94.8%) condition: 40.4/53.4 Wh (75.7%)
    volts: 11.9 min: 10.9 model: MSI BIF0_9 type: Li-ion serial: N/A status: N/A
CPU:
  Info: model: Intel Core i7-8750H bits: 64 type: MT MCP arch: Coffee Lake
    family: 6 model-id: 0x9E (158) stepping: 0xA (10) microcode: 0xF0
  Topology: cpus: 1x cores: 6 tpc: 2 threads: 12 smt: enabled cache:
    L1: 384 KiB desc: d-6x32 KiB; i-6x32 KiB L2: 1.5 MiB desc: 6x256 KiB
    L3: 9 MiB desc: 1x9 MiB
  Speed (MHz): avg: 2595 high: 3942 min/max: 800/4100 scaling:
    driver: intel_pstate governor: performance cores: 1: 3942 2: 3231 3: 2200
    4: 2200 5: 2200 6: 2200 7: 2787 8: 2200 9: 2200 10: 2201 11: 3588 12: 2200
    bogomips: 52815
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities:
  Type: itlb_multihit status: KVM: VMX disabled
  Type: l1tf
    mitigation: PTE Inversion; VMX: conditional cache flushes, SMT vulnerable
  Type: mds mitigation: Clear CPU buffers; SMT vulnerable
  Type: meltdown mitigation: PTI
  Type: spec_store_bypass
    mitigation: Speculative Store Bypass disabled via prctl
  Type: spectre_v1
    mitigation: usercopy/swapgs barriers and __user pointer sanitization
  Type: spectre_v2 mitigation: Retpolines, IBPB: conditional, IBRS_FW,
    STIBP: conditional, RSB filling
  Type: srbds mitigation: Microcode
  Type: tsx_async_abort status: Not affected
Graphics:
  Device-1: Intel CoffeeLake-H GT2 [UHD Graphics 630] vendor: Micro-Star MSI
    driver: i915 v: kernel ports: active: eDP-1 empty: none bus-ID: 00:02.0
    chip-ID: 8086:3e9b class-ID: 0300
  Device-2: NVIDIA GP104M [GeForce GTX 1070 Mobile] vendor: Micro-Star MSI
    driver: nvidia v: 510.73.05 alternate: nouveau,nvidia_drm non-free: 515.xx+
    status: current (as of 2022-05) arch: Pascal pcie: gen: 1 speed: 2.5 GT/s
    lanes: 16 link-max: gen: 3 speed: 8 GT/s bus-ID: 01:00.0
    chip-ID: 10de:1ba1 class-ID: 0300
  Device-3: Acer HD Webcam type: USB driver: uvcvideo bus-ID: 1-13:11
    chip-ID: 5986:1140 class-ID: 0e02 serial: <filter>
  Device-4: Logitech HD Pro Webcam C920 type: USB
    driver: snd-usb-audio,uvcvideo bus-ID: 1-3.4.3:13 chip-ID: 046d:082d
    class-ID: 0102 serial: <filter>
  Display: x11 server: X.Org v: 21.1.3 compositor: xfwm v: 4.16.1 driver: X:
    loaded: modesetting,nvidia unloaded: vesa alternate: fbdev,nouveau,nv
    gpu: i915 display-ID: :0.0 screens: 1
  Screen-1: 0 s-res: 3840x1080 s-dpi: 96 s-size: 1016x286mm (40.00x11.26")
    s-diag: 1055mm (41.55")
  Monitor-1: HDMI-1-0 pos: primary,left res: 1920x1080 hz: 60 dpi: 92
    size: 531x298mm (20.91x11.73") diag: 609mm (23.97") modes: N/A
  Monitor-2: eDP-1 pos: right res: 1920x1080 hz: 120 dpi: 128
    size: 381x214mm (15x8.43") diag: 437mm (17.2") modes: N/A
  OpenGL: renderer: Mesa Intel UHD Graphics 630 (CFL GT2) v: 4.6 Mesa 22.0.4
    direct render: Yes
Audio:
  Device-1: Intel Cannon Lake PCH cAVS vendor: Micro-Star MSI
    driver: snd_hda_intel v: kernel alternate: snd_soc_skl,snd_sof_pci_intel_cnl
    bus-ID: 00:1f.3 chip-ID: 8086:a348 class-ID: 0403
  Device-2: NVIDIA GP104 High Definition Audio driver: snd_hda_intel
    v: kernel pcie: gen: 1 speed: 2.5 GT/s lanes: 16 link-max: gen: 3
    speed: 8 GT/s bus-ID: 01:00.1 chip-ID: 10de:10f0 class-ID: 0403
  Device-3: Logitech HD Pro Webcam C920 type: USB
    driver: snd-usb-audio,uvcvideo bus-ID: 1-3.4.3:13 chip-ID: 046d:082d
    class-ID: 0102 serial: <filter>
  Sound Server-1: ALSA v: k5.17.9-1-MANJARO running: yes
  Sound Server-2: sndio v: N/A running: no
  Sound Server-3: PulseAudio v: 15.0 running: no
  Sound Server-4: PipeWire v: 0.3.51 running: yes
Network:
  Device-1: Intel Cannon Lake PCH CNVi WiFi driver: iwlwifi v: kernel
    bus-ID: 00:14.3 chip-ID: 8086:a370 class-ID: 0280
  IF: wlo1 state: down mac: <filter>
  Device-2: Qualcomm Atheros Killer E2500 Gigabit Ethernet
    vendor: Micro-Star MSI driver: alx v: kernel pcie: gen: 1 speed: 2.5 GT/s
    lanes: 1 port: 3000 bus-ID: 03:00.0 chip-ID: 1969:e0b1 class-ID: 0200
  IF: enp3s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
  IF-ID-1: virbr0 state: down mac: <filter>
Bluetooth:
  Device-1: Intel Bluetooth 9460/9560 Jefferson Peak (JfP) type: USB
    driver: btusb v: 0.8 bus-ID: 1-14:12 chip-ID: 8087:0aaa class-ID: e001
  Report: bt-adapter ID: hci0 rfk-id: 1 state: down
    bt-service: enabled,running rfk-block: hardware: no software: yes
    address: <filter>
Drives:
  Local Storage: total: 2.08 TiB used: 1.43 TiB (68.7%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Kingston
    model: RBUSNS8154P3256GJ size: 238.47 GiB block-size: physical: 512 B
    logical: 512 B speed: 15.8 Gb/s lanes: 2 type: SSD serial: <filter>
    rev: E8FK11.C temp: 48.9 C scheme: GPT
  ID-2: /dev/sda maj-min: 8:0 vendor: Crucial model: CT2000MX500SSD1
    size: 1.82 TiB block-size: physical: 512 B logical: 512 B speed: 6.0 Gb/s
    type: SSD serial: <filter> rev: 023 scheme: GPT
  ID-3: /dev/sdb maj-min: 8:16 type: USB vendor: Hama model: Hama
    size: 29.82 GiB block-size: physical: 512 B logical: 512 B type: N/A
    serial: <filter> rev: 1100 scheme: MBR
  SMART Message: Unknown USB bridge. Flash drive/Unsupported enclosure?
Partition:
  ID-1: / raw-size: 237.47 GiB size: 232.69 GiB (97.98%)
    used: 169.44 GiB (72.8%) fs: ext4 dev: /dev/dm-0 maj-min: 254:0
    mapped: luks-3352fb98-8855-4902-9528-db429256c07d
  ID-2: /boot/efi raw-size: 1024 MiB size: 1022 MiB (99.80%)
    used: 444 KiB (0.0%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1
  ID-3: /home raw-size: 1.82 TiB size: 1.79 TiB (98.37%)
    used: 1.24 TiB (69.5%) fs: ext4 dev: /dev/dm-1 maj-min: 254:1
    mapped: luks-654e7435-e8ca-4b13-8abb-18733a64eff7
Swap:
  Alert: No swap data was found.
Sensors:
  System Temperatures: cpu: 50.0 C pch: 50.0 C mobo: N/A
  Fan Speeds (RPM): N/A
Info:
  Processes: 352 Uptime: 1h 42m wakeups: 1 Memory: 15.47 GiB
  used: 2.92 GiB (18.9%) Init: systemd v: 250 tool: systemctl Compilers:
  gcc: 12.1.0 clang: 13.0.1 Packages: 2084 note: see --pkg pacman: 2041
  lib: 486 flatpak: 40 snap: 3 Shell: Zsh v: 5.9 running-in: terminator
  inxi: 3.3.16

❯ mhwd -l && mhwd -li
> 0000:01:00.0 (0300:10de:1ba1) Display controller nVidia Corporation:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
video-hybrid-intel-nvidia-prime            2021.12.18               false            PCI
video-hybrid-intel-nvidia-470xx-prime            2021.12.18               false            PCI
video-hybrid-intel-nvidia-390xx-bumblebee            2021.12.18               false            PCI
          video-nvidia            2021.12.18               false            PCI
    video-nvidia-470xx            2021.12.18               false            PCI
    video-nvidia-390xx            2021.12.18               false            PCI
           video-linux            2018.05.04                true            PCI
     video-modesetting            2020.01.13                true            PCI
            video-vesa            2017.03.12                true            PCI


> 0000:00:02.0 (0300:8086:3e9b) Display controller Intel Corporation:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
video-hybrid-intel-nvidia-prime            2021.12.18               false            PCI
video-hybrid-intel-nvidia-470xx-prime            2021.12.18               false            PCI
video-hybrid-intel-nvidia-390xx-bumblebee            2021.12.18               false            PCI
           video-linux            2018.05.04                true            PCI
     video-modesetting            2020.01.13                true            PCI
            video-vesa            2017.03.12                true            PCI


> Installed PCI configs:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
     video-modesetting            2020.01.13                true            PCI
video-hybrid-intel-nvidia-prime            2021.12.18               false            PCI


Warning: No installed USB configs!

❯ find /etc/X11/ -name "*.conf"
/etc/X11/xorg.conf.d/00-keyboard.conf
/etc/X11/mhwd.d/nvidia.conf

Info: /etc/X11/mhwd.d/nvidia.conf does not contain any config parameters

i think you should have there some mhwd.conf too, but im not sure… first check this link:
https://docs.xfce.org/xfce/xfce4-settings/display

Settings are not stored there - creating a profile does not change anything. Screens are always mirrored after reboot. Laptop screen is always at 120Hz (not changeable) while hdmi-attached screen only supports 60Hz.

since you deleted the configs from x11, probably reinstalling your video drivers could help… so are we going to try that? but first try deleting this file:

rm ~/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml

then reboot and check if the displays are properly detected

I deleted displays.xml and rebooted. At reboot only the laptop screen was switched on. I reconfigured everything in the xfce display settings and setup was remembered after another reboot. Still the 120Hz refresh rate of the laptop screen is not permanently changeable to 60Hz.

What is next?

so it did help, except for not able to change to freq? …so lets reinstall your drivers:
log out and enter into TTY with ctrl+alt+f2 - if f2 doesnt work, try f1-f6 keys isntead…
uninstall them with:
sudo mhwd -r pci video-hybrid-intel-nvidia-prime
sudo mhwd -r pci video-modesetting
install them again:
sudo mhwd -i pci video-hybrid-intel-nvidia-prime
sudo mhwd -i pci video-modesetting
reboot:
systemctl reboot

I did all this though sudo mhwd -i pci video-modesetting was not necessary as it seemed to be already installed with the prior command!?!

What do you need next?

thats all… it didnt work?

Well, the issue with starting in mirrored screens seems to be fixed. Thank you!

The laptop screens fixed refresh rate the still triggers me as it worked some time ago. I read somewhere it would be better to run both screens at the same refresh rate in a dual monitor setup.

i dont know about the same refresh rate in dual monitor setups… but did the refresh rate worked before?

Yes, I was once able to switch the laptop monitor to 60Hz permanently via the xfce-settings until some month ago. That was quite some time after deleting the .conf-files though.
Maybe a newer kernel- or driver-issue?

maybe try installing the 5.15 LTS kernel and try it with it, if it doesnt work, we can try installing video-linux drivers and test it with them …

No, thank you. If it stays like this it is good enough for now. Maybe it is fixed in later kernels.
I really appreciate your help! Thank you for your time & have a nice evening / day / morning / night!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.