Skip to main content

A declarative window instantiation utility for x11 sessions, heavily inspired by tmuxp.

Project description

xsessionp

Overview

A declarative window instantiation utility for x11 sessions, heavily inspired by tmuxp.

Compatibility

  • Tested with python 3.8

Installation

From pypi.org

$ pip install xsessionp

From source code

$ git clone https://github.com/crashvb/xsessionp
$ cd xsessionp
$ virtualenv env
$ source env/bin/activate
$ python -m pip install --editable .[dev]

Usage

TL;DR

Define a configuration file(s) declaring the desired end state:

# ~/.xsessionp/example.yml
---
desktop: 0
environment:
  xsp: makes_life_easy
windows:
- command:
  - /usr/bin/xed
  - --new-window
  copy_environment: false
  focus: true
  dimensions: 926x656
  hints:
    name: ^Unsaved Document.*
  position: 166,492
- command:
  - /usr/bin/gnome-terminal
  - --
  - tmux
  desktop: 0
  environment:
    GNOME_TERMINAL_SCREEN: ""
  dimensions: 1174x710
  hints:
    name: ^Terminal$
    class: ^\['gnome-terminal-server', 'Gnome-terminal'\]$
  position: 213,134
  shell: true
  start_directory: /tmp

A configuration can be instantiated using the load command:

$ xsp load example
Loading: /home/user/.xsessionp/example.yml

Commands

This packages makes available the xsessionp command, and the shorter xsp alias.

A listing of commands is available by executing: xsp --help. Command-specific usage is available by executing --help after the command (e.g.: xsp ls --help).

close-window

Closes a managed window(s).

$ xsp close-window --target /home/user/.xsessionp/example.yml:window[0]:262512556
Closed window: 119537674

learn

Capture metadata from a graphically selected window. Intended to assist with developing workspace configurations.

$ xsp learn
---
windows:
- command:
  - nemo
  - /home/user
  desktop: 0
  dimensions: 1667x918
  environment:
  - DBUS_SESSION_BUS_ADDRESS=unix:path /run/user/1000/bus
  hints:
    name: ^Home$
  position: 1717,264

list-windows

Lists managed windows in a given format.

$ xsp list-windows
ID         XSP:NAME                                         DESKTOP  POSITION    DIMENSIONS    NAME
119537674  /tmp/tmpqf3bcpzt/xclock.yml:window[0]:262512556  0        [25, 49]    [300, 300]    xclock
138412043  /tmp/tmpqf3bcpzt/xclock.yml:window[1]:262512711  0        [25, 399]   [300, 40]     xclock

load

Loads an xsessionp workspace for each instance of CONFIG specified.

$ xsp load example
Loading: /home/user/.xsessionp/example.yml

ls

Lists xsessionp workspace(s) discovered within each default configuration directory.

$ xsp ls
example
$ xsp ls --qualified
/home/user/.xsessionp/example.yml

reposition-window

Aligns the current position of a managed window(s) to match the embedded metadata.

$ xsp reposition-window -t /tmp/tmpqf3bcpzt/xclock.yml:window[0]:262512556
Repositioned window: 119537674

test

Perform basic acceptance tests by launching two xclock instances on the current desktop

$ xsp test
...
Loading: /tmp/tmpqf3bcpzt/xclock.yml

version

$ xsp version
x.y.z

Configuration

Any key defined at the root level (globals) will propagate to all windows as the default value for that key. Globals can be overridden in individual window configurations (locals), or omitted by added a key with a "no_" prefix (e.g.: no_dimensions). Keys with a no_ prefix have a higher precedence then those without.

command (type: list, str)

Command used to launch the window. Provided as args to subprocess.Popen.

copy_environment (type: bool, default: True)

If true, the environment of xsessionp will be used as the base for launched windows. Otherwise, and empty environment will be used instead. This does not affect values declared via environment.

desktop (type: int)

The X11 desktop to be assigned to the launched window. If not provided, desktop assignment is not performed, and defaults to the behavior of the underlying window manager.

dimensions (type: str)

The dimensions (geometry) to assigned to the launched window. Values should take the form of {width}x{height} or {width},{height}. If not provided, no sizing is performed.

disabled (type: bool, default: False)

If true, the window will not be selected when the configuration is loaded. This is intended to allow complex window configuration(s) to remain inline without needing to comment them.

environment (type Dict[str, str])

Key value pairs to be provided via the environment of the launched window. These values have precedence over the "base" environment; see copy_environment.

focus (type: bool, default: False)

If true, the window will be activated after all windows have been launched. If more than one window contains this value, the value is ignored.

hint_method (type: enum, values: AND, OR)

Boolean method by which hints are evaluated.

hints (type: Dict[str, str])

Distinguishing characteristics of the launched window that can be used to identify (guess) amongst otherwise ambiguous deltas.

Deterministically identifying the X11 window(s) that are created when a process is launched is difficult. Often the WM_PID atom is missing, or doesn't align with the PID of the process that was invoked, for various reasons. As such, a listing of X11 windows is captured both before and after the process is executed, and the difference (delta) is used to guess the correct window. If the size of the delta is equal to 1, then it is assumed to correspond to the execute process. If the size of the delta is greater than 1, then these hints are used to restrict which window is selected.

Common hints include: class, name, state, and type. Hint values are compiled into regular expression patterns prior to evaluating.

name (type: str, default: generated)

Name (xsp:name) use to select windows when the configuration is loaded, and to identify the window when executing commands.

position (type: str)

The position to assigned to the launched window. Values should take the form of {x},{y} or {x},{y}. If not provided, no positioning is performed.

search_delay (type: float, default: 0)

The amount of time, in seconds, to wait before searching for launched windows. See hints for an explanation of the methodology.

shell (type: bool, default: False)

If true, command will be executed via a shell. Provided as shell to subprocess.Popen.

snapped (type: bool, default: False)

If true, supporting window managers will be instructed to snap, rather than tile, the launched window.

start_directory (type: str, default: /)

The working directory of the launched window. Provided as cwd to subprocess.Popen.

start_timeout (type: int, default: 3)

The maximum amount of time, in seconds, to wait for launched windows to be visible, prior to sizing and positioning.

tile (type: str)

Mode to use when tiling the launched window. Tiling occurs after window sizing and positioning. If not specified, no tiling is performed.

Supported Tiling Modes

Linux Mint Cinnamon: BOTTOM, LEFT, LEFT_BOTTOM, LEFT_TOP, MAXIMIZE, NONE, RIGHT, RIGHT_BOTTOM, RIGHT_TOP, TOP

Environment Variables

Variable Default Value Description
XSESSIONP_CONFIGDIR ~/.xsessionp xsessionp configuration directory.

Development

Source Control

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xsessionp-0.1.2.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

xsessionp-0.1.2-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

Details for the file xsessionp-0.1.2.tar.gz.

File metadata

  • Download URL: xsessionp-0.1.2.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.3

File hashes

Hashes for xsessionp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5b4776203583a5bbfbd6b19d1b2042ace2ab232e248ddaca78472f39c35f149e
MD5 585e9463cad13bb24a6d3606c560f891
BLAKE2b-256 281a7e5818d6cbdfc69300628ba1027f1e060c202916e65882f89b24fea5d6d7

See more details on using hashes here.

File details

Details for the file xsessionp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: xsessionp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.3

File hashes

Hashes for xsessionp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b2a2034084129e89015612aeae5707a3084d40b558cf638008b2c9c075191d1
MD5 72ec3a561c2be60cedec201c35cfa2be
BLAKE2b-256 5860260cb8959136109b318eb0d0899e08a1d23512ea29bcf3991baf54c492f6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page