The ancestral form, which had rudimentary wings for brooding the nest, and which could fold them tightly to prevent impediments to running (as per Hopp and Orsen, in Feathered Dragons, 2004) could have leapt up into trees to roost and/or forage when they were not breeding.
Such wings need not have been rudimentary at all. The bigger the wings, the more eggs fit under them -- a straightforward Darwinian advantage. This goes twice if the wings were exapted for sexual selection.
Regarding life in trees, how good a glider can *Archaeopteryx* have been when it had that gap between wing and body, and don't chachalacas have a fully reverted hallux while that of *Confuciusornis* points medially and that of *Archaeopteryx* isn't rotated at all?