@@ -84,17 +84,17 @@ impl AppData {
8484 None
8585 }
8686
87- // fn get_pos_display_id(&self, pos: (i32, i32)) -> Option<usize> {
88- // let (pos_x, pos_y) = pos;
89- // for (i, ((width, height), (x, y))) in
90- // zip(&self.display_logic_size, &self.display_postion ).enumerate()
91- // {
92- // if pos_x >= *x && pos_x <= *x + *width && pos_y >= *y && pos_y <= *y + *height {
93- // return Some(i);
94- // }
95- // }
96- // None
97- // }
87+ fn get_pos_display_id ( & self , pos : ( i32 , i32 ) ) -> Option < usize > {
88+ let ( pos_x, pos_y) = pos;
89+ for ( i, ( ( width, height) , ( x, y) ) ) in
90+ zip ( & self . display_logic_size , & self . display_position ) . enumerate ( )
91+ {
92+ if pos_x >= * x && pos_x <= * x + * width && pos_y >= * y && pos_y <= * y + * height {
93+ return Some ( i) ;
94+ }
95+ }
96+ None
97+ }
9898
9999 fn get_pos_display_ids ( & self , pos : ( i32 , i32 ) , size : ( i32 , i32 ) ) -> Option < Vec < usize > > {
100100 let ( start_x, start_y) = pos;
@@ -190,11 +190,11 @@ impl AppData {
190190 ) ,
191191 ) ,
192192 ) {
193- println ! ( "{}, {}," , displayname , display_description ) ;
194- println ! ( " Size: {},{}" , x , y ) ;
195- println ! ( " LogicSize: {}, {}" , logic_x , logic_y ) ;
196- println ! ( " Position: {}, {}" , pos_x , pos_y ) ;
197- println ! ( " Scale: {}" , scale ) ;
193+ println ! ( "{displayname }, {display_description}" ) ;
194+ println ! ( " Size: {x },{y}" ) ;
195+ println ! ( " LogicSize: {logic_x }, {logic_y}" ) ;
196+ println ! ( " Position: {pos_x }, {pos_y}" ) ;
197+ println ! ( " Scale: {scale}" ) ;
198198 }
199199 }
200200}
@@ -348,6 +348,10 @@ enum ClapOption {
348348 height : i32 ,
349349 usestdout : bool ,
350350 } ,
351+ ShotWithColor {
352+ pos_x : i32 ,
353+ pos_y : i32 ,
354+ } ,
351355}
352356
353357enum SlurpParseResult {
@@ -461,6 +465,13 @@ fn main() {
461465 )
462466 . about ( "TakeScreenshot about whole screen" ) ,
463467 )
468+ . subcommand (
469+ Command :: new ( "color" )
470+ . long_flag ( "color" )
471+ . short_flag ( 'C' )
472+ . arg ( arg ! ( <Point > ... "Pos by slurp" ) )
473+ . about ( "Get Color of a point" ) ,
474+ )
464475 . subcommand (
465476 Command :: new ( "list_outputs" )
466477 . long_flag ( "list_outputs" )
@@ -515,6 +526,17 @@ fn main() {
515526 }
516527 take_screenshot ( ClapOption :: ShotWithFullScreen { usestdout } ) ;
517528 }
529+ Some ( ( "color" , submatchs) ) => {
530+ let posmessage = submatchs
531+ . get_one :: < String > ( "Point" )
532+ . expect ( "Need message" )
533+ . to_string ( ) ;
534+ let SlurpParseResult :: Finished ( pos_x, pos_y, _, _) = parseslurp ( posmessage) else {
535+ return ;
536+ } ;
537+ tracing_subscriber:: fmt ( ) . init ( ) ;
538+ take_screenshot ( ClapOption :: ShotWithColor { pos_x, pos_y } )
539+ }
518540 #[ cfg( feature = "gui" ) ]
519541 Some ( ( "gui" , _) ) => {
520542 tracing_subscriber:: fmt:: init ( ) ;
@@ -720,6 +742,28 @@ fn take_screenshot(option: ClapOption) {
720742 }
721743 }
722744 }
745+ ClapOption :: ShotWithColor { pos_x, pos_y } => {
746+ let xdg_output_manager = state. xdg_output_manager . clone ( ) . unwrap ( ) ;
747+ for i in 0 ..state. displays . len ( ) {
748+ xdg_output_manager. get_xdg_output ( & state. displays [ i] , & qh, ( ) ) ;
749+ event_queue. roundtrip ( & mut state) . unwrap ( ) ;
750+ }
751+ if let Some ( id) = state. get_pos_display_id ( ( pos_x, pos_y) ) {
752+ let manager = state. wlr_screencopy . as_ref ( ) . unwrap ( ) ;
753+ let shm = state. shm . clone ( ) . unwrap ( ) ;
754+ if let Some ( bufferdata) = wlrbackend:: capture_output_frame (
755+ & conn,
756+ & state. displays [ id] ,
757+ manager,
758+ & display,
759+ shm,
760+ ( 1 , 1 ) ,
761+ Some ( ( pos_x, pos_y, 1 , 1 ) ) ,
762+ ) {
763+ filewriter:: get_color ( bufferdata) ;
764+ }
765+ }
766+ }
723767 ClapOption :: ShowInfo => {
724768 let xdg_output_manager = state. xdg_output_manager . clone ( ) . unwrap ( ) ;
725769 for i in 0 ..state. displays . len ( ) {
0 commit comments