Skip to content

Commit ded1a15

Browse files
committed
Change set up of service/desktop app
1 parent a03d34f commit ded1a15

File tree

2 files changed

+98
-96
lines changed

2 files changed

+98
-96
lines changed

README.md

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -154,60 +154,63 @@ if needed. If you have multiple touchpads you can also specify
154154

155155
### STARTING AND STOPPING
156156

157-
Start the application immediately in the background using the command
158-
line utility:
157+
You must choose between starting the application as a [systemd user
158+
service](https://wiki.archlinux.org/index.php/Systemd/User), or as a
159+
[desktop
160+
application](https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html)
161+
(with an XDG compliant DE such as GNOME and KDE). The systemd user service
162+
option for `libinput-gestures` was added in Feb 2021 and provides more
163+
robust management and better logging than the desktop so is now the preferred choice.
164+
Choose one of the two following options:
159165

160-
libinput-gestures-setup start
166+
1. To set up the application as a [systemd user
167+
service](https://wiki.archlinux.org/index.php/Systemd/User):
161168

162-
You can stop the background app with:
169+
````
170+
libinput-gestures-setup service
171+
````
163172

164-
libinput-gestures-setup stop
173+
2. Or instead, to set up the application using your
174+
[DE](https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html):
175+
176+
````
177+
libinput-gestures-setup desktop
178+
````
165179

166-
You can enable the app to start automatically in the background when you
167-
log in (on an XDG compliant DE such as GNOME and KDE) with:
180+
After *choosing one of the above*, you can use then run the following commands:
181+
182+
Enable the app to start automatically in the background when you
183+
log in with:
168184

169185
libinput-gestures-setup autostart
170186

171-
You can disable the app from starting automatically with:
187+
Disable the app from starting automatically with:
172188

173189
libinput-gestures-setup autostop
174190

175-
You can restart the app or reload the configuration file with:
191+
Start the app immediately in the background:
192+
193+
libinput-gestures-setup start
194+
195+
Stop the background app immediately with:
196+
197+
libinput-gestures-setup stop
198+
199+
Restart the app, e.g. to reload the configuration file, with:
176200

177201
libinput-gestures-setup restart
178202

179-
You can check the status of the app with:
203+
Check the status of the app with:
180204

181205
libinput-gestures-setup status
182206

183-
Note on some uncommon systems `libinput-gestures-setup start` may fail
207+
Note if you are starting using the DE option and you are using some
208+
uncommon systems then `libinput-gestures-setup start` may fail
184209
to start the application returning you a message _Don't know how to
185210
invoke libinput-gestures.desktop_. If you get this error message,
186211
install the dex package, preferably from your system packages
187212
repository, and try again.
188213

189-
#### ALTERNATIVE TO START AS SYSTEMD USER SERVICE
190-
191-
If you prefer to start the application as a [systemd user
192-
service](https://wiki.archlinux.org/index.php/Systemd/User) rather than
193-
as a desktop application started by your DE, you can use the following
194-
commands:
195-
196-
To start the application immediately in the background, instead of
197-
`libinput-gestures-setup start` as in the previous section, do the
198-
following:
199-
200-
libinput-gestures-setup start-service
201-
202-
To enable the app to start automatically in the background when you log
203-
in to your DE, instead of `libinput-gestures-setup autostart` as in the
204-
previous section, do the following:
205-
206-
libinput-gestures-setup autostart-service
207-
208-
The other commands described in the previous section work also with the
209-
systemd user service.
210-
211214
### UPGRADE
212215

213216
# cd to source dir, as above

libinput-gestures-setup

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ DOCDIR="/usr/share/doc/$NAME"
1515
CNFDIR="/etc"
1616
HCFDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
1717
AUTDIR="$HCFDIR/autostart"
18+
SVCFLG="$HOME/.$NAME-service"
1819

1920
usage() {
2021
echo "Usage:"
2122
echo "As root: sudo $PROG install|uninstall"
22-
echo "As user: $PROG start|stop|restart|autostart|autostop|status|"
23-
echo " start-service|autostart-service"
23+
echo "As user: $PROG service|desktop|"
24+
echo " start|stop|restart|autostart|autostop|status"
2425
echo
2526
echo "-d <dir> (option sets DESTDIR for install/uninstall)"
2627
echo "-r (force allow root to perform user commands. PLEASE AVOID USING THIS!)"
@@ -114,53 +115,62 @@ user_action() {
114115
local svc_enabled="$3"
115116
local svc_running="$4"
116117

117-
if [[ $cmd == start ]]; then
118-
if [[ $svc_running == running ]]; then
119-
echo "Already running as a service."
120-
exit 1
121-
fi
122-
if [[ ! -f $APPDIR/$NAME.desktop ]]; then
123-
echo "$NAME is not installed."
118+
if [[ $cmd == service ]]; then
119+
if [[ $has_sysd -eq 0 ]]; then
120+
echo "Systemd not available, can not run as service."
124121
exit 1
125122
fi
126-
if de_start "$NAME"; then
127-
echo "$NAME started for desktop."
123+
touch $SVCFLG
124+
rm -fv $AUTDIR/$NAME.desktop
125+
elif [[ $cmd == desktop ]]; then
126+
rm -f $SVCFLG
127+
elif [[ $cmd == start ]]; then
128+
if [[ -f $SVCFLG ]]; then
129+
if [[ $has_sysd -eq 0 ]]; then
130+
echo "Systemd is not installed."
131+
exit 1
132+
fi
133+
if systemctl --user start $NAME.service; then
134+
echo "$NAME started as a user service."
135+
fi
136+
else
137+
if [[ ! -f $APPDIR/$NAME.desktop ]]; then
138+
echo "$NAME is not installed."
139+
exit 1
140+
fi
141+
if de_start "$NAME"; then
142+
echo "$NAME started for desktop."
143+
fi
128144
fi
129145
elif [[ $cmd == stop ]]; then
130146
if [[ $svc_running == running ]]; then
131147
systemctl --user stop $NAME.service
132-
echo "$NAME stopped as user service."
148+
echo "$NAME stopped as a user service."
133149
fi
134150

135151
for prog in libinput-debug-events $NAME; do
136152
if pkill -u $USER -f "$prog\$|$prog " &>/dev/null; then
137153
echo "$prog stopped for desktop."
138154
fi
139155
done
140-
elif [[ $cmd == start-service ]]; then
141-
if [[ $has_sysd -eq 0 ]]; then
142-
echo "Systemd is not installed."
143-
exit 1
144-
fi
145-
if systemctl --user start $NAME.service; then
146-
echo "$NAME started as user service."
147-
fi
148-
elif [[ $cmd == autostart-service ]]; then
149-
if [[ $has_sysd -eq 0 ]]; then
150-
echo "Systemd is not installed."
151-
exit 1
152-
fi
153-
if systemctl --user enable $NAME.service; then
154-
echo "$NAME enabled as user service."
155-
fi
156-
rm -fv $AUTDIR/$NAME.desktop
157156
elif [[ $cmd == autostart ]]; then
158-
if ! de_auto_start; then
159-
echo "$NAME is not installed."
160-
exit 1
161-
fi
162-
if [[ $has_sysd -eq 1 ]]; then
163-
systemctl --user disable $NAME.service &>/dev/null
157+
if [[ -f $SVCFLG ]]; then
158+
if [[ $has_sysd -eq 0 ]]; then
159+
echo "Systemd is not installed."
160+
exit 1
161+
fi
162+
if systemctl --user enable $NAME.service; then
163+
echo "$NAME enabled as a user service."
164+
fi
165+
rm -fv $AUTDIR/$NAME.desktop
166+
else
167+
if ! de_auto_start; then
168+
echo "$NAME is not installed."
169+
exit 1
170+
fi
171+
if [[ $has_sysd -eq 1 ]]; then
172+
systemctl --user disable $NAME.service &>/dev/null
173+
fi
164174
fi
165175
elif [[ $cmd == autostop ]]; then
166176
if [[ $has_sysd -eq 1 ]]; then
@@ -174,37 +184,31 @@ user_action() {
174184
echo "$NAME is not installed."
175185
fi
176186

177-
if [[ $svc_enabled == enabled ]]; then
178-
echo "$NAME is set to autostart as user service."
187+
if [[ -f $SVCFLG ]]; then
188+
echo "$NAME is set up as a user service."
179189
else
180-
echo "$NAME is not set to autostart as user service."
190+
echo "$NAME is set up as a desktop application."
181191
fi
182192

183-
if [[ -f $AUTDIR/$NAME.desktop ]]; then
184-
echo "$NAME is set to autostart as desktop application."
185-
else
186-
echo "$NAME is not set to autostart as desktop application."
187-
fi
188-
189-
local svc=0
190-
local de=0
191193
if [[ $svc_running == running ]]; then
192-
echo "$NAME is running as user service."
193-
svc=1
194+
echo "$NAME is currently running as a user service."
194195
else
195-
echo "$NAME is not running as user service."
196-
svc=0
197-
fi
198-
199-
if [[ $svc -eq 0 ]]; then
200196
if pgrep -u $USER -f "$NAME\$|$NAME " &>/dev/null; then
201-
echo "$NAME is running as desktop application."
202-
de=1
197+
echo "$NAME is currently running as a desktop application."
198+
else
199+
echo "$NAME is not currently running."
203200
fi
204201
fi
205202

206-
if [[ $de -eq 0 ]]; then
207-
echo "$NAME is not running as desktop application."
203+
if [[ $svc_enabled == enabled ]]; then
204+
echo "$NAME is set to autostart as a user service."
205+
rm -fv $AUTDIR/$NAME.desktop
206+
else
207+
if [[ -f $AUTDIR/$NAME.desktop ]]; then
208+
echo "$NAME is set to autostart as a desktop application."
209+
else
210+
echo "$NAME is not set to autostart."
211+
fi
208212
fi
209213

210214
if [[ -f $HCFDIR/$NAME.conf ]]; then
@@ -289,13 +293,8 @@ else
289293
fi
290294

291295
if [[ $cmd == restart ]]; then
292-
if [[ $svc_enabled == enabled || $svc_running == running ]]; then
293-
cmd=start-service
294-
else
295-
cmd=start
296-
fi
297-
298296
user_action "stop" $has_sysd $svc_enabled $svc_running
297+
cmd=start
299298
fi
300299

301300
user_action $cmd $has_sysd $svc_enabled $svc_running

0 commit comments

Comments
 (0)