Bug 312410 - unable to switch back to laptop monitor after external monitor has been unplugged and other way around
Summary: unable to switch back to laptop monitor after external monitor has been unplu...
Status: RESOLVED FIXED
Alias: None
Product: KScreen
Classification: Unclassified
Component: kded (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR major
Target Milestone: ---
Assignee: Alex Fiestas
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-31 00:17 UTC by Anton
Modified: 2016-05-23 16:27 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
.xsession-errors file (167.85 KB, application/octet-stream)
2012-12-31 00:18 UTC, Anton
Details
Xorg.log (64.50 KB, text/x-log)
2012-12-31 00:19 UTC, Anton
Details
.xsession-errors file (17.67 KB, text/plain)
2012-12-31 07:23 UTC, Anton
Details
Xorg.log (49.78 KB, text/plain)
2012-12-31 07:24 UTC, Anton
Details
xrandr --verbose output (10.38 KB, text/plain)
2012-12-31 07:38 UTC, Anton
Details
kscreen config 1 (341 bytes, application/octet-stream)
2013-01-02 12:17 UTC, Anton
Details
kscreen config 2 (208 bytes, application/octet-stream)
2013-01-02 12:17 UTC, Anton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anton 2012-12-31 00:17:27 UTC
I'm using kscreen with an external monitor. It crashes everytime I simply unplug and plug the external monitor back.


Reproducible: Always

Steps to Reproduce:
1. Connect an external monitor and switch off an internal monitor of a laptop.
2. Unplug an external monitor. Kscreen fails to switch on an internal monitor
3. Plug the external monitor. Kscreen fails to switch it on as well
4. Use a hot key on a laptop to get any kid of working combination



Application: kded4 ($Id$)
KDE Platform Version: 4.9.3
Qt Version: 4.8.4
Operating System: Linux 3.5.4-pentoo x86_64
Distribution: "Gentoo Base System release 2.1"

-- Information about the crash:
<In detail, tell us what you were doing  when the application crashed.>

The crash can be reproduced every time.

-- Backtrace:
Application: KDE Daemon (kdeinit4), signal: Segmentation fault
Using host libthread_db library "/lib64/libthread_db.so.1".
[Current thread is 1 (Thread 0x7f2308624780 (LWP 20739))]

Thread 2 (Thread 0x7f22efb60700 (LWP 20749)):
#0  0x00007f23059f85d3 in poll () from /lib64/libc.so.6
#1  0x00007f2302abc036 in ?? () from /usr/lib64/libglib-2.0.so.0
#2  0x00007f2302abc18c in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#3  0x00007f230717c02e in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#4  0x00007f23071436d2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#5  0x00007f2307143abd in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#6  0x00007f230701bf88 in QThread::exec() () from /usr/lib64/qt4/libQtCore.so.4
#7  0x00007f230711d730 in ?? () from /usr/lib64/qt4/libQtCore.so.4
#8  0x00007f230701eef6 in ?? () from /usr/lib64/qt4/libQtCore.so.4
#9  0x00007f2306d87fb6 in start_thread () from /lib64/libpthread.so.0
#10 0x00007f2305a0129d in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7f2308624780 (LWP 20739)):
[KCrash Handler]
#6  0x00007f22f2c0d1d4 in KScreen::Mode::refreshRate() const () from /usr/lib64/libkscreen.so.0
#7  0x00007f22f2e4c401 in ?? () from /usr/lib64/kde4/kded_kscreen.so
#8  0x00007f22f2e4a723 in KScreenDaemon::saveCurrentConfig() () from /usr/lib64/kde4/kded_kscreen.so
#9  0x00007f230715ddf6 in QObject::event(QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#10 0x00007f23061a9ea4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#11 0x00007f23061aef6b in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#12 0x00007f2307fbd4e6 in KApplication::notify(QObject*, QEvent*) () from /usr/lib64/libkdeui.so.5
#13 0x00007f2307144f4c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#14 0x00007f2307148e28 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/qt4/libQtCore.so.4
#15 0x00007f230717bdc7 in ?? () from /usr/lib64/qt4/libQtCore.so.4
#16 0x00007f2302abbd23 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
#17 0x00007f2302abc0a0 in ?? () from /usr/lib64/libglib-2.0.so.0
#18 0x00007f2302abc18c in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#19 0x00007f230717bfbf in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#20 0x00007f2306268cf6 in ?? () from /usr/lib64/qt4/libQtGui.so.4
#21 0x00007f23071436d2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#22 0x00007f2307143abd in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#23 0x00007f230714930b in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
#24 0x00007f22f6382cd8 in kdemain () from /usr/lib64/libkdeinit4_kded4.so
#25 0x00007f23086700bb in _start ()
Comment 1 Anton 2012-12-31 00:18:45 UTC
Created attachment 76106 [details]
.xsession-errors file
Comment 2 Anton 2012-12-31 00:19:26 UTC
Created attachment 76107 [details]
Xorg.log
Comment 3 Jekyll Wu 2012-12-31 03:50:21 UTC

*** This bug has been marked as a duplicate of bug 312231 ***
Comment 4 Anton 2012-12-31 07:11:48 UTC
I tested the latest trunk with the patch applied, the crash is gone, however my main problem is still there:

I'm not able to switch back to the laptop screen after I unplugged the external monitor.
So I'm changing the title and reopening...
Comment 5 Anton 2012-12-31 07:23:03 UTC
Created attachment 76108 [details]
.xsession-errors file
Comment 6 Anton 2012-12-31 07:24:25 UTC
Created attachment 76109 [details]
Xorg.log

updated logs from a just rebooted laptop
Comment 7 Anton 2012-12-31 07:38:18 UTC
Created attachment 76110 [details]
xrandr --verbose output

I only have 1 external monitor, however my bug might be still related to #312231. I'll keep an eye on it.
Comment 8 Daniel Vrátil 2013-01-01 14:54:43 UTC
So when you unplug the external monitor and open the laptop lid, the laptop monitor remains blank?
Comment 9 Anton 2013-01-02 04:21:43 UTC
yes the laptop remains black and I actually don't touch the lid (it would go into a sleep mode in my setup) and simply plugging/unplugging the external monitor.

Here is more info. I managed to turn on the laptop monitor using "xrandr" (blindly) and tried to plug to the external monitor back. kscreen failed again and now the external monitor reminds black.

Matthias Blaicher may be right in his comment https://bugs.kde.org/show_bug.cgi?id=312231#c4.
Comment 10 Aleksander Kamenik 2013-01-02 09:32:46 UTC
Anton, try switching to another tty and back to re-enable the blank LVDS1.

I had problems myself with sleep and monitor configuration. I think most problems are related so I won't open a new bug for this.


Setup: Thinkpad x220, dock with external monitor via displayport. Fedora 17, x64. My preferred setup is to use the external monitor as the secondary monitor on the right, but have it aligned by the bottom (not default top) of the screen.

Default: https://kilx.eu/pics/default.top.png
Bottom: https://kilx.eu/pics/bottom.png

I did three tests:

1. undock
     kscreen reconfigures correctly by disabling external monitor
   dock

   results: works 100%, external monitor configured and aligned by bottom

2. sleep by using Sleep button from KDE->Leave menu
   wake up using power button above the laptop keyboard
     during wake up i can see system messages on both screens

   results: works 100% as well

3. sleep by closing lid
   wake up by opening lid
     during wake up i see system messages only on the external monitor

   results: fail, kscreen has forgotten the custom position (external monitor is still to the right and secondary, but aligned via top, not bottom)
     open apps have been moved to the external monitor, as if LVDS1 was disabled meanwhile
     I fix the position (align by bottom) in kscreen, press apply and lvds1 goes blank
       fix this by switching to another tty for a second and back (press ctrl+alt+F2 and ctrl+alt+F1)

I see three problems in test 3.
 1. The internal LVDS1 screen takes time to power up when waking up by opening lid and kscreen reconfigures the screens too early (it only sees the external monitor)
 2. Then it does see LVDS1 and enables it but for some reason the position info is lost
 3. When changing the position LVDS1 goes blank and a switch to another tty and back works as a refresh which makes it work again

$ echo before sleep via lid close; md5sum .kde/share/apps/kscreen/*;cat .kde/share/apps/kscreen/9cc77b869fdd9dfa952de53c129ed353 ;echo
before sleep via lid close
04af62609bf7ab5fbc389058a10793ca  .kde/share/apps/kscreen/9cc77b869fdd9dfa952de53c129ed353
[ { "enabled" : true, "hash" : "fc7a53d5ea6898e59583336a3d00e62f", "mode" : { "refresh" : 59.9339, "size" : { "height" : 1080, "width" : 1920 } }, "pos" : { "x" : 1366, "y" : 0 }, "primary" : false, "rotation" : 1 }, { "enabled" : true, "hash" : "56a261ac023a91a83de96bf5cb585786", "mode" : { "refresh" : 60.0186, "size" : { "height" : 768, "width" : 1366 } }, "pos" : { "x" : 0, "y" : 312 }, "primary" : true, "rotation" : 1 } ]
$ echo after wake up via lid open; md5sum .kde/share/apps/kscreen/*;cat .kde/share/apps/kscreen/9cc77b869fdd9dfa952de53c129ed353 ;echo
after wake up via lid open
83e715b9904c88b493f7338b8cb267d6  .kde/share/apps/kscreen/9cc77b869fdd9dfa952de53c129ed353
[ { "enabled" : true, "hash" : "fc7a53d5ea6898e59583336a3d00e62f", "mode" : { "refresh" : 59.9339, "size" : { "height" : 1080, "width" : 1920 } }, "pos" : { "x" : 1366, "y" : 0 }, "primary" : false, "rotation" : 1 }, { "enabled" : true, "hash" : "56a261ac023a91a83de96bf5cb585786", "mode" : { "refresh" : 60.0186, "size" : { "height" : 768, "width" : 1366 } }, "pos" : { "x" : 0, "y" : 0 }, "primary" : true, "rotation" : 1 } ]

When testing I discovered that kscreen had created several configurations files in the apps/kscreen/ folder at times, but I don't know how to reproduce this.

Maybe the old kcm_display module is interfering? I did click the "ignore" checkbox so that there is no pop up window when monitor setup is changed. But it is compiled as I only installed libkscreen and kscreen in addition to the default Fedora KDE install.
Comment 11 Alex Fiestas 2013-01-02 10:10:31 UTC
Can you paste the content of ~/.kde/share/apps/kscreen/ ?

(In reply to comment #9)
> yes the laptop remains black and I actually don't touch the lid (it would go
> into a sleep mode in my setup) and simply plugging/unplugging the external
> monitor.
> 
> Here is more info. I managed to turn on the laptop monitor using "xrandr"
> (blindly) and tried to plug to the external monitor back. kscreen failed
> again and now the external monitor reminds black.
> 
> Matthias Blaicher may be right in his comment
> https://bugs.kde.org/show_bug.cgi?id=312231#c4.
Comment 12 Daniel Vrátil 2013-01-02 12:10:37 UTC
Git commit 168d178322b020e581fe189bd2ffdb855fa60d66 by Dan Vrátil.
Committed on 02/01/2013 at 12:50.
Pushed by dvratil into branch 'master'.

Make sure that in simpleOutput() case the output is enabled

Unplugging external monitor while laptop lid is closed
causes no outputs to be enabled, not even after opening
the lid, so make sure that the embedded output is always
enabled.
REVIEW: 108062

M  +4    -0    kded/generator.cpp
M  +4    -0    tests/testgenerator.cpp

http://commits.kde.org/kscreen/168d178322b020e581fe189bd2ffdb855fa60d66
Comment 13 Anton 2013-01-02 12:17:09 UTC
Created attachment 76139 [details]
kscreen config 1
Comment 14 Anton 2013-01-02 12:17:45 UTC
Created attachment 76140 [details]
kscreen config 2

btw, my led is always open
Comment 15 Aleksander Kamenik 2013-01-02 12:46:12 UTC
Tested with "Make sure that in simpleOutput() case the output is enabled".

Did not help in my case. The difference now was that after installing new libkscreen and kscreen and reboot KDE logged in and then disabled LVDS1, with external monitor working. Had to do the switch to other tty and back trick to reenable it. Configuration looked OK though with correct position.

Test 3 as in my previous comment had the same results. What I noticed when I fixed the position (align by bottom) KDE moved open applications to the external monitor as the primary was blank/disabled. I then had to do then switch tty refresh and move the open apps back manually.
Comment 16 Anton 2013-01-02 13:24:19 UTC
Nothing changed for me either
Comment 17 Alex Fiestas 2013-01-10 15:09:07 UTC
Git commit b06a0969dc3ac65d32d070b9460f3262703b88a7 by Àlex Fiestas.
Committed on 10/01/2013 at 16:03.
Pushed by afiestas into branch 'master'.

Do not save the generated configuration when lid is closed

Basically right now we were applying the "ideal config" everytime the
lid was being open or closed, smashing any existing configuration.

Now we behave like:

on lid CLOSED:
    -We apply an ideal config, which will take into account the new lid
     state

on lid OPEN:
    -We try to restore the previous configuration if any, or generate a
     new one.

M  +10   -2    kded/daemon.cpp
M  +1    -1    kded/daemon.h

http://commits.kde.org/kscreen/b06a0969dc3ac65d32d070b9460f3262703b88a7
Comment 18 Alex Fiestas 2013-01-10 15:09:50 UTC
Please, remove any configuration file under ~/.kde/share/apps/kscreen to make sure that you have right behavior.

Thanks !
Comment 19 Anton 2013-01-11 00:05:22 UTC
You probably fixed Aleksander's problem but not mine.

Again, I don't close/open lid. I simply unplug an external monitor.

The display switching hotkey (fn-f7) stopped working with the latest version as well.
Comment 20 Anton 2013-01-11 00:20:08 UTC
I'm wrong, it's 99% working, including the hotkey.

There is still some problem with the logic of the initial configuration. For example, then I unplugged the external monitor for the first time (after deleting configs files), the screen on the laptop was extended to an unexisting monitor. And it was full screen but flickering (like trying to switch to a different monitor) for the second time, and that's then the hotkey didn't help.
Comment 21 Aleksander Kamenik 2013-01-11 08:07:18 UTC
I haven't tested the lid/sleep problem, be cause after update to current versions of libkscreen and kscreen the position info is not remembered even after a simple undock/dock. This worked previously.

Investigating the issue I found that the positional info is not saved at all in the config file.

## this was generated after enabling and bottom aligning the second display. But here I can see it's still top aligned:
.kde/share/apps/kscreen/9cc77b869fdd9dfa952de53c129ed353
[ { "enabled" : true, "id" : "fc7a53d5ea6898e59583336a3d00e62f", "mode" : { "refresh" : 59.9339, "size" : { "height" : 1080, "width" : 1920 } }, "pos" : { "x" : 1366, "y" : 0 }, "primary" : false, "rotation" : 1 }, { "enabled" : true, "id" : "56a261ac023a91a83de96bf5cb585786", "mode" : { "refresh" : 60.0186, "size" : { "height" : 768, "width" : 1366 } }, "pos" : { "x" : 0, "y" : 0 }, "primary" : true, "rotation" : 1 } ]
Comment 22 Anton 2013-01-11 08:10:09 UTC
Aleksander, could you open a new bug for your issue please? It's getting messy here :\
Comment 23 Aleksander Kamenik 2013-01-11 08:12:49 UTC
I thought this might be a regression of the current bugfix, but you're probably right.
Comment 24 Alex Fiestas 2013-01-11 15:01:42 UTC
Anton, can you try the following?

-Upgrade to latest libkscreen/kscreen
-Remove any file in ~/.kde/share/apps/kscreen directory
-Execute in a terminal the following command:
      perl -e "while(1){system('xrandr'); sleep(5);}"
-Plug your screen, wait at least 6 seconds
-Unplug your screen, wait at least 6 seconds.

This will check if you are being affected by this bug:
bugs.freedesktop.org/show_bug.cgi?id=58405

Thanks !
Comment 25 Anton 2013-01-14 01:44:56 UTC
No, I don't have HDMI output.

Ok, I can't seems reproduce screen flickering. Let's focus on the extended desktop problem.
Here are the steps to reproduce:

1. Plug an external monitor (1920, 1200)
2. remove config filles:
rm  -r ~/.kde4/share/apps/kscreen/
3. Unplug an external monitor

Results:
Laptop screen (1280,800) will be switched to 3200, 800.

4. Press display switch hotkey

Result:
Unable to fix the resolution.

Xorg.log file (after an external monitor disconnect):
-------------------------------------------------------------------------
[  5742.033] (II) intel(0): EDID vendor "LEN", prod id 16401
[  5742.033] (II) intel(0): Printing DDC gathered Modelines:
[  5742.033] (II) intel(0): Modeline "1280x800"x0.0   69.30  1280 1328 1360 1403  800 803 809 821 -hsync -vsync (49.4 kHz eP)
[  5742.033] (II) intel(0): Modeline "1280x800"x0.0   57.59  1280 1328 1360 1403  800 803 809 821 -hsync -vsync (41.0 kHz e)
[  5742.136] (II) intel(0): switch to mode 1280x800 on crtc 3 (pipe 0)


.xsession-errors file:
-----------------------------

Applying config 
Finding a mode with:  
QSize(1280, 800) 
"60" 
Requested screen size is QSize(3200, 800) 
1 
Output 66 has CRTC 63 
Disabling:  66 (CRTC 63 ) 
XRRSetCrtcConfig() returned 0 
DPI:  97.6923 
Size:  QSize(3200, 800) 
MM:  832 x 208 
QSize(3200, 800)   832 x 208 
Enabling:  65 
Found free CRTC 63 
XRRSetCrtcConfig() returned 0 
displayBtn triggered 
displayButton:  5 
Config for one output 
Requested screen size is QSize(3200, 800) 
1 
displayBtn triggered 
displayButton:  1 
Config for one output 
Requested screen size is QSize(3200, 800) 
1
Comment 26 Alex Fiestas 2013-01-14 09:12:38 UTC
Anton, would you be able to connect on IRC so we can further debug this? requesting all the information via bugtrack is going to be rather a long process, while it could be a few minutes on IRC.

In case you can, I'm "afiestas" on irc.freenode.org
Comment 27 Alex Fiestas 2013-01-14 11:08:01 UTC
Git commit d43eb850be250147d45741e2fe2bd7f5c3637a75 by Àlex Fiestas.
Committed on 14/01/2013 at 12:06.
Pushed by afiestas into branch 'master'.

Reset screen position for singleOutput

We have to come out with a better way of doing this, we can't keep
reseting everything in all config methods.

M  +1    -0    kded/generator.cpp

http://commits.kde.org/kscreen/d43eb850be250147d45741e2fe2bd7f5c3637a75
Comment 28 Anton 2013-01-14 11:20:47 UTC
Thanks guys, 2 hours of debugging but it was totally worth it.
Comment 29 Aleksander Kamenik 2013-01-14 13:03:08 UTC
Just want to say that all the issues I reported here earlier have been fixed for me as well now. Thanks!
Comment 30 Alex Fiestas 2013-01-14 13:23:36 UTC
Thanks for getting back to us Aleksander, we are almost out of bugs so a release will come soon :)