This is just an infinitive. You could call it the continuous infinitive. It is used when an infinitive is needed, and the meaning refers to the (temporary) state, rather than an action.
Very often there is very little difference in meaning between the infinitive and the continuous infinitive, but sometimes it is required. Compare,
I happened to be waiting for the bus when the accident occurred.
I happened to wait for the bus when the accident occurred.
*I happened waiting for the bus when the accident occurred. (ungrammatical)
We want to indicate that the "wait" was ongoing at the time of the accident. But the "happened to ..." construction requires us to use an infinitive. And so only the first sentence works. The second suggests that the wait started and finished during the accident (odd). The last is ungrammatical.