radrow
radrow

Reputation: 7159

Get active window title in X11 Haskell library

I am trying to extract the title of the currently active window using X11 library.

I was trying to inspire myself with the xdotool code but I got stuck after getWindowProperty32 returned Foreign.C.Types.CLong that I couldn't handle in any way.

I know I could just create a new process with xdotool and read its output, but this is not the thing I am going to achieve. How can I do it via direct X server communication in Haskell?

Upvotes: 2

Views: 290

Answers (1)

Isaac van Bakel
Isaac van Bakel

Reputation: 1862

This is possible using getInputFocus and fetchName.

The code would look something like

getActiveWindowTitle :: Display -> IO (Maybe String)
getActiveWindowTitle display = do
  (window, _) = getInputFocus display
  fetchName display window

Upvotes: 2

Related Questions