From 3604b12fde54ffe0b049dd2f47ece4eba5689989 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 21 May 2020 09:35:55 +0200 Subject: Add check that looks if rofi is running inside rofi script mode. --- Examples/test_script_env.sh | 6 +++++- source/dialogs/script.c | 4 ++++ source/rofi.c | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) 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. -- cgit v1.2.3