Giter VIP home page Giter VIP logo

Comments (14)

phillipberndt avatar phillipberndt commented on May 23, 2024

Where did you put the script? Is it executable? Is it being executed if you issue autorandr -l profile manually?

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

Hi @phillipberndt

Sorry for not including those details. I've placed the script in ~/.autorandr/ and it is indeed executable.
I was also able to verify that it works when i execute autorandr -l profile.

So my problem is the fact that autorandr doesn't seem to know that a new monitor has been attached? otherwise, am not sure whats going on.

from autorandr.

phillipberndt avatar phillipberndt commented on May 23, 2024

Alright. Then the problem is a different one: Either autorandr isn't executed at all when you change the setup, or it loads a different profile.

What happens if you run autorandr -c? Does it load your profile, or another one? The --debug flag might help.

Since you're using Arch, am I right to assume that you installed autorandr using the aur package and that you're using systemd? In particular, do you have the two files

/lib/udev/rules.d/40-monitor-hotplug.rules
/lib/systemd/system/autorandr.service

on your system? What's the output of systemctl status autorandr.service?

If so, the next step is to check whether udevadm monitor shows an ACTION of type change in the drm SUBSYSTEM.

If it does, check whether executing /bin/systemctl start autorandr.service as root runs autorandr.

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

Thanks for the extensive list... here is what i found:

  1. autorandr -c loads the correct profile
  2. Yes, i installed autorandr using yaourt -S autorandr-git and both mentioned files exist
  3. using systemctl status autorandr.service i found out that the service was disabled. So i ran systemctl enable autorandr.service
  4. The output of systemctl status is:
● autorandr.service - autorandr execution hook
   Loaded: loaded (/usr/lib/systemd/system/autorandr.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

May 01 11:09:57 Rakan-arch autorandr[13512]: laptop (current)
May 01 11:09:57 Rakan-arch autorandr[13512]: Running autorandr as rakan for display :0
May 01 11:09:57 Rakan-arch systemd[1]: Started autorandr execution hook.
May 01 11:13:01 Rakan-arch systemd[1]: Starting autorandr execution hook...
May 01 11:13:02 Rakan-arch autorandr[14539]: work
May 01 11:13:02 Rakan-arch autorandr[14539]: home (detected) (current)
May 01 11:13:02 Rakan-arch autorandr[14539]: laptop (current)
May 01 11:13:02 Rakan-arch autorandr[14539]: Config already loaded
May 01 11:13:02 Rakan-arch autorandr[14539]: Running autorandr as rakan for display :0
May 01 11:13:02 Rakan-arch systemd[1]: Started autorandr execution hook.

The interesting part here, is that when executing sudo systemctl start autorandr.service, i get the same output, the service's Active flag is inactive and ps aux | grep autorandr gives me nothing.

  1. When i executed udevadm monitor i was able to see:
    UDEV [606.387336] change /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
    When i plug / unplug a new monitor.

So what i did is the following:

  • Check the contents of autorandr.service, i found the ExecStart to be:
ExecStart=/usr/bin/autorandr --batch --change --default default
  • When executing this manually via root i get:
➜  ~ sudo /usr/bin/autorandr --batch --change --debug --default default
--batch mode can only be used by root and if $DISPLAY is unset
  • Removing batch would result in:
➜  ~ sudo /usr/bin/autorandr --change --debug --default default      
Failed to load profile 'default': Profile not found (line 1035)
  • Removing --default default and --batch works.

So the question is, should i modify the command in autorandr.service?
Note: I tried doing so and now i get 'Failed to run xrandr` error when i start the service.

from autorandr.

phillipberndt avatar phillipberndt commented on May 23, 2024

The interesting part here, is that when executing sudo systemctl start autorandr.service, i get the same output, the service's Active flag is inactive and ps aux | grep autorandr gives me nothing.

That's correct, autorandr is not supposed to run all the time in the background. It's only started by udev when it detects a change and exits again after executing. The output of systemctl status looks good to me, that appears to work. Running as root will work as well, but you need to run the command as

sudo DISPLAY= /usr/bin/autorandr --batch --change --debug --default default

If you (un)plug your monitor, does new output appear in the journal? And: Is it the expected one? Or does autorandr still report to detect the old configuration?

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

Executing journal -xe brings this up:

May 01 14:41:50 Rakan-arch systemd[1]: Starting autorandr execution hook...
-- Subject: Unit autorandr.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit autorandr.service has begun starting up.
May 01 14:41:54 Rakan-arch autorandr[11110]: work
May 01 14:41:54 Rakan-arch autorandr[11110]: home
May 01 14:41:54 Rakan-arch autorandr[11110]: laptop (detected) (current)
May 01 14:41:54 Rakan-arch autorandr[11110]: Running autorandr as rakan for display :0
May 01 14:41:54 Rakan-arch systemd[1]: Started autorandr execution hook.
-- Subject: Unit autorandr.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit autorandr.service has finished starting up.
-- 
-- The start-up result is done.
May 01 14:41:54 Rakan-arch systemd[1]: Starting autorandr execution hook...
-- Subject: Unit autorandr.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit autorandr.service has begun starting up.
May 01 14:41:59 Rakan-arch autorandr[11219]: work
May 01 14:41:59 Rakan-arch autorandr[11219]: home (detected)
May 01 14:41:59 Rakan-arch autorandr[11219]: laptop (current)
May 01 14:41:59 Rakan-arch autorandr[11219]: Running autorandr as rakan for display :0
May 01 14:41:59 Rakan-arch systemd[1]: Started autorandr execution hook.
-- Subject: Unit autorandr.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit autorandr.service has finished starting up.
-- 
-- The start-up result is done.

At first, i unplugged the monitor and then plugged it back in... you can see that the "laptop" profile got loaded and then the "home" profile. So it seems like everything goes well there

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

It's worth noting that after plugging the monitor, i see some flickering but the display is only turned on when i switch "input" on my monitor.
Seems like there's a difference between detected and current. From the output above, autorandr detects the "home" profile but doesn't activate it while after switching "input" on my monitor the display turns on and then the profile is activated.
Looking at the output above, it occurred to me to execute

➜  ~ autorandr   
work
home (detected) (current)
laptop (current)

from autorandr.

phillipberndt avatar phillipberndt commented on May 23, 2024

Seems like there's a difference between detected and current.
Yes. detected means that autorandr detected that the setup matches the profile's setup, current means that this profile is currently loaded. autorandr will load the first profile that is detected if --change is given. That is, it should have loaded home at 14:41:59.

It's interesting that it doesn't. Could you add --debug to the autorandr command line in the systemd unit, please? (At the moment I suspect that autorandr simply is run too early. Try putting a preswitch script into the profile folder with [ -n "$AUTORANDR_BATCH_PID" ] && sleep 2 in it.)

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

I modified the systemd unit with --debug flag and added a preswitch script:

#!/usr/bin/env bash
[ -n "$AUTORANDR_BATCH_PID" ] && sleep 2

and made it executable in each profile directory. This seems to have made an issue in my system as when i plug my monitor, the display hangs and windows stop refreshing. So i removed those files and things are working again.
Here's the latest output from systemd status:

➜  .autorandr sudo systemctl status autorandr.service
● autorandr.service - autorandr execution hook
   Loaded: loaded (/usr/lib/systemd/system/autorandr.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

May 02 01:11:24 Rakan-arch autorandr[4781]: work
May 02 01:11:24 Rakan-arch autorandr[4781]: home (detected)
May 02 01:11:24 Rakan-arch autorandr[4781]: laptop (current)
May 02 01:11:24 Rakan-arch autorandr[4781]: | Differences between the two profiles:
May 02 01:11:24 Rakan-arch autorandr[4781]: | [Output HDMI-1] The output is disabled currently, but active in the new configuration
May 02 01:11:24 Rakan-arch autorandr[4781]: \-
May 02 01:11:24 Rakan-arch autorandr[4781]: Loading profile 'home'
May 02 01:11:24 Rakan-arch autorandr[4781]: Going to run:
May 02 01:11:24 Rakan-arch autorandr[4781]: Running autorandr as rakan for display :0
May 02 01:11:25 Rakan-arch systemd[1]: Started autorandr execution hook.

from autorandr.

phillipberndt avatar phillipberndt commented on May 23, 2024

This seems to have made an issue in my system as when i plug my monitor, the display hangs and windows stop refreshing. So i removed those files and things are working again.

Try making the sleep longer (for testing), like sleep 10. Does the screen freeze after 10 seconds, or does this work as expected?

The journal output from your last post isn't complete. journalctl should have the complete output. (journalctl messes up the order of the entries because autorandr uses both stdout and stderr and does not disable output buffering.. I'll have to change that apparently.) I'm in particular interested in the command that autorandr was attempting to run.

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

sleep 10 did the same thing. and now for some reason, i don't see anything in journalctl -xe related to autorandr. Here's the last snippet from journalctl followed by a status to the autorandr.service.

May 02 23:34:18 Rakan-arch systemd[3163]: Started Sound Service.
-- Subject: Unit UNIT has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit UNIT has finished starting up.
-- 
-- The start-up result is done.
May 02 23:34:19 Rakan-arch dbus-daemon[4916]: Activating service name='org.gnome.GConf'
May 02 23:34:19 Rakan-arch dbus-daemon[4916]: Successfully activated service 'org.gnome.GConf'
➜  ~ sudo systemctl status autorandr.service
● autorandr.service - autorandr execution hook
   Loaded: loaded (/usr/lib/systemd/system/autorandr.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

May 02 23:35:31 Rakan-arch autorandr[9232]: work
May 02 23:35:31 Rakan-arch autorandr[9232]: home (detected)
May 02 23:35:31 Rakan-arch autorandr[9232]: laptop (current)
May 02 23:35:31 Rakan-arch autorandr[9232]: | Differences between the two profiles:
May 02 23:35:31 Rakan-arch autorandr[9232]: | [Output HDMI-1] The output is disabled currently, but active in the new configuration
May 02 23:35:31 Rakan-arch autorandr[9232]: \-
May 02 23:35:31 Rakan-arch autorandr[9232]: Loading profile 'home'
May 02 23:35:31 Rakan-arch autorandr[9232]: Going to run:
May 02 23:35:31 Rakan-arch autorandr[9232]: Running autorandr as rakan for display :0
May 02 23:35:32 Rakan-arch systemd[1]: Started autorandr execution hook.

from autorandr.

phillipberndt avatar phillipberndt commented on May 23, 2024

Hm.. I'm sorry, I'm out of ideas here currently. All I can offer right now are ideas for workarounds:

You've written that executing autorandr manually does work. You could remove the udev- and systemd files and instead run srandrd (original source) with autorandr --change as an argument as your user.

from autorandr.

rakanalh avatar rakanalh commented on May 23, 2024

No worries... thanks for all the help. srandrd works well, thanks for the suggestion.

from autorandr.

JoeDupuis avatar JoeDupuis commented on May 23, 2024

Got the same issue.
Problem seems to be that even if you remove a screen, if the remaining screen (laptop) keeps the same config, it will detect that the config is already loaded.
It will somehow switch the active profile, but won't run the postswitch.
And you'll get :
May 01 11:13:02 Rakan-arch autorandr[14539]: Config already loaded

My laptop screen is 1800p but I run it at 900p when plugged into a 1080p monitor (because of the dpi difference).
I have two configs for the laptop, one hidpi and one low dpi. I used the postswitch to remap the touchscreen when unplugging the screen.
Noticed that the remaping wasn't executed when going from 1080p+900p -> 900p
but was executed correctly when going from 1080p+900p -> 1800p.
In reverse (900p(or 1800p) ->1080p+900p) postswitch is always run.

Tested out a predetect hook changing the resolution of the laptop so that it will be different enough during detection and then it runs the postswitch, but since it will also run when querying the config (running autorandr without arguments), this can't be used a a fix/hack.

I Fixed it by adding the --force flag overriding the systemd unit.
systemctl edit autorandr

and empty buffer will open

Add:

[Service]
ExecStart=/usr/bin/autorandr --batch --change --force --default default

save and it should solve your issue.

from autorandr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.