fvwmorg / fvwm3

FVWM version 3 -- the successor to fvwm2
Other
505 stars 79 forks source link

"GotoPage prev" should go to the previous page per desktop #968

Closed sanjoymahajan closed 5 months ago

sanjoymahajan commented 5 months ago

Upfront Information

Expected Behaviour

When switching desktops, I wanted also to switch to that desktop's most recently used page. The GotoDesktopAndPage built-in function doesn't allow specifying "prev" for the page. Thus, I made a function:

AddToFunc GotoDeskAndPreviousPage
 + I GotoDeskAndPage $0 0 0
 + I GotoPage prev

and bound it, for example:

Silent Key F2 A CS GotoDeskAndPreviousPage 1

with similar bindings for F1, F3, and F4.

Actual Behaviour

However, "GotoPage prev" seems to have only a global notion of the previous page, not a per-desktop notion. Thus, if I am using page (0,1) on desktop 1 and switch using the keybinding to desktop 3, it goes there to page (0,1), even if I had been using page (1,1) on desktop 3 before switching to desktop 1.

Even if that issue is fixed, my implementation may still not work: The "GotoDeskAndPage $0 0 0" line might make that desktop's previous page the (0,0) page. So, perhaps there is a better fix for this issue, or it's better classed as a feature request for GotoDeskAndPage (to support "prev" as the page argument)?

ThomasAdam commented 5 months ago

Hi @sanjoymahajan

I'm not sure I quite follow. GotoPag prev is already per-monitor aware. So it remembers each screen's last page, and if you run that command for either the implied current monitor, or a specific monitor, it works just fine for me.

sanjoymahajan commented 5 months ago

I wanted GotoPage prev to be specific to the desktop (I hadn't thought about the monitor). Or is it already desktop-aware? I may have misunderstood or done my test incorrectly.

ThomasAdam commented 5 months ago

I wanted GotoPage prev to be specific to the desktop (I hadn't thought about the monitor). Or is it already desktop-aware? I may have misunderstood or done my test incorrectly.

It's both -- in that, if you have: DesktopConfiguration global set (which is the default), then GotoPage prev will go to the previous page.

If you have: DesktopConfiguration per-monitor set, then the desktop on that monitor is the one which is used, and GotoPage prev works in the same way.

sanjoymahajan commented 5 months ago

I am using the default DesktopConfiguration (global). So I am not sure what is wrong. I will do some more tests and see if I can make a minimal config and example.

somiaj commented 5 months ago

I think I see what you are requesting, and you are correct, fvwm doesn't store the previous page per desk, only per monitor. So what you want is to recall the previous page per desk, per monitor.

Note that this could be implemented via storing this information in your setup using InfoStore along with FvwmEvent using the new_page event. Each time you move to a new page, use fvwm to save the variable of the previous page (you may have to first save the variable of the current page, then move this to the previous page), for instance bind the following function to the new_page event. I haven't tested this fully, but in theory it should work, you may need to tweak it though.

# Initialize the previous page and current page variables
# You need to do this for each desk you want to use.
InfoStoreAdd PrevPageX0 0
InfoStoreAdd PrevPageY0 0
InfoStoreAdd CurPageX0 0
InfoStoreAdd CurPageY0 0
InfoStoreAdd PrevPageX1 0
InfoStoreAdd PrevPageX2 0
InfoStoreAdd CurPageX1 0
InfoStoreAdd CurPageY1 0
...

# This function updates your variables when you switch pages.
DestroyFunc SavePageLoc
AddToFunc SavePageLoc
+ I InfoStoreAdd PrevPageX$[desk.n] $[infostore.CurPageY$[desk.n]]
+ I InfoStoreAdd PrevPageY$[desk.n] $[infostore.CurPageY$[desk.n]]
+ I InfoStoreAdd CurPageX[$desk.n] $[page.nx]
+ I InfoStoreAdd CurPageY[$desk.n] $[page.ny]

# Custom Previous Page Function
DestroyFunc MyPrevPage
AddToFunc MyPrevPage
+ I GotoPage $[infostore.PrevPageX$[desk.n]] $[infostore.PrevPageY$[desk.n]]

# Use FvwmEvent to update your variables
DestroyModuleConfig FE-NewPage: *
*FE-NewPage: Cmd Function
*FE-NewPage: new_page SavePageLoc

# Start FvwmEvent
AddToFunc StartFunction I Module FvwmEvent FE-NewPage

Note here is an alternative that should also work, seems you can also get the prev_page from the monitor variables, so instead adapt something like this.

DestroyFunc SavePageLoc
AddToFunc SavePageLoc
+ I InfoStoreAdd PrevPageX$[desk.n] $[monitor.$[monitor.primary].prev_pagex]
+ I InfoStoreAdd PrevPageY$[desk.n] $[monitor.$[monitor.primary].prev_pagey]

Though this might not be as good as the first approach, though simpler, it maybe harder to guarantee that the variable saved by fvwm is for the current desk you are on, though you could try it (as mentioned I'm only brain storming here, I have not tested any of this actually works).

ThomasAdam commented 5 months ago

Right, OK. Yes, this is something you can use FvwmEvent for. I'm going to close this "bug", as it can be implemented using something like the above.

sanjoymahajan commented 5 months ago

Thank you for the approaches and sample code. I have been experimenting with them. They hasn't worked yet (e.g., I cannot get a second FvwmEvent process to start). However, I think that the problem lies with my very incomplete / hack understanding of fvwm coding, so I am slowly working on that problem...

somiaj commented 5 months ago

@sanjoymahajan I did have a small issue with how I was calling the FvwmEvent function, I fixed that. Note how I've given FvwmEvent a new name, FE-NewPage, this way you can have multiple running, since they have a new name.