From ae691bb02576741667bc93b8e5be3d19d6b38d48 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 19 Jan 2020 18:36:36 +0100 Subject: [PATCH] systemd: tentative to manage session with systemd To me, I think it was cleaner to have a parameter with the current display. This way, the session is specific to the current display. It seems BindsTo doesn't think this way. --- README.md | 5 ----- bin/compton | 8 ------- bin/xsettingsd-setup | 9 +------- bin/xss-lock | 4 ++-- rc.lua | 1 - rc/start.lua | 11 ---------- rc/xrun.lua | 36 -------------------------------- systemd/autorandr@.service | 12 +++++++++++ systemd/awesome@.service | 12 +++++++++++ systemd/compton@.service | 14 +++++++++++++ systemd/inputplug@.service | 12 +++++++++++ systemd/misc-x@.service | 13 ++++++++++++ systemd/nm-applet@.service | 10 +++++++++ systemd/policykit-agent@.service | 10 +++++++++ systemd/redshift@.service | 10 +++++++++ systemd/xiccd@.service | 10 +++++++++ systemd/xsession@.target | 3 +++ systemd/xsettingsd@.service | 10 +++++++++ systemd/xss-lock@.service | 10 +++++++++ xsession | 14 +++---------- 20 files changed, 132 insertions(+), 82 deletions(-) delete mode 100755 bin/compton delete mode 100644 rc/xrun.lua create mode 100644 systemd/autorandr@.service create mode 100644 systemd/awesome@.service create mode 100644 systemd/compton@.service create mode 100644 systemd/inputplug@.service create mode 100644 systemd/misc-x@.service create mode 100644 systemd/nm-applet@.service create mode 100644 systemd/policykit-agent@.service create mode 100644 systemd/redshift@.service create mode 100644 systemd/xiccd@.service create mode 100644 systemd/xsession@.target create mode 100644 systemd/xsettingsd@.service create mode 100644 systemd/xss-lock@.service diff --git a/README.md b/README.md index bd4e496..6e62775 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,6 @@ Here some of the things you may be interested in: - It is modular. I am using `config` as a table to pass different things between "modules". - - In `rc/xrun.lua`, there is a `xrun` function which runs a program - only if it is not already running. Instead of relying on tools like - `ps`, it looks at the list of awesome clients and at the list of - connected clients with `xwininfo`. Seems reliable. - - I use a light transparency effect to tell if a window has the focus or not. It needs a composite manager. diff --git a/bin/compton b/bin/compton deleted file mode 100755 index df8034d..0000000 --- a/bin/compton +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -exec compton \ - --backend glx \ - --xrender-sync \ - --xrender-sync-fence \ - --vsync opengl-swc \ - --paint-on-overlay diff --git a/bin/xsettingsd-setup b/bin/xsettingsd-setup index 571c3a5..b11d0bf 100755 --- a/bin/xsettingsd-setup +++ b/bin/xsettingsd-setup @@ -9,9 +9,6 @@ case $(hostname),$(autorandr --current --skip-options gamma) in *,*) dpi=96 ;; esac -# Get xsettingsd PID -pid=$(xprop -name xsettingsd _NET_WM_PID 2> /dev/null | awk '{print $NF}') - change() { # Build xsettingsd.local { @@ -23,11 +20,7 @@ change() { } > ~/.xsettingsd # Signal xsettingsd - if [ x"$pid" = x ]; then - xsettingsd -c ~/.xsettingsd & - else - kill -HUP $pid - fi + systemctl --user reload xsettingsd@$(systemd-escape -- "$DISPLAY").service # Also use xrdb for very old stuff (you know, LibreOffice) echo Xft.dpi: $dpi | xrdb -merge diff --git a/bin/xss-lock b/bin/xss-lock index af548e9..4b96923 100755 --- a/bin/xss-lock +++ b/bin/xss-lock @@ -42,9 +42,9 @@ case "$1" in xdotool key XF86AudioStop # Then, lock screen echo "$(date --rfc-3339=seconds) $me: lock: lock screen" - pkill compton + systemctl --user stop compton@$(systemd-escape -- "$DISPLAY").service i3lock -n -e -i $HOME/.cache/awesome/current-wallpaper.png -t -f - ~/.config/awesome/bin/compton & + systemctl --user start compton@$(systemd-escape -- "$DISPLAY").service echo "$(date --rfc-3339=seconds) $me: lock: unlock screen" ;; esac diff --git a/rc.lua b/rc.lua index 3c3e2cf..eaf183c 100644 --- a/rc.lua +++ b/rc.lua @@ -61,7 +61,6 @@ config.hostname = awful.util.pread('uname -n'):gsub('\n', '') config.browser = "firefox" -- Remaining modules -loadrc("xrun") -- xrun function loadrc("appearance") -- theme and appearance settings loadrc("debug") -- debugging primitive `dbg()` diff --git a/rc/start.lua b/rc/start.lua index fa2418b..6d50edc 100644 --- a/rc/start.lua +++ b/rc/start.lua @@ -1,11 +1,5 @@ -- Start idempotent commands local execute = { - -- Kill any running nm-applet - "pkill nm-applet", - -- Start PulseAudio - "xset -b", -- Disable bell - -- Enable numlock - "numlockx on", -- Default browser "xdg-mime default " .. config.browser .. ".desktop " .. "x-scheme-handler/http " .. @@ -17,8 +11,3 @@ local execute = { } os.execute(table.concat(execute, ";")) - --- Spawn various X programs -xrun("polkit-gnome-authentication-agent-1", - "/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1") -xrun("NetworkManager Applet", "nm-applet") diff --git a/rc/xrun.lua b/rc/xrun.lua deleted file mode 100644 index 2d4f94f..0000000 --- a/rc/xrun.lua +++ /dev/null @@ -1,36 +0,0 @@ --- run a command only if the client does not already exist - -local xrun_now = function(name, cmd) - -- Try first the list of clients from awesome (which is available - -- only if awesome has fully started, therefore, this function - -- should be run inside a 0 timer) - local squid = { name, name:sub(1,1):upper() .. name:sub(2) } - if awful.client.cycle( - function(c) - return awful.rules.match_any(c, - { name = squid, - class = squid, - instance = squid }) - end)() then - return - end - - -- Not found, let's check with xwininfo. We can only check name but - -- we can catch application without a window... - if os.execute("xwininfo -name '" .. name .. "' > /dev/null 2> /dev/null") == 0 then - return - end - awful.util.spawn(cmd or name, false) -end - --- Run a command if not already running. -xrun = function(name, cmd) - -- We need to wait for awesome to be ready. Hence the timer. - local stimer = timer { timeout = 0 } - local run = function() - stimer:stop() - xrun_now(name, cmd) - end - stimer:add_signal("timeout", run) - stimer:start() -end diff --git a/systemd/autorandr@.service b/systemd/autorandr@.service new file mode 100644 index 0000000..72cbfd6 --- /dev/null +++ b/systemd/autorandr@.service @@ -0,0 +1,12 @@ +[Unit] +Description=Configure displays +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/autorandr --change --default default +Type=oneshot +RemainAfterExit=false + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/awesome@.service b/systemd/awesome@.service new file mode 100644 index 0000000..6f6183d --- /dev/null +++ b/systemd/awesome@.service @@ -0,0 +1,12 @@ +[Unit] +Description=Awesome window manager +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/awesome +ExecStopPost=/bin/systemctl --user stop graphical-session@%i.target +Restart=on-failure + +[Install] +RequiredBy=xsession@%i.target diff --git a/systemd/compton@.service b/systemd/compton@.service new file mode 100644 index 0000000..bbcb6c4 --- /dev/null +++ b/systemd/compton@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Compositor for X11 +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/compton --backend glx \ + --xrender-sync \ + --xrender-sync-fence \ + --vsync opengl-swc \ + --paint-on-overlay + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/inputplug@.service b/systemd/inputplug@.service new file mode 100644 index 0000000..bd9e0fb --- /dev/null +++ b/systemd/inputplug@.service @@ -0,0 +1,12 @@ +[Unit] +Description=XInput event monitor +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStartPre=/usr/bin/setxkbmap us +ExecStart=%h/bin/inputplug -0 -c %h/.config/awesome/bin/input-event +Type=forking + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/misc-x@.service b/systemd/misc-x@.service new file mode 100644 index 0000000..f4dc161 --- /dev/null +++ b/systemd/misc-x@.service @@ -0,0 +1,13 @@ +[Unit] +Description=Miscellaneous settings for X11 +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/xset -b +ExecStart=/usr/bin/numlock on +Type=oneshot +RemainAfterExit=false + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/nm-applet@.service b/systemd/nm-applet@.service new file mode 100644 index 0000000..bd2e4d3 --- /dev/null +++ b/systemd/nm-applet@.service @@ -0,0 +1,10 @@ +[Unit] +Description=Network Manager applet +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/nm-applet + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/policykit-agent@.service b/systemd/policykit-agent@.service new file mode 100644 index 0000000..a4ec080 --- /dev/null +++ b/systemd/policykit-agent@.service @@ -0,0 +1,10 @@ +[Unit] +Description=PolicyKit authentication agent +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1 + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/redshift@.service b/systemd/redshift@.service new file mode 100644 index 0000000..a05fec4 --- /dev/null +++ b/systemd/redshift@.service @@ -0,0 +1,10 @@ +[Unit] +Description=Set color temperature +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/redshift -l 2.35:48.87 -t 6500:3900 + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/xiccd@.service b/systemd/xiccd@.service new file mode 100644 index 0000000..13ecf0b --- /dev/null +++ b/systemd/xiccd@.service @@ -0,0 +1,10 @@ +[Unit] +Description=X color management +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/xiccd --edid + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/xsession@.target b/systemd/xsession@.target new file mode 100644 index 0000000..8cc0adc --- /dev/null +++ b/systemd/xsession@.target @@ -0,0 +1,3 @@ +[Unit] +Description=X session managed by systemd +BindsTo=graphical-session@%i.target diff --git a/systemd/xsettingsd@.service b/systemd/xsettingsd@.service new file mode 100644 index 0000000..a05e6fc --- /dev/null +++ b/systemd/xsettingsd@.service @@ -0,0 +1,10 @@ +[Unit] +Description=XSETTINGS daemon +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=/usr/bin/xsettingsd -c %h/.xsettingsd + +[Install] +WantedBy=graphical-session@%i.target diff --git a/systemd/xss-lock@.service b/systemd/xss-lock@.service new file mode 100644 index 0000000..f217d27 --- /dev/null +++ b/systemd/xss-lock@.service @@ -0,0 +1,10 @@ +[Unit] +Description=Manage X screen saver +PartOf=graphical-session@%i.target + +[Service] +Environment=DISPLAY=%I +ExecStart=%h/.config/awesome/bin/xss-lock start + +[Install] +WantedBy=graphical-session@%i.target diff --git a/xsession b/xsession index 808db4f..46db962 100644 --- a/xsession +++ b/xsession @@ -21,14 +21,6 @@ export QT_AUTO_SCREEN_SCALE_FACTOR=1 systemctl --user import-environment systemd-run -q --scope --user tmux start-server - -autorandr --change -~/.config/awesome/bin/xsettingsd-setup -~/.config/awesome/bin/compton & -~/.config/awesome/bin/xss-lock start & -xiccd --edid & -setxkbmap us -inputplug -0 -c ~/.config/awesome/bin/input-event 2> /dev/null -redshift -l 2.35:48.87 -t 6500:3900 2> /dev/null & - -exec awesome +mkdir -p ~/.config/systemd +ln -nsf ~/.config/awesome/systemd ~/.config/systemd/user +exec systemctl --user start --wait xsession@$(systemd-escape -- "$DISPLAY").target