# HG changeset patch # User Mikael Berthe # Date 1270289954 -7200 # Node ID 81cbb47f1aa6803a281276078e23c4dd7be8c08c # Parent cf95a475825c89e9f3d369e9ca3d2331988da70f [extsay] Add options to split the screen window diff -r cf95a475825c -r 81cbb47f1aa6 extsay-ng/README --- a/extsay-ng/README Sat Apr 03 00:50:17 2010 +0200 +++ b/extsay-ng/README Sat Apr 03 12:19:14 2010 +0200 @@ -8,6 +8,12 @@ option 'extsay_script_path' to the file path. You can set it in your mcabber configuration file. +Set the option 'extsay_split_win' to 1 if you want the helper script to +split the screen window and open the editor below the mcabber screen window. +This may not work for you, according to your screen configuration. +The option 'extsay_win_height' can be used to specify the height of the newly +created window, if you have enabled splitting. + /EXTSAY [jid] When you type /extsay, the module will send a command to screen to open a diff -r cf95a475825c -r 81cbb47f1aa6 extsay-ng/extsay.sh --- a/extsay-ng/extsay.sh Sat Apr 03 00:50:17 2010 +0200 +++ b/extsay-ng/extsay.sh Sat Apr 03 12:19:14 2010 +0200 @@ -5,8 +5,10 @@ # Copy this script on your system and specify the path for mcabber # by setting the 'extsay_script_path' option. # +# Usage: extsay.sh [jid [winsplit [height]]] +# # This script is free software. -# MiKael, 2010-04-02 +# MiKael, 2010-04-03 FIFOPATH="$HOME/.mcabber/mcabber.fifo" @@ -17,12 +19,23 @@ jid="." # Use argument as a recipient JID, if it is provided -[ $# -eq 1 ] && jid=$1 +[ $# -ge 1 ] && jid=$1 +[ $# -ge 2 ] && winsplit=$2 +[ $# -ge 3 ] && winheight=$3 # Leave if the FIFO is not available [ -p $FIFOPATH ] || exit 255 -tf=$(mktemp $tmpdir/extsay-XXXXXX) || exit 255 +tf=$(mktemp $tmpdir/extsay-$jid-XXXXXX) || exit 255 + +if [ x$winsplit = x"winsplit" ]; then + screen -r -X other + screen -r -X split + screen -r -X focus down + screen -r -X other + + [ $winheight -gt 0 ] && screen -r -X resize $winheight +fi # This will not work if the editor runs in the background! $editor $tf @@ -35,6 +48,10 @@ fi echo $cmd >> $FIFOPATH +if [ x$winsplit = x"winsplit" ]; then + screen -r -X remove +fi + # Do not remove the file too soon setsid sh -c "cd / && sleep 20 && rm $tf & :" /dev/null 2>&1 < /dev/null diff -r cf95a475825c -r 81cbb47f1aa6 extsay-ng/extsayng.c --- a/extsay-ng/extsayng.c Sat Apr 03 00:50:17 2010 +0200 +++ b/extsay-ng/extsayng.c Sat Apr 03 12:19:14 2010 +0200 @@ -44,26 +44,42 @@ .next = NULL, }; -// Forks and run the external helper script + +// Run the external helper script with parameters static void screen_run_script(const gchar *args) { GError *err = NULL; - gchar *argv[] = { "screen", "-r", "-X", "screen", NULL, NULL, NULL }; + gchar *argv[] = { "screen", "-r", "-X", "screen", NULL, + NULL, NULL, NULL, NULL }; gboolean ret; + gchar strwinheight[32]; + gboolean winsplit = settings_opt_get_int("extsay_split_win"); - // screen -r -X screen $path/extsay.sh + // screen -r -X screen $path/extsay.sh [jid [winsplit [height]]] argv[4] = (gchar*)settings_opt_get("extsay_script_path"); + // Helper script path if (!argv[4] || !argv[4][0]) { scr_log_print(LPRINT_NORMAL, "Please set option 'extsay_script_path'."); return; } + // Helper script parameter #1 if (args && *args) argv[5] = (gchar*)args; else argv[5] = "."; + // Update environment variables for the helper script + if (winsplit) { + gint winheight = settings_opt_get_int("extsay_win_height"); + argv[6] = "winsplit"; // Helper script parameter #2 + if (winheight > 0 && winheight < 256) { + snprintf(strwinheight, sizeof strwinheight, "%d", winheight); + argv[7] = strwinheight; // Helper script parameter #3 + } + } + ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,