You are not logged in.

#1 2021-05-23 18:57:53

AMTitan
Member
Registered: 2021-04-15
Posts: 33

Xmonad reopen programs on restart

Is there any way that I can restart my computer but once it is back and running I have all my windows in their workspace (without manually telling each program to run on startup in xmonad.hs)?

Offline

#2 2021-05-24 00:35:01

AMTitan
Member
Registered: 2021-04-15
Posts: 33

Re: Xmonad reopen programs on restart

And sorry if I worded this really bad but what I mean is like if I have firefox on workspace 2 and cmus on workspace 1, I could restart my computer and once I open it up again I would have cmus on workspace 1 and firefox on workspace 2. I was thinking there is probably a script out there that someone made that would do this.

Offline

#3 2021-05-24 06:08:14

MrNeuneu
Member
Registered: 2018-05-01
Posts: 22

Re: Xmonad reopen programs on restart

Hi,

Let me try to understand what you mean. I have several questions.
(1) First, the position of the applications should not be fixed by some static configuration: it should remember its last position. Right?
(2) Would hibernating instead of shutting down your computer be a solution?
(3) Do you want your applications to start automatically when you open your computer or only when you invoke them?
(4) Your applications have only one window? For instance, what if you open a text editor on workspace 1, then an other one on workspace 5? Do you want that both pop up again when you restart your computer? But then what exactly do you want to remember of the state of your programs and wouldn't it be better to just hibernate?

On my configuration, firefox already has the behavior you describe: I have a lot of firefox windows, on some workspaces (a lot of workspaces organized as a tree), and firefox remembers which window is on which workspace. At least approximately, because if I delete or add workspaces, firefox gets confused. This is very useful and I was surprised when I discovered this feature.

I planned to script some similar feature for pdf viewers and text editors, so if you are interested I can give the script to you when it's finished.

If you only have few applications with only one instance and window each, and that you want them to remember the last workspace they were on, I think it is doable with xdotool and a short wrapper around the programs you are interested in. For each application, you have a file storing the desktop it was onto the last time it was running. When you open an application, instead you execute a script which:
1. Launches the application.
2. Looks at the corresponding file, waits for the window to appear and displaces it to the right workspace.
3. Periodically stores the position of the window until it doesn't exist anymore.

I don't know if there is a way that doesn't involve periodically checking for the position of the window, even at the xmonad level.

Offline

#4 2021-05-24 11:45:08

AMTitan
Member
Registered: 2021-04-15
Posts: 33

Re: Xmonad reopen programs on restart

MrNeuneu wrote:

Hi,

Let me try to understand what you mean. I have several questions.
(1) First, the position of the applications should not be fixed by some static configuration: it should remember its last position. Right?
(2) Would hibernating instead of shutting down your computer be a solution?
(3) Do you want your applications to start automatically when you open your computer or only when you invoke them?
(4) Your applications have only one window? For instance, what if you open a text editor on workspace 1, then an other one on workspace 5? Do you want that both pop up again when you restart your computer? But then what exactly do you want to remember of the state of your programs and wouldn't it be better to just hibernate?

On my configuration, firefox already has the behavior you describe: I have a lot of firefox windows, on some workspaces (a lot of workspaces organized as a tree), and firefox remembers which window is on which workspace. At least approximately, because if I delete or add workspaces, firefox gets confused. This is very useful and I was surprised when I discovered this feature.

I planned to script some similar feature for pdf viewers and text editors, so if you are interested I can give the script to you when it's finished.

If you only have few applications with only one instance and window each, and that you want them to remember the last workspace they were on, I think it is doable with xdotool and a short wrapper around the programs you are interested in. For each application, you have a file storing the desktop it was onto the last time it was running. When you open an application, instead you execute a script which:
1. Launches the application.
2. Looks at the corresponding file, waits for the window to appear and displaces it to the right workspace.
3. Periodically stores the position of the window until it doesn't exist anymore.

I don't know if there is a way that doesn't involve periodically checking for the position of the window, even at the xmonad level.

1. yes
2. a restart would be better
3. automatically if possible
4. most of them do only have one window and the ones that have more I don't need to open all of them.
well that would be cool you can send it my way if you don't mind.
well I was thinking like instead of doing a normal restart you would type saverestart then it would save the positions then once it is done it restarts, but I don't know how to make a program go to a specific workspace in shell.

Offline

#5 2021-05-24 13:33:11

MrNeuneu
Member
Registered: 2018-05-01
Posts: 22

Re: Xmonad reopen programs on restart

Ok. To control the windows in shell, if you use X11 and not wayland, you can use wmctrl. You can list the windows and the desktops, move the windows, etc. It can work if you just have a finite list of applications, if when you shutdown you detect one desktop for each application and if when you start you launch an instance of each program and send it to the right desktop.

The problem is that this is not very consistent. What if you have a window named exactly like one of the applications you want to save? Ok, this is some edge case that you probably don't care about, but still. It would be better to have something more... "well-defined".

Offline

#6 2021-05-26 09:57:56

MrNeuneu
Member
Registered: 2018-05-01
Posts: 22

Re: Xmonad reopen programs on restart

As I said, here is the script I made for the pdf viewer. It creates a pipe file ~/.document_viewer_daemon/pipe_evince and stores its data in ~/.document_viewer_daemon/whereis. To open a new pdf, we send the command "open <pdf file>" into that pipe (I renamed /bin/evince to /bin/evince_ and the script in /bin/evince now does that). At startup, it opens each pdf in the desktop it was on at the last shutdown. (I deal with desktop names instead of desktop identifiers because these can change arbitrarily from session to session in my configuration.)

I think it is possible to modify that script to deal instead with arbitrary graphical programs, in such a way that in order to open a new application, we send the command "open <application name>" into the pipe file. But this script uses several hacks and the fact that it works is established experimentally. I don't know if it will work on other environments.

Last edited by MrNeuneu (2021-05-26 09:59:03)

Offline

Board footer

Powered by FluxBB