The test is whether the event has happened or habitually happens, against whether it is still ahead and unrealised.
Realised or habitual takes the indicative. Cuando llego a casa, ceno. Cuando llegué, ya se habían ido.
Not yet happened takes the subjunctive. Cuando llegues, llámame. The arrival is anticipated rather than actual, so it is subjunctive even though you fully expect it to happen.
That last point is the one that catches people. It is not about doubt. You can be completely certain and still use the subjunctive, because the trigger is that the event is unrealised rather than uncertain.
The same logic runs through hasta que, en cuanto, tan pronto como and antes de que, which always takes it.