Commit ae1fb7bc authored by epsi sayidina's avatar epsi sayidina

herbstluftwm idle event

parent 518c4b9e
#!/usr/bin/env bash
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# pipe
function content_init() {
monitor=$1
# initialize statusbar before loop
set_tag_value $monitor
set_windowtitle ''
get_statusbar_text $monitor
echo $buffer
}
function run_dzen2() {
monitor=$1
shift
parameters=$@
command_out="dzen2 $parameters -p"
{
content_init $monitor
} | $command_out
}
function detach_dzen2() {
monitor=$1
shift
parameters=$@
run_dzen2 $monitor $parameters &
}
function detach_transset() {
{
sleep 1
exec `(transset .8 -n dzentop >/dev/null)`
} &
}
......@@ -31,7 +31,7 @@ function handle_command_event() {
esac
}
function init_content() {
function content_init() {
monitor=$1
# initialize statusbar before loop
......@@ -42,7 +42,7 @@ function init_content() {
echo $buffer
}
function walk_content() {
function content_walk() {
monitor=$1
# start a pipe
......@@ -65,10 +65,9 @@ function run_dzen2() {
command_out="dzen2 $parameters"
{
init_content $monitor
walk_content $monitor # loop for each event
content_init $monitor
content_walk $monitor # loop for each event
} | $command_out
}
function detach_dzen2() {
......
......@@ -31,7 +31,7 @@ function handle_command_event() {
esac
}
function init_content() {
function content_init() {
monitor=$1
# initialize statusbar before loop
......@@ -42,7 +42,7 @@ function init_content() {
echo $buffer
}
function walk_content() {
function content_walk() {
monitor=$1
# start a pipe
......@@ -65,10 +65,9 @@ function run_dzen2() {
command_out="dzen2 $parameters"
{
init_content $monitor
walk_content $monitor # loop for each event
content_init $monitor
content_walk $monitor # loop for each event
} | $command_out
}
function detach_dzen2() {
......
module MyPipeHandler
( detachDzen2
, detachTransset
) 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
-- for use with transset
wSleep :: Int -> IO ()
wSleep mySecond = threadDelay (1000000 * mySecond)
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- pipe
contentInit :: Int -> Handle -> IO ()
contentInit monitor pipe_dzen2_in = do
-- initialize statusbar before loop
setTagValue monitor
setWindowtitle ""
text <- getStatusbarText monitor
hPutStrLn pipe_dzen2_in text
hFlush pipe_dzen2_in
runDzen2 :: Int -> [String] -> IO ()
runDzen2 monitor parameters = do
let command_out = "dzen2"
(Just pipe_dzen2_in, _, _, ph) <-
createProcess (proc command_out (parameters ++ ["-p"]))
{ std_in = CreatePipe }
contentInit monitor pipe_dzen2_in
hClose pipe_dzen2_in
detachDzen2 :: Int -> [String] -> IO ProcessID
detachDzen2 monitor parameters = forkProcess
$ runDzen2 monitor parameters
detachTransset :: IO ProcessID
detachTransset = forkProcess $ do
wSleep 1
system "transset .8 -n dzentop >/dev/null"
return ()
......@@ -20,10 +20,10 @@ import Data.List.Split
import MyOutput
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- helper
-- for use with transset
wSleep :: Int -> IO ()
wSleep mySecond = threadDelay (1000000 * mySecond)
......@@ -44,49 +44,49 @@ handleCommandEvent monitor event
column = splitOn "\t" event
origin = column !! 0
initContent :: Int -> Handle -> IO ()
initContent monitor pipe_in = do
contentInit :: Int -> Handle -> IO ()
contentInit monitor pipe_dzen2_in = do
-- initialize statusbar before loop
setTagValue monitor
setWindowtitle ""
text <- getStatusbarText monitor
hPutStrLn pipe_in text
hFlush pipe_in
hPutStrLn pipe_dzen2_in text
hFlush pipe_dzen2_in
walkContent :: Int -> Handle -> IO ()
walkContent monitor pipe_in = do
contentWalk :: Int -> Handle -> IO ()
contentWalk monitor pipe_dzen2_in = do
let command_in = "herbstclient"
(_, Just pipe_out, _, ph) <-
(_, Just pipe_idle_out, _, ph) <-
createProcess (proc command_in ["--idle"])
{ std_out = CreatePipe }
forever $ do
-- wait for next event
event <- hGetLine pipe_out
event <- hGetLine pipe_idle_out
handleCommandEvent monitor event
text <- getStatusbarText monitor
hPutStrLn pipe_in text
hFlush pipe_in
hPutStrLn pipe_dzen2_in text
hFlush pipe_dzen2_in
hClose pipe_out
hClose pipe_idle_out
runDzen2 :: Int -> [String] -> IO ()
runDzen2 monitor parameters = do
let command_out = "dzen2"
(Just pipe_in, _, _, ph) <-
(Just pipe_dzen2_in, _, _, ph) <-
createProcess (proc command_out parameters)
{ std_in = CreatePipe }
initContent monitor pipe_in
walkContent monitor pipe_in -- loop for each event
contentInit monitor pipe_dzen2_in
contentWalk monitor pipe_dzen2_in -- loop for each event
hClose pipe_in
hClose pipe_dzen2_in
detachDzen2 :: Int -> [String] -> IO ProcessID
detachDzen2 monitor parameters = forkProcess
......
......@@ -20,10 +20,10 @@ import Data.List.Split
import MyOutput
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- helper
-- for use with transset
wSleep :: Int -> IO ()
wSleep mySecond = threadDelay (1000000 * mySecond)
......@@ -44,49 +44,49 @@ handleCommandEvent monitor event
column = splitOn "\t" event
origin = column !! 0
initContent :: Int -> Handle -> IO ()
initContent monitor pipe_in = do
contentInit :: Int -> Handle -> IO ()
contentInit monitor pipe_dzen2_in = do
-- initialize statusbar before loop
setTagValue monitor
setWindowtitle ""
text <- getStatusbarText monitor
hPutStrLn pipe_in text
hFlush pipe_in
hPutStrLn pipe_dzen2_in text
hFlush pipe_dzen2_in
walkContent :: Int -> Handle -> IO ()
walkContent monitor pipe_in = do
contentWalk :: Int -> Handle -> IO ()
contentWalk monitor pipe_dzen2_in = do
let command_in = "herbstclient"
(_, Just pipe_out, _, ph) <-
(_, Just pipe_idle_out, _, ph) <-
createProcess (proc command_in ["--idle"])
{ std_out = CreatePipe }
forever $ do
-- wait for next event
event <- hGetLine pipe_out
event <- hGetLine pipe_idle_out
handleCommandEvent monitor event
text <- getStatusbarText monitor
hPutStrLn pipe_in text
hFlush pipe_in
hPutStrLn pipe_dzen2_in text
hFlush pipe_dzen2_in
hClose pipe_out
hClose pipe_idle_out
runDzen2 :: Int -> [String] -> IO ()
runDzen2 monitor parameters = do
let command_out = "dzen2"
(Just pipe_in, _, _, ph) <-
(Just pipe_dzen2_in, _, _, ph) <-
createProcess (proc command_out parameters)
{ std_in = CreatePipe }
initContent monitor pipe_in
walkContent monitor pipe_in -- loop for each event
contentInit monitor pipe_dzen2_in
contentWalk monitor pipe_dzen2_in -- loop for each event
hClose pipe_in
hClose pipe_dzen2_in
detachDzen2 :: Int -> [String] -> IO ProcessID
detachDzen2 monitor parameters = forkProcess
......
-- luaposix available in AUR
local posix = require "posix"
local common = require('.common')
local helper = require('.helper')
local output = require('.output')
local _M = {}
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- pipe
function _M.content_init(monitor, pipe_dzen2_out)
-- initialize statusbar before loop
output.set_tag_value(monitor)
output.set_windowtitle('')
local text = output.get_statusbar_text(monitor)
pipe_dzen2_out:write(text .. "\n")
pipe_dzen2_out:flush()
end
function _M.run_dzen2(monitor, parameters)
local command_out = 'dzen2 ' .. parameters .. ' -p'
local pipe_dzen2_out = assert(io.popen(command_out, 'w'))
_M.content_init(monitor, pipe_dzen2_out)
pipe_dzen2_out:close()
end
function _M.detach_dzen2(monitor, parameters)
local pid = posix.fork()
if pid == 0 then -- this is the child process
_M.run_dzen2(monitor, parameters)
else -- this is the parent process
-- nothing
end
end
function _M.detach_transset()
local pid = posix.fork()
if pid == 0 then -- this is the child process
common.sleep(1)
os.execute('transset .8 -n dzentop >/dev/null')
else -- this is the parent process
-- nothing
end
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- return
return _M
......@@ -29,42 +29,42 @@ function _M.handle_command_event(monitor, event)
end
end
function _M.init_content(monitor, process)
function _M.content_init(monitor, pipe_dzen2_out)
-- initialize statusbar before loop
output.set_tag_value(monitor)
output.set_windowtitle('')
local text = output.get_statusbar_text(monitor)
process:write(text .. "\n")
process:flush()
pipe_dzen2_out:write(text .. "\n")
pipe_dzen2_out:flush()
end
function _M.walk_content(monitor, process)
function _M.content_walk(monitor, pipe_dzen2_out)
-- start a pipe
command_in = 'herbstclient --idle'
local pipe_in = assert(io.popen(command_in, 'r'))
local pipe_idle_in = assert(io.popen(command_in, 'r'))
local text = ''
-- wait for each event
for event in pipe_in:lines() do
for event in pipe_idle_in:lines() do
_M.handle_command_event(monitor, event)
text = output.get_statusbar_text(monitor)
process:write(text .. "\n")
process:flush()
pipe_dzen2_out:write(text .. "\n")
pipe_dzen2_out:flush()
end -- for loop
pipein:close()
pipe_idle_in:close()
end
function _M.run_dzen2(monitor, parameters)
local command_out = 'dzen2 ' .. parameters
local pipe_out = assert(io.popen(command_out, 'w'))
local command_out = 'dzen2 ' .. parameters
local pipe_dzen2_out = assert(io.popen(command_out, 'w'))
_M.init_content(monitor, pipe_out)
_M.walk_content(monitor, pipe_out) -- loop for each event
_M.content_init(monitor, pipe_dzen2_out)
_M.content_walk(monitor, pipe_dzen2_out) -- loop for each event
pipe_out:close()
pipe_dzen2_out:close()
end
function _M.detach_dzen2(monitor, parameters)
......
......@@ -29,42 +29,42 @@ function _M.handle_command_event(monitor, event)
end
end
function _M.init_content(monitor, process)
function _M.content_init(monitor, pipe_dzen2_out)
-- initialize statusbar before loop
output.set_tag_value(monitor)
output.set_windowtitle('')
local text = output.get_statusbar_text(monitor)
process:write(text .. "\n")
process:flush()
pipe_dzen2_out:write(text .. "\n")
pipe_dzen2_out:flush()
end
function _M.walk_content(monitor, process)
function _M.content_walk(monitor, pipe_dzen2_out)
-- start a pipe
command_in = 'herbstclient --idle'
local pipe_in = assert(io.popen(command_in, 'r'))
local pipe_idle_in = assert(io.popen(command_in, 'r'))
local text = ''
-- wait for each event
for event in pipe_in:lines() do
for event in pipe_idle_in:lines() do
_M.handle_command_event(monitor, event)
text = output.get_statusbar_text(monitor)
process:write(text .. "\n")
process:flush()
pipe_dzen2_out:write(text .. "\n")
pipe_dzen2_out:flush()
end -- for loop
pipein:close()
pipe_idle_in:close()
end
function _M.run_dzen2(monitor, parameters)
local command_out = 'dzen2 ' .. parameters
local pipe_out = assert(io.popen(command_out, 'w'))
local command_out = 'dzen2 ' .. parameters
local pipe_dzen2_out = assert(io.popen(command_out, 'w'))
_M.init_content(monitor, pipe_out)
_M.walk_content(monitor, pipe_out) -- loop for each event
_M.content_init(monitor, pipe_dzen2_out)
_M.content_walk(monitor, pipe_dzen2_out) -- loop for each event
pipe_out:close()
pipe_dzen2_out:close()
end
function _M.detach_dzen2(monitor, parameters)
......
......@@ -3,6 +3,8 @@ package output;
use warnings;
use strict;
use Time::Piece;
use File::Basename;
use lib dirname(__FILE__);
......@@ -20,7 +22,8 @@ use constant TAG_SHOWS => ['一 ichi', '二 ni', '三 san', '四 shi',
# initialize variable segment
my $segment_windowtitle = '';
my @tags_status = [];
my @tags_status = [];
my $segment_datetime = '';
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# decoration
......@@ -51,6 +54,9 @@ sub get_statusbar_text {
foreach my $tag_status (@tags_status) {
$text .= output_by_tag($monitor, $tag_status);
}
# draw window title
# $text .= output_by_datetime();
# draw window title
$text .= output_by_title();
......@@ -111,6 +117,13 @@ sub output_by_title {
return $text;
}
sub output_by_datetime {
my $text = " ^r(5x0) ".SEPARATOR." ^r(5x0) ";
$text .= $segment_datetime;
return $text;
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# setting variables, response to event handler
......@@ -123,13 +136,27 @@ sub set_tag_value {
}
sub set_windowtitle {
my $windowtitle = shift;
my $windowtitle = shift;
my $icon = PRE_ICON."".POST_ICON;
$segment_windowtitle = " $icon "
. "^bg()^fg($color{'grey700'}) $windowtitle";
}
sub set_datetime {
my $date_icon = PRE_ICON."".POST_ICON;
my $date_format = '%a %b %d';
my $date_str = localtime->strftime($date_format);
my $date_text = "$date_icon ^bg()^fg($color{'grey700'}) $date_str";
my $time_icon = PRE_ICON."".POST_ICON;
my $time_format = '%H:%M:%S';
my $time_str = localtime->strftime($time_format);
my $time_text = "$date_icon ^bg()^fg($color{'blue500'}) $time_str";
$segment_datetime = "$date_text $time_text";
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# end of perl module
......
package pipehandler;
use warnings;
use strict;
use IO::Pipe;
use File::Basename;
use lib dirname(__FILE__);
use output;
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# pipe
sub content_init {
my $monitor = shift;
my $pipe_dzen2_out = shift;
# initialize statusbar before loop
output::set_tag_value($monitor);
output::set_windowtitle('');
my $text = output::get_statusbar_text($monitor);
print $pipe_dzen2_out $text."\n";
flush $pipe_dzen2_out;
}
sub run_dzen2 {
my $monitor = shift;
my $parameters = shift;
my $pipe_dzen2_out = IO::Pipe->new();
my $command = "dzen2 $parameters -p";
my $handle = $pipe_dzen2_out->writer($command);
content_init ($monitor, $pipe_dzen2_out);
$pipe_dzen2_out->close();
}
sub detach_dzen2 {
my $monitor = shift;
my $parameters = shift;
my $pid = fork;
return if $pid; # in the parent process
run_dzen2($monitor, $parameters);
exit;
}
sub detach_transset {
my $pid = fork;
return if $pid; # in the parent process
sleep 1;
system('transset .8 -n dzentop >/dev/null');
exit;
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# end of perl module
1;
......@@ -39,55 +39,54 @@ sub handle_command_event {
}
}
sub init_content {
sub content_init {
my $monitor = shift;
my $pipe_out = shift;
my $pipe_dzen2_out = shift;
# initialize statusbar before loop
output::set_tag_value($monitor);
output::set_windowtitle('');
my $text = output::get_statusbar_text($monitor);
print $pipe_out $text."\n";
flush $pipe_out;
print $pipe_dzen2_out $text."\n";
flush $pipe_dzen2_out;
}
sub walk_content {
sub content_walk {
my $monitor = shift;
my $pipe_out = shift;
my $pipe_dzen2_out = shift;
# start a pipe
my $pipe_in = IO::Pipe->new();
my $pipe_idle_in = IO::Pipe->new();
my $command = 'herbstclient --idle';
my $handle = $pipe_in->reader($command);
my $handle = $pipe_idle_in->reader($command);
my $text = '';
my $event = '';
while(<$pipe_in>) {
# wait for next event
$event = $_;
# wait for each event
while($event = <$pipe_idle_in>) {
handle_command_event($monitor, $event);
$text = output::get_statusbar_text($monitor);
print $pipe_out $text;
flush $pipe_out;
print $pipe_dzen2_out $text;
flush $pipe_dzen2_out;
}
$pipe_in->close();
$pipe_idle_in->close();
}
sub run_dzen2 {
my $monitor = shift;
my $parameters = shift;
my $pipe_out = IO::Pipe->new();
my $pipe_dzen2_out = IO::Pipe->new();
my $command = "dzen2 $parameters";
my $handle = $pipe_out->writer($command);
my $handle = $pipe_dzen2_out->writer($command);
init_content($monitor, $pipe_out);