[Gpm] gpm and screen
Johannes Zellner
johannes@zellner.org
Thu, 30 Nov 2000 23:14:04 +0100
--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
oops. here's the promised patch.
--
Johannes
--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gpm.screen.diff"
diff -rcw gpm-1.19.3.orig/liblow.c gpm-1.19.3/liblow.c
*** gpm-1.19.3.orig/liblow.c Tue Jul 18 14:06:06 2000
--- gpm-1.19.3/liblow.c Thu Nov 30 21:18:14 2000
***************
*** 77,83 ****
unsigned char _gpm_buf[6*sizeof(short)];
unsigned short * _gpm_arg = (unsigned short *)_gpm_buf +1;
! int gpm_consolefd=-1; /* used to invoke ioctl() */
int gpm_morekeys=0;
/*-------------------------------------------------------------------*/
static inline int putdata(int where, Gpm_Connect *what)
--- 77,84 ----
unsigned char _gpm_buf[6*sizeof(short)];
unsigned short * _gpm_arg = (unsigned short *)_gpm_buf +1;
! enum { GPM_FD_INVALID = -1, GPM_FD_SCREEN = -2 };
! int gpm_consolefd = GPM_FD_INVALID; /* used to invoke ioctl() */
int gpm_morekeys=0;
/*-------------------------------------------------------------------*/
static inline int putdata(int where, Gpm_Connect *what)
***************
*** 114,120 ****
SIG_DFL != gpm_saved_winch_hook.sa_handler) {
gpm_saved_winch_hook.sa_handler(signum);
} /*if*/
! if (ioctl(gpm_consolefd, TIOCGWINSZ, &win) == -1) {
return;
} /*if*/
if (!win.ws_col || !win.ws_row) {
--- 115,128 ----
SIG_DFL != gpm_saved_winch_hook.sa_handler) {
gpm_saved_winch_hook.sa_handler(signum);
} /*if*/
! if (GPM_FD_SCREEN == gpm_consolefd) {
! /* TODO: */
! win.ws_col = 80;
! win.ws_row = 25;
! } else if (gpm_consolefd <= 0)
! /* safety check */
! return;
! else if (ioctl(gpm_consolefd, TIOCGWINSZ, &win) == -1) {
return;
} /*if*/
if (!win.ws_col || !win.ws_row) {
***************
*** 177,183 ****
/*-------------------------------------------------------------------*/
int Gpm_Open(Gpm_Connect *conn, int flag)
{
! char tty[32];
char *term;
int i;
struct sockaddr_un addr;
--- 185,191 ----
/*-------------------------------------------------------------------*/
int Gpm_Open(Gpm_Connect *conn, int flag)
{
! char tty[64];
char *term;
int i;
struct sockaddr_un addr;
***************
*** 236,248 ****
if (!t) goto err;
strcpy(tty,t);
if (strncmp(tty,"/dev/tty",8) || !isdigit(tty[8]))
goto err;
conn->vc=atoi(tty+8);
}
else /* a default handler -- use console */
sprintf(tty,"/dev/tty0");
! if (gpm_consolefd==-1)
if ((gpm_consolefd=open(tty,O_WRONLY))<0)
{
gpm_debug_log(LOG_ERR,"%s: %s",tty,strerror(errno));
--- 244,283 ----
if (!t) goto err;
strcpy(tty,t);
if (strncmp(tty,"/dev/tty",8) || !isdigit(tty[8]))
+ {
+ char* sty = getenv("STY");
+ /* as set by SCREEN, e.g
+ * STY=417.tty1.kristine
+ * ^hostname
+ */
+ if (sty)
+ {
+ /* STY is set. Check, if it has a valid form */
+ int n, vc;
+ if (strlen(sty) >= sizeof tty
+ || 3 != sscanf(sty, "%d.tty%d.%s", &n, &vc, tty))
+ goto err;
+ else
+ {
+ /* we're inside a SCREEN session. Don't connect to
+ * the tty as below. TODO: how can we get lines
+ * and columns from SCREEN ? */
+ gpm_consolefd = GPM_FD_SCREEN;
+ conn->vc = vc;
+ win.ws_col = 80;
+ win.ws_row = 25;
+ }
+ }
+ else
goto err;
+ }
+ else
conn->vc=atoi(tty+8);
}
else /* a default handler -- use console */
sprintf(tty,"/dev/tty0");
! if (gpm_consolefd == GPM_FD_INVALID) /* NOT called for SCREEN */
if ((gpm_consolefd=open(tty,O_WRONLY))<0)
{
gpm_debug_log(LOG_ERR,"%s: %s",tty,strerror(errno));
***************
*** 254,259 ****
--- 289,295 ----
/*....................................... Get screen dimensions */
+ if (gpm_consolefd != GPM_FD_SCREEN) /* NOT called for SCREEN */
ioctl(gpm_consolefd, TIOCGWINSZ, &win);
if (!win.ws_col || !win.ws_row)
***************
*** 395,401 ****
sigaction(SIGWINCH, &gpm_saved_winch_hook, 0);
#endif
close(gpm_consolefd);
! gpm_consolefd=-1;
return 0;
}
--- 431,437 ----
sigaction(SIGWINCH, &gpm_saved_winch_hook, 0);
#endif
close(gpm_consolefd);
! gpm_consolefd = GPM_FD_INVALID;
return 0;
}
diff -rcw gpm-1.19.3.orig/special.c gpm-1.19.3/special.c
*** gpm-1.19.3.orig/special.c Mon Jan 17 22:34:00 2000
--- gpm-1.19.3/special.c Thu Nov 30 19:09:42 2000
***************
*** 26,31 ****
--- 26,32 ----
/* This file is compiled conditionally, see the Makefile */
+ #include <linux/limits.h> /* OPEN_MAX */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
--zYM0uCDKw75PZbzx--