@lonm Yeah, I thought it's an operating system level request, but it really isn't. Operating systems already do this.
E.g.: You are listening to music through your laptop speakers on full volume, when you put in your headphones, the volume will switch to the last user-defined volume level on this output, the same if you unplug your headphones.
The same happens on smartphones, just with a different implementation. Point is as long as you are using the normal audio jack, the operating system has no idea what is plugged in in the first place.
If you really want control, then using a dedicated DAC would be your best option.