this post was submitted on 04 Sep 2021
3 points (100.0% liked)

Linux

49865 readers
753 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Setup: Ubuntu, Openbox, notebook, occasionally an external screen.

I've set things up so that if an external monitor is attached when I start my notebook, a script (run by Openbox's autostart), xrandr makes that the primary monitor.

What I'd like to do is run that script when I turn off or otherwise disconnect that external monitor, so that I can make the notebook's built-in screen the primary again. Does anyone here have any ideas how to do that automatically?

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 0 points 3 years ago (1 children)

there's a file called status in cat /sys/class/drm/card0-CONNECTION where CONNECTION is the name xrandr --listmonitors shows on the right. So e.g. for me it looks like this:

$ xrandr --listmonitors
Monitors: 2
 0: +*DP-3 2560/553x1440/311+0+430  DP-3
 1: +DP-5 1440/553x2560/311+2560+0  DP-5

$ cat /sys/class/drm/card0-DP-3/status 
connected

You can watch this file with inotifywatch -e modify. You can put this in a systemd.path unit which calls your script as a one-shot or with an environment parameter.

You can also use srandrd but IMHO that's a bit overkill when you can do it with pid0 tools 😅

[–] [email protected] 0 points 3 years ago (1 children)

Hmm. Maybe I'm doing something wrong but doing

inotifywatch -e modify /sys/class/drm/card0-HDMI-A-2/status

only gives me "No events occurred." (after ctrl-c stops it). Oddly, I can see the file contents change (connected to disconnected and back again) if I cat it in a separate term window so I don't know what's going on.

[–] [email protected] 1 points 3 years ago* (last edited 3 years ago)

hm, maybe you need another event type. What GPU is it?

Events:
        access          file or directory contents were read
        modify          file or directory contents were written
        attrib          file or directory attributes changed
        close_write     file or directory closed, after being opened in
                        writeable mode
        close_nowrite   file or directory closed, after being opened in
                        read-only mode
        close           file or directory closed, regardless of read/write mode
        open            file or directory opened
        moved_to        file or directory moved to watched directory
        moved_from      file or directory moved from watched directory
        move            file or directory moved to or from watched directory
        move_self               A watched file or directory was moved.
        create          file or directory created within watched directory
        delete          file or directory deleted within watched directory
        delete_self     file or directory was deleted
        unmount         file system containing file or directory unmounted

May be create or delete