The war of 1676-1684 between the Holy League of Austria, Venice (and several other Italian powers including the Holy See), Polish-Lithuanian Commowealth and Tsardom of Russia on the one hand and the Ottoman Empire on the other ended by the Treaty of Constantinople, giving the parties involved the following gains:
The Habsburgs received from the Ottomans the Eğri Eyalet, Varat Eyalet, much of the Budin Eyalet, the northern part of the Temeşvar Eyalet and parts of the Bosnia Eyalet. This corresponded to much of Hungary, Croatia and Slavonia. The Principality of Transylvania remained nominally independent but was subject to the direct rule of Austrian governors. Poland recovered Podolia, including the dismantled fortress at Kamaniçe, as well as sovereignity over Moldavia and Yedisan. Venice obtained most of Dalmatia along with the Morea (the Peloponnese peninsula of southern Greece). Russia obtained the Azov and Dniepr fortrecess, though the Crimean offence plan failed.
The greatest setback so far was the untimely death of brother of Alexis II, Tsarevich Feodor, in summer 1682, after falling from horse during hunt. That meant that the plans of the Tsar regarding vassal Principality of Ruthenia were heavily retooled under the pressure from Polish-Lithuanian Commonwealth.
In the end, the conditions of Treaty of 1677 were revised. The new Grand Prince-elect was Charles Philip (Karol Filip), fourth son of King Philip I of Poland, who was to marry Tsarevna Sophia Romanova, sister to Alexis II.
The conditions were also revised to makev them more pro-Polish. The Brest Union was to remain in force in the lands of Grand Duchy of Ruthenia, the only limitation was that the pre-existing Orthodox monasteries were not to be converted into Greek Catholic (though there was no limits of new ones being built). Metrolpolitan bishop of Ruthenia was also to be subject to authority of Constantinople, and not Moscow.
The arrangement, with the new grand ducal couple being istalled in Kiev, was realised in 1687.