Giter Club home page Giter Club logo

xsession-manager's Introduction

Save and restore windows for X11 desktop environment like Gnome, and many other features.

This project was written in Bash originally. But now I'm completely rewriting it in Python which obviously makes it way more flexible, extensible.

If you are a Gnome 3 user and also want to use these similar features on Wayland, please give Another Window Session Manager a try, it's a Gnome extension, much more faster than xsm, and much more native experience on Gnome.

Downloads Supported Versions Pypi Versions Contributors

Install

Install dependencies

  • Fedora
dnf install python3-devel python3-tkinter wmctrl

Install xsession-manager via PyPi

pip3 install xsession-manager

Install xsession-manager via source code

Method-1: Using pip.

This method install xsession-manager in ~/.local/lib/python3.9/site-packages if you are a normal user, in /usr/local/lib/python3.9/site-packages if you are root.

cd the_root_of_source_code
pip install .

Method-2: Using setup.py

This method install xsession-manager in /usr/local/lib/python3.9/site-packages.

cd the_root_of_source_code
sudo python3 setup.py install

Common usage

  • Save running windows as a X session

Save all running GUI windows to xsession-default

xsm -s

Specify a session name like, my-session-name, restore it later on by running xsm -s my-session-name. This feature should be very helpful when you have multiple tasks to do and each task needs different GUI apps.

xsm -s my-session-name

Note:

  1. It will save some window states, which include Always on Top and Always on Visible Workspace and will be used when executing xsm -r or xsm -ma.
  • Close running windows except those apps with mutiple windows. It's better to leave them to the user to close by hand, some apps like JetBrain's IDEs may have their own session.
xsm -c
  • Close running windows include those apps with mutiple windows.
xsm -c -im
  • Restore the saved X session

Restore all GUI apps using the saved session named xsession-default

xsm -r

Restore gnome-system-monitor using the saved session named my-session-name

xsm -r my-session-name -i gnome-system-monitor
  • Move running windows to their Workspaces according to the saved X session
xsm -ma
  • List saved X sessions
xsm -l
  • View the details of a saved X sessions
xsm -t xsession-default

Full usage:

usage: xsm [-h] [-s [SAVE]] [-c [CLOSE_ALL ...]] [-im] [-r [RESTORE]] [-ri RESTORING_INTERVAL] [-pr [PR]] [-l] [-t [DETAIL]]
           [-x EXCLUDE [EXCLUDE ...]] [-i INCLUDE [INCLUDE ...]] [-ma [MOVE_AUTOMATICALLY]] [--version] [-v] [-vv]

options:
  -h, --help            show this help message and exit
  -s [SAVE], --save [SAVE]
                        Save the current session. Save to the default session if not specified a session name.
  -c [CLOSE_ALL ...], --close-all [CLOSE_ALL ...]
                        Close the windows gracefully. Close all windows if only -c/--close-all present. Or close one or more
                        apps if arguments provided, which supports <window_id>, <pid>, <app_name> or <title_name> exactly the
                        same as -x. For example: `xsm -c gedit 23475 0x03e00004`
  -im, --including-apps-with-multiple-windows
                        Close the windows gracefully including apps with multiple windows
  -r [RESTORE], --restore [RESTORE]
                        Restore a session gracefully. Restore the default session if not specified a session name.
  -ri RESTORING_INTERVAL, --restoring-interval RESTORING_INTERVAL
                        Specify the interval between restoring applications, in seconds. The default is 2 seconds.
  -pr [PR]              Pop up a dialog to ask user whether to restore a X session.
  -l, --list            List the sessions.
  -t [DETAIL], --detail [DETAIL]
                        Check out the details of a session.
  -x EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
                        Exclude apps from the operation according to <window_id>, <pid>, <app_name> or <title_name>. Require
                        at least one value
  -i INCLUDE [INCLUDE ...], --include INCLUDE [INCLUDE ...]
                        Include apps from the operation according to <window_id>, <pid>, <app_name> or <title_name>. Require
                        at least one value
  -ma [MOVE_AUTOMATICALLY], --move-automatically [MOVE_AUTOMATICALLY]
                        Auto move windows to specified workspaces according to a saved session. The default session is
                        `xsession-default`
  --version             show program's version number and exit
  -v, --verbose         Print debugging information
  -vv                   Print more debugging information, could contain sensitive info

If you want to restore the previous X session automatically after login

Here is a solution. If you are using Fedora, create a file named auto-restore-working-state.desktop and the Exec should be:

xsm -pr

Then put this file into ~/.config/autostart.

For example:

[Desktop Entry]
Name=Auto Restore saved X Windows
Comment=
Icon=
Exec=xsm -pr
Terminal=false
Type=Application
X-GNOME-Autostart-Delay=20

NOTE: You can also use xsession-manager instead of xsm.

Todo:

TODO

xsession-manager's People

Contributors

nlpsuge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xsession-manager's Issues

[question] automatically xsm -s

How can I run xsm-s automatically when the system shutdown / reboot / logout?

I'm using raspberry pi OS 32bit Lite and gnome

Moving windows in an elegant way

The biggest challenge is that I can not find a way to create enough workspaces in python or in other language.

The current way which is done via gsettings is not elegant definitely and has a flaw if user prefer Dynamic Workspaces, using which setting the empty workspace will be removed automatically.

Using Static Workspaces is not perfect either due to the Gnome Shell can not add more workspaces than the maximum Number of Workspaces.

I've learned that a extension named Minimum Workspaces is exactly what I wanted. But I hope this job can be done in a standalone application.

xsm does not start on Ubuntu MATE 20.04 LTS

Steps to reproduce:

  1. Have Ubuntu MATE 20.04 LTS installed

  2. Install xsession-manager as follows:

    sudo apt-get install python3-dev wmctrl python3-pip python3-tk curl libcurl4-openssl-dev libssl-dev python-is-python3
    sudo pip3 install xsession-manager
    
  3. Try to launch it by xsm

Expected results:

  • xsm shows usage

Actual results:

  • xsm shows error as follows:

    $ xsm
    Traceback (most recent call last):
      File "/usr/local/bin/xsm", line 8, in <module>
        sys.exit(run())
      File "/usr/local/lib/python3.8/dist-packages/xsession_manager/main.py", line 10, in run
        check_login_condition()
      File "/usr/local/lib/python3.8/dist-packages/xsession_manager/main.py", line 27, in check_login_condition
        original_login_user = os.getlogin()
    OSError: [Errno 6] No such device or address
    

I'm not a Python expert, but simple searching gives the idea to change os.getlogin() โ†’ os.getenv('LOGNAME'). This fixes this bug.

Convert four assignment statements to the usage of augmented operators

๐Ÿ‘€ Some source code analysis tools can help to find opportunities for improving software components.
๐Ÿ’ญ I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/xsession_manager/arguments_handler.py b/xsession_manager/arguments_handler.py
index b023809..95fc754 100755
--- a/xsession_manager/arguments_handler.py
+++ b/xsession_manager/arguments_handler.py
@@ -170,7 +170,7 @@ class ArgumentsHandler():
                 try:
                     file_path = Path(constants.Locations.BASE_LOCATION_OF_SESSIONS, file)
                     with open(file_path, 'r') as f:
-                        num = num + 1
+                        num += 1
                         namespace_objs: XSessionConfig = json.load(f, object_hook=lambda d: Namespace(**d))
                         print(str(num) +'. ' + namespace_objs.session_name, 
                               namespace_objs.session_create_time, 
@@ -201,7 +201,7 @@ class ArgumentsHandler():
                 # Print data according to declared order
                 ordered_variables = vars(XSessionConfigObject)['__annotations__']
                 for x_session_config_object in x_session_config_objects:
-                    count = count + 1
+                    count += 1
                     print('%d.' % count)
 
                     # Get fields in declared order
diff --git a/xsession_manager/xsession_manager.py b/xsession_manager/xsession_manager.py
index ed8777e..f4ead2f 100755
--- a/xsession_manager/xsession_manager.py
+++ b/xsession_manager/xsession_manager.py
@@ -233,7 +233,7 @@ class XSessionManager:
             while Gtk.events_pending():
                 Gtk.main_iteration()
 
-            retry_count_down = retry_count_down - 1
+            retry_count_down -= 1
 
             self._suppress_log_if_already_in_workspace = True
             self.move_window(session_name)
@@ -281,7 +281,7 @@ class XSessionManager:
                         running_restores.append(index)
                         is_running = True
                         with self.instance_lock:
-                            self.restore_app_countdown = self.restore_app_countdown - 1
+                            self.restore_app_countdown -= 1
                         break
                 if is_running:
                     continue

New to xsm

I am running Mate Desktop on Rocky Linux 9 and am looking for a way to save sessions that also have multiple copies of the same window, e.g. terminal windows where the user is in different directories.

I have tried xsm but have two issues I hope I have simply missed the solution to:

  • How to save and restore sessions where there are multiple copies of the same application, e.g. terminal windows where the user is in different directories?
  • How to have the different applications restored to the Mate running application panel in the same order they were when the session was saved? In other words, not only to the correct workspace but also in the same order within each workspace?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.