create/delete new desk on demand

once I’ve got an idea to have separate desktop for some applications. it is very convinient to work if such application has a lot of windows (like opendx with my programs). some time it is necessary to have some opendx programs opened and it becames hard to find required window. another example is working with several remote host: for each I need ssh terminal, file manager with remote filesystem mounted, probably applications running remotely through X-windows protocol. it is better to have separate desktop for every host again.
but you never know a priori how much hosts you will open (or how much instances of applications will be runned), furthermore, this number is changing dynamically: you might stop working with one host, but continue with others, start new program, than deside to return to previous, etc.
thus you have 2 option (at least):
a) to have a_lot of desktop fefined from very beginning, for a case if you do a lot of things simultaneously and have trouble with navigating through them and problem to find free desktop for newly started application (I cannot really predefine particular deskop for particular opendx instance)
b) create new desktop on demand, as such necessety appiars.
I’v chosen second option but cannot find out how to implement this. I’m very beginner in FVWM (actually I choose it because of this idea :slight_smile:

the first problem I met is FVWM doesn’t really know how much desktops have windows (does it?)
second how to track changes?
and how to reflect these changes on FvwmPager?
(basically I do not want to see free desktops on it. so I need some how pack or renumber desktops)

cann’t you give some hints?

Something I remember Tavis had done in his config was to use a very small FvwmButtons which would cycle through all his desks. Remember that your DesktopSize that you set, can be used. Here’s the module code for the FvwmButtons alias:

DestroyFunc LockingSlide
AddToFunc LockingSlide
+ I Test (!State 2) Break
+ I State 2 False
+ I AnimatedMove $0 $1
+ I State 2 True

# A little control panel for switching desks.
DestroyModuleConfig DeskControl: *
*DeskControl: Columns 1
*DeskControl: Rows 3
*DeskControl: Colorset 17
*DeskControl: Frame 1
*DeskControl: Padding 1 1
*DeskControl: Font "xft:snap;-artwiz-snap-*-r-*-*-*-*-*-*-*-*-iso8859-1"
*DeskControl: (1x1, Title "<", Action(Mouse 1) GotoDesk -1)
*DeskControl: (1x1, Title ">", Action(Mouse 1) GotoDesk 1)
*DeskControl: (1x1, Id desk, Title "$[desk.n]", Action(Mouse 1) `Next (CirculateHit, DeskControl) PipeRead 'echo LockingSlide keep $$(test $[w.y] -lt 0 && echo 0 || echo w-$$(($[w.height]-$height))p)'`)

Well, I’m not sure if it is what you’re asking, but in my FvwmPager (that gets swallowed in an FvwmButtons instance) I set the title of the Pager to the number of windows open on it. Here’s the code:

DestroyModuleConfig FvwmEvent-count: *
*FvwmEvent-count: Cmd
*FvwmEvent-count: PassId
*FvwmEvent-count: add_window FvwmCountDestroyWindows
*FvwmEvent-count: destroy_window FvwmCountDestroyWindows

DestroyFunc  FvwmCountDestroyWindows
AddToFunc  FvwmCountDestroyWindows
+ I SetEnv WinNum 0
+ I All (CurrentDesk !Transient) \
    PipeRead 'echo SetEnv WinNum $$$$(($$$$WinNum + 1))'
+ I DesktopName $[desk.n] ($[WinNum])

Module FvwmEvent FvwmEvent-count

Whether that’s of any use or not…?

– Thomas Adam

I have something similar in my config (sortened version):

DestroyFunc NewDesk
AddToFunc NewDesk
+ I Piperead "echo SetEnv FVWMMaxDeskNumber $$[ $[FVWMMaxDeskNumber] + 1 ]"
+ I KillModule FvwmPager
+ I Module FvwmPager 0 $[FVWMMaxDeskNumber]
+ I GotoDeskAndPage $[FVWMMaxDeskNumber] 0 0
+ I Module FvwmForm FormDeskName

DestroyFunc DeleteLastDesk
AddToFunc DeleteLastDesk
+ I DesktopName $[FVWMMaxDeskNumber]
+ I Piperead "echo SetEnv FVWMMaxDeskNumber $$[ $[FVWMMaxDeskNumber] - 1 ]"
+ I KillModule FvwmPager
+ I Module FvwmPager 0 $[FVWMMaxDeskNumber]

The idea is to store the number of desks in the environment variable FVWMMaxDeskNumber, increment and decrement it on demand, and do a restart of the pager. The drawback is that only the last desk can be deleted, but with a simple

All (CurrentDesk, !Sticky) MoveToDesk 0 x

you can move all the windows to another desk.

The full version of these functions (and a simple FvwmForm for asking for a desktop name) can be found in my config: www-i6.informatik.rwth-aachen.de … /fvwm.html

I’ll explore you config in details latter… but as well as I understand for now, you define page names through environment variables… this gives me idea create not new desk but new pages (before I thought that if FVWM cannot name pages and I cannot use them for my purpose) so it is not necessary to restart pager, number of pages will change automatically.
is there any pitfall in this approach?

about “DeleteLastDesk” last desk, I think different:
maybe it is better to keep variable like Last_free_desktop on order to know where put new application and Last_desktop for pager propelly display all desktops.

there are 2 more questions:
is there way to determine that some page/desk have no windows on it, except windows existing on allpages like pager?
is it time/memory consuming to move all windows from one page/desktop to another?

Hmm… maybe something like:

DestroyFunc foo
AddToFunc foo
+ I All (CurrentDesk !Transient) \ 
    PipeRead 'echo SetEnv WinNum $$$$(($$$$WinNum + 1))'
+ I PipeRead '[[ $[WinNum] > 0 ]] && echo CODE HERE BECAUSE THERE WERE WINDOWS || echo NO WINDOWS ON CURRENT DESK'

Adapt as necessary.

No, not really. See “MoveToDesk”, “MoveToPage” in ‘man fvwm’.

– Thomas Adam

Yes, I use the Fvwm internal desk naming scheme and an additional page naming (via environment variables) for pages. This allows me to have some hierarchical organization of my applications, something like:

Tools -> Web Browser, Fvwm Console
ProjectA -> Source, Testing, Report

It is up to you if pages, desktops or a combination of both is what you need.

am I right that first line of this function compute number of windows? is it efficient?

to call this function I need to know that somthing happend on the desk (actually not necessarly on the current desk), is there way to determnig this? I mean it is necessary to call this functon when event like open/close window happend. and actually you need to know what happend not only on current desk, but other desks too (application may crush and close all windows). so is there any function something like Last_event_happend in FVWM?
(I’m sorry if I ask too much silly questions, but I’m really newbie)

Efficient enough, I suppose. :slight_smile:

Have a look at “man FvwmEvent” – there’s a whole host of event actions you can bind that to.

– Thomas Adam