From e7ece2aaba975b78499ad936a4a1b4287c2c5216 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Sun, 30 Aug 2020 15:15:04 -0400 Subject: [PATCH] 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 --- autoquit.sh | 51 +++++++++++++++++++++++++++++++++++++++++++ autostart.sh | 32 +++++++++++++++------------ autostart_blocking.sh | 22 ------------------- dwm.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 36 deletions(-) create mode 100755 autoquit.sh delete mode 100755 autostart_blocking.sh diff --git a/autoquit.sh b/autoquit.sh new file mode 100755 index 0000000..9fb01c5 --- /dev/null +++ b/autoquit.sh @@ -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 diff --git a/autostart.sh b/autostart.sh index 8598aa9..f9322d1 100755 --- a/autostart.sh +++ b/autostart.sh @@ -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) diff --git a/autostart_blocking.sh b/autostart_blocking.sh deleted file mode 100755 index 485447d..0000000 --- a/autostart_blocking.sh +++ /dev/null @@ -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 diff --git a/dwm.c b/dwm.c index c9884bf..3d7af31 100644 --- a/dwm.c +++ b/dwm.c @@ -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;