From 99b566ae2697136e3d4a9cfccc466e2a5cd7f3d6 Mon Sep 17 00:00:00 2001
From: Bill Kendrick
Date: Wed, 3 Apr 2019 22:49:04 -0700
Subject: [PATCH] Support SIGUSR1/2 for immediate(ish) quit-and-save
Respond to a SIGUSR1 or SIGUSR2 signal by configuring itself
for autosave, saving a new file, or overwriting the current,
respectively, and sending itself a SIGTERM (which _generally_
causes Tux Paint to quit, depending on where you are in the UI).
Closes https://sourceforge.net/p/tuxpaint/feature-requests/188/
---
docs/CHANGES.txt | 16 +++++++++++--
docs/en/README.txt | 28 +++++++++++-----------
docs/en/SIGNALS.txt | 50 ++++++++++++++++++++++++++++++++++++++++
docs/en/html/README.html | 7 ++++--
src/tuxpaint.c | 32 +++++++++++++++++++------
5 files changed, 109 insertions(+), 24 deletions(-)
create mode 100644 docs/en/SIGNALS.txt
diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt
index 939227de7..ebbb44d66 100644
--- a/docs/CHANGES.txt
+++ b/docs/CHANGES.txt
@@ -2,13 +2,13 @@ CHANGES.txt for Tux Paint
Tux Paint - A simple drawing program for children.
-Copyright (c) 2002-2018
+Copyright (c) 2002-2019
Various contributors (see below, and AUTHORS.txt)
http://www.tuxpaint.org/
$Id$
-2018.Dec.18 (0.9.24)
+2019.Apr.3 (0.9.24)
* Bug Fixes
---------
* Correct issue that prevented Tux Paint from lauching on Mac OS X 10.7.
@@ -34,6 +34,14 @@ $Id$
Use "--newcolorslast" option.
(Suggested by Bernard Verhaeghe)
+ * Recognize signals (SIGUSR1 and SIGUSR2) on POSIX systems,
+ which causes Tux Paint to quit, first saving the current drawing
+ (if unsaved) (like "--autosave"), either saving a new image
+ (like "--saveovernew") (via SIGUSR1), or overwritting the current
+ drawing (like "--saveover") (via SIGUSR2).
+ (Thanks to Flavio Airundo for the idea; closes
+ https://sourceforge.net/p/tuxpaint/feature-requests/188/)
+
* Documentation updates
---------------------
* Mended link to MinGW/MSYS instructions at John Popplewell's website.
@@ -41,6 +49,10 @@ $Id$
* Improved and expanded usage info (e.g., "tuxpaint --help" output)
+ * Documentation on POSIX signals recognized by Tux Paint (e.g.,
+ the new "SIGUSR1" & "SIGUSR2") added to a new doc file,
+ "SIGNALS.txt".
+
* Misc
----
* Verbose debugging, and "DEBUG_PRINTF()" macro now available;
diff --git a/docs/en/README.txt b/docs/en/README.txt
index ae4278609..e87dff5d1 100644
--- a/docs/en/README.txt
+++ b/docs/en/README.txt
@@ -3,22 +3,22 @@
A simple drawing program for children
- Copyright 2002-2018 by various contributors; see AUTHORS.txt
+ Copyright 2002-2019 by various contributors; see AUTHORS.txt
http://www.tuxpaint.org/
- June 14, 2002 - December 18, 2018
+ June 14, 2002 - April 3, 2019
----------------------------------------------------------------------
- +------------------------------------------------------------------------+
- |Table of Contents |
- |------------------------------------------------------------------------|
- | * About |
- | * Using Tux Paint |
- | * Loading Other Pictures into Tux Paint |
- | * Further Reading |
- | * How to Get Help |
- +------------------------------------------------------------------------+
+ +-------------------------------------------+
+ |Table of Contents |
+ |-------------------------------------------|
+ | * About |
+ | * Using Tux Paint |
+ | * Loading Other Pictures into Tux Paint |
+ | * Further Reading |
+ | * How to Get Help |
+ +-------------------------------------------+
----------------------------------------------------------------------
@@ -97,8 +97,8 @@ Loading Tux Paint
Windows Users
- [Icon]
- Tux Paint
+ [Icon]
+ Tux Paint
If you installed Tux Paint on your computer using the
'Tux Paint Installer,' it will have asked you whether you wanted a
@@ -876,6 +876,8 @@ Doing it Manually
Notes on creating PNG format bitmapped images for use in Tux Paint.
* SVG.txt
Notes on creating SVG format vector images for use in Tux Paint.
+ * SIGNALS.txt
+ Information about POSIX signals Tux Paint responds to.
----------------------------------------------------------------------
diff --git a/docs/en/SIGNALS.txt b/docs/en/SIGNALS.txt
new file mode 100644
index 000000000..17535dfd6
--- /dev/null
+++ b/docs/en/SIGNALS.txt
@@ -0,0 +1,50 @@
+SIGNALS.txt for Tux Paint
+
+Tux Paint - A simple drawing program for children.
+
+Copyright 2019 by Bill Kendrick and others
+bill@newbreedsoftware.com
+http://www.tuxpaint.org/
+
+April 3, 2019
+
+Tux Paint responds to the following signals (which can be
+sent to the program's process via `kill` or `killall`, for
+example).
+
+ * SIGTERM (also, [Ctrl]+[C] from a terminal running "tuxpaint")
+
+ Tux Paint responds as if the "Quit" button were pressed,
+ or the desktop environment was told to close Tux Paint
+ (e.g., by clicking a window close button, or pressing
+ [Alt]+[F4] on most systems).
+
+ From the main interface, Tux Paint will prompt whether or
+ not you wish to quit, and (unless overridden by "--autosave")
+ if you'd like to save the current drawing (if unsaved),
+ and if so, and it's a modified version of an existing drawing
+ (unless overridden by "--saveover" or "--saveovernew"),
+ whether or not to overwrite the existing drawing, or save
+ to a new file.
+
+ From other parts of the interface, the signal is currently
+ interpreted as a request to go back (e.g., from the
+ "New" dialog back to the main interface), as if a "Back"
+ button in Tux Paint were clicked, or the [Esc] key pressed.
+
+ * SIGUSR1 & SIGUSR2
+
+ Tux Paint responds by setting its "--autosave" option, and either
+ "--saveovernew" (for SIGUSR1) or "--saveover" (for SIGUSR2),
+ and sending itself a SIGTERM signal.
+
+ So, from the main interface, Tux Paint should quit almost immediately,
+ with no questions asked.
+
+ From other parts of the interface, unfortunately, Tux Paint
+ will go back one level in the interface. Therefore, at this time,
+ it may be necessary to send this signal to Tux Paint a few times,
+ for it to quit completely.
+
+ e.g., `killall -s SIGUSR1 tuxpaint`
+
diff --git a/docs/en/html/README.html b/docs/en/html/README.html
index 5e09968cc..049cd4c96 100644
--- a/docs/en/html/README.html
+++ b/docs/en/html/README.html
@@ -17,12 +17,12 @@ version
A simple drawing program for children
-Copyright 2002-2018 by various contributors; see AUTHORS.txt
+
Copyright 2002-2019 by various contributors; see AUTHORS.txt
http://www.tuxpaint.org/
June 14, 2002 -
- December 18, 2018
+ April 3, 2019
@@ -1159,6 +1159,9 @@ version
SVG.txt
Notes on creating SVG format vector images for use in Tux Paint.
+ SIGNALS.txt
+ Information about POSIX signals Tux Paint responds to.
+
diff --git a/src/tuxpaint.c b/src/tuxpaint.c
index 185afb53d..095d85b11 100644
--- a/src/tuxpaint.c
+++ b/src/tuxpaint.c
@@ -1197,6 +1197,7 @@ static int disable_save;
static int ok_to_use_lockfile = 1;
static int start_blank;
static int autosave_on_quit;
+static int no_prompt_on_quit = 0;
static int dont_do_xor;
static int dont_load_stamps;
@@ -7732,13 +7733,19 @@ static int generate_fontconfig_cache(void *vp)
((c) >= 'a' && (c) <= 'f') ? ((c) - 'a' + 10) : 0)
#ifndef WIN32
-/**
- * FIXME
- */
static void signal_handler(int sig)
{
- (void)sig;
// It is not legal to call printf or most other functions here!
+ if (sig == SIGUSR1 || sig == SIGUSR2) {
+ autosave_on_quit = 1;
+ no_prompt_on_quit = 1;
+ if (sig == SIGUSR1) {
+ promptless_save = SAVE_OVER_NO;
+ } else {
+ promptless_save = SAVE_OVER_ALWAYS;
+ }
+ raise(SIGTERM);
+ }
}
#endif
@@ -13808,9 +13815,16 @@ static int do_quit(int tool)
{
int done, tmp_tool;
- done = do_prompt_snd(PROMPT_QUIT_TXT,
- PROMPT_QUIT_YES, PROMPT_QUIT_NO, SND_AREYOUSURE,
- (TOOL_QUIT % 2) * 48 + 24, (TOOL_QUIT / 2) * 48 + 40 + 24);
+ if (!no_prompt_on_quit)
+ {
+ done = do_prompt_snd(PROMPT_QUIT_TXT,
+ PROMPT_QUIT_YES, PROMPT_QUIT_NO, SND_AREYOUSURE,
+ (TOOL_QUIT % 2) * 48 + 24, (TOOL_QUIT / 2) * 48 + 40 + 24);
+ }
+ else
+ {
+ done = 1;
+ }
if (done && !been_saved && !disable_save)
{
@@ -24209,6 +24223,10 @@ static void setup(void)
instead of 'Ok') */
signal(SIGPIPE, signal_handler);
+
+ /* Set up signal for no-questions-asked remote closing of app */
+ signal(SIGUSR1, signal_handler);
+ signal(SIGUSR2, signal_handler);
#endif
}