Replace Xmobar with Polybar

- Remove unneeded imports
- Move global tangle path to individual code blocks
- Add docks hook to avoid polybar when tiling
- Add dwm-style workspace cycling
- Fix keybindings to put ctrl before shift
- Reset window sizes when force re-tiling
- Add ewmhDesktopsEventHook to myEventHook for polybar integration
- Launch polybar instead of xmobar
- No tangle xmobar config and delete it
- Add polybar config from dwm with bunch of tweaks
This commit is contained in:
Sravan Balaji
2021-05-10 23:47:00 -04:00
parent 6293138f1e
commit f803927440
8 changed files with 2554 additions and 113 deletions

1396
README.org

File diff suppressed because it is too large Load Diff

1092
polybar/config.ini Normal file

File diff suppressed because it is too large Load Diff

37
polybar/launch.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
#!/bin/bash
BAR="mybar"
CONFIG="~/.xmonad/polybar/config.ini"
NUM_MONITORS=0
CONNECTED_MONITORS=$(xrandr --query | grep " connected" | cut -d" " -f1)
TRAY_POS="right"
killall -q polybar
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
rm /tmp/polybar.pids
sleep 1
for m in $CONNECTED_MONITORS; do
let "NUM_MONITORS+=1"
done
if [ $NUM_MONITORS == 1 ]; then
# Launch on only monitor w/ systray
MONITOR=$CONNECTED_MONITORS TRAY_POS=$TRAY_POS polybar --reload -c $CONFIG $BAR &
else
PRIMARY=$(xrandr --query | grep " connected" | grep "primary" | cut -d" " -f1)
OTHERS=$(xrandr --query | grep " connected" | grep -v "primary" | cut -d" " -f1)
# Launch on primary monitor w/ systray
MONITOR=$PRIMARY TRAY_POS=$TRAY_POS polybar --reload -c $CONFIG $BAR &
sleep 1
# Launch on all other monitors w/o systray
for m in $OTHERS; do
MONITOR=$m TRAY_POS=none polybar --reload -c $CONFIG $BAR &
done
fi
echo "$!" >>/tmp/polybar.pids

View File

@@ -0,0 +1,18 @@
#!/bin/bash
#!/bin/bash
# Check if dunst is running
if pgrep -x "dunst" > /dev/null
then
is_paused=$(dunstctl is-paused)
if [[ $is_paused == 'false' ]]; then
status_icon=" on"
elif [[ $is_paused == 'true' ]]; then
status_icon=" off"
fi
else
status_icon=" off"
fi
echo $status_icon

View File

@@ -0,0 +1,20 @@
#!/bin/bash
#!/usr/bin/bash
mediaStatus=$(playerctl --player=playerctld metadata 2>&1)
if [[ "$mediaStatus" == "No player could handle this command" ]]; then
echo " N/A"
else
artist=$(playerctl --player=playerctld metadata --format '{{ artist }}')
title=$(playerctl --player=playerctld metadata --format '{{ title }}')
status=$(playerctl --player=playerctld metadata --format '{{ status }}')
if [[ $status == "Paused" ]]; then
status_icon=" "
elif [[ $status == "Playing" ]]; then
status_icon=" "
fi
echo "$status_icon $artist - $title"
fi

View File

@@ -0,0 +1,13 @@
#!/bin/bash
#!/bin/sh
if ! num_updates=$(paru -Qu 2>/dev/null | wc -l); then
# if ! updates_aur=$(yay -Qum 2>/dev/null | wc -l); then
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then
# if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
# if ! updates_aur=$(pikaur -Qua 2> /dev/null | wc -l); then
# if ! updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l); then
num_updates=0
fi
echo "$num_updates"

View File

@@ -1,31 +0,0 @@
Config { font = "xft:FiraCode Nerd Font Mono:weight=bold:pixelsize=12:antialias=true:hinting=true"
, additionalFonts = []
, borderColor = "black"
, border = TopB
, bgColor = "black"
, fgColor = "white"
, alpha = 255
, position = Top
, textOffset = -1
, iconOffset = -1
, lowerOnStart = True
, pickBroadest = False
, persistent = False
, hideOnStart = False
, iconRoot = "."
, allDesktops = True
, overrideRedirect = True
, commands = [ Run Weather "K7D2" ["-t","<station>: <tempF>F","-L","18","-H","25","--normal","green","--high","red","--low","lightblue"] 36000
, Run Network "wlp0s20f3" ["-L","0","-H","32","--normal","green","--high","red"] 10
, Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run Memory ["-t","Mem: <usedratio>%"] 10
, Run Swap [] 10
, Run Com "uname" ["-s","-r"] "" 36000
, Run Date "%a %b %_d %Y %H:%M:%S" "date" 10
, Run StdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = "%StdinReader% }\
\{ %cpu% | %memory% * %swap% | %wlp0s20f3% | <fc=#ee9a00>%date%</fc> | %uname%"
}

View File

@@ -6,9 +6,6 @@ import System.Exit
import qualified XMonad.StackSet as W
import qualified Data.Map as M
-- system
import System.IO (hPutStrLn)
-- util
import XMonad.Util.Run (safeSpawn, unsafeSpawn, runInTerm, spawnPipe)
import XMonad.Util.SpawnOnce
@@ -16,13 +13,14 @@ import XMonad.Util.EZConfig (additionalKeysP, additionalMouseBindings)
-- hooks
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks (avoidStruts, docksStartupHook, manageDocks, ToggleStruts(..))
import XMonad.Hooks.ManageDocks (docks, avoidStruts, docksStartupHook, manageDocks, ToggleStruts(..))
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageHelpers (isFullscreen, isDialog, doFullFloat, doCenterFloat, doRectFloat)
import XMonad.Hooks.Place (placeHook, withGaps, smart)
-- actions
import XMonad.Actions.CopyWindow
import XMonad.Actions.CycleWS
-- layout
import XMonad.Layout.NoBorders
@@ -57,8 +55,8 @@ myKeys =
++
[
-- dwm-like add/remove window to/from all workspaces
("M-S-C-a", windows copyToAll) -- copy window to all workspaces
, ("M-S-C-z", killAllOtherCopies) -- kill copies of window on other workspaces
("M-C-S-a", windows copyToAll) -- copy window to all workspaces
, ("M-C-S-z", killAllOtherCopies) -- kill copies of window on other workspaces
-- modify tiled window size
, ("M-a", sendMessage MirrorShrink) -- decrease vertical window size
@@ -71,16 +69,27 @@ myKeys =
, ("M-f", sendMessage $ JumpToLayout "Full")
, ("M-S-f", sequence_
[ withFocused $ windows . W.sink
, refresh
, sendMessage $ JumpToLayout "Full"])
, ("M-t", sendMessage $ JumpToLayout "Spacing ResizableTall")
, ("M-S-t", sequence_
[ withFocused $ windows . W.sink
, refresh
, sendMessage $ JumpToLayout "Spacing ResizableTall"])
, ("M-g", sendMessage $ JumpToLayout "Spacing Grid")
, ("M-S-g", sequence_
[ withFocused $ windows . W.sink
, refresh
, sendMessage $ JumpToLayout "Spacing Grid"])
-- cycle & move between screens
, ("M-,", prevScreen)
, ("M-S-,", shiftPrevScreen)
, ("M-C-S-,", swapPrevScreen)
, ("M-.", nextScreen)
, ("M-S-.", shiftNextScreen)
, ("M-C-S-.", swapNextScreen)
-- launch rofi
, ("M-p", spawn "rofi -show combi")
, ("M-c", spawn "rofi -show clipboard")
@@ -164,6 +173,8 @@ myManageHook = composeAll
myPlacement = withGaps (16,0,16,0) (smart (0.5,0.5))
myEventHook = ewmhDesktopsEventHook
myStartupHook = do
-- System Restore Processes
spawnOnce "/home/sravan/.screenlayout/default.sh &" -- restore default screen layout
@@ -171,7 +182,6 @@ myStartupHook = do
spawnOnce "numlockx on &" -- enable numlock
-- System Tray Applications
spawnOnce "volctl &" -- PulseAudio Volume Control
spawnOnce "nyrna &" -- Nyrna Application Suspend
spawnOnce "blueman-applet &" -- Blueman Bluetooth Manager
spawnOnce "nm-applet &" -- Network Manager Applet
@@ -189,10 +199,11 @@ myStartupHook = do
spawnOnce "light-locker --lock-on-suspend --lock-on-lid &" -- screen lock for lightdm
main = do
-- `xmobar -x 0` launches the bar on monitor 0
xmproc <- spawnPipe "xmobar -x 0 /home/sravan/.xmonad/xmobar.config"
-- launches xmobar as a dock
xmonad $ ewmh desktopConfig
-- launches polybar
spawn "/home/sravan/.xmonad/polybar/launch.sh &"
-- launches xmonad
xmonad $ docks $ ewmh desktopConfig
{ manageHook = manageDocks <+> myManageHook <+> placeHook myPlacement <+> manageHook desktopConfig
, startupHook = myStartupHook
, layoutHook = myLayout
@@ -201,24 +212,15 @@ main = do
, modMask = myModMask
, normalBorderColor = myNormalBorderColor
, focusedBorderColor = myFocusedBorderColor
, logHook = dynamicLogWithPP xmobarPP
{ ppOutput = \x -> hPutStrLn xmproc x
, ppCurrent = xmobarColor "green" "" . wrap "[" "]" -- current workspace in xmobar
, ppVisible = xmobarColor "cyan" "" -- visible but not current workspace
, ppHidden = xmobarColor "yellow" "" . wrap "+" "" -- hidden workspaces in xmobar
, ppHiddenNoWindows = xmobarColor "white" "" -- hidden workspaces (no windows)
, ppTitle = xmobarColor "purple" "" . shorten 80 -- title of active window in xmobar
, ppSep = " | " -- separators in xmobar
, ppUrgent = xmobarColor "red" "" . wrap "!" "!" -- urgent workspace
, ppOrder = \(ws:l:t:ex) -> [ws,l,t]
}
-- focusFollowsMouse = myFocusFollowsMouse,
-- clickJustFocuses = myClickJustFocuses,
-- workspaces = myWorkspaces,
-- keys = myKeys,
-- mouseBindings = myMouseBindings,
-- handleEventHook = myEventHook,
} `additionalKeysP` myKeys
, handleEventHook = myEventHook
, focusFollowsMouse = myFocusFollowsMouse
, clickJustFocuses = myClickJustFocuses
, workspaces = myWorkspaces
, mouseBindings = myMouseBindings
-- , logHook = myLogHook
-- , keys = myKeys
}
`additionalKeysP` myKeys
help :: String
help = unlines ["The default modifier key is 'alt'. Default keybindings:",