From f6e40b8bf8e9048e9b575da8e788491818e6cf96 Mon Sep 17 00:00:00 2001 From: keni Date: Fri, 15 Jan 2010 17:51:28 +0000 Subject: [PATCH] have core ask windowport if suspend is ok PORTS: Please make sure I've done the right thing for/to your code. This patch adds a new winproc that lets the window port approve or cancel the suspend request - this should take care of the Mac Qt lockup issue. In addition, Unix suspend is restricted to accounts that can use the shell if SYSCF is defined. --- doc/window.doc | 3 +++ include/extern.h | 2 ++ include/winprocs.h | 1 + src/cmd.c | 18 +++++++++++++++--- src/windows.c | 11 +++++++++++ sys/amiga/winami.c | 2 ++ sys/mac/macwin.c | 1 + sys/share/ioctl.c | 10 ++++++++++ sys/unix/sysconf | 6 +++--- sys/wince/mswproc.c | 1 + win/X11/winX.c | 1 + win/gem/wingem.c | 1 + win/gnome/gnbind.c | 1 + win/tty/wintty.c | 1 + win/win32/mswproc.c | 1 + 15 files changed, 54 insertions(+), 6 deletions(-) diff --git a/doc/window.doc b/doc/window.doc index 79b663265..29c955ace 100644 --- a/doc/window.doc +++ b/doc/window.doc @@ -488,6 +488,9 @@ suspend_nhwindows(str) -- Prepare the window to be suspended. resume_nhwindows() -- Restore the windows after being suspended. +can_suspend() -- Tell the core if the window system will allow the game + to be suspended now. If unconditionally yes or no, use + genl_can_suspend_yes() or genl_can_suspend_no(). start_screen() -- Only used on Unix tty ports, but must be declared for completeness. Sets up the tty to work in full-screen diff --git a/include/extern.h b/include/extern.h index d6c855abe..5d5e29413 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2574,6 +2574,8 @@ E boolean FDECL(mwelded, (struct obj *)); /* ### windows.c ### */ E void FDECL(choose_windows, (const char *)); +E boolean NDECL(genl_can_suspend_no); +E boolean NDECL(genl_can_suspend_yes); E char FDECL(genl_message_menu, (CHAR_P,int,const char *)); E void FDECL(genl_preference_update, (const char *)); E char *FDECL(genl_getmsghistory, (BOOLEAN_P)); diff --git a/include/winprocs.h b/include/winprocs.h index da65f220c..c2c3f0019 100644 --- a/include/winprocs.h +++ b/include/winprocs.h @@ -80,6 +80,7 @@ struct window_procs { void FDECL((*win_status_threshold), (int,int,anything,int,int,int)); # endif #endif + boolean NDECL((*win_can_suspend)); }; extern diff --git a/src/cmd.c b/src/cmd.c index d0877a465..878ab5565 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -109,6 +109,8 @@ extern int NDECL(dozap); /**/ extern int NDECL(doorganize); /**/ #endif /* DUMB */ +static int NDECL(dosuspend_core); /**/ + static int NDECL((*timed_occ_fn)); STATIC_PTR int NDECL(doprev_message); @@ -2124,9 +2126,7 @@ static const struct func_tab cmdlist[] = { {C('w'), TRUE, wiz_wish}, #endif {C('x'), TRUE, doattributes}, -#ifdef SUSPEND - {C('z'), TRUE, dosuspend}, -#endif + {C('z'), TRUE, dosuspend_core}, {'a', FALSE, doapply}, {'A', FALSE, doddoremarm}, {M('a'), TRUE, doorganize}, @@ -3586,4 +3586,16 @@ char def; return (*windowprocs.win_yn_function)(qbuf, resp, def); } +int +dosuspend_core(){ +#ifdef SUSPEND + /* Does current window system support suspend? */ + if( (*windowprocs.win_can_suspend)()){ + /* NB: SYSCF SHELLERS handled in port code. */ + dosuspend(); + } else +#endif + Norep("Suspend command not available."); +} + /*cmd.c*/ diff --git a/src/windows.c b/src/windows.c index 8816bb737..03f2db51a 100644 --- a/src/windows.c +++ b/src/windows.c @@ -88,6 +88,16 @@ struct win_choices { { 0, 0 } /* must be last */ }; +boolean +genl_can_suspend_no(){ + return FALSE; +} + +boolean +genl_can_suspend_yes(){ + return TRUE; +} + STATIC_OVL void def_raw_print(s) @@ -316,6 +326,7 @@ static struct window_procs hup_procs = { genl_status_threshold, # endif # endif /* STATUS_VIA_WINDOWPORT */ + genl_can_suspend_no, }; static void FDECL((*previnterface_exit_nhwindows), (const char *)) = 0; diff --git a/sys/amiga/winami.c b/sys/amiga/winami.c index 623a2b9bd..a663f14ea 100644 --- a/sys/amiga/winami.c +++ b/sys/amiga/winami.c @@ -93,6 +93,7 @@ struct window_procs amii_procs = genl_status_threshold, # endif #endif + genl_can_suspend_yes, }; /* The view window layout uses the same function names so we can use @@ -164,6 +165,7 @@ struct window_procs amiv_procs = genl_status_threshold, # endif #endif + genl_can_suspend_yes, }; unsigned short amii_initmap[ AMII_MAXCOLORS ]; diff --git a/sys/mac/macwin.c b/sys/mac/macwin.c index 8e5bea8a1..9f40b6f34 100644 --- a/sys/mac/macwin.c +++ b/sys/mac/macwin.c @@ -3293,6 +3293,7 @@ struct window_procs mac_procs = { 0, // mac_end_screen, genl_outrip, genl_preference_update, + genl_can_suspend_no, }; /*macwin.c*/ diff --git a/sys/share/ioctl.c b/sys/share/ioctl.c index 240ee7774..779fdd5b7 100644 --- a/sys/share/ioctl.c +++ b/sys/share/ioctl.c @@ -155,6 +155,16 @@ setioctls() int dosuspend() { +#ifdef SYSCF + /* NB: check_user_string() is port-specific. */ + if( !sysopt.shellers + || !sysopt.shellers[0] + || !check_user_string(sysopt.shellers) + ){ + Norep("Suspend command not available."); + return; + } +#endif # ifdef SIGTSTP if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) { suspend_nhwindows((char *)0); diff --git a/sys/unix/sysconf b/sys/unix/sysconf index 6b8e71fdd..644339098 100644 --- a/sys/unix/sysconf +++ b/sys/unix/sysconf @@ -9,11 +9,11 @@ # A value of * allows anyone to enter debugging mode. WIZARDS=root,games -# Users allowed to use the ! (shell escape) command. Uses the same syntax -# as the WIZARDS option above. +# Users allowed to use the ! (shell escape) command or to suspend the game. +# Uses the same syntax as the WIZARDS option above. #SHELLERS= -# Limit the number of simultaneous games (see also and nethack.sh). +# Limit the number of simultaneous games (see also nethack.sh). MAXPLAYERS=10 # If not null, added to string "To get local support, " in the support diff --git a/sys/wince/mswproc.c b/sys/wince/mswproc.c index 3f8c80e64..64ebb0c4b 100644 --- a/sys/wince/mswproc.c +++ b/sys/wince/mswproc.c @@ -108,6 +108,7 @@ struct window_procs mswin_procs = { genl_status_threshold, # endif #endif + genl_can_suspend_no, }; /* diff --git a/win/X11/winX.c b/win/X11/winX.c index 8facc8e5b..1532c1f24 100644 --- a/win/X11/winX.c +++ b/win/X11/winX.c @@ -173,6 +173,7 @@ struct window_procs X11_procs = { genl_status_threshold, # endif #endif + genl_can_suspend_no, /* XXX may not always be correct */ }; /* diff --git a/win/gem/wingem.c b/win/gem/wingem.c index fc257c1e2..69b079030 100644 --- a/win/gem/wingem.c +++ b/win/gem/wingem.c @@ -111,6 +111,7 @@ struct window_procs Gem_procs = { genl_status_threshold, # endif #endif + genl_can_suspend_no, }; #ifdef MAC diff --git a/win/gnome/gnbind.c b/win/gnome/gnbind.c index ef74ea7ff..c304cdb5b 100644 --- a/win/gnome/gnbind.c +++ b/win/gnome/gnbind.c @@ -90,6 +90,7 @@ struct window_procs Gnome_procs = { genl_status_threshold, # endif #endif + genl_can_suspend_yes, }; /* diff --git a/win/tty/wintty.c b/win/tty/wintty.c index cbdf85d01..948d8e459 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -137,6 +137,7 @@ struct window_procs tty_procs = { genl_status_threshold, # endif #endif + genl_can_suspend_yes, }; static int maxwin = 0; /* number of windows in use */ diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 78b7c9be3..de2d6df5c 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -136,6 +136,7 @@ struct window_procs mswin_procs = { genl_status_threshold, # endif #endif + genl_can_suspend_yes, }; -- 2.40.0