• Shareni@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    6 months ago

    Then I misunderstood your question. I’m pretty sure you can do all of these things:

    "only primary, “only secondary”, “mirrored” “side by side”

    But it’s not like in a DE where you jump through those modes with a keybinding. Instead you generate an xrandr config. It can preserve the position if you unplug an extra monitor and then plug it back in.

    If you need that quickswitch functionality, you can generate configs for all of those scenarios and just use a script to cycle through them.

    You could also use built in wm functionality. For example you can create modes (I think that’s what it’s called) in i3. Press a shortcut, it opens up a menu, and you can choose your option (load an xrandr config).

    Another option is to use Xfce or KDE, and replace the default wm. It’s the best option if you’re lazy about setting everything up. That’s why I’m currently running Xfce + I3. That functionality is useless for me as the Xfce version doesn’t seem to allow you to customise those configurations. The regular display configuration is pretty useful though.

    • Ignotum@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      6 months ago

      Quickswitch or automatic switch to a different profile, i often found myself enabling an external display and disabling the built-in one, then when packing down my laptop i forgot to manually configure the built in, meaning when i got home i had a laptop with a blank screen, Sometimes i was able to log in, open a terminal and enable the screen, other times i would have to reboot it. Something that could automatically enable the builtin if no external display is connected would’ve gone a long way for my usecase (my attempts at writing scripts for that never worked from what i recall, something got messed up when going to sleep)

      Doesn’t xfce use a dm? What kind of display configuration does it give? A gui for manually configuring the layout or something more?

      • Shareni@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        6 months ago

        Here’s an extremely simple solution, just bind this to a shortcut:

        #!/bin/bash
        
        if [[ -z "${MONITOR}" || "${MONITOR}" == "internal" ]]; then
            export MONITOR="external" 
            ~/dotfiles/xrandr/external.sh
        else
            export MONITOR="internal" 
            ~/dotfiles/xrandr/internal.sh
        fi
        

        and just autostart internal.sh

        I’d most likely keep it like that and go on with my day, but here’s an ai response for automating it:

        To trigger a script when an external monitor is connected or disconnected, you can use udev, the device manager for the Linux kernel.

        Here’s a step-by-step plan:

        1. Create a script that will be triggered when the monitor is connected or disconnected. For example, /usr/local/bin/monitor-hotplug.sh. Make sure to make it executable with chmod +x /usr/local/bin/monitor-hotplug.sh.
        #!/bin/bash
        
        export DISPLAY=:0
        export XAUTHORITY=/home/username/.Xauthority  # replace "username" with your actual username
        
        xrandr | grep "HDMI1 connected"  # replace "HDMI1" with your actual monitor identifier
        if [ $? -eq 0 ]; then
            # commands to run when the monitor is connected
        else
            # commands to run when the monitor is disconnected
        fi
        
        1. Create a udev rule that will trigger the script. For example, /etc/udev/rules.d/95-monitor-hotplug.rules.
        SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/monitor-hotplug.sh"
        
        1. Reload udev rules with the following command:
        sudo udevadm control --reload-rules
        

        Now, whenever an external monitor is connected or disconnected, the monitor-hotplug.sh script will be triggered.

        Please note that you’ll need to replace “HDMI1” with your actual monitor identifier, which you can find by running xrandr without any arguments. Also, replace “username” with your actual username.

        And here’s an example of using modes in i3 if you need to switch between multiple configurations:

        set $mode_system System (k) lock, (l) logout, (u) suspend, (h) hibernate, (r) reboot, (s) shutdown
        mode "$mode_system" {
            bindsym k exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh lock, mode "default"
            bindsym l exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh logout, mode "default"
            bindsym u exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh suspend, mode "default"
            bindsym h exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh hibernate, mode "default"
            bindsym r exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh reboot, mode "default"
            bindsym s exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh shutdown, mode "default"
        
            # back to normal: Enter or Escape
            bindsym Return mode "default"
            bindsym Escape mode "default"
        }
        
        bindsym control+mod1+X mode "$mode_system"
        

        Doesn’t xfce use a dm?

        Display manager?

        A gui for manually configuring the layout or something more?

        Basic stuff you’d expect, and it has a quick switch keybinding to go between a few basic configurations.

        • Ignotum@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          6 months ago

          Display manager I thought the d stood for Desktop, but i’m thinking of de, i see i’ve been mixing up terms, i’ve also been under the incorrect understanding that window managers and desktop environments were mutually exclusive, e.g. a desktop environment like xfce would conflict with a window manager like i3

          Those scripts look cleaner than mine, perhaps i should give it another go, i’m currently on ubuntu, but many of the packets being 15 years out of date is starting to get annoying, i miss aur with its [xxx]-git packages

          • Shareni@programming.dev
            link
            fedilink
            arrow-up
            1
            ·
            6 months ago

            X11 DEs have a built in wm. For example xfce has something like xfce-wm. If you disable it’s autostart and replace it with a different one like I3, you get the benefits of both worlds.

            Compositors in Wayland work that way because the whole thing is a monolith.

            i’m currently on ubuntu, but many of the packets being 15 years out of date is starting to get annoying

            Use an external package manager. For simplicity I suggest flatpak or snap. I prefer nix, but the setup is more complicated. That way you’ve got a rock solid system, but fresh or bleeding edge userland packages.