mc/gnome/gkey.c
Timur Bakeyev be7cbf3768 Glibing... (3)
Wed Jan 27 03:14:46 1999  Timur Bakeyev <mc@bat.ru>

	* Converted memory managment to Glib - where it wasn't done. Now we
	use g_new()/g_malloc()/g_strdup()/g_free() routings. copy_strings() re-
	placed by g_strconcat(), and sprintf() by g_snprintf(). Some other,
	minor changes.
1999-01-27 01:14:57 +00:00

82 lines
1.7 KiB
C

/*
* Midnight Commander -- GNOME edition
*
* Copyright 1997 The Free Software Foundation
*
* Author:Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include "global.h"
#include "x.h"
#include "key.h"
/* The tty.h file is included since we try to use as much object code
* from the curses distribution as possible so we need to send back
* the same constants that the code expects on the non-X version
* of the code. The constants may be the ones from curses/ncurses
* or our macro definitions for slang
*/
struct trampoline {
select_fn fn;
void *fn_closure;
int fd;
int tag;
};
void
callback_trampoline (gpointer data, gint source, GdkInputCondition condition)
{
struct trampoline *t = data;
/* return value is ignored */
(*t->fn)(source, t->fn_closure);
}
/*
* We need to keep track of the select callbacks, as we need to release
* the trampoline closure.
*/
GList *select_list;
void
add_select_channel (int fd, select_fn callback, void *info)
{
struct trampoline *t;
t = g_new (struct trampoline, 1);
t->fn = callback;
t->fd = fd;
t->fn_closure = info;
t->tag = gdk_input_add (fd, GDK_INPUT_READ, callback_trampoline, t);
g_list_prepend (select_list, t);
}
static struct trampoline *tclosure;
static void
find_select_closure_callback (gpointer data, gpointer user_data)
{
struct trampoline *t = data;
int *pfd = (int *) user_data;
if (t->fd == *pfd)
tclosure = data;
}
void
delete_select_channel (int fd)
{
tclosure = 0;
g_list_foreach (select_list, find_select_closure_callback, &fd);
if (tclosure){
select_list = g_list_remove (select_list, tclosure);
gdk_input_remove (tclosure->tag);
g_free (tclosure);
} else {
fprintf (stderr, "PANIC: could not find closure for %d\n", fd);
}
}