diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 726a7d2c..78adcc5e 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -3218,17 +3218,26 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch, return err; } -int uxsel_input_add(int fd, int rwx) { +struct uxsel_id { + int id; +}; + +uxsel_id *uxsel_input_add(int fd, int rwx) { + uxsel_id *id = snew(uxsel_id); + int flags = 0; if (rwx & 1) flags |= GDK_INPUT_READ; if (rwx & 2) flags |= GDK_INPUT_WRITE; if (rwx & 4) flags |= GDK_INPUT_EXCEPTION; assert(flags); - return gdk_input_add(fd, flags, fd_input_func, NULL); + id->id = gdk_input_add(fd, flags, fd_input_func, NULL); + + return id; } -void uxsel_input_remove(int id) { - gdk_input_remove(id); +void uxsel_input_remove(uxsel_id *id) { + gdk_input_remove(id->id); + sfree(id); } char *setup_fonts_ucs(struct gui_data *inst) diff --git a/unix/unix.h b/unix/unix.h index b2c45788..d7bed49a 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -118,6 +118,7 @@ void premsg(struct termios *); void postmsg(struct termios *); /* The interface used by uxsel.c */ +typedef struct uxsel_id uxsel_id; void uxsel_init(void); typedef int (*uxsel_callback_fn)(int fd, int event); void uxsel_set(int fd, int rwx, uxsel_callback_fn callback); @@ -126,8 +127,8 @@ int select_result(int fd, int event); int first_fd(int *state, int *rwx); int next_fd(int *state, int *rwx); /* The following are expected to be provided _to_ uxsel.c by the frontend */ -int uxsel_input_add(int fd, int rwx); /* returns an id */ -void uxsel_input_remove(int id); +uxsel_id *uxsel_input_add(int fd, int rwx); /* returns an id */ +void uxsel_input_remove(uxsel_id *id); /* uxcfg.c */ struct controlbox; diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index bfd4f0ff..2f9826b8 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -88,8 +88,8 @@ void pageant_log(void *ctx, const char *fmt, va_list ap) * In Pageant our selects are synchronous, so these functions are * empty stubs. */ -int uxsel_input_add(int fd, int rwx) { return 0; } -void uxsel_input_remove(int id) { } +uxsel_id *uxsel_input_add(int fd, int rwx) { return NULL; } +void uxsel_input_remove(uxsel_id *id) { } /* * More stubs. diff --git a/unix/uxplink.c b/unix/uxplink.c index 64c3cabc..40b12661 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -533,8 +533,8 @@ void sigwinch(int signum) * In Plink our selects are synchronous, so these functions are * empty stubs. */ -int uxsel_input_add(int fd, int rwx) { return 0; } -void uxsel_input_remove(int id) { } +uxsel_id *uxsel_input_add(int fd, int rwx) { return NULL; } +void uxsel_input_remove(uxsel_id *id) { } /* * Short description of parameters. diff --git a/unix/uxsel.c b/unix/uxsel.c index e2979c9a..fa48507f 100644 --- a/unix/uxsel.c +++ b/unix/uxsel.c @@ -19,7 +19,7 @@ struct fd { int fd; int rwx; /* 4=except 2=write 1=read */ uxsel_callback_fn callback; - int id; /* for uxsel_input_remove */ + uxsel_id *id; /* for uxsel_input_remove */ }; static tree234 *fds; @@ -80,7 +80,8 @@ void uxsel_del(int fd) { struct fd *oldfd = find234(fds, &fd, uxsel_fd_findcmp); if (oldfd) { - uxsel_input_remove(oldfd->id); + if (oldfd->id) + uxsel_input_remove(oldfd->id); del234(fds, oldfd); sfree(oldfd); } diff --git a/unix/uxsftp.c b/unix/uxsftp.c index 21d7f40f..7039b69b 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -26,8 +26,8 @@ * In PSFTP our selects are synchronous, so these functions are * empty stubs. */ -int uxsel_input_add(int fd, int rwx) { return 0; } -void uxsel_input_remove(int id) { } +uxsel_id *uxsel_input_add(int fd, int rwx) { return NULL; } +void uxsel_input_remove(uxsel_id *id) { } char *x_get_default(const char *key) {