I looked into USB-IF PD spec awhile ago to better understand how negotiation is done and roles are chosen. I came away disappointed, as it’s less intelligent than one might hope.
First, regarding controlling which device receives vs provides charge, I didn’t see any mention even suggesting that control of that be exposed to the user. And without standards being set by the USB-IF on how to expose control, I think it’s unlikely to be a feature we’ll see made available at the OS level. I really hope that they created a standard and I just missed it, or that they have plans to.
Of course, they talk about how devices advertise their capabilities, negotiate, and are expected to behave. For the case of devices capable of both receiving and providing charge, known as DRP (Dual-Role Power), they are able to declare a preference. E.g. DRP, prefer to receive charge. But if two DRP devices are connected that either have the same preference or perhaps don’t declare a preference, well, they say the two devices will literally choose at random which one receives power. This is what it says they are supposed to do.
TL;DR - if you connect your power bank and laptop, and you find that it’s random if the power bank provides charge or instead receives charge, well, unplug them and try again to get the direction you want. It seems that it’s literally supposed to be random.
You should be able to do it, if you can insert yourself in between the PD negotiation. But I don’t know if there is any open and easy library for doing PD DRP or PD Source negotiation yourself in a microcontroller, or if there’s a PD DRP or PD Source controller chip which offers easy dynamic control and passes enough information out to a microcontroller so that you could use it to build a Man-in-the-Middle device.
I know of a couple open libraries for either acting as a PD Sink (request charge), or for controlling a dedicated PD Sink controller chip. Such as this, github.com/CentyLab/AP33772S-Cpp. Just don’t know of one for PD DRP or PD Source.