Skip to content

Instantly share code, notes, and snippets.

@qolarnix
Last active November 27, 2022 18:42
Show Gist options
  • Save qolarnix/25b377a2725f7bc6efca3fb7e3a8d090 to your computer and use it in GitHub Desktop.
Save qolarnix/25b377a2725f7bc6efca3fb7e3a8d090 to your computer and use it in GitHub Desktop.
FreeBSD Polybar Module - Curwin (xwindow improved, requires xdotool)
#!/usr/local/bin/php
<?php
/*
* Curwin
* Improved xwindow polybar module with support for custom class names
*/
$wm_desktop = shell_exec('xdotool getwindowfocus 2>/dev/null');
$wm_desktop = preg_replace('/\s+/', '', $wm_desktop);
$window_class = shell_exec('xprop -id $(xdotool getactivewindow 2>/dev/null) WM_CLASS 2>/dev/null | awk \'NF {print $NF}\' | sed \'s/"/ /g\'');
$window_class = preg_replace('/\s+/', '', $window_class);
$desktop_class = 'Desktop';
if ($wm_desktop == '10486050' || $wm_desktop == '12583202'): echo $desktop_class;
elseif ($window_class == 'Gnome-terminal'): echo "%{F#ffffff}Terminal%{u-}";
elseif ($window_class == 'Xfwm4-tweaks-settings'): echo "%{F#ffffff}Window Manager Tweaks%{u-}";
elseif ($window_class == 'Xfwm4-settings'): echo "%{F#ffffff}Window Manager Settings%{u-}";
else: echo "%{F#ffffff}$window_class%{u-}";
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment