From 4d513748011529d0a6d911fbdebcfe3c41b22e1c Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sat, 10 Oct 2026 18:52:07 +0200 Subject: [PATCH] Add movie mode for watching videos on the external monitor The screen layout and trayer setup moved from xmonad.hs to a shared screen-layout script. lf opens videos with movie. --- .config/lf/lfrc | 1 + .config/xmonad/xmonad.hs | 20 ++++---------------- .local/bin/movie | 14 ++++++++++++++ .local/bin/screen-layout | 21 +++++++++++++++++++++ 4 files changed, 40 insertions(+), 16 deletions(-) create mode 100755 .local/bin/movie create mode 100755 .local/bin/screen-layout diff --git a/.config/lf/lfrc b/.config/lf/lfrc index a33a374..8d1e405 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -38,6 +38,7 @@ cmd open &{{ case $(file --mime-type -Lb $f) in text/*) lf -remote "send $id \$$EDITOR \$fx";; application/json) lf -remote "send $id \$$EDITOR \$fx";; + video/*) movie $fx > /dev/null 2> /dev/null;; *) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;; esac }} diff --git a/.config/xmonad/xmonad.hs b/.config/xmonad/xmonad.hs index 6fadfd2..404bbc8 100644 --- a/.config/xmonad/xmonad.hs +++ b/.config/xmonad/xmonad.hs @@ -68,30 +68,18 @@ myScreenshotDir = "/home/fuxino/Pictures/Screenshots/" myScreenshotName :: String myScreenshotName = "Screenshot-%Y-%m-%d-%H%M%S.png" --- Sets up the outputs and the wallpaper, and leaves the tray's monitor in $tray +-- Sets up the outputs, the wallpaper and trayer; shared with ~/.local/bin/movie myScreenLayout :: String -myScreenLayout = - "if xrandr --query | grep -q '^HDMI-1-0 connected'; then" - ++ " xrandr --output HDMI-1-0 --preferred --primary --output eDP-1 --right-of HDMI-1-0 --preferred; tray=1;" - ++ " else xrandr --output eDP-1 --preferred --primary --output HDMI-1-0 --off; tray=0; fi" - ++ "; ~/.fehbg" - --- Replaces any running trayer, so there's never more than one -myTrayer :: String -myTrayer = - "pkill -x trayer; while pgrep -x trayer > /dev/null; do sleep 0.1; done; \ - \trayer -l --edge top --align right --SetDockType true \ - \--SetPartialStrut true --expand true --widthtype request \ - \--tint 0x232634 --height 18 --monitor $tray" +myScreenLayout = "/home/fuxino/.local/bin/screen-layout" -- Safe to re-run (e.g. spawnOnce after this string changes and xmonad restarts) myScreenSetup :: String myScreenSetup = - "sleep 1; " ++ myScreenLayout ++ "; pgrep -x picom > /dev/null || picom -b -c; " ++ myTrayer + "sleep 1; " ++ myScreenLayout ++ "; pgrep -x picom > /dev/null || picom -b -c" -- Run when a monitor is (dis)connected; restarts trayer so it moves to the right screen myScreenHotplug :: String -myScreenHotplug = myScreenLayout ++ "; " ++ myTrayer +myScreenHotplug = myScreenLayout myScratchpads :: [NamedScratchpad] myScratchpads = diff --git a/.local/bin/movie b/.local/bin/movie new file mode 100755 index 0000000..8be5852 --- /dev/null +++ b/.local/bin/movie @@ -0,0 +1,14 @@ +#!/bin/bash +# Plays videos on the external monitor only, with the laptop screen off. +# Opened from lf for video/* files; restores the normal layout when mpv exits. + +# Single-screen mode only makes sense with the external monitor plugged in +if ! xrandr --query | grep -q '^HDMI-1-0 connected'; then + exec mpv "$@" +fi + +trap ~/.local/bin/screen-layout EXIT +trap 'exit 130' INT TERM HUP + +xrandr --output eDP-1 --off +mpv "$@" diff --git a/.local/bin/screen-layout b/.local/bin/screen-layout new file mode 100755 index 0000000..3602ff5 --- /dev/null +++ b/.local/bin/screen-layout @@ -0,0 +1,21 @@ +#!/bin/bash +# Sets up the outputs, wallpaper and trayer for whatever monitors are connected. +# Called by xmonad at startup and on monitor (dis)connect, and by `movie` on exit. + +if xrandr --query | grep -q '^HDMI-1-0 connected'; then + xrandr --output HDMI-1-0 --preferred --primary --output eDP-1 --right-of HDMI-1-0 --preferred + tray=1 +else + xrandr --output eDP-1 --preferred --primary --output HDMI-1-0 --off + tray=0 +fi + +~/.fehbg + +# Replace any running trayer, so there's never more than one +pkill -x trayer +while pgrep -x trayer > /dev/null; do sleep 0.1; done +trayer -l --edge top --align right --SetDockType true \ + --SetPartialStrut true --expand true --widthtype request \ + --tint 0x232634 --height 18 --monitor "$tray" > /dev/null 2>&1 & +disown