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