@@ -634,6 +634,28 @@ impl WidgetMachine {
634634 actions
635635 }
636636
637+ /// Attempts to acquire capabilities that have been requested by the widget during the initial
638+ /// capability negotiation handshake.
639+ fn process_requested_capabilities ( & mut self , requested : Capabilities ) -> Vec < Action > {
640+ match self . send_matrix_driver_request ( AcquireCapabilities {
641+ desired_capabilities : requested. clone ( ) ,
642+ } ) {
643+ None => Vec :: new ( ) ,
644+ Some ( ( request, action) ) => {
645+ request. then ( |result, machine| {
646+ machine. process_acquired_capabilities ( result, requested)
647+ } ) ;
648+ vec ! [ action]
649+ }
650+ }
651+ }
652+
653+ /// Performs an initial capability negotiation handshake.
654+ ///
655+ /// The sequence is as follows: the machine sends a [`RequestCapabilities`] `toWidget` action,
656+ /// the widget responds with its requested capabilities, the machine attempts to acquire the
657+ /// requested capabilities from the driver, then it sends a [`NotifyCapabilitiesChanged`]
658+ /// `toWidget` action to tell the widget which capabilities were approved.
637659 fn negotiate_capabilities ( & mut self ) -> Vec < Action > {
638660 let mut actions = Vec :: new ( ) ;
639661
@@ -643,28 +665,13 @@ impl WidgetMachine {
643665
644666 self . capabilities = CapabilitiesState :: Negotiating ;
645667
646- let Some ( ( request, action) ) = self . send_to_widget_request ( RequestCapabilities { } ) else {
647- // We're done, return early.
648- return actions;
649- } ;
650-
651- request. then ( |response, machine| {
652- let requested_capabilities = response. capabilities ;
653-
654- let Some ( ( request, action) ) = machine. send_matrix_driver_request ( AcquireCapabilities {
655- desired_capabilities : requested_capabilities. clone ( ) ,
656- } ) else {
657- // We're done, return early.
658- return Vec :: new ( ) ;
659- } ;
660-
668+ if let Some ( ( request, action) ) = self . send_to_widget_request ( RequestCapabilities { } ) {
661669 request. then ( |result, machine| {
662- machine. process_acquired_capabilities ( result, requested_capabilities )
670+ machine. process_requested_capabilities ( result. capabilities )
663671 } ) ;
664- vec ! [ action]
665- } ) ;
672+ actions . push ( action) ;
673+ }
666674
667- actions. push ( action) ;
668675 actions
669676 }
670677}
0 commit comments