os:linux:general:auto-win
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
os:linux:general:auto-win [2024/07/19 15:59] – created jay | os:linux:general:auto-win [2024/07/19 18:08] (current) – [Prerequisites] jay | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Automatically Adjust Your Window Positions ====== | ====== Automatically Adjust Your Window Positions ====== | ||
+ | ===== Overview ===== | ||
+ | I often plug my work laptop into different monitors, or sets of monitors, and this means that I have rearrange my windows each time I plug/unplug monitors. | ||
+ | ===== Prerequisites ===== | ||
+ | The first, and most important, prerequisite is that **you must be using X11, and NOT Wayland**. | ||
+ | |||
+ | ==== Packages ==== | ||
+ | You must ensure you have the following packages installed: | ||
+ | |||
+ | * **xwininfo**: | ||
+ | * **wmctrl**: | ||
+ | * **edid-decode**: | ||
+ | |||
+ | There are 2 Python scripts included (below), but neither of them have any dependencies beyond the standard library. | ||
+ | |||
+ | ==== The Files ==== | ||
+ | All the files you will need for this are available here: {{ : | ||
+ | |||
+ | In there you will find the following files: | ||
+ | |||
+ | * **adjwin.py**: | ||
+ | * **adjwin.json**: | ||
+ | * **auto-win.py**: | ||
+ | * **adjwin.service**: | ||
+ | * **adjwin.timer**: | ||
+ | |||
+ | ===== Installing the Files ===== | ||
+ | This is basically just a matter of copying the files into their proper locations. | ||
+ | |||
+ | ==== The Scripts ==== | ||
+ | These are pretty simple. | ||
+ | |||
+ | ==== The Systemd User Files ==== | ||
+ | These are also simple. | ||
+ | |||
+ | <code bash> | ||
+ | cp adjwin.service adjwin.timer ~/ | ||
+ | </ | ||
+ | |||
+ | ==== The Config ==== | ||
+ | I've included my config as an example/ | ||
+ | |||
+ | <code bash> | ||
+ | # Note the " | ||
+ | cp adjwin.json ~/ | ||
+ | </ | ||
+ | |||
+ | ===== Configuration ===== | ||
+ | I'm not going to lie, this is going to be the most painful part of this, but you should only have to do this once for each of your monitor configs. | ||
+ | |||
+ | ==== Config Structure ==== | ||
+ | Again, this is a JSON file to avoid dependencies. Therefore, I would highly recommend using some sort of JSON editor for this. VSCode works pretty well, as does good ol' '' | ||
+ | |||
+ | The structure of the file is as follows. | ||
+ | |||
+ | <code json> | ||
+ | { | ||
+ | " | ||
+ | "built in": { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | "< | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | ... | ||
+ | ], | ||
+ | "< | ||
+ | ... | ||
+ | ] | ||
+ | }, | ||
+ | "< | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | ... | ||
+ | ], | ||
+ | "< | ||
+ | ... | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | I'm going to come back to the '' | ||
+ | |||
+ | ==== Window Configurations ==== | ||
+ | As you can see, you can configure multiple window configurations. | ||
+ | |||
+ | First, you'll likely want a configuration for your laptop itself, which we'll call " | ||
+ | |||
+ | < | ||
+ | xwininfo: Window id: 0x2800192 " | ||
+ | |||
+ | Absolute upper-left X: 3173 | ||
+ | Absolute upper-left Y: 49 | ||
+ | Relative upper-left X: 3173 | ||
+ | Relative upper-left Y: 49 | ||
+ | Width: 1744 | ||
+ | Height: 1382 | ||
+ | Depth: 32 | ||
+ | Visual: 0x5bb | ||
+ | Visual Class: TrueColor | ||
+ | Border width: 0 | ||
+ | Class: InputOutput | ||
+ | Colormap: 0x2800003 (not installed) | ||
+ | Bit Gravity State: NorthWestGravity | ||
+ | Window Gravity State: NorthWestGravity | ||
+ | Backing Store State: NotUseful | ||
+ | Save Under State: no | ||
+ | Map State: IsViewable | ||
+ | Override Redirect State: no | ||
+ | Corners: | ||
+ | -geometry 1744x1382+3173+49 | ||
+ | </ | ||
+ | |||
+ | The bits we're interested in here are the " | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Note that the " | ||
+ | |||
+ | Also note that the " | ||
+ | |||
+ | Now, you can actually test this. Move and/or resize that window, then run the following (after saving your config file): | ||
+ | |||
+ | <code bash> | ||
+ | adjwin.py laptop | ||
+ | </ | ||
+ | |||
+ | Your window should move/resize right back to where it was. Note that you don't //have to// automate this and can just create your configs and manually run '' | ||
+ | |||
+ | Now, just add any other windows to your laptop configuration and/or create other named window configs. | ||
+ | |||
+ | ==== Configuring for '' | ||
+ | This part of the configuration is about the '' | ||
+ | |||
+ | There is one special part of the '' | ||
+ | |||
+ | You should get some output like this: | ||
+ | |||
+ | < | ||
+ | Found the following monitors: | ||
+ | Monitor(manufacturer=' | ||
+ | Monitor(manufacturer=' | ||
+ | Monitor(manufacturer=' | ||
+ | </ | ||
+ | |||
+ | We're going to use that info in our '' | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | "built in": { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | }, | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | ... | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | As noted above, the "built in" section refers to the monitor built in to your laptop. | ||
+ | |||
+ | The " | ||
+ | |||
+ | ==== Systemd Config ==== | ||
+ | There is one small change you need to make to the included '' | ||
+ | |||
+ | After that, we just need to run a a couple of commands to enable the timer. | ||
+ | |||
+ | <code bash> | ||
+ | systemctl --user daemon-reload | ||
+ | systemctl --user enable adjwin.timer | ||
+ | systemctl --user start adjwin.timer | ||
+ | </ | ||
+ | |||
+ | That's it. Every 2 seconds '' |
os/linux/general/auto-win.1721404772.txt.gz · Last modified: 2024/07/19 15:59 by jay