Subject: FVWM: Store and Recall MousePosition? (ALT+Mouse3-Resize)

From: Gert Brinkmann <[email-masked]>
Date: Sun, 28 Dec 2003 23:30:41 +0100

Hello,

while trying to write a resize-function that behaves like the 
ALT+Mouse3-Resizing(*) in other WMs, I have a problem: How can the 
Mouse-Pointer be stored and later be recalled? I am trying it like... 
(see below). Result: The mouse pointer is not moved after resizing. Does 
anybody has an idea how to solve this?

(*) How it should work: Press ALT and Mouse3-Button => Resize the window 
at the corner of the window that is nearest to the mouse pointer. After 
this resize operation the mouse pointer should be placed where it has 
been before starting the resize operation. (It would be optimal if this 
initial position would be modified by the value you have moved the mouse 
while resizing.)

----------------------------------------------
DestroyFunc MyResize
AddToFunc MyResize
+ M StoreMousePos
+ M WarpToNearestEdge
+ M Resize
+ M RecallMousePos

DestroyFunc StoreMousePos
AddToFunc StoreMousePos
+ M SetEnv POINTERX $[pointer.wx]
+ M SetEnv POINTERY $[pointer.wy]

DestroyFunc RecallMousePos
AddToFunc RecallMousePos
+ M WarpToWindow $[POINTERX] $[POINTERY]

DestroyFunc WarpToNearestEdge
AddToFunc WarpToNearestEdge
+ M WarpToWindow 100 100
----------------------------------------------

The function WarpToNearestEdge currently is just a dummy function. Later 
it really should warp to the nearest edge. Does anybody has an idea how 
to do this? (How can be arithemtics implemented in the 
fvwm-config-language?)

Thanks,

Gert
--
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: Mon, 29 Dec 2003 00:47:00 +0000

> initial position would be modified by the value you have moved the mouse 

You overuse the "M" specifier, such functions are not reusable and this
is usually not what you want.

I would say any complex function should normally have only one "M",
like in this sample:

  DestroyFunc MyResizeDispatcher
  AddToFunc   MyResizeDispatcher
  + C MyResize0
  + M MyResize
  + H MyResize
  + D MyResize2

The rest of the configuration is your whole example above with all 8 "M"
replaced with "I". Then it works. Just don't forget "p" here:

  WarpToWindow $[POINTERX]p $[POINTERY]p

Regards,
Mikhael.

---

From: Gert Brinkmann <[email-masked]>
Date: Tue, 30 Dec 2003 22:10:57 +0100

> I would say any complex function should normally have only one "M",

OK. Just one question to be sure to understand how execution of this 

>   AddToFunc   MyResizeDispatcher

All of the lines are walked through sequentially from top to bottom? The 
"C" or "M" is just a condition if the line is executed or not, but 
execution is not paused until such a condition is fulfilled? Is this right?

>   WarpToWindow $[POINTERX]p $[POINTERY]p

Yes, with this hints the function works as expected. Thank you very 
much. Here is the current version of the functions:

-----------------------------------------------
DestroyFunc MyResize
AddToFunc MyResize
+ I StoreMousePos
+ I WarpToNearestEdge
+ I Resize
+ I RecallMousePos

DestroyFunc StoreMousePos
AddToFunc StoreMousePos
+ I SetEnv POINTERX $[pointer.wx]
+ I SetEnv POINTERY $[pointer.wy]

DestroyFunc RecallMousePos
AddToFunc RecallMousePos
+ I WarpToWindow $[POINTERX]p $[POINTERY]p

+ I WarpToWindow 100 100

Mouse 3 WTSF M MyResize
-----------------------------------------------

What is missing now is to calculate the nearest edge and add the mouse 
movement to the POINTERX/Y values. How can you calculate something in a 
function? I need something like

DestroyFunc WarpToNearestEdge
AddToFunc WarpToNearestEdge
+ I SetEnv WARPX ($[w.width]/2 - $[pointer.wx] > 0 ? 0 : 100)
+ I SetEnv WARPY ($[w.height]/2 - $[pointer.wy] > 0 ? 0 : 100)
+ I WarpToWindow $[WARPX] $[WARPY]

There does not seem to exist a fvwm internal arithmetic language, so 
maybe I have to use a shell command that returns "0" or "100"?

Ciao,

Gert

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 31 Dec 2003 00:05:10 +0000

> execution is not paused until such a condition is fulfilled? Is this right?

Yes, this is right for these specifiers, but not if we also add "I".
It is better to look into complex functions from a different point.

The whole function is stored in the memory divided in parts before
its execution.

Any function has 5 possible independent parts, the "I" specifier part,
and "C", "M", "H", "D". Each such part preserves the command order.
But the order of the specifier parts themselves is not important,
they may be even mixed, i.e.:

  + C something1
  + M something2
  + C something3

is equivalent to:

  + M something2
  + C something1
  + C something3

When the function is called, the "I" part is always exacuted, if any.
Then only if the function is called from a mouse press, additionally one
and only one of the parts "C", "M", "H" or "D" is executed too if any,
depending on whether it was a mouse "c"lick, a mouse "m"otion, a mouse
"h"olding or a mouse "d"ouble click.

This simplified explanation is enough to understand complext functions.
I think the man page has its own explanation too.

> much. Here is the current version of the functions:

Well, if you use "I" then Resize is started immediatelly on the mouse
press, if you want it to start on a click or a motion, then use what
I wrote in the previous reply.

You would better create a shell script ~/bin/my_wrap_pointer receiving
two parameters and printing this line (just an example):

  WarpToWindow 75 68

Then, define this function like:

  AddToFunc WarpToNearestEdge
  + I PipeRead `my_wrap_pointer $[pointer.wx] $[pointer.wy]`

Regards,
Mikhael.