Backport a few fixes from the KDE codebase.