1+ #[ cfg( feature = "selector" ) ]
2+ use crate :: utils:: get_region_area;
13use dialoguer:: { FuzzySelect , theme:: ColorfulTheme } ;
24use eyre:: { Result , bail} ;
35use libwayshot:: WayshotConnection ;
4- #[ cfg( feature = "selector" ) ]
5- use libwaysip:: WaySip ;
6-
7- #[ cfg( feature = "selector" ) ]
8- use crate :: utils:: waysip_to_region;
96
107/// Describes what was captured, used to build the notification body.
118#[ derive( Debug , Clone ) ]
@@ -39,10 +36,11 @@ pub fn capture(
3936 conn : & WayshotConnection ,
4037 mode : & CaptureMode ,
4138 cursor : bool ,
39+ freeze : bool ,
4240) -> Result < ( image:: DynamicImage , ShotResult ) > {
4341 match mode {
4442 #[ cfg( feature = "selector" ) ]
45- CaptureMode :: Geometry => capture_geometry ( conn, cursor) ,
43+ CaptureMode :: Geometry => capture_geometry ( conn, cursor, freeze ) ,
4644 CaptureMode :: Toplevel ( name) => capture_toplevel_by_name ( conn, name, cursor) ,
4745 CaptureMode :: ChooseToplevel => capture_toplevel_interactive ( conn, cursor) ,
4846 CaptureMode :: Output ( name) => capture_output_by_name ( conn, name, cursor) ,
@@ -56,21 +54,17 @@ pub fn capture(
5654fn capture_geometry (
5755 conn : & WayshotConnection ,
5856 cursor : bool ,
57+ freeze : bool ,
5958) -> Result < ( image:: DynamicImage , ShotResult ) > {
60- let image = conn. screenshot_freeze (
61- |w_conn| {
62- let info = WaySip :: new ( )
63- . with_connection ( w_conn. conn . clone ( ) )
64- . with_selection_type ( libwaysip:: SelectionType :: Area )
65- . get ( )
66- . map_err ( |e| libwayshot:: Error :: FreezeCallbackError ( e. to_string ( ) ) ) ?
67- . ok_or_else ( || {
68- libwayshot:: Error :: FreezeCallbackError ( "No area selected" . to_string ( ) )
69- } ) ?;
70- waysip_to_region ( info. size ( ) , info. left_top_point ( ) )
71- } ,
72- cursor,
73- ) ?;
59+ let image = if freeze {
60+ conn. screenshot_freeze (
61+ |w_conn| get_region_area ( w_conn) . map_err ( libwayshot:: Error :: FreezeCallbackError ) ,
62+ cursor,
63+ ) ?
64+ } else {
65+ let region = get_region_area ( conn) . map_err ( |e| eyre:: eyre!( "{e}" ) ) ?;
66+ conn. screenshot ( region, cursor) ?
67+ } ;
7468 Ok ( ( image, ShotResult :: Area ) )
7569}
7670
0 commit comments