Search code examples
linuxhaskellwindowforeground

Get foreground window title using Haskell on Linux


Under Windows, it is possible to get the foreground window title using: getForegroundWindow

Is there an equivalent way to get foreground window title using Haskell on Linux? (preferably without using FFI)


Solution

  • Using the X11 library:

    import Graphics.X11
    import Graphics.X11.Xlib.Extras
    
    main = do
      d <- openDisplay ""
      (w, _) <- getInputFocus d
      s <- fetchName d w
      print s