diff options
author | Dave Davenport <qball@gmpclient.org> | 2020-05-21 09:35:55 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2020-05-21 09:35:55 +0200 |
commit | 3604b12fde54ffe0b049dd2f47ece4eba5689989 (patch) | |
tree | d06a82acf7d017be49a3a3cb5b4ef8057186d4c5 | |
parent | a4c5a92199249369f1f312f83f6ac3995c6c64f9 (diff) |
Add check that looks if rofi is running inside rofi script mode.
-rwxr-xr-x | Examples/test_script_env.sh | 6 | ||||
-rw-r--r-- | source/dialogs/script.c | 4 | ||||
-rw-r--r-- | source/rofi.c | 11 |
3 files changed, 20 insertions, 1 deletions
diff --git a/Examples/test_script_env.sh b/Examples/test_script_env.sh index 64899eb7..7753a845 100755 --- a/Examples/test_script_env.sh +++ b/Examples/test_script_env.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash - +if [ -z "${ROFI_OUTSIDE}" ] +then + echo "run this script in rofi". + exit +fi echo -en "\x00no-custom\x1ftrue\n" echo "${ROFI_RETV}" diff --git a/source/dialogs/script.c b/source/dialogs/script.c index c7cc6d70..d008996e 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -157,6 +157,10 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE); g_free ( str_value ); + str_value = g_strdup_printf("%d", (int) getpid()); + env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE); + g_free ( str_value ); + if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); diff --git a/source/rofi.c b/source/rofi.c index 88002324..0b47a9c7 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -788,6 +788,17 @@ int main ( int argc, char *argv[] ) return EXIT_SUCCESS; } + { + const char *ro_pid = g_getenv("ROFI_OUTSIDE"); + if ( ro_pid != NULL ) { + int ro_pidi = g_ascii_strtoll ( ro_pid, NULL, 0 ); + if ( kill ( ro_pidi, 0 ) == 0 ) { + printf ( "Do not launch rofi from inside rofi.\r\n" ); + return EXIT_FAILURE; + } + } + } + // Detect if we are in dmenu mode. // This has two possible causes. // 1 the user specifies it on the command-line. |