| dwm-exitmenu-6.3.diff - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| dwm-exitmenu-6.3.diff (3498B) | |
| --- | |
| 1 diff --git a/config.def.h b/config.def.h | |
| 2 index a2ac963..92a6a81 100644 | |
| 3 --- a/config.def.h | |
| 4 +++ b/config.def.h | |
| 5 @@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucm… | |
| 6 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", d… | |
| 7 static const char *termcmd[] = { "st", NULL }; | |
| 8 | |
| 9 +#include "exitdwm.c" | |
| 10 static Key keys[] = { | |
| 11 /* modifier key function argu… | |
| 12 { MODKEY, XK_p, spawn, {.v … | |
| 13 @@ -94,7 +95,7 @@ static Key keys[] = { | |
| 14 TAGKEYS( XK_7, 6) | |
| 15 TAGKEYS( XK_8, 7) | |
| 16 TAGKEYS( XK_9, 8) | |
| 17 - { MODKEY|ShiftMask, XK_q, quit, {0} … | |
| 18 + { MODKEY|ShiftMask, XK_e, exitdwm, {0} }, | |
| 19 }; | |
| 20 | |
| 21 /* button definitions */ | |
| 22 diff --git a/exitdwm.c b/exitdwm.c | |
| 23 new file mode 100644 | |
| 24 index 0000000..74c514f | |
| 25 --- /dev/null | |
| 26 +++ b/exitdwm.c | |
| 27 @@ -0,0 +1,87 @@ | |
| 28 +# include <stdio.h> | |
| 29 +# include <string.h> | |
| 30 + | |
| 31 +void exitdwm () | |
| 32 +{ | |
| 33 +# if \ | |
| 34 + defined S_LOCK || \ | |
| 35 + defined S_RESTART_DWM || \ | |
| 36 + defined S_OFFSCREEN || \ | |
| 37 + defined S_EXIT || \ | |
| 38 + defined S_REBOOT || \ | |
| 39 + defined S_SHUTDOWN || \ | |
| 40 + defined S_LOCK_ICON || \ | |
| 41 + defined S_RESTART_DWM_ICON || \ | |
| 42 + defined S_OFFSCREEN_ICON || \ | |
| 43 + defined S_EXIT_ICON || \ | |
| 44 + defined S_REBOOT_ICON || \ | |
| 45 + defined S_SHUTDOWN_ICON || \ | |
| 46 + defined S_FORMAT || \ | |
| 47 + defined S_FORMAT_CLEAR | |
| 48 +# error (conflicting macro names) | |
| 49 +# endif | |
| 50 + | |
| 51 +# define S_LOCK "Lock" | |
| 52 +# define S_RESTART_DWM "restart Dwm" | |
| 53 +# define S_OFFSCREEN "Off-screen" | |
| 54 +# define S_EXIT "Exit" | |
| 55 +# define S_REBOOT "Reboot" | |
| 56 +# define S_SHUTDOWN "Shutdown" | |
| 57 +# define S_LOCK_ICON "\uf023" // <= FontAwesome … | |
| 58 +# define S_RESTART_DWM_ICON "\uf01e" | |
| 59 +# define S_OFFSCREEN_ICON "\uf108" | |
| 60 +# define S_EXIT_ICON "\uf2f5" | |
| 61 +# define S_REBOOT_ICON "\uf021" | |
| 62 +# define S_SHUTDOWN_ICON "\uf011" | |
| 63 + | |
| 64 +# define S_FORMAT(ACTION) S_##ACTION##_ICON " " S_##ACTION | |
| 65 +# define S_FORMAT_CLEAR "sed 's/^..//'" | |
| 66 + | |
| 67 + FILE * exit_menu = popen ( | |
| 68 + "echo \"" | |
| 69 + S_FORMAT (LOCK) "\n" | |
| 70 + S_FORMAT (RESTART_DWM) "\n" | |
| 71 + S_FORMAT (OFFSCREEN) "\n" | |
| 72 + S_FORMAT (EXIT) "\n" | |
| 73 + S_FORMAT (REBOOT) "\n" | |
| 74 + S_FORMAT (SHUTDOWN) | |
| 75 + "\" | dmenu -p exit: | " S_FORMAT_CLEAR | |
| 76 + , | |
| 77 + "r" | |
| 78 + ); | |
| 79 + | |
| 80 + char exit_action [16]; | |
| 81 + | |
| 82 + if ( | |
| 83 + exit_menu == NULL || | |
| 84 + fscanf (exit_menu, "%15[a-zA-Z -]", exit_action) == EOF | |
| 85 + ) { | |
| 86 + fputs ("Error. Failure in exit_dwm.", stderr); | |
| 87 + goto close_streams; | |
| 88 + } | |
| 89 + | |
| 90 + if (strcmp (exit_action, S_LOCK) == 0) system ("slock & sleep .… | |
| 91 + else if (strcmp (exit_action, S_RESTART_DWM) == 0) quit (& (con… | |
| 92 + else if (strcmp (exit_action, S_OFFSCREEN) == 0) system ("sleep… | |
| 93 + else if (strcmp (exit_action, S_EXIT) == 0) quit (& (const Arg)… | |
| 94 + else if (strcmp (exit_action, S_REBOOT) == 0) system ("systemct… | |
| 95 + else if (strcmp (exit_action, S_SHUTDOWN) == 0) system ("system… | |
| 96 + | |
| 97 +close_streams: | |
| 98 + pclose (exit_menu); | |
| 99 + | |
| 100 +# undef S_LOCK | |
| 101 +# undef S_RESTART_DWM | |
| 102 +# undef S_OFFSCREEN | |
| 103 +# undef S_EXIT | |
| 104 +# undef S_REBOOT | |
| 105 +# undef S_SHUTDOWN | |
| 106 +# undef S_LOCK_ICON | |
| 107 +# undef S_RESTART_DWM_ICON | |
| 108 +# undef S_OFFSCREEN_ICON | |
| 109 +# undef S_EXIT_ICON | |
| 110 +# undef S_REBOOT_ICON | |
| 111 +# undef S_SHUTDOWN_ICON | |
| 112 +# undef S_FORMAT | |
| 113 +# undef S_FORMAT_CLEAR | |
| 114 +} |