use loginctl to terminate the $USER session
This should work distro/init system agnostic as long as elogind or logind is present and running on a Linux system rather than force killing a specific window manager.
Reference:
https://www.freedesktop.org/software/systemd/man/loginctl.html
not sure if this works on systemd distros but you can also use loginctl to reboot, poweroff and suspoend a system as well.