Commit 94a7fbc2 authored by epsi sayidina's avatar epsi sayidina

herbstluftwm tags with lemonbar

parent feae0ccf
......@@ -44,7 +44,7 @@ function get_statusbar_text() {
done
# draw window title
output_leftside_top
output_by_title
text+=$buffer
buffer=$text
......@@ -99,7 +99,7 @@ function output_by_tag() {
buffer="$text_pre$text_name$text_post"
}
function output_leftside_top() {
function output_by_title() {
local text=" ^r(5x0) $separator ^r(5x0) "
text+="$segment_windowtitle"
buffer=$text
......
......@@ -7,8 +7,6 @@ module MyOutput
import Data.IORef
import System.IO.Unsafe
import qualified Data.Text as T
import System.Process
import System.IO
......@@ -59,7 +57,7 @@ getStatusbarText :: Int -> IO String
getStatusbarText monitor = do
tags <- readIORef tagsStatus
let tagText = join $ map (outputByTag monitor) tags
let titleText = outputLeftsideTop
let titleText = outputByTitle
let text = (tagText ++) <$> titleText
text
......@@ -107,8 +105,8 @@ outputByTag monitor tagStatus = textPre ++ textName ++ textPost
++ rightHardArrow
else ""
outputLeftsideTop :: IO String
outputLeftsideTop = do
outputByTitle :: IO String
outputByTitle = do
segment <- readIORef segmentWindowtitle
let text = " ^r(5x0) " ++ separator ++ " ^r(5x0) " ++ segment
......@@ -135,5 +133,6 @@ setTagValue monitor = do
setWindowtitle :: String -> IO ()
setWindowtitle windowtitle = do
let icon = preIcon ++ "\61444" ++ postIcon
let text = " " ++ icon ++ " ^bg()^fg(" ++ myColor "grey700" ++ ") " ++ windowtitle
let text = " " ++ icon ++ " ^bg()"
++ "^fg(" ++ myColor "grey700" ++ ") " ++ windowtitle
writeIORef segmentWindowtitle text
......@@ -46,7 +46,7 @@ function _M.get_statusbar_text(monitor)
end
-- draw window title
text = text .. _M.output_leftside_top()
text = text .. _M.output_by_title()
return text
end
......@@ -105,7 +105,7 @@ function _M.output_by_tag(monitor, tag_status)
return text_pre .. text_name .. text_post
end
function _M.output_leftside_top()
function _M.output_by_title()
local text = ' ^r(5x0) ' .. _M.separator .. ' ^r(5x0) '
.. _M.segment_windowtitle
......
......@@ -50,7 +50,7 @@ sub get_statusbar_text {
}
# draw window title
$text .= output_leftside_top();
$text .= output_by_title();
return $text;
}
......@@ -101,7 +101,7 @@ sub output_by_tag {
return $text_pre . $text_name . $text_post;
}
sub output_leftside_top {
sub output_by_title {
my $text = " ^r(5x0) $separator ^r(5x0) ";
$text .= $segment_windowtitle;
......
......@@ -44,7 +44,7 @@ function get_statusbar_text($monitor)
}
// draw window title
$text .= output_leftside_top();
$text .= output_by_title();
return $text;
}
......@@ -102,7 +102,7 @@ function output_by_tag($monitor, $tag_status)
return $text_pre . $text_name . $text_post;
}
function output_leftside_top()
function output_by_title()
{
global $separator;
global $segment_windowtitle;
......
......@@ -42,7 +42,7 @@ def get_statusbar_text(monitor):
text += output_by_tag(monitor, tag_status)
# draw window title
text += output_leftside_top()
text += output_by_title()
return text
......@@ -58,8 +58,9 @@ def output_by_tag(monitor, tag_status):
if tag_mark == '#':
text_pre = '^bg(' + color['blue500'] + ')' \
'^fg(' + color['black'] + ')' + right_hard_arrow + \
'^bg(' + color['blue500'] + ')' \
'^fg(' + color['black'] + ')' \
+ right_hard_arrow \
+ '^bg(' + color['blue500'] + ')' \
'^fg(' + color['white'] + ')'
elif tag_mark == '+':
text_pre = '^bg(' + color['yellow500'] + ')' \
......@@ -91,7 +92,7 @@ def output_by_tag(monitor, tag_status):
return (text_pre + text_name + text_post)
def output_leftside_top():
def output_by_title():
text = ' ^r(5x0) ' + separator + ' ^r(5x0) '
text += segment_windowtitle
......
......@@ -41,7 +41,7 @@ def get_statusbar_text(monitor)
text << output_by_tag(monitor, tag_status) }
# draw window title
text << output_leftside_top()
text << output_by_title()
end
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
......@@ -88,7 +88,7 @@ def output_by_tag(monitor, tag_status)
text_pre + text_name + text_post
end
def output_leftside_top()
def output_by_title()
text = " ^r(5x0) #{@separator} ^r(5x0) "
text << @segment_windowtitle
end
......
......@@ -61,7 +61,7 @@ function get_lemon_parameters() {
get_top_panel_geometry $panel_height "${geometry[@]}"
# geometry: -g widthxheight+x+y
g_res="${width}x${height}+${xpos}+${ypos}"
geom_res="${width}x${height}+${xpos}+${ypos}"
# color, with transparency
local bgcolor="#aa000000"
......@@ -74,7 +74,7 @@ function get_lemon_parameters() {
local font_awesome="FontAwesome-9"
# finally
lemon_parameters=" -g $g_res -u 2"
lemon_parameters=" -g $geom_res -u 2"
lemon_parameters+=" -B $bgcolor -F $fgcolor"
lemon_parameters+=" -f $font_takaop -f $font_awesome -f $font_symbol"
}
......@@ -43,7 +43,7 @@ function get_statusbar_text() {
# draw window title
text+='%{r}'
output_leftside_top
output_by_title
text+=$buffer
buffer=$text
......@@ -82,9 +82,14 @@ function output_by_tag() {
esac
# ----- tag by number
# clickable tags
local text_name=''
text_name+="%{A:herbstclient focus_monitor \"$monitor\" && "
text_name+="herbstclient use \"$tag_index\":} $tag_name %{A} "
# non clickable tags
local text_name=" $tag_name "
# local text_name=" $tag_name "
# ----- post tag
......@@ -94,12 +99,13 @@ function output_by_tag() {
text_post+="%{B-}%{F${color['blue500']}}"
text_post+="%{U${color['red500']}}%{+u}${right_hard_arrow}";
fi
text_post+='%{B-}%{F-}%{-u}'
text_clear='%{B-}%{F-}%{-u}'
buffer="$text_pre$text_name$text_post"
buffer="$text_pre$text_name$text_post$text_clear"
}
function output_leftside_top() {
function output_by_title() {
local text="$segment_windowtitle $separator "
buffer=$text
}
......
#!/usr/bin/env bash
# This is a modularized config for herbstluftwm tags in dzen2 statusbar
# This is a modularized config for herbstluftwm tags in lemonbar
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# libraries
......
......@@ -67,7 +67,7 @@ function run_lemon() {
{
init_content $monitor
walk_content $monitor # loop for each event
} | $command_out
} | $command_out | sh
}
......
module MyGMC (myColor, colorSchemes) where
-- colorschemes
import Data.Map as M
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- google material colors
-- https://material.io/guidelines/style/color.html
-- Color names are easier to remember:
-- Signature/ Declaration of Associative Array/ Hash/ Dictionary/ Map
colorSchemes :: [(String, String)]
colorSchemes =
[("white", "#ffffff")
,("black", "#000000")
,("grey50", "#fafafa")
,("grey100", "#f5f5f5")
,("grey200", "#eeeeee")
,("grey300", "#e0e0e0")
,("grey400", "#bdbdbd")
,("grey500", "#9e9e9e")
,("grey600", "#757575")
,("grey700", "#616161")
,("grey800", "#424242")
,("grey900", "#212121")
,("red50", "#ffebee")
,("red100", "#ffcdd2")
,("red200", "#ef9a9a")
,("red300", "#e57373")
,("red400", "#ef5350")
,("red500", "#f44336")
,("red600", "#e53935")
,("red700", "#d32f2f")
,("red800", "#c62828")
,("red900", "#b71c1c")
,("redA100", "#ff8a80")
,("redA200", "#ff5252")
,("redA400", "#ff1744")
,("redA700", "#d50000")
,("pink50", "#fce4ec")
,("pink100", "#f8bbd0")
,("pink200", "#f48fb1")
,("pink300", "#f06292")
,("pink400", "#ec407a")
,("pink500", "#e91e63")
,("pink600", "#d81b60")
,("pink700", "#c2185b")
,("pink800", "#ad1457")
,("pink900", "#880e4f")
,("pinkA100", "#ff80ab")
,("pinkA200", "#ff4081")
,("pinkA400", "#f50057")
,("pinkA700", "#c51162")
,("blue50", "#e3f2fd")
,("blue100", "#bbdefb")
,("blue200", "#90caf9")
,("blue300", "#64b5f6")
,("blue400", "#42a5f5")
,("blue500", "#2196f3")
,("blue600", "#1e88e5")
,("blue700", "#1976d2")
,("blue800", "#1565c0")
,("blue900", "#0d47a1")
,("blueA100", "#82b1ff")
,("blueA200", "#448aff")
,("blueA400", "#2979ff")
,("blueA700", "#2962ff")
,("yellow50", "#fffde7")
,("yellow100", "#fff9c4")
,("yellow200", "#fff59d")
,("yellow300", "#fff176")
,("yellow400", "#ffee58")
,("yellow500", "#ffeb3b")
,("yellow600", "#fdd835")
,("yellow700", "#fbc02d")
,("yellow800", "#f9a825")
,("yellow900", "#f57f17")
,("yellowA100", "#ffff8d")
,("yellowA200", "#ffff00")
,("yellowA400", "#ffea00")
,("yellowA700", "#ffd600")
,("teal50", "#e0f2f1")
,("teal100", "#b2dfdb")
,("teal200", "#80cbc4")
,("teal300", "#4db6ac")
,("teal400", "#26a69a")
,("teal500", "#009688")
,("teal600", "#00897b")
,("teal700", "#00796b")
,("teal800", "#00695c")
,("teal900", "#004d40")
,("tealA100", "#a7ffeb")
,("tealA200", "#64ffda")
,("tealA400", "#1de9b6")
,("tealA700", "#00bfa5")
,("green50", "#e8f5e9")
,("green100", "#c8e6c9")
,("green200", "#a5d6a7")
,("green300", "#81c784")
,("green400", "#66bb6a")
,("green500", "#4caf50")
,("green600", "#43a047")
,("green700", "#388e3c")
,("green800", "#2e7d32")
,("green900", "#1b5e20")
,("greenA100", "#b9f6ca")
,("greenA200", "#69f0ae")
,("greenA400", "#00e676")
,("greenA700", "#00c853")
,("orange50", "#fff3e0")
,("orange100", "#ffe0b2")
,("orange200", "#ffcc80")
,("orange300", "#ffb74d")
,("orange400", "#ffa726")
,("orange500", "#ff9800")
,("orange600", "#fb8c00")
,("orange700", "#f57c00")
,("orange800", "#ef6c00")
,("orange900", "#e65100")
,("orangeA100", "#ffd180")
,("orangeA200", "#ffab40")
,("orangeA400", "#ff9100")
,("orangeA700", "#ff6d00")
,("deepOrange50", "#fbe9e7")
,("deepOrange100", "#ffccbc")
,("deepOrange200", "#ffab91")
,("deepOrange300", "#ff8a65")
,("deepOrange400", "#ff7043")
,("deepOrange500", "#ff5722")
,("deepOrange600", "#f4511e")
,("deepOrange700", "#e64a19")
,("deepOrange800", "#d84315")
,("deepOrange900", "#bf360c")
,("deepOrangeA100", "#ff9e80")
,("deepOrangeA200", "#ff6e40")
,("deepOrangeA400", "#ff3d00")
,("deepOrangeA700", "#dd2c00")
]
myColor :: String -> String
myColor key = M.findWithDefault "#ffffff" key (fromList colorSchemes)
module MyHelper
( getMonitor
, getGeometry
, getLemonParameters
) where
import System.Process
import System.IO
import System.Exit
import Control.Monad
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- helpers
getMonitor :: [String] -> Int
getMonitor args
| length(args) > 0 = read (args !! 0) :: Int
| otherwise = 0
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- geometry calculation
getGeometry :: Int -> IO [Int]
getGeometry monitor = do
let args = ["monitor_rect", show(monitor)]
(_, Just pipe_out, _, ph) <-
createProcess (proc "herbstclient" args)
{ std_out = CreatePipe }
raw <- hGetContents pipe_out
_ <- waitForProcess ph
when (raw == "") $ do
putStrLn $ "Invalid monitor " ++ show(monitor)
exitSuccess
let geometry = map (read::String->Int) (words raw)
return geometry
-- geometry has the format X Y W H
data XYWH = XYWH String String String String
getTopPanelGeometry :: Int -> [Int] -> XYWH
getTopPanelGeometry
height geometry = XYWH
(show (geometry !! 0))
(show (geometry !! 1))
(show (geometry !! 2))
(show height)
getBottomPanelGeometry :: Int -> [Int] -> XYWH
getBottomPanelGeometry
height geometry = XYWH
(show (geometry !! 0))
(show ((geometry !! 3) - height))
(show (geometry !! 2))
(show height)
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- lemonbar Parameters
getLemonParameters :: Int -> [Int] -> [String]
getLemonParameters
panelHeight geometry = [
"-g", geom_res, "-u", "2",
"-B", bgcolor, "-F", fgcolor,
"-f", font_takaop,
"-f", font_awesome,
"-f", font_symbol
]
where
-- calculate geometry
XYWH xpos ypos width height = getTopPanelGeometry
panelHeight geometry
-- geometry: -g widthxheight++y
geom_res = width ++ "x" ++ height
++ "+" ++ xpos ++ "+" ++ xpos
-- color, with transparency
bgcolor = "#aa000000"
fgcolor = "#ffffff"
-- XFT: require lemonbar_xft_git
font_takaop = "takaopgothic-9"
font_bottom = "monospace-9"
font_symbol = "PowerlineSymbols-11"
font_awesome = "FontAwesome-9"
module MyOutput
( setWindowtitle
, setTagValue
, getStatusbarText
) where
import Data.IORef
import System.IO.Unsafe
import System.Process
import System.IO
import Control.Monad
import MyGMC
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- initialize
-- custom tag names
tagShows :: [String]
tagShows = ["一 ichi", "二 ni", "三 san", "四 shi",
"五 go", "六 roku", "七 shichi", "八 hachi", "九 kyū", "十 jū"]
-- initialize variable segment
-- simulate global variable using unsafe
segmentWindowtitle :: IORef String
segmentWindowtitle = unsafePerformIO $ newIORef ""
tagsStatus :: IORef [String]
tagsStatus = unsafePerformIO $ newIORef []
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- decoration
separator = "%{B-}%{F" ++ myColor "yellow500" ++ "}|%{B-}%{F-}"
-- Powerline Symbol
rightHardArrow = "\57520"
rightSoftArrow = "\57521"
leftHardArrow = "\57522"
leftSoftArrow = "\57523"
-- theme
preIcon = "%{F" ++ myColor "yellow500" ++ "}"
postIcon = "%{F-}"
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- main
getStatusbarText :: Int -> IO String
getStatusbarText monitor = do
tags <- readIORef tagsStatus
let tagText = "%{l}" ++ (join $ map (outputByTag monitor) tags)
let titleText = ("%{r}" ++) <$> outputByTitle
let text = (tagText ++) <$> titleText
text
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- each segments
outputByTag :: Int -> String -> String
outputByTag monitor tagStatus =
textPre ++ textName ++ textPost ++ textClear
where
-- text = ''
tagIndex = drop 1 tagStatus
tagMark = take 1 tagStatus
index = (read::String->Int) tagIndex - 1 -- zero based
tagName = tagShows !! index
----- pre tag
textPre = case tagMark of
"#" -> "%{B" ++ myColor "blue500" ++ "}"
++ "%{F" ++ myColor "black" ++ "}"
++ "%{U" ++ myColor "white" ++ "}%{+u}"
++ rightHardArrow
++ "%{B" ++ myColor "blue500" ++ "}"
++ "%{F" ++ myColor "white" ++ "}"
++ "%{U" ++ myColor "white" ++ "}%{+u}"
"+" -> "%{B" ++ myColor "yellow500" ++ "}"
++ "%{F" ++ myColor "grey400" ++ "}"
":" -> "%{B-}"
++"%{F" ++ myColor "white" ++ "}"
++ "%{U" ++ myColor "red500" ++ "}%{+u}"
"!" -> "%{B" ++ myColor "red500" ++ "}"
++ "%{F" ++ myColor "white" ++ "}"
++ "%{U" ++ myColor "white" ++ "}%{+u}"
_ -> "%{B-}"
++ "%{F" ++ myColor "grey600" ++ "}%{-u}"
----- tag by number
-- non clickable tags
textName = " " ++ tagName ++ " "
----- post tag
textPost = if (tagMark == "#")
then "%{B-}"
++ "%{F" ++ myColor "blue500" ++ "}"
++ "%{U" ++ myColor "red500" ++ "}%{+u}"
++ rightHardArrow
else ""
textClear = "%{B-}%{F-}%{-u}"
outputByTitle :: IO String
outputByTitle = do
segment <- readIORef segmentWindowtitle
let text = segment ++ " " ++ separator ++ " "
return text
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- setting variables, response to event handler
--import Data.IORef
setTagValue :: Int -> IO ()
setTagValue monitor = do
let args = ["tag_status", show(monitor)]
(_, Just pipe_out, _, ph) <-
createProcess (proc "herbstclient" args)
{ std_out = CreatePipe }
raw <- hGetContents pipe_out
_ <- waitForProcess ph
let statusList = words raw
writeIORef tagsStatus statusList
setWindowtitle :: String -> IO ()
setWindowtitle windowtitle = do
let icon = preIcon ++ "\61444" ++ postIcon
let text = " " ++ icon ++ " %{B-}"
++ "%{F" ++ myColor "grey700" ++ "} " ++ windowtitle
writeIORef segmentWindowtitle text
module MyPipeHandler
( detachLemon
) where
import System.Process
import System.Posix.Types
import System.Exit
import GHC.IO.Handle
import System.IO
import System.Posix.Process
import Control.Concurrent
import Control.Monad
-- cabal install split
import Data.List.Split
import MyOutput
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- helper
wSleep :: Int -> IO ()
wSleep mySecond = threadDelay (1000000 * mySecond)
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- pipe
handleCommandEvent :: Int -> String -> IO ()
handleCommandEvent monitor event
| origin == "reload" = do system("pkill lemonbar"); return ()
| origin == "quit_panel" = do exitSuccess; return ()
| elem origin tagCmds = do setTagValue monitor