How to get current workspace information from Xmonad through bash command / file?

902 Views Asked by At

I need the information about the current workspace/screen from Xmonad. I need it externally in a bash script so that I can perform some function based on the current workspace where I am in.

I searched the web and it seems like dynamicLog is one of the way to do this. But am not able to figure out how exactly to send the information from Xmonad into a file. What I am trying to do is that make Xmonad update a certain file with the current workspace information whenever it changes.

Can this be done through DynamicLogger?

My current Xmonad dynamicLog section is as follows:

   , logHook            = dynamicLogWithPP 
                           xmobarPP
                           { ppOutput = hPutStrLn xmproc
                           , ppTitle = xmobarColor "darkgreen" "" . shorten 100
                           }

Alternatively, looking at another method on the web, I tried something like

.
.
.
import XMonad.Hooks.SetWMName
import XMonad.Hooks.EwmhDesktops
import XMonad.Util.Cursor



myStartupHook        = do
  startupHook gnomeConfig
--  spawn "xcompmgr -cfC -t-9 -l-11 -r9  -D6 &"
  setDefaultCursor xC_left_ptr <+>  ewmhDesktopsStartup >> setWMName "Xmonad"

.
.
.

...to be used for the utility wmctrl but it did not work. Its output was like -

$ wmctrl -d
Cannot get number of desktops properties. (_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)

Any help on any of the above is appreciated.

Thanks

1

There are 1 best solutions below

0
On

xprop utility is probably what you're looking for. To my knowledge, it works with every window manager, including XMonad. It provides information about desktops, windows and bunch of other stuff on X11. Here's example of it's output on my system:

$ xprop -root
_NET_DESKTOP_VIEWPORT(CARDINAL) = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
AT_SPI_BUS(STRING) = "unix:path=/run/user/1000/at-spi/bus_0,guid=1e117f5891f27107a4d3b3fe62a2c9d2"
ESETROOT_PMAP_ID(PIXMAP): pixmap id # 0xa00001
_XROOTPMAP_ID(PIXMAP): pixmap id # 0xa00001
_NET_SUPPORTING_WM_CHECK(WINDOW): window id # 0x400001
_NET_SUPPORTED(ATOM) = _NET_WM_STATE, _NET_WM_STATE_FULLSCREEN, _NET_SUPPORTING_WM_CHECK, _NET_WM_NAME, _NET_WM_STATE_HIDDEN, _NET_WM_STATE_DEMANDS_ATTENTION, _NET_NUMBER_OF_DESKTOPS, _NET_CLIENT_LIST, _NET_CLIENT_LIST_STACKING, _NET_CURRENT_DESKTOP, _NET_DESKTOP_NAMES, _NET_ACTIVE_WINDOW, _NET_WM_DESKTOP, _NET_WM_STRUT, _NET_DESKTOP_VIEWPORT
_NET_ACTIVE_WINDOW(WINDOW): window id # 0x220000f
_NET_CURRENT_DESKTOP(CARDINAL) = 2
_NET_CLIENT_LIST_STACKING(WINDOW): window id # 0xe00002, 0x1e0002c, 0x220000f
_NET_CLIENT_LIST(WINDOW): window id # 0xe00002, 0x1e0002c, 0x220000f
_NET_DESKTOP_NAMES(UTF8_STRING) = "1", "2", "3", "4", "5", "6", "7", "8", "9"
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 9
GDK_VISUALS(INTEGER) = 1757, 2175
_XKB_RULES_NAMES(STRING) = "evdev", "pc105", "us,ru", "qwerty", "grp:alt_shift_toggle"
XFree86_has_VT(INTEGER) = 1
XFree86_VT(INTEGER) = 7
Xorg_Seat(STRING) = "seat0"

You can also specify which properties you want to get:

$ xprop -root _NET_NUMBER_OF_DESKTOPS _NET_CLIENT_LIST _NET_ACTIVE_WINDOW _NET_CURRENT_DESKTOP
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 9
_NET_CLIENT_LIST(WINDOW): window id # 0xe00002, 0x1e0002c, 0x220000f
_NET_ACTIVE_WINDOW(WINDOW): window id # 0x220000f
_NET_CURRENT_DESKTOP(CARDINAL) = 2

It behaves the same way with windows, which you might find useful for finding out which desktops are being occupied:

$ xprop -id 0x1e0002c _NET_WM_DESKTOP
_NET_WM_DESKTOP(CARDINAL) = 1

Manual page for xprop contains some more useful flags, so make sure to check it.