To: vim-dev@vim.org Subject: Patch 6.1a.036 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1a.036 Problem: GTK: the save-yourself event was not handled. Solution: Catch the save-yourself event and preserve swap files. (Neil Bird) Files: src/gui_gtk_x11.c *** ../vim61a.035/src/gui_gtk_x11.c Sat Mar 2 11:20:06 2002 --- src/gui_gtk_x11.c Thu Mar 7 19:12:53 2002 *************** *** 115,124 **** #define DFLT_FONT "-adobe-courier-medium-r-normal-*-14-*-*-*-m-*-*-*" /* ! * Atom used to communicate save yourself from the X11 session manager. There ! * is no need to move this into the GUI struct, since this should be always ! * constant. */ static GdkAtom save_yourself_atom = GDK_NONE; /* --- 115,124 ---- #define DFLT_FONT "-adobe-courier-medium-r-normal-*-14-*-*-*-m-*-*-*" /* ! * Atoms used to communicate save-yourself from the X11 session manager. There ! * is no need to move them into the GUI struct, since they should be constant. */ + static GdkAtom wm_protocols_atom = GDK_NONE; static GdkAtom save_yourself_atom = GDK_NONE; /* *************** *** 491,497 **** { if (e->type == GDK_PROPERTY_NOTIFY && GDK_WINDOW_XWINDOW(e->window) == commWindow ! && e->atom == commProperty && e->state == GDK_PROPERTY_NEW_VALUE) { XEvent xev; --- 491,498 ---- { if (e->type == GDK_PROPERTY_NOTIFY && GDK_WINDOW_XWINDOW(e->window) == commWindow ! && e->atom == commProperty ! && e->state == (guint)GDK_PROPERTY_NEW_VALUE) { XEvent xev; *************** *** 1561,1574 **** } #endif /* GTK_DND */ - #if 0 - /* Not used yet, because I don't know how to catch the WM_SAVE_YOURSELF event. - */ /* * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. * This is an ugly use of X functions. GTK doesn't offer an alternative. */ ! static void setup_save_yourself(void) { Atom *existing; --- 1562,1572 ---- } #endif /* GTK_DND */ /* * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. * This is an ugly use of X functions. GTK doesn't offer an alternative. */ ! static void setup_save_yourself(void) { Atom *existing; *************** *** 1601,1607 **** XFree(existing); } } ! #endif /* * Setup the window icon & xcmdsrv comm after the main window has been realized. --- 1599,1646 ---- XFree(existing); } } ! ! /* ! * GDK handler for X ClientMessage events. ! */ ! /*ARGSUSED*/ ! static GdkFilterReturn ! gdk_wm_protocols_filter(GdkXEvent *xev, GdkEvent *event, gpointer data) ! { ! /* From example in gdkevents.c/gdk_wm_protocols_filter */ ! XEvent *xevent = (XEvent *)xev; ! ! if (xevent != NULL) ! { ! if ((Atom)(xevent->xclient.data.l[0]) == save_yourself_atom) ! { ! out_flush(); ! ml_sync_all(FALSE, FALSE); /* preserve all swap files */ ! ! /* Set the window's WM_COMMAND property, to let the window manager ! * know we are done saving ourselves. We don't want to be ! * restarted, thus set argv to NULL. */ ! XSetCommand(gui.dpy, GDK_WINDOW_XWINDOW(gui.mainwin->window), ! NULL, 0); ! } ! ! /* ! * Functionality from gdkevents.c/gdk_wm_protocols_filter; ! * Registering this filter apparently overrides the default GDK one, ! * so we need to perform its functionality. There seems no way to ! * register for WM_PROTOCOLS, and only process the WM_SAVE_YOURSELF ! * bit; it's all or nothing. ! */ ! else if ((Atom)(xevent->xclient.data.l[0]) == gdk_wm_delete_window) ! { ! event->any.type = GDK_DELETE; ! return GDK_FILTER_TRANSLATE; ! } ! } ! ! return GDK_FILTER_REMOVE; ! } ! /* * Setup the window icon & xcmdsrv comm after the main window has been realized. *************** *** 1668,1678 **** gdk_window_set_icon(gui.mainwin->window, NULL, icon, icon_mask); } ! #if 0 /* Setup to indicate to the window manager that we want to catch the * WM_SAVE_YOURSELF event. */ setup_save_yourself(); - #endif #ifdef FEAT_CLIENTSERVER if (serverName == NULL && serverDelayedStartName != NULL) --- 1707,1719 ---- gdk_window_set_icon(gui.mainwin->window, NULL, icon, icon_mask); } ! /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ ! gdk_add_client_message_filter(wm_protocols_atom, ! gdk_wm_protocols_filter, NULL); ! /* Setup to indicate to the window manager that we want to catch the * WM_SAVE_YOURSELF event. */ setup_save_yourself(); #ifdef FEAT_CLIENTSERVER if (serverName == NULL && serverDelayedStartName != NULL) *************** *** 1933,1938 **** --- 1974,1980 ---- GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); gui.visibility = GDK_VISIBILITY_UNOBSCURED; + wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); reread_rcfiles_atom = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); *************** *** 2088,2094 **** { if (event->message_type == save_yourself_atom) { ! /* NOTE: this is never reached! */ out_flush(); ml_sync_all(FALSE, FALSE); /* preserve all swap files */ return TRUE; --- 2130,2136 ---- { if (event->message_type == save_yourself_atom) { ! /* NOTE: this is never reached! See gdk_wm_protocols_filter(). */ out_flush(); ml_sync_all(FALSE, FALSE); /* preserve all swap files */ return TRUE; *** ../vim61a.035/src/version.c Thu Mar 7 20:14:43 2002 --- src/version.c Thu Mar 7 20:15:47 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 36, /**/ -- hundred-and-one symptoms of being an internet addict: 183. You move your coffeemaker next to your computer. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///