@@ -735,6 +735,73 @@ update_clipboard (PortalTestWin *win)
735735 }
736736}
737737
738+ static void
739+ inputcapture_session_started (GObject * source ,
740+ GAsyncResult * result ,
741+ gpointer data )
742+ {
743+ XdpInputCaptureSession * ic = XDP_INPUT_CAPTURE_SESSION (source );
744+ PortalTestWin * win = data ;
745+ g_autoptr (GError ) error = NULL ;
746+ GList * zones ;
747+ g_autoptr (GString ) s = NULL ;
748+
749+ if (!xdp_input_capture_session_start_finish (ic , result , & error ))
750+ {
751+ g_warning ("Failed to start inputcapture session: %s" , error -> message );
752+ return ;
753+ }
754+
755+ zones = xdp_input_capture_session_get_zones (ic );
756+ s = g_string_new ("" );
757+ for (GList * elem = g_list_first (zones ); elem ; elem = g_list_next (elem ))
758+ {
759+ XdpInputCaptureZone * zone = elem -> data ;
760+ guint w , h ;
761+ gint x , y ;
762+
763+ g_object_get (zone ,
764+ "width" , & w ,
765+ "height" , & h ,
766+ "x" , & x ,
767+ "y" , & y ,
768+ NULL );
769+
770+ g_string_append_printf (s , "%ux%u@%d,%d " , w , h , x , y );
771+ }
772+ gtk_label_set_label (GTK_LABEL (win -> inputcapture_label ), s -> str );
773+
774+ update_clipboard (win );
775+ }
776+
777+ static void
778+ inputcapture_session_created2 (GObject * source ,
779+ GAsyncResult * result ,
780+ gpointer data )
781+ {
782+ XdpPortal * portal = XDP_PORTAL (source );
783+ PortalTestWin * win = data ;
784+ g_autoptr (GError ) error = NULL ;
785+ g_autoptr (GString ) s = NULL ;
786+ XdpInputCaptureSession * ic ;
787+
788+ ic = xdp_portal_create_input_capture_session2_finish (portal , result , & error );
789+ if (ic == NULL )
790+ {
791+ g_warning ("Failed to create inputcapture session: %s" , error -> message );
792+ return ;
793+ }
794+ win -> session = xdp_input_capture_session_get_session (ic );
795+ win -> input_capture_session = ic ;
796+
797+ xdp_input_capture_session_start (ic ,
798+ NULL ,
799+ XDP_INPUT_CAPABILITY_POINTER | XDP_INPUT_CAPABILITY_KEYBOARD ,
800+ NULL ,
801+ inputcapture_session_started ,
802+ win );
803+ }
804+
738805static void
739806inputcapture_session_created (GObject * source ,
740807 GAsyncResult * result ,
@@ -783,12 +850,24 @@ start_input_capture (PortalTestWin *win)
783850
784851 update_clipboard (win );
785852
786- xdp_portal_create_input_capture_session (win -> portal ,
787- NULL ,
788- XDP_INPUT_CAPABILITY_POINTER | XDP_INPUT_CAPABILITY_KEYBOARD ,
789- NULL ,
790- inputcapture_session_created ,
791- win );
853+ if (xdp_portal_get_input_capture_version_sync (win -> portal , NULL , NULL ) > 1 )
854+ {
855+ g_print ("Using new input capture session construction API\n" );
856+ xdp_portal_create_input_capture_session2 (win -> portal ,
857+ NULL ,
858+ inputcapture_session_created2 ,
859+ win );
860+ }
861+ else
862+ {
863+ g_print ("Using legacy input capture session construction API\n" );
864+ xdp_portal_create_input_capture_session (win -> portal ,
865+ NULL ,
866+ XDP_INPUT_CAPABILITY_POINTER | XDP_INPUT_CAPABILITY_KEYBOARD ,
867+ NULL ,
868+ inputcapture_session_created ,
869+ win );
870+ }
792871}
793872
794873static void
0 commit comments