diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index c872772160..5bb2162fa7 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -24,6 +24,8 @@ int use_gui_macvim_draw_string = 1; static int use_graphical_sign = 0; +static BOOL is_macos_high_sierra_or_later = NO; + // Max number of files to add to MRU in one go (this matches the maximum that // Cocoa displays in the MRU -- if this changes in Cocoa then update this // number as well). @@ -283,6 +285,15 @@ gui_mch_init(void) [[MMBackend sharedInstance] addToMRU:filenames]; } +#if defined(MAC_OS_X_VERSION_10_10) + { + NSOperatingSystemVersion version = {10, 13, 0}; + + is_macos_high_sierra_or_later = + [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version]; + } +#endif + return OK; } @@ -2315,8 +2326,9 @@ static int vimModMaskToEventModifierFlags(int mods) -// -- Channel Support ------------------------------------------------------ +// -- Job and Channel Support ------------------------------------------------------ +#if defined(FEAT_JOB_CHANNEL) void * gui_macvim_add_channel(channel_T *channel, ch_part_T part) { @@ -2340,6 +2352,14 @@ gui_macvim_remove_channel(void *cookie) dispatch_release(s); } + void +gui_macvim_cleanup_job_all(void) +{ + if (is_macos_high_sierra_or_later) + job_cleanup_all(); +} + +#endif // FEAT_JOB_CHANNEL // -- Graphical Sign Support ------------------------------------------------ diff --git a/src/channel.c b/src/channel.c index 404219bddf..42ed7c2f50 100644 --- a/src/channel.c +++ b/src/channel.c @@ -5686,4 +5686,38 @@ job_stop(job_T *job, typval_T *argvars, char *type) return 1; } +# ifdef FEAT_GUI_MACVIM + void +job_cleanup_all(void) +{ + job_T *job; + + for (job = first_job; job != NULL; job = job->jv_next) + { + channel_T *channel = job->jv_channel; + ch_part_T part; + + if (channel == NULL || job->jv_status != JOB_FINISHED) + continue; + + /* check the socket and pipes */ + for (part = PART_SOCK; part < PART_IN; ++part) + { + sock_T fd = channel->ch_part[part].ch_fd; + + if (fd != INVALID_FD) + { + int r = channel_wait(channel, fd, 0); + + if (r == CW_READY) + channel_read(channel, part, "job_cleanup_all"); + else if (r == CW_ERROR) + ch_close_part_on_error(channel, part, TRUE, + "job_cleanup_all"); + } + } + } +} +# endif + #endif /* FEAT_JOB_CHANNEL */ diff --git a/src/misc2.c b/src/misc2.c index 61336ded7f..99ddc1d641 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -6361,6 +6361,11 @@ parse_queued_messages(void) channel_handle_events(FALSE); # endif +# if defined(FEAT_GUI_MACVIM) && defined(FEAT_JOB_CHANNEL) + if (gui.in_use) + gui_macvim_cleanup_job_all(); +# endif + # ifdef FEAT_NETBEANS_INTG /* Process the queued netbeans messages. */ netbeans_parse_messages(); diff --git a/src/proto/channel.pro b/src/proto/channel.pro index b2f84caf85..ec12cd5dd3 100644 --- a/src/proto/channel.pro +++ b/src/proto/channel.pro @@ -71,4 +71,5 @@ job_T *job_start(typval_T *argvars, jobopt_T *opt_arg); char *job_status(job_T *job); void job_info(job_T *job, dict_T *dict); int job_stop(job_T *job, typval_T *argvars, char *type); +void job_cleanup_all(void); /* vim: set ft=c : */ diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index a7949bfc6c..cdf3e0058d 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -240,6 +240,8 @@ im_set_control(int enable); gui_macvim_add_channel(channel_T *channel, ch_part_T part); void gui_macvim_remove_channel(void *cookie); + void +gui_macvim_cleanup_job_all(void); void gui_mch_drawsign(int row, int col, int typenr);