@@ -24,9 +24,7 @@ use std::{
2424use x11:: {
2525 xinerama,
2626 xlib:: {
27- self , Cursor , GCForeground , XAllocColor , XButtonPressedEvent , XClearWindow , XColor ,
28- XCreateFontCursor , XDefaultColormap , XDefaultRootWindow , XDefaultScreen , XFlush , XGCValues ,
29- XParseColor , XSetWindowBackground , XUnmapWindow , XWindowAttributes ,
27+ self , Atom , Cursor , GCForeground , XAllocColor , XButtonPressedEvent , XClearWindow , XColor , XCreateFontCursor , XDefaultColormap , XDefaultRootWindow , XDefaultScreen , XFlush , XGCValues , XGetWindowProperty , XInternAtom , XParseColor , XSetWindowBackground , XUnmapWindow , XWindowAttributes
3028 } ,
3129} ;
3230
@@ -513,12 +511,43 @@ impl GridWM {
513511 . into_owned ( )
514512 } ;
515513 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- ) )
514+ return Ok ( win_title) ;
521515 }
516+
517+ // if above fails
518+ unsafe {
519+ let net_wm_name = XInternAtom ( self . display , CString :: new ( "_NET_WM_NAME" ) . unwrap ( ) . as_ptr ( ) , 0 ) ;
520+ let utf8 = XInternAtom ( self . display , CString :: new ( "UTF8_STRING" ) . unwrap ( ) . as_ptr ( ) , 0 ) ;
521+
522+ let mut actual_type: Atom = std:: mem:: zeroed ( ) ;
523+ let mut actual_format: i32 = std:: mem:: zeroed ( ) ;
524+ let mut nitems: u64 = std:: mem:: zeroed ( ) ;
525+ let mut bytes_after: u64 = std:: mem:: zeroed ( ) ;
526+ let mut data: * mut u8 = std:: ptr:: null_mut ( ) ;
527+
528+ if XGetWindowProperty (
529+ self . display ,
530+ window,
531+ net_wm_name,
532+ 0 ,
533+ !0 ,
534+ 0 ,
535+ utf8,
536+ & mut actual_type,
537+ & mut actual_format,
538+ & mut nitems,
539+ & mut bytes_after,
540+ & mut data,
541+ ) == 0 && !data. is_null ( ) {
542+ let win_title = std:: ffi:: CStr :: from_ptr ( data as * const i8 )
543+ . to_string_lossy ( )
544+ . into_owned ( ) ;
545+ xlib:: XFree ( data as * mut _ ) ;
546+ return Ok ( win_title) ;
547+ }
548+ }
549+
550+ Err ( GridWMError :: Other ( format ! ( "failed to get name for window {}" , window) ) )
522551 }
523552
524553 fn get_focused ( & self ) -> Option < Window > {
@@ -727,7 +756,6 @@ impl GridWM {
727756 }
728757
729758 // TODO: maybe move it somewhere else
730- // TODO: fix bar disappearing when window is dragged over it
731759 fn draw_bar ( & self , content : Option < String > ) {
732760 unsafe {
733761 let root = XDefaultRootWindow ( self . display ) ;
0 commit comments