You are not logged in.

#1 2013-12-10 19:53:29

0x29a
Member
Registered: 2012-09-28
Posts: 101

Background commands chain

Hello there!

I'm trying to make something like a rudimentary splash screen script for .xinitrc using stuff already available.
My goal is to achieve commands chain similar to these below:

launch cairo-compmgr &
launch terminal with a welcome message &
sleep 6 (while cairo-compmgr is loading) && display gif image #for cute animation

and here comes the problem. 

sleep 6 (while gif image is displayed ) && killall gif image displaying program instances && display another gif &

problematic thingie yet again...

 sleep 3 && killall cairo-compmgr 

Problematic stuff comes in the middle.
&& operator waits for successful exit code (that is forever)
; operator does stuff immeditely (not what I want)

I want stuff to go on while program is still working, but it has to be synchronised...
Maybe these programs appear somehow in a processes list and I could catch'em this way?
I've tried launching those apps separately, calibrating sleep arguments, but it varies from time to time and I need something sure.

I hope You guys can understand me...

Thanks in advance! Any help appreciated.

Regards

Last edited by 0x29a (2013-12-10 20:03:15)

Offline

#2 2013-12-10 20:17:49

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: Background commands chain

so you're starting cairo-compmgr only to display some gifs, then kill it again?
and you want the first gif to be displayed only after cairo-compmgr becomes fully operational?
so your solution lies in finding out more about cairo-compmgr.
maybe there's some file or some variable that can be queried for "compositor active"?

other wise i can see nothing wrong with your script.

but i think i'm still missing sth here.

&& operator waits for successful exit code (that is forever)

what is forever? in which case exactly does it wait "forever" for a succesful exit code?

Last edited by ondoho (2013-12-10 20:19:06)

Offline

#3 2013-12-10 20:22:25

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Background commands chain

If you type 'ls foo' the command exists immediately after doing what it's told i.e. printing the listing.
'qiv foo.jpg' opens a picture for viewing ... and sits there waiting for user to do sth e.g. move to another picture or quit. If you don't do anything, it will sit there forever and the command that is supposed to run after qiv finishes will not run.

Offline

#4 2013-12-10 20:47:17

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: Background commands chain

yes but op can always put

qiv some.gif &
sleep 6 && killall qiv

it's hackish but why not.
or, slightly better:

qiv some.gif &
pid=$!
sleep 6 && kill $pid

Last edited by ondoho (2013-12-10 20:50:29)

Offline

#5 2013-12-10 20:54:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Background commands chain

I know, I was answering your question what does it mean "forever".

Offline

#6 2013-12-10 22:32:30

0x29a
Member
Registered: 2012-09-28
Posts: 101

Re: Background commands chain

All right!

We're onto something here...

I'll try with ondoho's trick in a few minutes.
Meanwhile: It waits for exit code forever, because gif is displayed in loop. Full code I've found for displaying animated gif in a middle of a screen (pretty automated approach, but gifview with those parameters alone gives a same result for me) :

#!/bin/sh
# Uses xwinwrap to display given animated .gif in the center of the screen

if [ $# -ne 1 ]; then
    echo 1>&2 Usage: $0 image.gif
    exit 1
fi

#get screen resolution
SCRH=`xrandr | awk '/current/ { print $8 }'`
SCRW=`xrandr | awk '/current/ { print $10 }'`
SCRW=${SCRW%\,}

#get gif resolution
IMGHW=`gifsicle --info $1 | awk '/logical/ { print $3 }'`
IMGH=${IMGHW%x*}
IMGW=${IMGHW#*x}

#calculate position
POSH=$((($SCRH/2)-($IMGH/2)))
POSW=$((($SCRW/2)-($IMGW/2)))

xwinwrap -g ${IMGHW}+${POSH}+${POSW} -ov -ni -s -nf -- gifview --unoptimize --min-delay 10 -w WID $1 -a

exit 0

by memorygap


Ondoho: very cool functionality, I wasn't aware of that! Thanks!

Unfortunately, since there is only one instance of each necessary app after login to X, killall does the same thing...
If only there was a way to determine whether process is loaded up and fully functional, and start counting seconds to kill it exactly from this moment...

Edit:

I think the best way of telling what I'm trying to achieve here will be posting whole code of that.... thing...
It's a little lame and it serves solely for eye-candy purposes and it slows down my work, but... Well... U get the picture:

1) config.h from DWM; autostart configuration

static const char *tags[] = { " VARIOUS TAGS" };

static const Rule rules[] = {
	/* various rules */
	{NULL,	NULL,	"STARTUP RAPORT",   0,	True, -1},
	
};

next: lame code for those old school, sci-fi movie bootup report (MO-TH-UR-6000 inspired wink  )

asdf="WELCOME BACK...";
for(int i = 0;i<= asdf.length() ; i++)
{
usleep(130000);
cout<<asdf[i];
cout.flush();
}
cout<<endl;
asdf="HAVE A VERY PRODUCTIVE DAY";
for(int i = 0;i<= asdf.length() ; i++)
{
usleep(12000);
cout<<asdf[i];
cout.flush();
}

And this should be displayed while cairo-compmgr is loading.

And here goes xinitrc:

cairo-compmgr& # starts for like 6 secs

xfce4-terminal --title="STARTUP RAPORT" -x ~/.greetings &

# other stuff...

sleep 6 && ~/.wallpaper ~/.cube.gif & # http://i.minus.com/ibojv6bk6YBqAq.gif

sleep 12 && killall gifview & #after animation is over, it kills first gif, so it fades into darkness...

sleep 13 && ~/.wallpaper ~/.loaded.gif & #http://i.minus.com/iEGI3FRMZvQRa.gif , second one appears...

sleep 15 && killall cairo-compmgr && firefox& # and it stays there. I dont see it anyways until I get back to this tag

#btw. firefox & cairo-compmgr dont play well together... 
 
while true; do
   xsetroot -name "$( date +"%F %R" ) $(acpi -b | awk 'sub(/,/,"") {print $3, $4}')"
   sleep 1m    # Taken from Arch Wiki :) 
done &
exec dwm

Yeah, I know, there must be some more elegant solution, but that's why I'm asking for help, right? smile

As You can probably see, all configuration is kind'a lightweight and I dont need (nor want) c-cm to run at all times...
Since it's resource hog, results vary from time to time. With those sleep $ values I've achieved best effect so far... But it's not ql enough. And, while I'm doing this, I can learn something important on how my favourite system handles process management and other thingies...

I can remember some lectures about semaphores in multithreaded programming...
Maybe there is something similar for shell commands? That $! trick seems to be a tip of an iceberg

Last edited by 0x29a (2013-12-10 23:27:53)

Offline

Board footer

Powered by FluxBB