]> skyeroc.xyz Git - dgamelaunch/commitdiff
Move the terminal resize to when you're watching the game.
authorPasi Kallinen <paxed@alt.org>
Sun, 18 Oct 2009 18:24:22 +0000 (18:24 +0000)
committerPasi Kallinen <paxed@alt.org>
Sun, 18 Oct 2009 18:24:22 +0000 (18:24 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@501 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

dgamelaunch.c
examples/dgl_menu_watchmenu_help.txt
ttyplay.c
ttyplay.h

index b54b06f12011da82d824cf286c5bdca1ab577c5d..b1eb954bfb6a83833ebc3043e610c8e19098ad88 100644 (file)
@@ -372,7 +372,7 @@ void
 inprogressmenu (int gameid)
 {
     const char *selectorchars = "abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ";
-  int i, menuchoice, len = 20, offset = 0, doresizewin = 0;
+  int i, menuchoice, len = 20, offset = 0;
   static dg_sortmode sortmode = NUM_SORTMODES;
   time_t ctime;
   struct dg_game **games = NULL;
@@ -383,6 +383,9 @@ inprogressmenu (int gameid)
   int max_height = -1;
   int selected = -1;
 
+  int resizex = -1;
+  int resizey = -1;
+
   char *selectedgame = NULL;
 
   int abs_max_height;
@@ -559,10 +562,6 @@ inprogressmenu (int gameid)
          clear ();
          break;
 
-       case '1':
-           doresizewin = (doresizewin ? 0 : 1);
-           break;
-
        case 13:
        case 10:
        case KEY_ENTER:
@@ -608,32 +607,19 @@ watchgame:
               clear ();
               refresh ();
               endwin ();
-             if (doresizewin)
-               {
-                 /*
-                  * Let curses deal with the resize later. Perhaps this is
-                  * not the best way.
-                  */
-                 sigemptyset (&toblock);
-                 sigaddset (&toblock, SIGWINCH);
-                 sigprocmask (SIG_BLOCK, &toblock, &oldmask);
-                 printf ("\033[8;%d;%dt",
-                   games[idx]->ws_row,
-                   games[idx]->ws_col);
-                 fflush (stdout);
-               }
+
+             resizey = games[idx]->ws_row;
+             resizex = games[idx]->ws_col;
              if (loggedin)
                  setproctitle("%s [watching %s]", me->username, chosen_name);
              else
                  setproctitle("<Anonymous> [watching %s]", chosen_name);
-              ttyplay_main (ttyrecname, 1);
+              ttyplay_main (ttyrecname, 1, resizex, resizey);
              if (loggedin)
                  setproctitle("%s", me->username);
              else
                  setproctitle("<Anonymous>");
               initcurses ();
-             if (doresizewin)
-               sigprocmask (SIG_SETMASK, &oldmask, NULL);
             }
         }
 
index 22feb71170d35bf7cee81add01b0daa738c359cd..dfde163ecce6d9aedb7bc0e1784221528f04ee6b 100644 (file)
 
  While watching a game
  ---------------------
- q        returns back to the watching menu.
+ q        return back to the watching menu.
  m        send mail to the player (requires login).
  s        toggle charset stripping between DEC/IBM/none.
-
+ r        resize your terminal to match the player's terminal.
 
 
  Press 'q' or space to return to the watching menu.
index c269f46d67a1f34335ebbfd5d7e9b18407adb250..5a9c7a7e52118efe8ef937da34a43cb1cc276e4e 100644 (file)
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -61,6 +61,9 @@
 int stripped = NO_GRAPHICS;
 static int got_sigwinch = 0;
 
+static int term_resizex = -1;
+static int term_resizey = -1;
+
 void
 ttyplay_sigwinch_func(int sig)
 {
@@ -247,6 +250,10 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
             case 'q':
               return READ_EOF;
               break;
+           case 'r':
+               if (term_resizex > 0 && term_resizey > 0)
+                   printf ("\033[8;%d;%dt", term_resizey, term_resizex);
+               break;
            case 's':
              switch (stripped)
              {
@@ -445,7 +452,7 @@ ttypeek (FILE * fp, double speed)
 
 
 int
-ttyplay_main (char *ttyfile, int mode)
+ttyplay_main (char *ttyfile, int mode, int resizex, int resizey)
 {
   double speed = 1.0;
   ReadFunc read_func = ttyread;
@@ -465,6 +472,12 @@ ttyplay_main (char *ttyfile, int mode)
   new.c_cc[VTIME] = 0;
   tcsetattr (0, TCSANOW, &new); /* Make it current */
 
+
+  if (resizex > 0 && resizey > 0) {
+      term_resizex = resizex;
+      term_resizey = resizey;
+  }
+
   got_sigwinch = 0;
   old_sigwinch = signal(SIGWINCH, ttyplay_sigwinch_func);
 
@@ -479,5 +492,7 @@ ttyplay_main (char *ttyfile, int mode)
   if (old_sigwinch != SIG_ERR)
       signal(SIGWINCH, old_sigwinch);
 
+  term_resizex = term_resizey = -1;
+
   return 0;
 }
index 1dd36e85b411c8a800c89e6f4de05693bc2b2cde..27e1a6c0c05fe1817e828b43bd1612d791319b84 100644 (file)
--- a/ttyplay.h
+++ b/ttyplay.h
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include "ttyrec.h"
 
-int ttyplay_main (char *ttyfile, int mode);
+int ttyplay_main (char *ttyfile, int mode, int resizex, int resizey);
 
 typedef double (*WaitFunc) (struct timeval prev,
                             struct timeval cur, double speed);