Autoquit Script & Autostart Consolidation

- Create autoquit script to end all autostarted processes on quit
- Move process from autostart_blocking to autostart
- Fix missing "\" in autostart
- Add runautoquit function to dwm.c
- Call runautoquit after run exits in dwm.c main
This commit is contained in:
Sravan Balaji
2020-08-30 15:15:04 -04:00
parent 7d5b1b38a2
commit e7ece2aaba
4 changed files with 120 additions and 36 deletions

51
autoquit.sh Executable file
View File

@@ -0,0 +1,51 @@
#!/bin/bash
########################
# Startup Applications #
########################
# List of applications to kill on exit
declare -a applications_array=(\
# System Tray Applications
"volctl" \ # PulseAudio Volume Control
"nyrna" \ # Nyrna Application Suspend
"blueman-tray" \ # Blueman Bluetooth Manager
"nm-applet" \ # Network Manager Applet
"kdeconnect-indi" \ # KDE Connect
"flameshot" \ # Flameshot Screenshot Tool
# Background Processes
"picom" \ # Picom Compositor
"deadd-notificat" \ # Deadd Notification Center
"greenclip" \ # Greenclip Clipboard Manager
"redshift-gtk" \ # Redshift Blue Light Filter
"polkit-gnome-au" \ # GNOME Polkit Authentication Agent
"slstatus" \ # slstatus status bar
"light-locker" \ # LightDM Locker
# Hardware Driver Applications
"solaar" \ # Logitech Mouse Driver
"polychromatic-t" \ # Razer Keyboard Customization
)
# Kill applications
for i in "${applications_array[@]}"
do
pkill -9 $i &
done
#####################
# Cloud Drive Rsync #
#####################
# Local cloud storage directory
local_clone_dir="$HOME/Cloud"
# List of remotes as defined in rclone
declare -a remote_array=(\
"OneDrive - Personal" \
"Google Drive - Personal" \
)
# Unmount Remotes
for i in "${remote_array[@]}"
do
local_path="$local_clone_dir"/"$i"
fusermount -u "$local_path" &
done

View File

@@ -5,23 +5,27 @@
########################
# List of applications to run on start
declare -a applications_array=(\
# System Restore Processes
"bash /home/sravan/.screenlayout/default-screen-layout.sh" \ # Restore default screen layout
"nitrogen --restore" \ # Restore wallpaper
# System Tray Applications
"volctl" \ # PulseAudio Volume Control
"nyrna" \ # Nyrna Application Suspend
"blueman-tray" \ # Blueman Bluetooth Manager
"nm-applet" \ # Network Manager Applet
"kdeconnect-indicator" \ # KDE Connect
"flameshot" \ # Flameshot Screenshot Tool
"volctl" \ # PulseAudio Volume Control
"nyrna" \ # Nyrna Application Suspend
"blueman-tray" \ # Blueman Bluetooth Manager
"nm-applet" \ # Network Manager Applet
"kdeconnect-indicator" \ # KDE Connect
"flameshot" \ # Flameshot Screenshot Tool
# Background Processes
"deadd-notification-center" \ # Deadd Notification Center
"greenclip daemon" \ # Greenclip Clipboard Manager
"redshift-gtk" \ # Redshift Blue Light Filter
"/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1" # GNOME Polkit Authentication Agent
"slstatus" \ # slstatus status bar
"light-locker --lock-on-suspend --lock-on-lid" \ # LightDM Locker
"picom --config /home/sravan/.config/picom/picom.conf" \ # Picom Compositor
"deadd-notification-center" \ # Deadd Notification Center
"greenclip daemon" \ # Greenclip Clipboard Manager
"redshift-gtk" \ # Redshift Blue Light Filter
"/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1" \ # GNOME Polkit Authentication Agent
"slstatus" \ # slstatus status bar
"light-locker --lock-on-suspend --lock-on-lid" \ # LightDM Locker
# Hardware Driver Applications
"solaar --window=hide" \ # Logitech Mouse Driver
"polychromatic-tray-applet" \ # Razer Keyboard Customization
"solaar --window=hide" \ # Logitech Mouse Driver
"polychromatic-tray-applet" \ # Razer Keyboard Customization
)
# Run applications (ignore if they don't exist)

View File

@@ -1,22 +0,0 @@
#!/bin/bash
##############################
# Startup Blocking Processes #
##############################
# List of processes to run on start
declare -a processes_array=(\
"picom --config /home/sravan/.config/picom/picom.conf" \ # Start compositor using configuration file
"bash /home/sravan/.screenlayout/default-screen-layout.sh" \ # Restore default screen layout
"nitrogen --restore" \ # Restore wallpaper
)
# Run processes (ignore if they don't exist)
for i in "${processes_array[@]}"
do
if ! command -v $i > /dev/null
then
do_nothing() { :; }
else
$i &
fi
done

51
dwm.c
View File

@@ -226,6 +226,7 @@ static void resizerequest(XEvent *e);
static void restack(Monitor *m);
static void run(void);
static void runautostart(void);
static void runautoquit(void);
static void scan(void);
static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
static void sendmon(Client *c, Monitor *m);
@@ -283,6 +284,8 @@ static void comboview(const Arg *arg);
/* variables */
static const char autostartblocksh[] = "autostart_blocking.sh";
static const char autostartsh[] = "autostart.sh";
static const char autoquitblocksh[] = "autoquit_blocking.sh";
static const char autoquitsh[] = "autoquit.sh";
static Systray *systray = NULL;
static const char broken[] = "broken";
static const char dwmdir[] = "dwm";
@@ -1674,6 +1677,53 @@ runautostart(void)
free(path);
}
void
runautoquit(void)
{
char *pathpfx;
char *path;
struct stat sb;
if (dwmdir != NULL && *dwmdir != '\0') {
/* space for path segments, separators and nul */
pathpfx = ecalloc(1, strlen(rootdir) + strlen(dwmdir) + 2);
if (sprintf(pathpfx, "%s/%s", rootdir, dwmdir) <= 0) {
free(pathpfx);
return;
}
}
/* check if the autoquit script directory exists */
if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) {
/* the specified dwm root directory does not exist or is not a directory */
free(pathpfx);
return;
}
/* try the blocking script first */
path = ecalloc(1, strlen(pathpfx) + strlen(autoquitblocksh) + 2);
if (sprintf(path, "%s/%s", pathpfx, autoquitblocksh) <= 0) {
free(path);
free(pathpfx);
}
if (access(path, X_OK) == 0)
system(path);
/* now the non-blocking script */
if (sprintf(path, "%s/%s", pathpfx, autoquitsh) <= 0) {
free(path);
free(pathpfx);
}
if (access(path, X_OK) == 0)
system(strcat(path, " &"));
free(pathpfx);
free(path);
}
void
scan(void)
{
@@ -2640,6 +2690,7 @@ main(int argc, char *argv[])
scan();
runautostart();
run();
runautoquit();
cleanup();
XCloseDisplay(dpy);
return EXIT_SUCCESS;