Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-31 Thread Thomas Adam
On Mon, Oct 31, 2011 at 12:33:00AM +, Harry portobello wrote:
 hullo,
 
 2011/10/30 Thomas Adam tho...@fvwm.org:
  On Sun, Oct 30, 2011 at 08:09:52PM +, Harry portobello wrote:
  How do i do this with FvwmEvent? Thanks..
 
  Something like:
 
     DestroyFunc CountWindow
     AddToFunc   CountWindow
     + I SetEnv WindowCount 0
     + I All ($[w.class], !Transient) PipeRead \
         `echo SetEnv WindowCount ((WindowCount + 1))`
     + I PipeRead `[ $WindowCount = 1 ]  echo \
         WindowStyle TitleFormat %n || echo Nop`
     + I UnsetEnv WindowCount
 
     DestroyModuleConfig FE-tweakttformat
     *FE-tweakttformat: add_window CountWindow
 
     AddToFunc StartFunction I Module FvwmEvent FE-tweakttformat
 
  Change to suit your needs.  I have not tested this myself.
 
 this works but is complex. can you tell me how it works? would be nice
 still for such things to be part of %t for titleformat

It works like this; although I should point out that what I am about to
detail to you has little to do with FVWM and more generally about basic
shell constructs.

DestroyFunc CountWindow
AddToFunc   CountWindow

Destroys and recreates a function named CountWindow.

    + I SetEnv WindowCount 0

Sets up an environment variable called WindowCount which we initially set to
zero [1].

    + I All ($[w.class], !Transient) PipeRead \
        `echo SetEnv WindowCount ((WindowCount + 1))`

This does all of the work for us.  Note that here, $[w.class] expands to the
window's class, which we're using as a reference point to count all windows
of this type.  There's two things going on here which you should be aware
of:

* We don't pass in the window name.  This is because when CountWindow is
  called via FvwmEvent, it's already running in the window context of the
  window which had the action.  Since we're using add_window, each window
  that is mapped is referenced without us needing to track it manually.

* We're using the window ring to go through all windows, looking for ones
  match the class name, as well as those which are not transient.  It is not
  enough in this context to initially use the window's WM_NAME or resource,
  as they can change, and you wanted an accurate count, so...

Then we call PipeRead to put us in a shell -- perform some expression with
it, and then tell FVWM to do something.  This will be called once per match
from the All command, and all we're doing here is incrementing the value
stored in $[WindowCount] each time.

    + I PipeRead `[ $WindowCount = 1 ]  echo \
        WindowStyle TitleFormat %n || echo Nop`

Having collected all of that, we then check to see how many instances of
that window exist.  If there's only one instance of such a window we've just
mapped, then we set its TitleFormat to just %n; otherwise we ask FVWM to do
nothing (Nop).  By using a Nop, we ensure that for all other cases, the
TitleFormat used via usual Style conditions are met instead.  This means
any window with a count here  1, will be counted by %t in the usual way.

    + I UnsetEnv WindowCount

Since we're now done with what we need, clear out the WindowCount
environment variable.

    DestroyModuleConfig FE-tweakttformat
    *FE-tweakttformat: add_window CountWindow

This destroys and creates a new module alias called FE-tweakttformat, which
we'll be asking FvwmEvent to look after.  In this instance, we're only
interested in newly-created windows, hence we've defined the add_window
event, which will call out CountWindow function whenever new windows are
mapped.

    AddToFunc StartFunction I Module FvwmEvent FE-tweakttformat

Finally, we'll ask FVWM to start FvwmEvent with this module alias when it
starts up at init, and again should we restart FVWM.

HTH,

-- Thomas Adam

[1]  Using environment variables in this way is useful; the persistency of
this value is cleared at the end of the function -- a very *good* use of
SetEnv here.   But people forget to clear out the environment variable
afterwards, cluttering up the environment with stale information.



Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-30 Thread Harry portobello
2011/10/29 Thomas Adam tho...@fvwm.org:
 On Sat, Oct 29, 2011 at 10:38:36PM +0200, Michael Großer wrote:
 Thomas Adam wrote:
  On Sat, Oct 29, 2011 at 12:37:04PM +0100, Harry portobello wrote:
  hullo,
 
  On 19 October 2011 18:51, elliot s elliot...@gmail.com wrote:
   Version 2.6.3:
   Previous versions only added the (%t) when there was a repeated name.
   The new code always adds it.
   I worked around the %t in add_window.c by checking if count was
   non-zero, tho that wouldnt kill the parens, which i changed to a space
   in my fvwmrc.
 
  the patch with this email i have written stops the number of window if
  it is 1 - but what must i do to delete the brackets?
 

 [...]

 
  I'm still not going to fix this; there is nothing broken.


 Maybe, Harry should politely ask for a new feature?
 If there are people who need such kind of behaviour, then
 the specification could be extended with a new option, maybe
 a switch?

 It's a count -- the number of windows matching a condition.  It was a bug in
 the original that it never put the number 1 there for a single instance.
 Adding in a flag is confusing and rather amusing to document why.  If you
 *really* can't live without this, script it with FvwmEvent.

How do i do this with FvwmEvent? Thanks..

Harry



Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-30 Thread Harry portobello
hullo,

2011/10/30 Thomas Adam tho...@fvwm.org:
 On Sun, Oct 30, 2011 at 08:09:52PM +, Harry portobello wrote:
 How do i do this with FvwmEvent? Thanks..

 Something like:

    DestroyFunc CountWindow
    AddToFunc   CountWindow
    + I SetEnv WindowCount 0
    + I All ($[w.class], !Transient) PipeRead \
        `echo SetEnv WindowCount ((WindowCount + 1))`
    + I PipeRead `[ $WindowCount = 1 ]  echo \
        WindowStyle TitleFormat %n || echo Nop`
    + I UnsetEnv WindowCount

    DestroyModuleConfig FE-tweakttformat
    *FE-tweakttformat: add_window CountWindow

    AddToFunc StartFunction I Module FvwmEvent FE-tweakttformat

 Change to suit your needs.  I have not tested this myself.

this works but is complex. can you tell me how it works? would be nice
still for such things to be part of %t for titleformat

Harry



Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-30 Thread Michael Großer
 2011/10/30 Thomas Adam tho...@fvwm.org:
`echo SetEnv WindowCount ((WindowCount + 1))`

Nice to see that there is an alternative way to perform
calculations without the use of bc. This idea could eliminate
a dependency of my FVWM scripts ;-)




Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-29 Thread Harry portobello
hullo,

On 19 October 2011 18:51, elliot s elliot...@gmail.com wrote:
 Version 2.6.3:
 Previous versions only added the (%t) when there was a repeated name.
 The new code always adds it.
 I worked around the %t in add_window.c by checking if count was
 non-zero, tho that wouldnt kill the parens, which i changed to a space
 in my fvwmrc.

the patch with this email i have written stops the number of window if
it is 1 - but what must i do to delete the brackets?

i do not like the new titleformat command because this is now very hard to do

Harry


patch
Description: Binary data


Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-29 Thread Michael Großer
Thomas Adam wrote:
 On Sat, Oct 29, 2011 at 12:37:04PM +0100, Harry portobello wrote:
 hullo,
 
 On 19 October 2011 18:51, elliot s elliot...@gmail.com wrote:
  Version 2.6.3:
  Previous versions only added the (%t) when there was a repeated name.
  The new code always adds it.
  I worked around the %t in add_window.c by checking if count was
  non-zero, tho that wouldnt kill the parens, which i changed to a space
  in my fvwmrc.
 
 the patch with this email i have written stops the number of window if
 it is 1 - but what must i do to delete the brackets?
 

[...]

 
 I'm still not going to fix this; there is nothing broken.


Maybe, Harry should politely ask for a new feature?
If there are people who need such kind of behaviour, then
the specification could be extended with a new option, maybe
a switch?



Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-29 Thread Thomas Adam
On Sat, Oct 29, 2011 at 10:38:36PM +0200, Michael Großer wrote:
 Thomas Adam wrote:
  On Sat, Oct 29, 2011 at 12:37:04PM +0100, Harry portobello wrote:
  hullo,
  
  On 19 October 2011 18:51, elliot s elliot...@gmail.com wrote:
   Version 2.6.3:
   Previous versions only added the (%t) when there was a repeated name.
   The new code always adds it.
   I worked around the %t in add_window.c by checking if count was
   non-zero, tho that wouldnt kill the parens, which i changed to a space
   in my fvwmrc.
  
  the patch with this email i have written stops the number of window if
  it is 1 - but what must i do to delete the brackets?
  
 
 [...]
 
  
  I'm still not going to fix this; there is nothing broken.
 
 
 Maybe, Harry should politely ask for a new feature?
 If there are people who need such kind of behaviour, then
 the specification could be extended with a new option, maybe
 a switch?

It's a count -- the number of windows matching a condition.  It was a bug in
the original that it never put the number 1 there for a single instance.
Adding in a flag is confusing and rather amusing to document why.  If you
*really* can't live without this, script it with FvwmEvent.

-- Thomas Adam

-- 
Deep in my heart I wish I was wrong.  But deep in my heart I know I am
not. -- Morrissey (Girl Least Likely To -- off of Viva Hate.)



Re: FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-20 Thread Thomas Adam
On Wed, Oct 19, 2011 at 10:51:59AM -0700, elliot s wrote:
 Version 2.6.3:
 Previous versions only added the (%t) when there was a repeated name.
 The new code always adds it.

This is not a bug, but rather very much by deliberate design.  The old logic
tried to do this before but failed, and when I refactored everything I
fixed it.  So this is how it's going to be with %t from now on.

-- Thomas Adam



FVWM: (Icon)TitleFormat doesnt quite work like IndexedWindowName for one window

2011-10-19 Thread elliot s
Version 2.6.3:
Previous versions only added the (%t) when there was a repeated name.
The new code always adds it.
I worked around the %t in add_window.c by checking if count was
non-zero, tho that wouldnt kill the parens, which i changed to a space
in my fvwmrc.