Why do I have Wayland packages installed although my system is not using Wayland?

I am using Ubuntu MATE 17.10. The release notes never mentioned anything about Wayland, and I've always assumed this system was using the Xorg display server.

However, today I ran the usual

sudo apt update && sudo apt full-upgrade

and noticed that the output included:

The following packages will be upgraded:
  libwayland-client0 libwayland-cursor0 libwayland-server0 [...]

I thought, that's odd. Is my system using Wayland after all?

As suggested by Byte Commander in chat, I looked for running processes (using pgrep Xorg and pstree), and found Xorg but no Wayland. So I'm pretty sure Wayland is not running. I looked for Wayland packages:

dpkg -l | grep [Ww]ayland
ii  kwayland-data                         4:5.38.0-0ubuntu1                        all          Qt library wrapper for Wayland libraries - data files
ii  kwayland-integration:amd64            4:5.10.5-0ubuntu1                        amd64        kwayland runtime integration plugins
ii  libkf5waylandclient5:amd64            4:5.38.0-0ubuntu1                        amd64        Qt library wrapper for Wayland libraries
ii  libqt5waylandclient5:amd64            5.9.1-2                                  amd64        QtWayland client library
ii  libqt5waylandcompositor5:amd64        5.9.1-2                                  amd64        QtWayland compositor library
ii  libwayland-client0:amd64              1.14.0-1ubuntu0.1                        amd64        wayland compositor infrastructure - client library
ii  libwayland-cursor0:amd64              1.14.0-1ubuntu0.1                        amd64        wayland compositor infrastructure - cursor library
ii  libwayland-egl1-mesa:amd64            17.2.8-0ubuntu0~17.10.1                  amd64        implementation of the Wayland EGL platform -- runtime
ii  libwayland-server0:amd64              1.14.0-1ubuntu0.1                        amd64        wayland compositor infrastructure - server library
ii  qtwayland5:amd64                      5.9.1-2                                  amd64        QtWayland platform plugin

Why do I have these packages related to Wayland even though I'm not using Wayland?


Thanks to Byte Commander and Eliah Kagan making suggestions in chat I was able to figure out that these packages were installed as dependencies.

As suggested I simulated removing Wayland related packages... When I tried pretending to remove all Wayland-related packages...

apt remove '.*wayland.*' -s

the result looked apocalyptic, with a full-screen terminal full of packages being removed, including the entire ubuntu-mate-desktop metapackage and all its adjuncts, the xorg package (oops!) and marco (MATE's default window manager).

But just removing kwayland-data only seemed to remove a couple of other mysterious packages kwayland-integration and libkf5waylandclient5...

So as Eliah Kagan suggested I tried asking aptitude why I had these packages, for example

$ aptitude why kwayland-data
i   konsole              Depends    libkf5windowsystem5 (>= 4.96.0)                           
i A libkf5windowsystem5  Recommends kwayland-integration                                      
i A kwayland-integration Depends    libkf5waylandclient5 (>= 4:5.27.0+p16.10+git20161029.2052)
i A libkf5waylandclient5 Depends    kwayland-data (= 4:5.38.0-0ubuntu1) 

Ahh! That makes sense. I installed Konsole because other terminal emulators don't support CTL.

By asking aptitude why over and over like a persistent toddler, it's possible to find out why any particular package is required or has been installed, for example:

$ aptitude why libwayland-egl1-mesa
i   libwebkit2gtk-4.0-37 Depends libwayland-egl1-mesa (>= 10.0.2) | libwayland-egl1
$ aptitude why libwayland-cursor0
i   libgtk-3-0 Depends libwayland-cursor0 (>= 1.9.91)
$ aptitude why libgtk-3-0
i   mate-utils Depends libgtk-3-0 (>= 3.16.2)
$ aptitude why mate-utils
i   ubuntu-mate-desktop Depends mate-utils

Simulating removal of packages like libgtk-3-0 (be careful not to actually remove them...) reveals more about the dependency structures in play.

Conclusion

I have these packages because other packages surprisingly depend on them. Some, such as kwayland-data, installed as a dependency of a dependency of a package recommended by a dependency of a non-essential package I installed myself, could be safely removed, but others, such as libwayland-egl1-mesa are dependencies of packages integral to my system, and removing them would be disastrous! With APT's --simulate or -s flag and aptitude we can safely investigate these matters.