The following command can be used on Debian, and certain other distributions:
update-alternatives --list x-window-manager
If successfully executed, this will print the full path to the configured window manager binary.
The current logic for determining the WM based upon process name should be refactored in order to also apply it here. If a match isn't found found, preferably print just the binary name rather than the full path.