Hi all!
First, thank you for your great awesome wm!
Coming straight from windowmaker many years ago, I like it very much.
For my date and time widget I'm using a vicious widget:
mytextclock = widget({ type = "textbox" })
vicious.register(mytextclock, vicious.widgets.date, "%d.%m %H:%M", 60)
Now, if I start awesome e.g. at 18:00:50h, the displayed time will be
wrong after 10 seconds because the widget will be updated first after 60
seconds.
That means 50 seconds wrong time for each minute. Ok, I could reduce the
update interval, but that's not what I wanted to do.
I had no idea how to fix it with the widget itself, so I wrote a simple
perl script, that will sync the time of the widget at a 'full minute'.
For that I added some lines to my rc.lua:
svdw = os.getenv("HOME") .. "/bin/awesome_svdw.pl mytextclock"
...
awful.util.spawn_with_shell(svdw)
mytextclock: the date widget, the needed argument for the script
os.getenv("HOME") .. "/bin/awesome_svdw.pl: path to the script
awesome_svdw.pl must be executable (chmod u+x)
If someone has the same problem, take a look at the attached script.
cu
Juergen
#!/usr/bin/perl -w
# ----------------------------------------------------------------------------
# awesome_svdw: Sync vicious Date Widget
# copyright 2012 Juergen Descher
# ----------------------------------------------------------------------------
# Restart vicious widget date at full minute.
#
# usage: awesome_scdw date_widget_name
#
# To sync the widget:
# - start this script e.g. from the rc.lua (autostart)
# e.g.
# svdw = os.getenv("HOME") .. "/bin/awesome_svdw.pl mytextclock"
# ...
# awful.util.spawn_with_shell(svdw)
# - use a cronjob
# ----------------------------------------------------------------------------
use 5.006;
#use Carp; # don't use die in modules
#use Carp::Clan; # or better use this
use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time gettimeofday);
use FileHandle;
use strict;
use warnings;
my $Version = 0.01;
sub version {
$Version;
}
my $widget = shift;
die ( "usage: scdw date_widget_name" ) unless defined $widget;
my $script = "awesome_svdw";
my $user = $ENV{USER};
my $blkf = $ENV{HOME} . "/.$script";
my $awesome_client = "/usr/bin/awesome-client";
# check for awesome
my $awes_inst = readpipe("/usr/bin/pgrep -u $user -c -f '^awesome\$'");
chomp $awes_inst;
if ( $awes_inst != 1 ) {
die "$script: Don't kown what to do with $awes_inst instances of awesome wm";
}
# don't run if an other instance of this script is running
if ( -f $blkf ) { die "$script: file $blkf exist"; }
# create a 'blocking' file
open( FH, ">$blkf" ) or die "$script: Can't create $blkf: $!";
close(FH);
$SIG{INT} = sub { unlink $blkf; print STDERR "got ctrl-c\n"; exit; };
my $sec = ( (localtime)[0] );
if ( $sec == 0 ) {
sleep(1.0);
$sec = ( (localtime)[0] );
}
# wait for next minute
sleep( 60 - $sec );
# restart widget
open( A, "|$awesome_client" );
A->autoflush(1);
print A "vicious.unregister($widget, true)\n";
print A "vicious.activate($widget)\n";
close A;
unlink($blkf);