summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libunix.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-17 19:45:07 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-17 19:45:07 +0000
commitb7516d279965cc139c24507688047172bb7a0f7f (patch)
treefbf8b141c74def2fbfe2fb343e457dad0ae24cb7 /crawl-ref/source/libunix.cc
parent23c5277317de657f8376d1b5f33144948a811a42 (diff)
downloadcrawl-ref-b7516d279965cc139c24507688047172bb7a0f7f.tar.gz
crawl-ref-b7516d279965cc139c24507688047172bb7a0f7f.zip
Basic SIGWINCH handling for Unix. Still needs to handle some cases (resizing
the term in the level-map doesn't work right, for instance). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1593 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libunix.cc')
-rw-r--r--crawl-ref/source/libunix.cc53
1 files changed, 47 insertions, 6 deletions
diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc
index 133eb70620..a1d8b5e0ce 100644
--- a/crawl-ref/source/libunix.cc
+++ b/crawl-ref/source/libunix.cc
@@ -46,6 +46,8 @@
#include "enum.h"
#include "externs.h"
#include "files.h"
+#include "stuff.h"
+#include "view.h"
#ifdef UNICODE_GLYPHS
#include <wchar.h>
@@ -192,6 +194,8 @@ static int unix_multibyte_strlen(const std::string &s)
}
#endif
+static void unix_handle_terminal_resize();
+
static void termio_init()
{
tcgetattr(0, &def_term);
@@ -217,12 +221,16 @@ static void termio_init()
crawl_state.multibyte_strlen = unix_multibyte_strlen;
}
#endif
+
+ crawl_state.terminal_resize_handler = unix_handle_terminal_resize;
}
-int getch_ck() {
+int getch_ck()
+{
int c = getch();
- switch (c) {
+ switch (c)
+ {
// [dshaligram] MacOS ncurses returns 127 for backspace.
case 127:
case KEY_BACKSPACE: return CK_BKSP;
@@ -239,8 +247,17 @@ int getch_ck() {
}
}
-#if defined(USE_UNIX_SIGNALS) && defined(SIGHUP_SAVE)
+#if defined(USE_UNIX_SIGNALS)
+static void handle_sigwinch(int)
+{
+ if (crawl_state.waiting_for_comand)
+ handle_terminal_resize();
+ else
+ crawl_state.terminal_resized = true;
+}
+
+#ifdef SIGHUP_SAVE
/* [ds] This SIGHUP handling is primitive and far from safe, but it
* should be better than nothing. Feel free to get rigorous on this.
*/
@@ -265,8 +282,9 @@ static void handle_hangup(int)
exit(1);
}
}
+#endif // SIGHUP_SAVE
-#endif // USE_UNIX_SIGNALS && SIGHUP_SAVE
+#endif // USE_UNIX_SIGNALS
static WINDOW *Message_Window;
static void setup_message_window()
@@ -275,14 +293,23 @@ static void setup_message_window()
crawl_view.msgp.y - 1, crawl_view.msgp.x - 1 );
if (!Message_Window)
{
- fprintf(stderr, "Unable to create message window!");
- exit(1);
+ if (crawl_state.need_save)
+ save_game(true);
+
+ // Never reaches here unless the game didn't need saving.
+ end(1, false, "Unable to create message window!");
}
scrollok(Message_Window, true);
idlok(Message_Window, true);
}
+static void unix_handle_terminal_resize()
+{
+ unixcurses_shutdown();
+ unixcurses_startup();
+}
+
void clear_message_window()
{
wattrset( Message_Window, curs_fg_attr(LIGHTGREY) );
@@ -337,6 +364,8 @@ void unixcurses_startup( void )
#ifdef SIGHUP_SAVE
signal(SIGHUP, handle_hangup);
#endif
+
+ signal(SIGWINCH, handle_sigwinch);
#endif
@@ -366,6 +395,12 @@ void unixcurses_startup( void )
void unixcurses_shutdown()
{
+ if (Message_Window)
+ {
+ delwin(Message_Window);
+ Message_Window = NULL;
+ }
+
// resetty();
endwin();
@@ -379,6 +414,12 @@ void unixcurses_shutdown()
#ifdef SIGINT
signal(SIGINT, SIG_DFL);
#endif
+
+#ifdef SIGHUP_SAVE
+ signal(SIGHUP, SIG_DFL);
+#endif
+
+ signal(SIGWINCH, SIG_DFL);
#endif
}