Subject: FVWM: Using Schedule reliably

From: Tavis Ormandy <[email-masked]>
Date: Tue, 11 May 2004 14:50:47 +0100

Hi there, I'm having real trouble understanding how to use schedule
correctly so that my scheduled jobs will work (or at least remain queued)
during periods where, for example, the pointer is grabbed.

I have a function that I would like to continue running every few seconds
testing a condition, and performing an action, until the window is deleted.

basically, like this:

AddToFunc NewWindowFunc
+ I Test (foobar) Exec something
+ I Echo Still running!
+ I Schedule 5000 NewWindowFunc

The idea is to keep a xwd cache of windows while they are unobscured, so
that when they are obscured I can still use screenshots of them, I would
like to use FvwmEvent to start a function like this in the context of all
new windows, then just keep testing every few seconds (the overhead seems
pretty low in my tests). But my scheduled jobs keep dissapearing, can anyone
offer any suggestions?

This is what I have right now, it works, but I would like to be able to just
keep caching without some event happening:

# FvwmEvent runs on some events:
AddToFunc StartFunction I Module FvwmEvent ExposeCache
DestroyModuleConfig ExposeCache: *
*ExposeCache: add_window CacheWindow
*ExposeCache: raise_window CacheWindow
*ExposeCache: focus_change CacheWindow
*ExposeCache: dewindowshade CacheWindow
*ExposeCache: destroy_window "Exec rm -f $[FVWM_USERDIR]/cache.$[w.id].xwd"

# Take a picture
AddToFunc CacheWindow I ThisWindow (Raised, !Shaded, !Iconic) Exec nice xwd
-screen -silent -id $[w.id] -out $[FVWM_USERDIR]/cache.$[w.id].xwd

AddToFunc ExitFunction I Exec rm -f $[FVWM_USERDIR]/cache.*

# WindowList style command...
DestroyFunc FvwmExpose
AddToFunc FvwmExpose
+ I AddToMenu FvwmExposeMenu ".: e x p o s e :." Title
+ I + DynamicPopDownAction DestroyMenu FvwmExposeMenu
+ I All (CurrentDesk, AcceptsFocus) Test (f
$[FVWM_USERDIR]/cache.$[w.id].xwd) \
    PipeRead "convert -scale 128 -frame 1x1 -mattecolor black -quality 0
xwd:$[FVWM_USERDIR]/cache.$[w.id].xwd \
	png:$[FVWM_USERDIR]/icon.exp.$[w.id].png && echo AddToMenu FvwmExposeMenu
\
	%$[FVWM_USERDIR]/icon.exp.$[w.id].png%\\\'\"$[w.name]\"\\\' WindowID
$[w.id] WindowListFunc \
	&& echo AddToMenu FvwmExposeMenu \\\"\\\" Nop || echo Nop"
+ I Popup FvwmExposeMenu
+ I Exec exec rm -f $[FVWM_USERDIR]/icon.exp.*

-- 
-------------------------------------
[email-masked] | finger me for my gpg key.
-------------------------------------------------------

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Piotr Zielinski <[email-masked]>
Date: Tue, 11 May 2004 18:27:24 +0100

Tavis> I'm having real trouble understanding how to use schedule
Tavis> correctly so that my scheduled jobs will work (or at least
Tavis> remain queued) during periods where, for example, the pointer
Tavis> is grabbed.

I posted a similar question a couple of weeks ago but there were no
replies.  The manual says that a scheduled command X will be executed
in the same window context as "Schedule 4234 X", but it's rather vague
on how this is implemented.  I can only _speculate_ that when the
pointer is about to leave a window, all scheduled commands for that
window are executed.  What happens to all Schedule commands issued by
these scheduled commands I don't know.  Sometimes they seem to
disappear.  Sometimes not.

Tavis> The idea is to keep a xwd cache of windows while they are
Tavis> unobscured, so that when they are obscured I can still use
Tavis> screenshots of them,

At the moment, I'm using FvwmAuto to take a screenshot of every window
that has had focus for at least 10 seconds (once) and it works pretty
well.  But I probably will switch to your method soon.

Tavis> But my scheduled jobs keep dissapearing, can anyone
Tavis> offer any suggestions?

Since it's a mystery for me what exactly happens to scheduled command
while switching the window context, I'd (re)schedule NewWindowFunc
every time the window context is changed (using FvwmEvent).  To avoid
having more and more "threads" taking snapshots, I'd use a fixed
schedule id (say 173) and add deschedule to the code:

AddToFunc NewWindowFunc
+ I Test (foobar) Exec something
+ I Echo Still running!
+ I Deschedule 173
+ I Schedule 173 5000 NewWindowFunc

Piotr