@@ -686,6 +686,30 @@ impl WidgetMachine {
686686 actions
687687 }
688688
689+ /// Attempts to acquire capabilities that have been requested by the widget
690+ /// during the initial capability negotiation handshake.
691+ fn process_requested_capabilities ( & mut self , requested : Capabilities ) -> Vec < Action > {
692+ match self . send_matrix_driver_request ( AcquireCapabilities {
693+ desired_capabilities : requested. clone ( ) ,
694+ } ) {
695+ None => Vec :: new ( ) ,
696+ Some ( ( request, action) ) => {
697+ request. add_response_handler ( |result, machine| {
698+ machine. process_acquired_capabilities ( result, requested)
699+ } ) ;
700+ vec ! [ action]
701+ }
702+ }
703+ }
704+
705+ /// Performs an initial capability negotiation handshake.
706+ ///
707+ /// The sequence is as follows: the machine sends a [`RequestCapabilities`]
708+ /// `toWidget` action, the widget responds with its requested
709+ /// capabilities, the machine attempts to acquire the
710+ /// requested capabilities from the driver, then it sends a
711+ /// [`NotifyCapabilitiesChanged`] `toWidget` action to tell the widget
712+ /// which capabilities were approved.
689713 fn negotiate_capabilities ( & mut self ) -> Vec < Action > {
690714 let mut actions = Vec :: new ( ) ;
691715
@@ -695,28 +719,13 @@ impl WidgetMachine {
695719
696720 self . capabilities = CapabilitiesState :: Negotiating ;
697721
698- let Some ( ( request, action) ) = self . send_to_widget_request ( RequestCapabilities { } ) else {
699- // We're done, return early.
700- return actions;
701- } ;
702-
703- request. add_response_handler ( |response, machine| {
704- let requested_capabilities = response. capabilities ;
705-
706- let Some ( ( request, action) ) = machine. send_matrix_driver_request ( AcquireCapabilities {
707- desired_capabilities : requested_capabilities. clone ( ) ,
708- } ) else {
709- // We're done, return early.
710- return Vec :: new ( ) ;
711- } ;
712-
722+ if let Some ( ( request, action) ) = self . send_to_widget_request ( RequestCapabilities { } ) {
713723 request. add_response_handler ( |result, machine| {
714- machine. process_acquired_capabilities ( result, requested_capabilities )
724+ machine. process_requested_capabilities ( result. capabilities )
715725 } ) ;
716- vec ! [ action]
717- } ) ;
726+ actions . push ( action) ;
727+ }
718728
719- actions. push ( action) ;
720729 actions
721730 }
722731}
0 commit comments