Plasma desktop kstart: cannot connect to X server - What now?

Updated: March 4, 2019

Here's an interesting little problem. I was merrily using my Plasma desktop when suddenly it went kaput. But kaput in a bad way, not a good way. This translates into windows decorations being all gone and nothing really responding to mouse clicks. And here comes the conundrum train, nonstop to Foobar. I wanted to restart the Plasma shell and just get back to working - after all, I mentioned this workaround a couple of times in the past, like my Slimbook & Kubuntu combat reports. Indeed. Except ...

This didn't work. In the virtual console (the only thing that actually was working), I had the kstart: cannot connect to X server error. At this point, a reboot or magic were needed, and I really wanted to have to avoid rebooting. In general, rebooting is a lazy way of fixing issues, and it should be done sparingly. So let's talk about a better, less destructive way.

Teaser

You gotta be in it to kwin it

Aha. That's the pun of the century. And thanks go to some smart KDE folks who actually happened to be sitting next to me while I was gently crying in the corner. The thing is, sometimes the KWin window manager can get confused or die, and we need to bring it back to life. Let's do this in a nice, clean way. Open a virtual console - Ctrl + Alt + F1-7 (except the one you're currently using with a borked desktop), and login there with your credentials.

export DISPLAY=:0
kwin_x11

Next, export the display and start the kwin_x11 process. This should give you back some control of your desktop. Go back to your virtual console with the desktop session and start KRunner (a highly useful multi-purpose integrated Plasma desktop application launcher).

Krunner

In the command window, type:

kwin_x11 --replace

This will replace the window manager session running in one of the other virtual consoles with a new one. Then, finally, we can start the Plasma shell, and be back to living la vida loca:

plasmashell

Problem solved. Plasma desktop running. No reboots. Job done.

Conclusion

This was short but sweet. Especially since we did not need to destroy our desktop session, and that's always a bonus. I am happy that the Plasma desktop is resilient enough to survive window manager crashes, and this tutorial shows how to accomplish that without any extra tears being shed. In fact, I'd suggest you write down the necessary steps and commands into a text file or a script, so you can use them when the need strikes, especially if you do not have another system that you could use to search for online information.

With all the data and tweaks I've laid down in my Slimbook & Kubuntu reports, plus the various Plasma secrets articles, I guess you have pretty much everything you need to keep a vibrant desktop session running for days and weeks on end, and even if something goes wrong now and then, you do not need to reboot and lose your work. Well, there you go. We're done here. Keep on Plasmaing.

Cheers.

You may also like: