dotfiles/mpv/.local/bin/umpv
Marty Oehme 6ac552d3d5
Switch to wayland
Added a simple wayland configuration.
Currently set up simple wayland configuration based on river window
manager and waybar.
Rivercarro is the layout manager, being the same in principle as rivertile,
the default layout manager for river, only it comes with smart gaps
(gaps turn off if there is only one window open)
and monocle mode (give one window all space).

Runs `keyd` in the background to replace the old `xcape` capslock switching
(capslock is escape and if held control).
Uses `swaybg` to set a wallpaper.

Added powermenu and lockscreen scripts.
Improved lockscreen script to detect and work for wayland.
Moved old rofi mode 'powermenu' to more general powermenu script,
which works with any rofi-like selector (dmenu, bemenu, wofi, etc.)
Loses some of its design quality but since it was wonky anyway,
and I rarely see the menu,
we could repurpose its functionality for a more general powermenu
concept.
Currently hardcoded for `bemenu` but can be easily swapped and possibly
even extended back to rofi.
Fixed file upload link sharing to clipboard.

Updated rofi-pass to pass-pick.
Made rofi-pass universal and less integrated to rofi - that's also the
reason for the name change.
`pass-pick` works with rofi (default), bemenu or dmenu. In theory it
should also work with any other picker that contains a stdin listing
function similar to dmenu.
It has been definitely tested both on rofi and bemenu.
The best user experience still reigns on rofi, where available keys are
displayed on the picker and the keys themselves make the most sense.
But all functions can be reached from bemenu as well, though the key
mappings are more arbitrary and can not be changed as in rofi.
The autofilling tool works with both xdotool and ydotool, so should work
both on X11 and on Wayland. Ydotool ideally requires its daemon to be
running, otherwise some of the typing may get gut off. Otherwise no
change should be necessary.

Updated qutebrowser open_download for bemenu.
Updated download opening script to work with both rofi and bemenu.
Prefers original rofi implementation but works with both, and can be set
to use a custom dmenu-like file picker as well.

Add brightnessctl and removed custom audio / brightness scripts since they
became unnecessary.

Updated bootstrap script to include system files:
With `keyd` taking its configuration from the `/etc` directory and not
home, a second stow stage was necessary. These stow files are in a
module called `system-packages` inside the top-level `bootstrap` stow
package.
They will not be installed by the default dotfile stow invocation but
have been integrated as an extra step into the install script.
Installing this module requires sudo privileges!

Switched vifm überzug to sixel graphics rendering.
überzug relies on X11 functionality to work, while sixel does not.
Unfortunately, alacritty does not work with sixel graphics yet, only
foot does (somewhat).

Waybar currently runs the gruvbox dark soft color scheme.
Added the old polybar archupdates script to waybar and extended it to
output json format with additional metadata that waybar can read.
Can still output the old plaintext format that polybar expects.
Added a wireguard connection to waybar,shows if currently
connected to either a wireguard or tun VPN service.
If so, shows an icon in the waybar - that can be hovered over to show
the full assigned IP address.
Added an upcoming event display to waybar,
a simple event indicator to show upcoming events on the calendar, on
hovering over it the tooltip lists all upcoming events.

Added `screenshot` script to take simple screenshots and
rectangle region shots of the current output.
Can be invoked through the river shortcut PrintScr:
`PrintScr` - Fullscreen screenshot
`Mod+PrintScr` - Region screenshot
`Shift+PrintScr` - Fullscreen screenshot and file upload
`Mod+Shift+PrintScr` - Region screenshot and file upload

Extended `sharefile` to take paths through stdin and make
use of `fd` if it is found on the system.
2021-11-30 22:30:07 +01:00

104 lines
3.4 KiB
Python
Executable file

#!/usr/bin/env python3
"""
This script emulates "unique application" functionality on Linux. When starting
playback with this script, it will try to reuse an already running instance of
mpv (but only if that was started with umpv). Other mpv instances (not started
by umpv) are ignored, and the script doesn't know about them.
This only takes filenames as arguments. Custom options can't be used; the script
interprets them as filenames. If mpv is already running, the files passed to
umpv are appended to mpv's internal playlist. If a file does not exist or is
otherwise not playable, mpv will skip the playlist entry when attempting to
play it (from the GUI perspective, it's silently ignored).
If mpv isn't running yet, this script will start mpv and let it control the
current terminal. It will not write output to stdout/stderr, because this
will typically just fill ~/.xsession-errors with garbage.
mpv will terminate if there are no more files to play, and running the umpv
script after that will start a new mpv instance.
Note: you can supply custom mpv path and options with the MPV environment
variable. The environment variable will be split on whitespace, and the
first item is used as path to mpv binary and the rest is passed as options
_if_ the script starts mpv. If mpv is not started by the script (i.e. mpv
is already running), this will be ignored.
"""
import sys
import os
import socket
import errno
import subprocess
import string
files = sys.argv[1:]
# this is the same method mpv uses to decide this
def is_url(filename):
parts = filename.split("://", 1)
if len(parts) < 2:
return False
# protocol prefix has no special characters => it's an URL
allowed_symbols = string.ascii_letters + string.digits + "_"
prefix = parts[0]
return all(map(lambda c: c in allowed_symbols, prefix))
# make them absolute; also makes them safe against interpretation as options
def make_abs(filename):
if not is_url(filename):
return os.path.abspath(filename)
return filename
files = [make_abs(f) for f in files]
SOCK = os.path.join(str(os.getenv("HOME")), ".umpv_socket")
sock = None
try:
sock = socket.socket(socket.AF_UNIX)
sock.connect(SOCK)
except socket.error as e:
if e.errno == errno.ECONNREFUSED:
sock = None
pass # abandoned socket
elif e.errno == errno.ENOENT:
sock = None
pass # doesn't exist
else:
raise e
if sock:
# Unhandled race condition: what if mpv is terminating right now?
for f in files:
# escape: \ \n "
f = f.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
f = '"' + f + '"'
sock.send(("raw loadfile " + f + " append\n").encode("utf-8"))
else:
# Let mpv recreate socket if it doesn't already exist.
opts = (os.getenv("MPV") or "mpv").split()
opts.extend(
[
"--no-terminal",
"--force-window",
"--input-ipc-server=" + SOCK,
# position on lower left screen corner
# contains funky fix for slight resizings depending on video
# move it 10px more left than it wants; 5px more up
"--geometry=15%+-10-+5",
"--on-all-workspaces",
"--force-window=immediate",
"--x11-name=float",
"--wayland-app-id=float",
"--",
]
)
opts.extend(files)
subprocess.check_call(opts)