File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub enum GridWMError {
77 DisplayNotFound ( String ) ,
88 NulString ( NulError ) ,
99 ScreenNotFound ( String ) ,
10+ Other ( String ) ,
1011}
1112
1213impl fmt:: Display for GridWMError {
@@ -17,6 +18,7 @@ impl fmt::Display for GridWMError {
1718 GridWMError :: ScreenNotFound ( screen) => write ! ( f, "screen {} not found" , screen) ,
1819 GridWMError :: Io ( err) => write ! ( f, "io error: {}" , err) ,
1920 GridWMError :: Toml ( err) => write ! ( f, "failed to parse toml: {}" , err) ,
21+ GridWMError :: Other ( err) => write ! ( f, "{}" , err) ,
2022 }
2123 }
2224}
Original file line number Diff line number Diff line change @@ -503,6 +503,41 @@ impl GridWM {
503503 self . set_desktop ( self . current_desktop , desktop) ;
504504 }
505505
506+ fn get_name ( & self , window : Window ) -> Result < String , GridWMError > {
507+ let mut win_name: * mut i8 = std:: ptr:: null_mut ( ) ;
508+ let status = unsafe { xlib:: XFetchName ( self . display , window, & mut win_name) } ;
509+ if status != 0 && !win_name. is_null ( ) {
510+ let win_title = unsafe {
511+ std:: ffi:: CStr :: from_ptr ( win_name)
512+ . to_string_lossy ( )
513+ . into_owned ( )
514+ } ;
515+ unsafe { xlib:: XFree ( win_name as * mut _ ) } ;
516+ Ok ( win_title)
517+ } else {
518+ Err ( GridWMError :: Other (
519+ "failed to fetch window name" . to_string ( ) ,
520+ ) )
521+ }
522+ }
523+
524+ fn get_focused ( & self ) -> Option < Window > {
525+ unsafe {
526+ let mut focused: Window = std:: mem:: zeroed ( ) ;
527+ let mut revert: i32 = std:: mem:: zeroed ( ) ;
528+ xlib:: XGetInputFocus (
529+ self . display ,
530+ & mut focused as * mut Window ,
531+ & mut revert as * mut i32 ,
532+ ) ;
533+ if focused == 0 || focused == xlib:: PointerRoot as u64 {
534+ None
535+ } else {
536+ Some ( focused)
537+ }
538+ }
539+ }
540+
506541 fn remove_window ( & mut self , event : xlib:: XEvent ) {
507542 let event: xlib:: XUnmapEvent = From :: from ( event) ;
508543 let mut desktop = self . get_desktop ( self . current_desktop ) ;
You can’t perform that action at this time.
0 commit comments