You are not logged in.
Hi i am facing a similar issue to this thread that i found : https://bbs.archlinux.org/viewtopic.php?id=269810
TL;DR : Is there a way to always automatically force KDE to reset display setting on every boot? I need it to be ephemeral.
With this new laptop i modify display settings a lot during a single runtime, either on internal or external displays. If i were to shut down the laptop in a different resolution than native for the internal display, while it's connected to an external display, i will get blank screens (both internal and externals). And that is even if i boot without the external screens connected.
Right now the fix is without display to open a terminal and type an alias for the main display to revert to native resolution.
So it would simply be easier to have the display settings reset on every login. Single screen named eDP-1 1600x2560 60hz.
What would be the best way to implement this behavior? Can i have KDE purge ~/.local/share/kscreen automatically on login?
ThinkPad P16s AMD / KDE
Offline
https://wiki.archlinux.org/title/KDE#Autostart - I guess ~/.config/plasma-workspace/env/somescript.sh should hit early enough.
Offline
You can either remove that file before you start plasma (... maybe an early user service[1] with a Before=plasma-workspace.service if you want to make this explictly for the user, more guaranteed would be a system multi-user level service that will wipe it anyway regardless)
Alternatively you can also disable kscreen entirely to simply rely on xorgs default behaviour (assuming you are running on xorg, on wayland kscreen is what defines the default behaviour) by disabling it in
kcmshell5 kcm_kdedEdit: Or that, in case the plasma autostart scripts don't hit early enough the above are some other options
Offline
Thank you for your brilliant responses. I have something working.
Note that this solution uses mv for kscreen and not rm.
I will write down my current entire working solution :
---
First i turned on lingering for quardah (as root)
loginctl enable-lingersecond as user i made the directory and the service file
cd
mkdir -p .config/systemd/user/
nano .config/systemd/user/resetdisplay.servicewith the content
[Unit]
Description=Moves kscreen config as backup on login to reset it
Before=plasma-workspace.service
[Service]
Type=oneshot
WorkingDirectory=%h/.local/share/
ExecStart=/bin/bash -c "if [ -d ~/.local/share/kscreen ]; then mv ~/.local/share/kscreen ~/.local/share/kscreen.bak; fi"
RemainAfterExit=yes
CPUSchedulingPolicy=idle
IOSchedulingClass=3
[Install]
WantedBy=default.targetand then enable, daemon-reload
systemctl --user enable resetdisplay.service
systemctl --user daemon-reloadreboot
---
and voilà it works.
Now there is a little detail @V1del; this solution does not seem to work if i log out but only on reboot. i am unsure why expected the ""Before=plasma-workspace.service"" to be triggered on login.
Actually because i am understanding this better i think i can detail the actual issue a little better. The problem comes from these two aliases i use repeatedly during runtime :
#ThinkPad output alias here
alias eDP11600='xrandr --output eDP-1 --mode 2560x1600'
alias eDP11536='xrandr --output eDP-1 --mode 2048x1536 --set "scaling mode" "Full"'And the previous issue only exists when i shut down the laptop in the second mode (--mode 2048x1536 --set "scaling mode" "Full"') what this does is it forces the 4:3 resolution to be stretched for an old game i play as some sort of accessibility workaround. But it seems this mode is not flushed properly on reboot.
What would actually be best is for the internal screen eDP-1 to be forced to the first mode instead so the others screen config remains intact.
actually as i write this i think i can just try running the xrandr command and see if it works i'll still leave the previous response here for future references.
EDIT:
I tried changing the ExecStart line in the file for the following
ExecStart=/bin/xrandr --output eDP-1 --mode 2560x1600And it does not work, i get a "xrandr: Can't open display" error in systemctl --user status resetdisplay.service
I will try with "After" plasma-workspace instead of before brb need to reboot.
EDIT2: No even when using "After" it does nothing.
EDIT3: I tried seth's mention of KDE autostart and i've tried adding an executable script in KDE's autostart feature on login but it doesn't work either. I found this post here ( https://unix.stackexchange.com/question … md-service ) mentioning that the DISPLAY variable might be inaccessible for systemd but i thought kde would be able to see it ![]()
i have to get to bed let me know what you think ![]()
Last edited by Quardah (2022-09-21 02:42:12)
ThinkPad P16s AMD / KDE
Offline
RemainAfterExit=yes
The user serviec won't terminate
executable script in KDE's autostart feature on login but it doesn't work either.
Doesntwork™ how?
$DISPLAY should™ be exported and accessible at this point - if you inject
echo "DISPLAY: $DISPLAY" >> /tmp/kscreen.dbg what does it say?
Do you get away w/ "xrandr --display :0 …"?
You could also try to sanitize the resolution in ~/.config/plasma-workspace/shutdown/ - but I'm not sure whether kscreen will still pick that up.
Alternatively you can also disable kscreen entirely
Offline
If you want this to also run on logout you'd duplicate the command in an ExecStop= directive. RemainAfterExit=true should logically be fine, especially if you want a ExecStop trigger on logout (if you explicitly want a logout/login trigger you should however not enable lingering of the user session, that way they will explicitly be invoked precisely on login and logout, instead of system start/shutdown)
Offline
executable script in KDE's autostart feature on login but it doesn't work either.
Doesntwork™ how?
$DISPLAY should™ be exported and accessible at this point - if you injectecho "DISPLAY: $DISPLAY" >> /tmp/kscreen.dbgwhat does it say?
Do you get away w/ "xrandr --display :0 …"?You could also try to sanitize the resolution in ~/.config/plasma-workspace/shutdown/ - but I'm not sure whether kscreen will still pick that up.
V1del wrote:Alternatively you can also disable kscreen entirely
Hi. Sorry for the late response i worked all day.
You are right, my "doesn't work" is not explicative enough. What i did was put an executable script with a single line in my /home/myuser/bin/ dir and use KDE's systemsettings to have it automatically run on login. I tried setting the computer in non-native resolution (forced wide 4:3 2048*1536) and reboot, but the screens would give me the same behavior as before. I am unsure how to check if the script did run.
The single line is "xrandr --output eDP-1 --mode 2560x1600" which is the alias.
I understand with your reply that the echo command will confirm that the script does run. I've added it now to the file and it does run on login. I do get "DISPLAY: 0" as expected in the tmp file.
But the command still does not force the display to use the right mode. While the screen is blank i can open a terminal on an external monitor and run xrandr to get the following output :
[myuser@P16s ~]$ xrandr
Screen 0: minimum 320 x 200, current 3640 x 1920, maximum 16384 x 16384
eDP-1 connected primary 2048x1536+0+320 (normal left inverted right x axis y axis) 344mm x 215mm
2560x1600 60.00 + 50.01 48.01 59.97
2560x1440 59.95
2048x1536 60.00* It still runs in 2048x1536
This is the content of the script right now : (i tried with both --display :0 and --output eDP-1 and both gives the same results)
[myuser@P16s ~]$ cat bin/resetDisplay
#!/bin/bash
xrandr --display :0 --mode 2560x1600
echo "DISPLAY: $DISPLAY" >> /tmp/kscreen.dbg-----
Actually i tried the following :
[myuser@P16s ~]$ cat bin/resetDisplay
#!/bin/bash
xrandr >> /tmp/xrandr_output.debug
xrandr --output eDP-1 --mode 2560x1600 >> /tmp/xrandr_test.dbg
echo "DISPLAY: $DISPLAY" >> /tmp/kscreen.dbgand /tmp/xrandr_output.debug contains the following :
[myuser@P16s ~]$ cat /tmp/xrandr_output.debug
Screen 0: minimum 320 x 200, current 4480 x 1600, maximum 16384 x 16384
eDP-1 connected primary 2560x1600+0+0 (normal left inverted right x axis y axis) 344mm x 215mm
2560x1600 60.00*+ 50.01 48.01 59.97
2560x1440 59.95
2048x1536 60.00 And so now what i believe happens is that KDE actuall starts using the native resolution (also on the login screen i have the proper resolution), the script then tries to apply the same resolution to it (so it does nothing) and THEN the buggy resolution is applied.
Actually is it possible that resolutions that are set for
--set "scaling mode" "Full"can't come back properly after reboot?
Let me know what you think.
EDIT:
Yep. That seems to be the case. I tried another mode that i know works
xrandr --output eDP-1 --mode 1440x900 and reboot. The login screen uses native resolution, but on login the previous 1440x900 resolution is reapplied.
And now that seems to be the real problem, is that KDE fails at reapplying the
xrandr --output eDP-1 --mode 2048x1536 --set "scaling mode" "Full"resolution.
You know what, it used to work on my T540p (i7-4600M intel) but it does not work on the P16s which is AMD. Maybe that's related to the problem?
I really gotta get to bed this time but thank you both for assisting me.
@V1del if i understand correctly if i were to go back to the service solution, using the RemainAfterExit will allow me to have both an ExecStart and ExecStop without lingering? I think that's the best solution and if i rewrite this thing i'll have the native resolution forced on both actions.
Last edited by Quardah (2022-09-22 03:26:36)
ThinkPad P16s AMD / KDE
Offline
What i did was put an executable script with a single line in my /home/myuser/bin/ dir and use KDE's systemsettings to have it automatically run on login.
That's too late, you really have to use the ~/.config/plasma-workspace/env scripts as they're supposed to be executed *before* the session.
The single line is "xrandr --output eDP-1 --mode 2560x1600" which is the alias.
And original the plan was to get rid of the kscreen config before the session.
Sanitizing the modeline is only an option when *ending* the session (and hopefully early enough for kscreen to pick it up and re-apply the sanitized modeline on the next session)
Offline
What i did was put an executable script with a single line in my /home/myuser/bin/ dir and use KDE's systemsettings to have it automatically run on login.
That's too late, you really have to use the ~/.config/plasma-workspace/env scripts as they're supposed to be executed *before* the session.
The single line is "xrandr --output eDP-1 --mode 2560x1600" which is the alias.
And original the plan was to get rid of the kscreen config before the session.
Sanitizing the modeline is only an option when *ending* the session (and hopefully early enough for kscreen to pick it up and re-apply the sanitized modeline on the next session)
I have to go run errands but i will try this over the weekend. Thank you for helping me, i really appreciate the efforts.
You are right at first i believed removing kscreen would have been the better option, but to be honest it's more about the different behavior from the T540p to the P16s that bugs me. As mentioned before, the T540p could come back up on the forced 4:3 screen resolution, but the P16s cannot.
If i understand correctly, dropping the same script in ~/.config/plasma-workspace/env will have it run before the session, and so kscreen will pick it up and force it, right? I will try this over the weekend and give you an update.
All in all the even better solution would be to have the screen simply capable of coming back up on 2048x1536 stretched. It's really a bummer that for some reason it just doesn't behave the same as on the T540p. It was also running KDE.
Optimally that would simply be the best solution (after all my fumbling, i'm sorry i'm not really clear when i ramble). If the screen could simply come back up on stretch resolution after a reboot all would be well. I know this was not what the thread was originally for and i can open another thread if need be for this specific issue.
I noticed another different behavior is that in systemsettings display section if i change the resolution on the fly for the eDP-1 display it will not stick to its right external display properly. It'll either overlap (if i go from 2048x1536 to 2560x1600) or it'll create a gap if i go the other way around. (i should probably open another thread for this issue too)
From 2048x1536 to 2560x1600 :
https://i.imgur.com/REpQtvA.png
From 2560x1600 to 2048x1536 :
ThinkPad P16s AMD / KDE
Offline
so kscreen will pick it up and force it, right?
Wrong (probably) - if you mean to "xrandr --output eDP-1 --mode 2560x1600", kscreen will steamroll its own configuration over that.
What you (probably) could do in ~/.config/plasma-workspace/env would be to remove the kscreen configuration.
If the screen could simply come back up on stretch resolution after a reboot all would be well.
Alternatively you can also disable kscreen entirely to simply rely on xorgs default behaviour
Offline