@@ -636,6 +636,30 @@ impl WidgetMachine {
636636 actions
637637 }
638638
639+ /// Attempts to acquire capabilities that have been requested by the widget
640+ /// during the initial capability negotiation handshake.
641+ fn process_requested_capabilities ( & mut self , requested : Capabilities ) -> Vec < Action > {
642+ match self . send_matrix_driver_request ( AcquireCapabilities {
643+ desired_capabilities : requested. clone ( ) ,
644+ } ) {
645+ None => Vec :: new ( ) ,
646+ Some ( ( request, action) ) => {
647+ request. then ( |result, machine| {
648+ machine. process_acquired_capabilities ( result, requested)
649+ } ) ;
650+ vec ! [ action]
651+ }
652+ }
653+ }
654+
655+ /// Performs an initial capability negotiation handshake.
656+ ///
657+ /// The sequence is as follows: the machine sends a [`RequestCapabilities`]
658+ /// `toWidget` action, the widget responds with its requested
659+ /// capabilities, the machine attempts to acquire the
660+ /// requested capabilities from the driver, then it sends a
661+ /// [`NotifyCapabilitiesChanged`] `toWidget` action to tell the widget
662+ /// which capabilities were approved.
639663 fn negotiate_capabilities ( & mut self ) -> Vec < Action > {
640664 let mut actions = Vec :: new ( ) ;
641665
@@ -645,28 +669,13 @@ impl WidgetMachine {
645669
646670 self . capabilities = CapabilitiesState :: Negotiating ;
647671
648- let Some ( ( request, action) ) = self . send_to_widget_request ( RequestCapabilities { } ) else {
649- // We're done, return early.
650- return actions;
651- } ;
652-
653- request. then ( |response, machine| {
654- let requested_capabilities = response. capabilities ;
655-
656- let Some ( ( request, action) ) = machine. send_matrix_driver_request ( AcquireCapabilities {
657- desired_capabilities : requested_capabilities. clone ( ) ,
658- } ) else {
659- // We're done, return early.
660- return Vec :: new ( ) ;
661- } ;
662-
672+ if let Some ( ( request, action) ) = self . send_to_widget_request ( RequestCapabilities { } ) {
663673 request. then ( |result, machine| {
664- machine. process_acquired_capabilities ( result, requested_capabilities )
674+ machine. process_requested_capabilities ( result. capabilities )
665675 } ) ;
666- vec ! [ action]
667- } ) ;
676+ actions . push ( action) ;
677+ }
668678
669- actions. push ( action) ;
670679 actions
671680 }
672681}
0 commit comments