Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run the extension from the terminal #34

Open
txirrindulari opened this issue Jan 31, 2022 · 11 comments
Open

How to run the extension from the terminal #34

txirrindulari opened this issue Jan 31, 2022 · 11 comments
Labels

Comments

@txirrindulari
Copy link

Hi, this is not a issue, but trying to find a way to control the extension from terminal and gnome 40.4.0
I want to use it within kvm hooks to save the current session with a given name and then restart the session again.
Is there any way to accomplish this?

@nlpsuge nlpsuge added the new feature New feature or request label Feb 2, 2022
@nlpsuge
Copy link
Owner

nlpsuge commented Feb 2, 2022

Hi @txirrindulari ,

If you are using X11, you can install xsession-manager via pip3 install xsession-manager and then follow the instructions of If you want to restore the previous X session automatically after login. It's very easy. xsession-manager is a command line tool. It should fit your needs if you are running Gnome on X11.

This extension probably can't be used in terminal directly. Maybe it can be used via D-Bus, I'm not sure about this. And I have been adding the feature of WIP: [Feature] Restore saved windows automatically after login #33. But it will take time to finish, I don't have much time for it recently.

@nlpsuge
Copy link
Owner

nlpsuge commented Feb 20, 2022

It's possible to use features of this extension from the terminal via D-Bus.

Here is a working example: https://github.com/ickyicky/window-calls/blob/b0223fca3348a115e8bb220709bc069cde78c615/extension.js#L44.

After installing https://extensions.gnome.org/extension/4724/window-calls/, run the below command in the terminal to retrieve all the running windows:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List

See also:
https://gist.github.com/rbreaves/257c3edfa301786e66e964d7ac036269

@curiousercreative
Copy link

@nlpsuge I believe I'm after what the OP is after and that's just the ability to invoke the same functionality that's invoked upon pressing "Save open windows" and "restore windows from saved session", but on the terminal. For example, I'm previously using lwsm and with that I can simply lwsm save NAME_OF_SESSION and lwsm restore NAME_OF_SESSION. Ultimately, because some apps do not properly restore state automatically I need to manually restore it's state before restoring window arrangement. Here's what my script currently looks like because Tilix doesn't restore state automatically.

#!/bin/bash
# start tilix since lwsm can't seem to restore previous session
tilix -s ~/ownCloud/work/tilix.json
xdg-open ~/ownCloud/work

# wait a moment for tilix to open
# sleep 5

# restore the rest of the windows and the geometries of previously opened
lwsm restore work

@nlpsuge
Copy link
Owner

nlpsuge commented Mar 2, 2022

If I understand correctly, we need a command line tool which wraps the calling of the core functions of this extension, such as Save open windows and restore windows from saved session.

I'm pretty sure this can be implemented via D-Bus.

awsm-client is a proper name for the command line tool.

The calling graph is this: awsm-client => D-Bus services => core functions.
image

@nlpsuge
Copy link
Owner

nlpsuge commented Mar 2, 2022

@curiousercreative

Another solution is adding a new option in the Preferences to allow all or some apps to be restored via the saved cmd line instead of the .desktop file.

In your example, the saved cmd line for Tilix should be tilix -s ~/ownCloud/work/tilix.json.

But this may not always work, because the cmd line is not always the expected one, I guess it completely depends on the app itself.

Anyway, I have a plan to provide a awsm-client. On the terminal, we can do a lot more things.

@curiousercreative
Copy link

@nlpsuge thanks for detailing a plan for awsm-client, I think that's exactly what we're looking for! Thanks also for the suggestion with the desktop file.

@curiousercreative
Copy link

curiousercreative commented Apr 28, 2022

@nlpsuge this is going a bit off-topic, but related to working around the lack of cli for the extension. I'm attempting to create a desktop file for restoring this tilix session as described above. It's located at ~/.local/share/applications/work.Tilix.desktop with contents

[Desktop Entry]
Version=1.0
Name=Common Energy Tilix
Comment=A tiling terminal for Gnome
Keywords=shell;prompt;command;commandline;cmd;
Exec=tilix -s /home/user/Desktop/work.json
Terminal=false
Type=Application
StartupNotify=true
Categories=System;TerminalEmulator;X-GNOME-Utilities;
Icon=com.gexperts.Tilix

This desktop file launches the expected tilix session. I then position it on the display in the correct position and attempt to save the session using the extension. Seems to save properly, but upon restore, an empty tilix session window is created (in the correct position though) rather than the tilix saved session. Upon further inspection of the saved session in ~/.config/another-window-session-manager/sessions/test reveals that a default tilix desktop file was selected

{
            "cmd": [
                "tilix",
                "--quake"
            ],           
            "desktop_file_id": "com.gexperts.Tilix.desktop",
            "desktop_file_id_full_path": "/usr/share/applications/com.gexperts.Tilix.desktop",
}

The app_name, window_title and other attributes appear correct though. How does the extension determine which desktop file to load?

NOTE: in my case the cmd is also wrong when this long running process (a terminal window that hides when not in focus) is running. If I kill that process, then the cmd is correct and reflects what is found in the desktop file that launched the window.

I should also mention this behavior was encountered on Pop!_OS 22.04, GNOME 42, X11

@nlpsuge
Copy link
Owner

nlpsuge commented May 8, 2022

Hi @curiousercreative,

Sorry for the delay. I've been busy lately and forget your post.

Short answer:

Add StartupWMClass=Tilix to the ~/.local/share/applications/work.Tilix.desktop and try again. If it does not work, use StartupWMClass=tilix instead and try again.

[Desktop Entry]
Version=1.0
Name=Common Energy Tilix
Comment=A tiling terminal for Gnome
Keywords=shell;prompt;command;commandline;cmd;
Exec=tilix -s /home/user/Desktop/work.json
Terminal=false
Type=Application
StartupNotify=true
Categories=System;TerminalEmulator;X-GNOME-Utilities;
Icon=com.gexperts.Tilix
StartupWMClass=Tilix

I hope it works for you. :)

@nlpsuge
Copy link
Owner

nlpsuge commented May 8, 2022

How does the extension determine which desktop file to load?

It probably depends on AppSystem.lookup_app(a desktop id - such as firefox.desktop) and the property of one of wm_class and wm_class_instance in the desktop file.


const shell_app = this._defaultAppSystem.lookup_app(desktop_file_id)

StartupWMClass=${wmClass}
# If the former does not work, use the below line instead.
# If it still does not work, please fill an issue at:
# https://github.com/nlpsuge/gnome-shell-extension-another-window-session-manager/issues
# StartupWMClass=${wmClassInstance}

@curiousercreative
Copy link

curiousercreative commented May 9, 2022

Add StartupWMClass=Tilix to the ~/.local/share/applications/work.Tilix.desktop and try again. If it does not work, use StartupWMClass=tilix instead and try again.

That first one seems to have done the trick, thanks very much!

@curiousercreative
Copy link

Add StartupWMClass=Tilix to the ~/.local/share/applications/work.Tilix.desktop and try again. If it does not work, use StartupWMClass=tilix instead and try again.

On my laptop I run Wayland more often and there I am using the second lowercase. I had to save/restore/save multiple times to get things working, so perhaps that attribute is not the determining factor...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants