So for now I'm doing it if there is a queen+rook (also now in endgame where pieces <5 but still queen + rook), if the king is castled, or has moved (cant castle, caught in center or somewhere). I suppose I could also add :
OR moved_queen_rook AND moved_king_rook....
Another approach could be to smoothly scale all king-safety related terms (shelter as well as others) depending on the existing material of the opponent. This would avoid the dangerous effect of jumping evaluations just by one trading move. In the given position it would also treat king safety slightly more important for white (since black has an additional piece) than for black. Furthermore, king safety might also include a notion of how well the king is defended by friendly pieces, which would also help in your example position.