unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lennart Borgman <lennart.borgman.073@student.lu.se>
Cc: emacs-pretest-bug@gnu.org, Emacs Devel <emacs-devel@gnu.org>
Subject: Re: Exit hooks not run at logout on w32
Date: Thu, 29 Jun 2006 16:52:08 +0200	[thread overview]
Message-ID: <44A3E918.5000304@student.lu.se> (raw)
In-Reply-To: <44A3A2DE.4040507@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2275 bytes --]

Jason Rumney wrote:
> Lennart Borgman wrote:
>> Thanks. I did a post_msg and it works as I want it now. My concern 
>> was that data was lost on reboots and logouts (that has happened to 
>> me). Now it works like for other w32 apps:
>
> What other w32 apps are you talking about? The Windows programming 
> guidelines are pretty clear that the only time to interrupt shutdown 
> is when you are performing an operation that cannot be interrupted - 
> CD burning is given as an example. In that case you are supposed to 
> ask the user one Yes/No question about whether they want to abort the 
> shutdown.
I was going to say I am not aware of any other application that throws 
away data without asking the user at logoff. However a test showed that 
Thunderbird behaves that way too ;-|

I guess we are misunderstanding each other in some way. Let us see if we 
can clear this out. To see what I mean look Notepad for example. Edit a 
file without saving the changes and try to log off. You will be prompted 
by Notepad to save the changes before Notepad exits. And the log off 
process waits for Notepad to finish. I think that is good behaviour.

I am a very surprised about what the Windows programming guideline seems 
to say. Can you give me a link to it? There is a message named 
WM_QUERYENDSESSION that I thought was sent for applications to save 
data. (Though Emacs does not receive this. It is not clear to me why.)

>
> As I said at the start of the thread, it would be correct for Emacs to 
> flush its autosave buffers to disk at this point, but not to start 
> asking all the questions that save-buffers-kill-emacs does. What if 
> Emacs is on a secondary monitor, and the Graphics driver shuts it off 
> when it receives the shutdown message? Emacs will be delaying shutdown 
> waiting for a response, while the user cannot see it.
The problem with autosave is that data might be lost if the user happens 
to use some other tool to edit the files afterwards.

Is there some way to discover cases like the one with secondary 
monitors? Should there perhaps be an option telling what Emacs should do 
in these situations (with the choices autosave and ask the user to save 
changed data)?

I attach my patch as it looks now. Please try it to see how it works.

[-- Attachment #2: logout-patch.diff --]
[-- Type: text/plain, Size: 4483 bytes --]

? logout-patch.diff
Index: keyboard.c
===================================================================
RCS file: /sources/emacs/emacs/src/keyboard.c,v
retrieving revision 1.854
diff -u -r1.854 keyboard.c
--- keyboard.c	5 May 2006 06:43:50 -0000	1.854
+++ keyboard.c	29 Jun 2006 06:35:22 -0000
@@ -530,6 +530,9 @@
 #endif
 Lisp_Object Qdrag_n_drop;
 Lisp_Object Qsave_session;
+#ifdef WINDOWSNT
+Lisp_Object Qw32_endsession_event;
+#endif
 #ifdef MAC_OS
 Lisp_Object Qmac_apple_event;
 #endif
@@ -4061,6 +4064,13 @@
           obj = Fcons (Qsave_session, Qnil);
 	  kbd_fetch_ptr = event + 1;
         }
+#ifdef WINDOWSNT
+      else if (event->kind == W32_ENDSESSION_EVENT)
+        {
+          obj = Fcons (Qw32_endsession_event, Qnil);
+	  kbd_fetch_ptr = event + 1;
+        }
+#endif
       /* Just discard these, by returning nil.
 	 With MULTI_KBOARD, these events are used as placeholders
 	 when we need to randomly delete events from the queue.
@@ -5872,6 +5882,11 @@
     case SAVE_SESSION_EVENT:
       return Qsave_session;
 
+#ifdef WINDOWSNT
+    case W32_ENDSESSION_EVENT:
+      return Qw32_endsession_event;
+#endif
+
 #ifdef MAC_OS
     case MAC_APPLE_EVENT:
       {
@@ -10904,6 +10919,11 @@
   Qsave_session = intern ("save-session");
   staticpro (&Qsave_session);
 
+#ifdef WINDOWSNT
+  Qw32_endsession_event = intern ("w32-endsession-event");
+  staticpro (&Qw32_endsession_event);
+#endif
+
 #ifdef MAC_OS
   Qmac_apple_event = intern ("mac-apple-event");
   staticpro (&Qmac_apple_event);
@@ -11531,6 +11551,9 @@
    * 			    "handle-select-window"); */
   initial_define_lispy_key (Vspecial_event_map, "save-session",
 			    "handle-save-session");
+  /* W32 log off event */
+  initial_define_lispy_key (Vspecial_event_map, "w32-endsession-event",
+                            "save-buffers-kill-emacs");
 }
 
 /* Mark the pointers in the kboard objects.
Index: termhooks.h
===================================================================
RCS file: /sources/emacs/emacs/src/termhooks.h,v
retrieving revision 1.74
diff -u -r1.74 termhooks.h
--- termhooks.h	5 May 2006 06:45:04 -0000	1.74
+++ termhooks.h	29 Jun 2006 06:39:35 -0000
@@ -328,6 +328,10 @@
      save yourself before shutdown. */
   SAVE_SESSION_EVENT,
 
+#ifdef WINDOWSNT
+  W32_ENDSESSION_EVENT,
+#endif
+
 #ifdef MAC_OS
   /* Generated when an Apple event, a HICommand event, or a Services
      menu event is received and the corresponding handler is
Index: w32console.c
===================================================================
RCS file: /sources/emacs/emacs/src/w32console.c,v
retrieving revision 1.45
diff -u -r1.45 w32console.c
--- w32console.c	6 Feb 2006 15:23:21 -0000	1.45
+++ w32console.c	29 Jun 2006 12:35:04 -0000
@@ -41,6 +41,7 @@
 #undef HAVE_WINDOW_SYSTEM
 #include "frame.h"
 #include "w32inevt.h"
+#include "w32term.h"
 
 /* from window.c */
 extern Lisp_Object Frecenter ();
@@ -95,8 +96,31 @@
 ctrl_c_handler (unsigned long type)
 {
   /* Only ignore "interrupt" events when running interactively.  */
-  return (!noninteractive
-	  && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT));
+/*   return (!noninteractive */
+/* 	  && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT)); */
+  if (!noninteractive) {
+    switch (type)
+      {
+      case CTRL_C_EVENT:
+      case CTRL_BREAK_EVENT:
+        return TRUE;
+      case CTRL_CLOSE_EVENT: // 2
+      case CTRL_LOGOFF_EVENT: // 5
+      case CTRL_SHUTDOWN_EVENT: // 6
+        /* Ending session so tell user */
+        //printf("ctrl_c_handler=%d, dwWindowsThreadid=%d\n", type, dwWindowsThreadId); fflush(stdout);
+        {
+          W32Msg wmsg;
+          wmsg.msg.hwnd = 0;
+          wmsg.msg.message = WM_EMACS_KILL;
+          wmsg.msg.wParam = 0;
+          wmsg.msg.lParam = 0;
+          post_msg(&wmsg);
+          return TRUE;
+        }
+      }
+  }
+  return FALSE;
 }
 
 /* If we're updating a frame, use it as the current frame
Index: w32term.c
===================================================================
RCS file: /sources/emacs/emacs/src/w32term.c,v
retrieving revision 1.246
diff -u -r1.246 w32term.c
--- w32term.c	5 Jun 2006 21:20:59 -0000	1.246
+++ w32term.c	29 Jun 2006 12:31:57 -0000
@@ -4668,6 +4668,11 @@
 	    }
 	  break;
 
+        case WM_EMACS_KILL:
+          //printf("w32_read_socket WM_EMACS_KILL\n"); fflush(stdout);
+          inev.kind = W32_ENDSESSION_EVENT;
+	  break;
+
 	case WM_INITMENU:
 	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
 

[-- Attachment #3: Type: text/plain, Size: 161 bytes --]

_______________________________________________
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug

       reply	other threads:[~2006-06-29 14:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <44A005B7.2080904@student.lu.se>
     [not found] ` <44A01733.4010600@gnu.org>
     [not found]   ` <44A03B61.8080501@student.lu.se>
     [not found]     ` <ufyhrva9u.fsf@jasonrumney.net>
     [not found]       ` <44A2B99B.1020002@student.lu.se>
     [not found]         ` <44A2F974.7040609@gnu.org>
     [not found]           ` <44A31C19.5050000@student.lu.se>
     [not found]             ` <44A3A2DE.4040507@gnu.org>
2006-06-29 14:52               ` Lennart Borgman [this message]
2006-06-29 15:00                 ` Exit hooks not run at logout on w32 David Kastrup
2006-06-29 16:16                   ` Lennart Borgman
2006-06-29 21:40                     ` Mathias Dahl
2006-06-29 22:42                       ` Lennart Borgman
2006-07-04  6:55                         ` Lennart Borgman
2006-07-04  8:13                           ` Jason Rumney
2006-07-05 15:36                             ` Stuart D. Herring
2006-07-04  8:36                           ` Mathias Dahl
2006-07-04  8:49                             ` Jason Rumney
2006-07-04 16:49                               ` Lennart Borgman
2006-07-04  9:24                             ` Kim F. Storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44A3E918.5000304@student.lu.se \
    --to=lennart.borgman.073@student.lu.se \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-pretest-bug@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).