Detect screen dimensions _before_ attaching to the server.
authorArt Cancro <ajc@uncensored.citadel.org>
Wed, 7 Dec 2011 18:04:37 +0000 (13:04 -0500)
committerArt Cancro <ajc@uncensored.citadel.org>
Wed, 7 Dec 2011 18:04:37 +0000 (13:04 -0500)
Also moved check_screen_dims() to screen.c where it belongs.

citadel/textclient/citadel.c
citadel/textclient/commands.c
citadel/textclient/screen.c
citadel/textclient/screen.h

index e1c504aa55979506e5b59cdf421b0754f0732914..b30bef5be8f8770e2d4b8c207a5104d580aa6246 100644 (file)
@@ -86,8 +86,6 @@ char editor_paths[MAX_EDITORS][SIZ];  /* paths to external editors */
 char printcmd[SIZ];            /* print command */
 int editor_pid = (-1);
 char fullname[USERNAME_SIZE];
-int screenwidth;
-int screenheight;
 unsigned room_flags;
 unsigned room_flags2;
 int entmsg_ok = 0;
@@ -107,7 +105,6 @@ char newnow;
 long highest_msg_read;         /* used for <A>bandon room cmd */
 long maxmsgnum;                        /* used for <G>oto */
 char sigcaught = 0;
-char have_xterm = 0;           /* are we running on an xterm? */
 char rc_username[USERNAME_SIZE];
 char rc_password[32];
 char hostbuf[SIZ];
@@ -1050,32 +1047,6 @@ void forget_this_floor(CtdlIPC *ipc)
 }
 
 
-/* 
- * Figure out the physical screen dimensions, if we can
- * WARNING:  this is now called from a signal handler!
- */
-void check_screen_dims(void)
-{
-#ifdef TIOCGWINSZ
-       struct {
-               unsigned short height;  /* rows */
-               unsigned short width;   /* columns */
-               unsigned short xpixels;
-               unsigned short ypixels;         /* pixels */
-       } xwinsz;
-
-       if (have_xterm) {       /* dynamically size screen if on an xterm */
-               if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
-                       if (xwinsz.height)
-                               screenheight = (int) xwinsz.height;
-                       if (xwinsz.width)
-                               screenwidth = (int) xwinsz.width;
-               }
-       }
-#endif
-}
-
-
 /*
  * set floor mode depending on client, server, and user settings
  */
@@ -1562,6 +1533,11 @@ int main(int argc, char **argv)
        
 
        screen_new();
+       /* Get screen dimensions.  First we go to a default of 80x24.
+        * Then attempt to read the actual screen size from the terminal.
+        */
+       check_screen_dims();
+
 
 #ifdef __CYGWIN__
        newprompt("Connect to (return for local server): ", hostbuf, 64);
@@ -1625,9 +1601,6 @@ int main(int argc, char **argv)
        scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
                   ipc->ServInfo.site_location);
 
-       screenwidth = 80;       /* default screen dimensions */
-       screenheight = 24;
-       
        scr_printf(" pause    next    stop\n");
        scr_printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
        formout(ipc, "hello");  /* print the opening greeting */
@@ -1799,21 +1772,7 @@ NEWUSR:  if (IsEmptyStr(rc_password)) {
        CtdlMakeTempFileName(temp2, sizeof temp2);
        CtdlMakeTempFileName(tempdir, sizeof tempdir);
 
-       /* Get screen dimensions.  First we go to a default of 80x24.  Then
-        * we try to get the user's actual screen dimensions off the server.
-        * However, if we're running on an xterm, all this stuff is
-        * irrelevant because we're going to dynamically size the screen
-        * during the session.
-        */
-       screenwidth = 80;
-       screenheight = 24;
        r = CtdlIPCGetConfig(ipc, &myself, aaa);
-       if (getenv("TERM") != NULL)
-               if (!strcmp(getenv("TERM"), "xterm")) {
-                       have_xterm = 1;
-               }
-       check_screen_dims();
-
        set_floor_mode(ipc);
 
        /* Enter the lobby */
@@ -1833,7 +1792,7 @@ NEWUSR:   if (IsEmptyStr(rc_password)) {
                mcmd = getcmd(ipc, argbuf);     /* Get keyboard command */
 
 #ifdef TIOCGWINSZ
-               check_screen_dims();            /* if xterm, get screen size */
+               check_screen_dims();            /* get screen size */
 #endif
 
                if (termn8 == 0)
index e98dad3872955267bc358fa2d75392baead8b30e..d5c93e84c66265fafae7354764ee25986f852957 100644 (file)
@@ -755,9 +755,6 @@ void load_command_set(void)
                if (!strncasecmp(buf, "expcmd=", 7))
                        strcpy(rc_exp_cmd, &buf[7]);
 
-               if (!strncasecmp(buf, "local_screen_dimensions=", 24))
-                       have_xterm = (char) atoi(&buf[24]);
-
                if (!strncasecmp(buf, "use_floors=", 11)) {
                        if (!strcasecmp(&buf[11], "yes"))
                                rc_floor_mode = RC_YES;
index 67cd2f506e56890c4637ff79552f6dff544464ff..c79d693fd8e1599fba5e534fd5b816a83a96640e 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdarg.h>
 #include <ctype.h>
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #include "sysdep.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
@@ -44,17 +45,39 @@ char status_line[1024] = "     ";
 /* the default paginator prompt will be replaced by the server's prompt when we learn it */
 char *moreprompt = " -- more -- ";
 
-extern int screenheight;
-extern int screenwidth;
+int screenheight = 24;
+int screenwidth = 80;
 int lines_printed = 0;
 int cols_printed = 0;
 
 extern int rc_ansi_color;
 extern int rc_prompt_control;
-extern void check_screen_dims(void);
-
 void do_keepalive(void);
 
+/*
+ * Attempt to discover the screen dimensions. 
+ * WARNING: This is sometimes called from a signal handler.
+ */
+void check_screen_dims(void)
+{
+#ifdef TIOCGWINSZ
+       struct {
+               unsigned short height;  /* rows */
+               unsigned short width;   /* columns */
+               unsigned short xpixels;
+               unsigned short ypixels; /* pixels */
+       } xwinsz;
+
+       if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
+               if (xwinsz.height)
+                       screenheight = (int) xwinsz.height;
+               if (xwinsz.width)
+                       screenwidth = (int) xwinsz.width;
+       }
+#endif
+}
+
+
 /*
  * Initialize the screen
  */
@@ -222,7 +245,6 @@ RETSIGTYPE scr_winch(int signum)
        /* if we receive this signal, we must be running
         * in a terminal that supports resizing.
         */
-       have_xterm = 1;
        caught_sigwinch = 1;
        check_screen_dims();
        signal(SIGWINCH, scr_winch);
index 7ed7f66dd240c8ab4a265fd864342cc8a33ad9a1..825a550a4d09a0ccd52669d6513767e500b8620e 100644 (file)
@@ -14,3 +14,7 @@ void wait_indicator(int state);
 void ctdl_beep(void);
 void scr_wait_indicator(int);
 extern char status_line[];
+extern void check_screen_dims(void);
+
+extern int screenwidth;
+extern int screenheight;