comparison finch/libgnt/gntmain.c @ 18421:e16d097c5739

Allow executing another application (eg. PAGER) that will use the same console.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 03 Jul 2007 08:54:34 +0000
parents 310bad6dafe4
children 84d318eadc62
comparison
equal deleted inserted replaced
18420:e2b8b17fc62c 18421:e16d097c5739
218 218
219 static gboolean 219 static gboolean
220 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) 220 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null)
221 { 221 {
222 char keys[256]; 222 char keys[256];
223 int rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE); 223 int rd;
224 char *k; 224 char *k;
225
226 if (wm->mode == GNT_KP_MODE_WAIT_ON_CHILD)
227 return FALSE;
228
229 rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE);
225 if (rd < 0) 230 if (rd < 0)
226 { 231 {
227 int ch = getch(); /* This should return ERR, but let's see what it really returns */ 232 int ch = getch(); /* This should return ERR, but let's see what it really returns */
228 endwin(); 233 endwin();
229 printf("ERROR: %s\n", strerror(errno)); 234 printf("ERROR: %s\n", strerror(errno));
620 625
621 GntClipboard *gnt_get_clipboard() 626 GntClipboard *gnt_get_clipboard()
622 { 627 {
623 return clipboard; 628 return clipboard;
624 } 629 }
630
625 gchar *gnt_get_clipboard_string() 631 gchar *gnt_get_clipboard_string()
626 { 632 {
627 return gnt_clipboard_get_string(clipboard); 633 return gnt_clipboard_get_string(clipboard);
628 } 634 }
635
636 #if GLIB_CHECK_VERSION(2,4,0)
637 static void
638 reap_child(GPid pid, gint status, gpointer data)
639 {
640 wm->mode = GNT_KP_MODE_NORMAL;
641 clear();
642 setup_io();
643 refresh_screen();
644 }
645 #endif
646
647 gboolean gnt_giveup_console(const char *wd, char **argv, char **envp,
648 gint *stin, gint *stout, gint *sterr)
649 {
650 #if GLIB_CHECK_VERSION(2,4,0)
651 GPid pid = 0;
652
653 if (!g_spawn_async_with_pipes(wd, argv, envp,
654 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
655 (GSpawnChildSetupFunc)endwin, NULL,
656 &pid, stin, stout, sterr, NULL))
657 return FALSE;
658
659 wm->mode = GNT_KP_MODE_WAIT_ON_CHILD;
660 g_child_watch_add(pid, reap_child, NULL);
661
662 return TRUE;
663 #else
664 return FALSE;
665 #endif
666 }
667
668 gboolean gnt_is_refugee()
669 {
670 #if GLIB_CHECK_VERSION(2,4,0)
671 return (wm && wm->mode == GNT_KP_MODE_WAIT_ON_CHILD);
672 #else
673 return FALSE;
674 #endif
675 }
676