Support launching with `systemd-run`

Runs in a user scope via `systemd-run --user --scope`.
This commit is contained in:
James Reed 2020-08-19 12:36:08 -06:00
parent da2caa7315
commit da7b3c31de
No known key found for this signature in database
GPG Key ID: 0BE2BD33C5E8125E
5 changed files with 21 additions and 14 deletions

View File

@ -93,10 +93,11 @@ usage: awesome-launch [options] COMMAND...
options: options:
-h Show help message -h Show help message
-s Launch with systemd-run
-j Launch with firejail -j Launch with firejail
-f FACTORY Launch via a window factory -f FACTORY Launch via a window factory
-i ID The single instance ID to use -i ID The single instance ID to use
-s Spawn if not already running -1 Spawn if not already running
-r Raise or spawn -r Raise or spawn
``` ```

View File

@ -7,10 +7,11 @@ usage() {
options: options:
-h Show help message -h Show help message
-s Launch with systemd-run
-j Launch with firejail -j Launch with firejail
-f FACTORY Launch via a window factory -f FACTORY Launch via a window factory
-i ID The single instance ID to use -i ID The single instance ID to use
-s Spawn if not already running -1 Spawn if not already running
-r Raise or spawn' -r Raise or spawn'
} }
@ -19,14 +20,15 @@ usage_error() {
exit 2 exit 2
} }
while getopts ':hjf:i:sr' opt; do while getopts ':hsjf:i:1r' opt; do
case "$opt" in case "$opt" in
h) usage; exit ;; h) usage; exit ;;
s) systemd=true ;;
j) firejail=true ;; j) firejail=true ;;
f) factory="$OPTARG" ;; f) factory="$OPTARG" ;;
i) id="$OPTARG" ;; i) id="$OPTARG" ;;
s) func='s' ;; 1) func='spawn.single_instance' ;;
r) func='r' ;; r) func='spawn.raise_or_spawn' ;;
*) usage_error *) usage_error
esac esac
done done
@ -35,17 +37,12 @@ shift $((OPTIND - 1))
[ $# -eq 0 ] && usage_error [ $# -eq 0 ] && usage_error
case "${func-}" in
s) name='spawn.single_instance' ;;
r) name='spawn.raise_or_spawn' ;;
*) name='spawn'
esac
awesome-client " awesome-client "
args = { args = {
${id+id = '$id',} ${id+id = '$id',}
${systemd+systemd = '$systemd',}
${firejail+firejail = '$firejail',} ${firejail+firejail = '$firejail',}
${factory+factory = '$factory',} ${factory+factory = '$factory',}
} }
require('awesome-launch').$name('$*', args) require('awesome-launch').${func-spawn}('$*', args)
" "

View File

@ -95,6 +95,7 @@ end
-- @param args.timeout Seconds after which to stop waiting for a client to spawn. -- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns. -- @param args.callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag). -- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.systemd If true, run cmd with systemd-run.
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @return The client's ID. -- @return The client's ID.
-- @function launch.spawn -- @function launch.spawn
@ -140,6 +141,10 @@ local function spawn(cmd, args)
launch_cmd = launch_cmd .. " -f " .. args.factory launch_cmd = launch_cmd .. " -f " .. args.factory
end end
if args.systemd then
launch_cmd = launch_cmd .. " -s"
end
if args.firejail then if args.firejail then
launch_cmd = launch_cmd .. " -j" launch_cmd = launch_cmd .. " -j"
end end
@ -173,6 +178,7 @@ setmetatable(launch.spawn, {__call = function (_, ...) spawn(...) end})
-- @param args.timeout Seconds after which to stop waiting for a client to spawn. -- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns. -- @param args.callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag). -- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.systemd If true, run cmd with systemd-run.
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered. -- @param args.filter Function to filter clients that are considered.
-- @return The client's ID. -- @return The client's ID.
@ -199,6 +205,7 @@ end
-- @param args.callback Function to call with client when it spawns. -- @param args.callback Function to call with client when it spawns.
-- @param args.raise_callback Function to call with client when it spawns or is raised. -- @param args.raise_callback Function to call with client when it spawns or is raised.
-- @param args.factory The factory to use (see wm-launch's -f flag). -- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.systemd If true, run cmd with systemd-run.
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered. -- @param args.filter Function to filter clients that are considered.
-- @return The client's ID. -- @return The client's ID.

View File

@ -1,7 +1,7 @@
--- Launch clients as panels. --- Launch clients as panels.
-- --
-- @author James Reed <jcrd@tuta.io> -- @author James Reed <jcrd@tuta.io>
-- @copyright 2019 James Reed -- @copyright 2019-2020 James Reed
-- @module awesome-launch.panel -- @module awesome-launch.panel
local awful = require("awful") local awful = require("awful")
@ -49,6 +49,7 @@ end
-- @param args.timeout Seconds after which to stop waiting for a client to spawn. -- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns. -- @param args.callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag). -- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.systemd If true, run cmd with systemd-run.
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered. -- @param args.filter Function to filter clients that are considered.
-- @param args.scale Percent to scale client (see awful.placement.scale). -- @param args.scale Percent to scale client (see awful.placement.scale).

View File

@ -1,7 +1,7 @@
--- Create new workspaces and launch accompanying clients. --- Create new workspaces and launch accompanying clients.
-- --
-- @author James Reed <jcrd@tuta.io> -- @author James Reed <jcrd@tuta.io>
-- @copyright 2019 James Reed -- @copyright 2019-2020 James Reed
-- @module awesome-launch.workspace -- @module awesome-launch.workspace
local awful = require("awful") local awful = require("awful")
@ -105,6 +105,7 @@ end
-- @param args.timeout Seconds after which to stop waiting for a client to spawn. -- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns. -- @param args.callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag). -- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.systemd If true, run cmd with systemd-run.
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @param tag The tag. -- @param tag The tag.
-- @function client.add -- @function client.add