nix/wm: add polybar instead of xmobar

This commit is contained in:
Dmitriy Pleshevskiy 2022-08-24 23:54:30 +03:00
parent 3d941845b1
commit 60b7339ce2
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
9 changed files with 179 additions and 25 deletions

View file

@ -42,7 +42,10 @@ in
];
# window manager
wm.xmonad.enable = true;
wm = {
xmonad.enable = true;
bar.polybar.enable = true;
};
# shell
shell = {
@ -109,9 +112,9 @@ in
};
};
xsession.initExtra = "
xrandr --output HDMI-A-0 --rotate right --left-of DisplayPort-1
";
xsession.initExtra = ''
xrandr --output HDMI-A-0 --rotate right --left-of DisplayPort-1
'';
xdg = {
enable = true;

1
nix/wm/bar/default.nix Normal file
View file

@ -0,0 +1 @@
[ ./polybar ]

View file

@ -0,0 +1,109 @@
{ lib, config, pkgs, ...}:
with lib;
let
cfg = config.wm.bar.polybar;
colors = {
orange = "#ee9a00";
};
in
{
options.wm.bar.polybar = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable polybar status bar";
};
};
config = mkIf cfg.enable {
services.polybar = {
enable = true;
script = "polybar &";
settings = {
"bar/main" = {
monitor = "DisplayPort-1";
width = "100%";
height = "16px";
font = [
"Fira Code:size=9:antialias=true"
"Fira Code:bold:size=0:antialias=true"
];
radius = 0;
modules = {
left = "xmonad";
center = "date wifi";
right = "lang time";
};
};
"module/date" = {
type = "internal/date";
interval = 10;
date = "%a %d %b %Y";
label = "%date%";
format.padding = 1;
};
"module/time" = {
type = "internal/date";
time = "%H:%M:%S";
label = {
text = "%time%";
font = 2;
foreground = colors.orange;
};
};
"module/lang" = {
type = "internal/xkeyboard";
format = {
text = "<label-layout>";
padding = 1;
};
};
# TODO: fix amixer
"module/volume" = {
type = "custom/script";
exec = "~/scripts/get_volume.sh";
interval = 1;
format = {
prefix = "Vol: ";
padding = 1;
};
};
"module/wifi" = {
type = "internal/network";
interval = 3;
interface = {
text = "wlxd03745e1e87b";
type = "wireless";
};
label.connected = "%essid% %signal%";
format.connected = {
prefix = "| ";
suffix = "%";
};
};
"module/xmonad" = mkIf config.wm.xmonad.enable {
type = "custom/script";
exec = "${pkgs.xmonad-log}/bin/xmonad-log";
tail = true;
};
"global/wm" = {
margin = {
bottom = 0;
top = 0;
};
};
};
};
};
}

View file

@ -1,3 +1 @@
[
./xmonad
]
[ ./xmonad ] ++ (import ./bar)

View file

@ -29,6 +29,11 @@ import XMonad.Util.Run
import qualified Data.Map as M
import qualified XMonad.StackSet as W
-- Imports for Polybar
import qualified Codec.Binary.UTF8.String as UTF8
import qualified DBus as D
import qualified DBus.Client as D
-- The preferred terminal program, which is used in a binding below and by
-- certain contrib modules.
--
@ -62,27 +67,19 @@ myModMask = mod1Mask
--
-- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
--
myWorkspaces = ["1:web", "2:code", "3:code", "4:code"] <> map show [5..6] <> ["7:fin", "8:cfg", "9:chat"]
myWorkspaces = ["web", "dev", "dev2", "dev3", "fin", "sys", "com"]
-- Border colors for unfocused and focused windows, respectively.
--
myNormalBorderColor = "#444"
myFocusedBorderColor = "#f00"
------------------------------------------------------------------------
-- Now run xmonad with all the defaults we set up.
main :: IO ()
main = mkDbusClient >>= main'
-- Run xmonad with the settings you specify. No need to modify this.
--
main = xmonad . ewmhFullscreen . ewmh . xmobarProp $ defaults
-- A structure containing your configuration settings, overriding
-- fields in the default config. Any you don't override, will
-- use the defaults defined in xmonad/XMonad/Config.hs
--
-- No need to modify this.
--
defaults = def
main' :: D.Client -> IO ()
main' dbus = xmonad . docks . ewmhFullscreen . ewmh $ def
-- simple stuff
{ terminal = myTerminal
, focusFollowsMouse = myFocusFollowsMouse
@ -99,10 +96,52 @@ defaults = def
, layoutHook = myLayout
, manageHook = myManageHook
, handleEventHook = myEventHook
, logHook = myLogHook
, logHook = myPolybarLogHook dbus
, startupHook = myStartupHook
}
------------------------------------------------------------------------
-- Polybar settings (needs DBus client).
--
mkDbusClient :: IO D.Client
mkDbusClient = do
dbus <- D.connectSession
D.requestName dbus (D.busName_ "org.xmonad.log") opts
return dbus
where
opts = [D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]
-- Emit a DBus signal on log updates
dbusOutput :: D.Client -> String -> IO ()
dbusOutput dbus str =
let opath = D.objectPath_ "/org/xmonad/Log"
iname = D.interfaceName_ "org.xmonad.Log"
mname = D.memberName_ "Update"
signal = D.signal opath iname mname
body = [D.toVariant $ UTF8.decodeString str]
in D.emit dbus $ signal { D.signalBody = body }
polybarHook :: D.Client -> PP
polybarHook dbus =
let wrapper c = wrap ("%{F" <> c <> "}") "%{F-}"
blue = "#2E9AFE"
gray = "#7F7F7F"
orange = "#ea4300"
purple = "#9058c7"
red = "#722222"
in def { ppOutput = dbusOutput dbus
, ppCurrent = wrapper blue
, ppVisible = wrapper purple
, ppUrgent = wrapper orange
, ppHidden = wrapper gray
, ppHiddenNoWindows = wrapper red
, ppTitle = wrapper purple . shorten 90
}
myPolybarLogHook dbus = myLogHook <+> dynamicLogWithPP (polybarHook dbus)
------------------------------------------------------------------------
-- Layouts:
@ -175,8 +214,8 @@ myManageHook = composeAll
, className =? "Gnome-calculator" --> doFloat
, className =? "Gnome-font-viewer" --> doFloat
, className =? "Org.gnome.Nautilus" --> doFloat
, resource =? "telegram-desktop" --> doShift "9:chat"
, className =? "Thunderbird" --> doShift "9:chat"
, resource =? "telegram-desktop" --> doShift "com"
, className =? "Thunderbird" --> doShift "com"
-- my libs
, resource =? "hwt" --> doFloat
]

View file

@ -28,6 +28,10 @@ in
enable = true;
enableContribAndExtras = true;
config = ./config.hs;
extraPackages = mkIf config.wm.bar.polybar.enable (hp: [
hp.dbus
hp.monad-logger
]);
};
};
};

View file

@ -83,8 +83,8 @@ myCommands =
, "--normal" , colorYellow
]
(10 `seconds`)
, Run $ ComX "/bin/bash" ["-c", "~/.config/xmobar/scripts/get_volume.sh"] "N/A" "volume" 3
, Run $ ComX "/bin/bash" ["-c", "~/.config/xmobar/scripts/exchangerate.sh"] "N/A" "usdrub" (60 `seconds`)
, Run $ ComX "/bin/bash" ["-c", "~/scripts/get_volume.sh"] "N/A" "volume" 3
, Run $ ComX "/bin/bash" ["-c", "~/scripts/exchangerate.sh"] "N/A" "usdrub" (60 `seconds`)
, Run XMonadLog
]
where