Subject: FVWM: maximum # of windows

From: "Czarina Caro L. Tablante 1995-24644" <[email-masked]>
Date: Tue, 5 Sep 2000 15:47:16 -0800 (GMT)

Hi!

I need to make sure the # of netscape windows a user has at any
single session is limited to, say, 5. how do i make sure that this is
the case? i have other windows, there are sxpms which would be
included if i counted the # of windows open. i need to set a maximum
for the netscape windows only. 

Thanks! :)

C
--
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: Dan Espen <[email-masked]>
Date: Tue, 05 Sep 2000 08:35:12 -0400

> for the netscape windows only. 

I don't  believe there is any  way to do  this without changing source
code.

--
Dan Espen
444 Hoes Lane  Room RRC 1C-214           E-mail: [email-masked]
Piscataway, NJ 08854                     Phone: (732) 699-5570
--
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: Mikhael Goikhman <[email-masked]>
Date: Tue, 5 Sep 2000 19:38:09 +0200

> for the netscape windows only. 

Well, this is possible with a little shell+fvwmrc programming.
To find how many Netscape (or other) windows are open execute:

  xwininfo -display :0 -tree -root | grep Netscape | wc -l

Use 'grep -v 1x1+0+0' or similar to ignore the first Netscape window.
Now there are 2 choices for you.

1) Define FvwmEvent with add_window like described here (for 2.3 and 2.2):

  http://www.hpc.uh.edu/fvwm/archive/0006/msg00382.html
  http://www.hpc.uh.edu/fvwm/archive/0006/msg00393.html

Your add_window callback can be like this (works in the betas only):

  + I PipeRead `verify-window "$w" "$n" "$r" "$c"`

verify-window is your shell script, which gets an id of a new window
as the first parameter, name, resource name and resource class as the next
parameters. Now, do what you want with this window: leave it, kill it.
If you want to leave it, just do not output anything, otherwise print
this fvwm command to the standard output: WindowId $w Delete.

2) You can run a cron job, which counts windows and kills (if needed)
some of them (I hate to suggest this fascist mode, poor users). :-)

xwininfo can give you id's of windows, experiment with:

  xwininfo -tree -root | grep Netscape | sed 's/  */ /g' | cut -d" " -f2

To kill (dangerous) a window giving its id, execute:

  xkill -id 0x1215f2e

Just tried xkill, it does not work well. I.e. it kills entire netscape,
rather than only one window, it does not use X delete protocol.

There is an alternative to xkill. Run FvwmCommandS in user's StartFunction
and then execute a shell command from the cron job:

  FvwmCommand 'WindowId 0x1215f2e Delete'

Regards,
Mikhael.

---

From: "Warren Burke" <[email-masked]>
Date: Wed, 6 Sep 2000 01:48:42 -0400

On Sep 5,  7:38pm, Mikhael Goikhman wrote:
> Subject: Re: FVWM: maximum # of windows
>-- End of excerpt from Mikhael Goikhman

Will this also work in fvwm95 ?

Regards,
  Warren Burke

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 6 Sep 2000 21:55:24 +0200

> Will this also work in fvwm95 ?

This is an obsolete window manager. It was based on fvwm-2.0.43.
Please consider to upgrade your window manager if you need support.

This list only deals with the stable fvwm version (2.2.4) and the
developement version (2.3.21). Pre-2.2 versions are not supported.

Regards,
Mikhael.

---

From: "Czarina Caro L. Tablante 1995-24644" <[email-masked]>
Date: Fri, 8 Sep 2000 17:24:33 -0800 (GMT)

Hi! I'm having some trouble implementing this (pardon a newbie).

i added this to my .fvwm2rc :

*NewWindowEventCmd
*NewWindowPassId
*NewWindow add_window FuncFocusWindow

AddToFunc FuncFocusWindow
+ I PipeRead `windows "$w" "$n" "$r" "$c"

FvwmEvent NewWindowEvent

(end)

i'm really new with this stuff, and i've been reading everything i can 
find on the web, but i cant find what those variables "$w", "$n", etc 
are or where/how i can get them.

this is my windows script:

#!/bin/sh

info=$(xwininfo -display :0 -tree -root | grep Navigator | wc -l)
if [ "$info" -gt 3 ]; then
	FvwmCommand WindowId $w Delete
fi

(end)

i'm almost 100% sure what i did was incorrect. i dont get what u 
mean by printing "WindowId $w Delete" to standard output too.

Thanks!

C

---

From: Mikhael Goikhman <[email-masked]>
Date: Fri, 8 Sep 2000 22:02:01 +0200

I got two private messages saying it is good to speak about betas here.

> Hi! I'm having some trouble implementing this (pardon a newbie).

Implementing something non-standard or unknown always can be problematic.
I suggested two solutions (in 2.2.4 only an idea with cron job may work),
but you should choose yourself their implementations to match your needs.

> + I PipeRead `windows "$w" "$n" "$r" "$c"

A missing backtick at the end of this line is a typo, right?
Also probably rename FuncFocusWindow to FuncVerifyWindow just to be clear.
This FvwmEvent implementation only works with fvwm betas, you know.

> FvwmEvent NewWindowEvent

Here you start an FvwmEvent's alias NewWindowEvent, but you define a
configuration for another alias NewWindow (*NewWindow lines above).

> are or where/how i can get them.

You can find an explanation about $w in the fvwm 2.2.4 man page.
Other variables are new and explained in the current beta man pages.
When you are viewing a man page, type: /\$w <Enter>

> 	FvwmCommand WindowId $w Delete

This line is incorrect. $w will be interpreted by sh as an empty string.
You can use $1 (window id), $2 (window name), $3, $4 in the shell script.
Also FvwmCommand(1) gets only one parameter. So the line could be:

  FvwmCommand "WindowId $1 Delete"

But you should understand what happens. You call this script within
PipeRead, it usually only makes sence if the script outputs something.
My intend was (please reread that message) to call FvwmCommand from
a cron job and here to print a fvwm command.

Also 'windows' script and FvwmCommand should be in your unix path, or
you can specify their full paths. Errors can be found in X Server output.

> mean by printing "WindowId $w Delete" to standard output too.

Try in the script: echo "WindowId $1 Delete"

Regards,
Mikhael.

---

From: "Czarina Caro L. Tablante 1995-24644" <[email-masked]>
Date: Sun, 10 Sep 2000 16:39:34 -0800 (GMT)

> but you should choose yourself their implementations to match your needs.

yup, i decided to use FvwmEvent implementation. however, my version 
of fvwm is 2.2.4, and we cant install a beta version. does this mean 
i'll have to use force, i.e., use cron to kill the new window? but 
that isnt a good way to solve the problem, right?

> configuration for another alias NewWindow (*NewWindow lines above).

i guess i misunderstood what i read off the archives. it shouldve 
been FvwmEvent NewWindow then, i guess.

>   FvwmCommand "WindowId $1 Delete"

this is where i'm lost again. this script should send something back
to .fvwm2rc's PipeRead (+ I PipeRead `windows "$w" "$n" "$r" "$c") so
shouldnt i be putting "+ I WindowId $w Delete" (without the quotes)
here below the PipeRead line? What i cant understand is how i can
send the variables from the shell script back to .fvwm2rc or should 
i not be doing that anymore?
 
> a cron job and here to print a fvwm command.

i used the FvwmCommand solution. if it doesnt work for 2.2.4, i 
guess i'll have to switch to the cron job implementation.

Thanks!

C

---

From: Mikhael Goikhman <[email-masked]>
Date: Mon, 11 Sep 2000 14:12:09 +0200

I gave up to explain and decided to do your homework. :)
Here is a solution for fvwm version 2.2.3 and up. It works surprizingly
well for me, but as I already said, for the betas I would implement more
correct, faster and less hardcoded solution.

Create this $HOME/bin/verify_netscape_windows script:

#!/bin/sh
: ${DISPLAY=:0}
NUM_LIMIT=6
num_total=`xwininfo -tree -root | grep Netscape | wc -l`
if [ "$num_total" -gt $NUM_LIMIT ]; then
	num_tokill=$[$num_total - $NUM_LIMIT]
	for wid in `xwininfo -tree -root | grep Netscape | \
	sed 's/  */ /g' | cut -d" " -f2 | head -$num_tokill`; do
		FvwmCommand "WindowId $wid Delete"
	done
fi

And add this line to your fvwm2rc (without 2 leading spaces):

  AddToFunc StartFunction I FvwmCommandS

There are 3 choices now (after restarting fvwm):
1) run the script verify_netscape_windows manually
2) run the script verify_netscape_windows from a cron job
3) run the script verify_netscape_windows automatically when fvwm places
a new window. For this to work, add the following lines to your fvwm2rc:

  *FvwmEventCmd Exec
  *FvwmEvent add_window verify_netscape_windows
  AddToFunc StartFunction I FvwmEvent

Tested for fvwm 2.2.4 & 2.3.21, Netscape 3 & 4.

Regards,
Mikhael.

---

From: "Czarina Caro L. Tablante 1995-24644" <[email-masked]>
Date: Tue, 12 Sep 2000 13:35:14 -0800 (GMT)

WOW! thanks! it worked! i wouldnt have written this kind of code (i'm too
new into this). i didnt even know till now that some of those commands u
used existed. i made some slight modifications, and i'll be doing a little
tinkering with it too, since i want to output a small window to inform the
user that his new window is about to be killed. if i get that done, 
i'll paste it here. again, thanks so much :)

C