1: #ifndef lint 2: static char *rcsid = "$Header: initial.c,v 10.4 86/02/01 16:21:01 tony Rel $"; 3: #endif lint 4: #ifdef sun 5: /* 6: * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided 7: * for unrestricted use provided that this legend is included on all tape 8: * media and as a part of the software program in whole or part. Users 9: * may copy or modify these drivers without charge, but are not authorized 10: * to license or distribute them to anyone else except as part of a product or 11: * program developed by the user. 12: * 13: * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND 14: * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A 15: * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE 16: * PRACTICE. 17: * 18: * The Sun X Drivers are provided with no support and without any obligation 19: * on the part of Sun Microsystems, Inc. to assist in their use, correction, 20: * modification or enhancement. 21: * 22: * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 23: * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X 24: * DRIVERS OR ANY PART THEREOF. 25: * 26: * In no event will Sun Microsystems, Inc. be liable for any lost revenue 27: * or profits or other special, indirect and consequential damages, even if 28: * Sun has been advised of the possibility of such damages. 29: * 30: * Sun Microsystems, Inc. 31: * 2550 Garcia Avenue 32: * Mountain View, California 94043 33: */ 34: 35: #ifndef lint 36: static char sccsid[] = "%Z%%M% %I% %E% Copyright 1986 Sun Micro"; 37: #endif 38: 39: /*- 40: * Copyright 1985, Massachusetts Institute of Technology 41: * Copyright (c) 1986 by Sun Microsystems, Inc. 42: */ 43: 44: /* initial.c Routines to open & close display 45: * 46: * OpenDisplay Open it 47: * InitDisplay Download it 48: * DisplayDead Check if dead 49: * Allocate_space Allocate some temporary storage 50: * 51: */ 52: 53: /* 54: * ToDo: 55: * Look in environment/defaults for programs to start 56: */ 57: 58: 59: #include <stdio.h> 60: #include <fcntl.h> 61: #include <errno.h> 62: #include <sys/time.h> 63: #include <sys/ioctl.h> 64: #include <sys/signal.h> 65: #include <sun/fbio.h> 66: #include "Xsun.h" 67: #include <pixrect/pixrect_hs.h> 68: #include <sunwindow/rect.h> 69: #include <sunwindow/rectlist.h> 70: #include <sunwindow/pixwin.h> 71: #include <sunwindow/win_screen.h> 72: #include <sunwindow/win_struct.h> 73: #include <sunwindow/win_input.h> 74: 75: extern int InputReader(); 76: 77: struct pixwin *Display; 78: struct pixrect *PixRect; 79: u_char InvPix[256]; 80: 81: short Sun_From_X_Op[] = { 82: PIX_CLR, /* GXclear */ 83: PIX_SRC&PIX_DST, /* GXand */ 84: PIX_SRC&PIX_NOT(PIX_DST), /* GXandReverse */ 85: PIX_SRC, /* GXcopy */ 86: PIX_NOT(PIX_SRC)&PIX_DST, /* GXandInverted */ 87: PIX_DST, /* GXnoop */ 88: PIX_SRC^PIX_DST, /* GXxor */ 89: PIX_SRC|PIX_DST, /* GXor */ 90: PIX_NOT(PIX_SRC)&PIX_NOT(PIX_DST), /* GXnor */ 91: PIX_NOT(PIX_SRC)^PIX_DST, /* GXequiv */ 92: PIX_NOT(PIX_DST), /* GXinvert */ 93: PIX_SRC|PIX_NOT(PIX_DST), /* GXorReverse */ 94: PIX_NOT(PIX_SRC), /* GXcopyInverted */ 95: PIX_NOT(PIX_SRC)|PIX_DST, /* GXorInverted */ 96: PIX_NOT(PIX_SRC)|PIX_NOT(PIX_DST), /* GXnand */ 97: PIX_SET, /* GXset */ 98: }; 99: 100: int vsdev = -1; 101: extern int errno; 102: DEVICE *CurrentDevice; 103: 104: #define PARENT "WINDOW_GFX" 105: /* Open the display */ 106: static char *parent; 107: 108: /*ARGSUSED*/ 109: OpenDisplay (devname) 110: char *devname; 111: { 112: struct screen sc; 113: extern char *getenv(); 114: 115: signal (SIGWINCH, SIG_IGN); 116: parent = getenv(PARENT); 117: bzero((caddr_t) & sc, sizeof sc); 118: if (*devname != '/') 119: devname = "/dev/fb"; 120: strncpy(sc.scr_fbname, devname, SCR_NAMESIZE); 121: if (parent) { 122: /* Running under "overview" */ 123: int pfd; 124: 125: if ((pfd = open(parent, 2, 0)) < 0) { 126: fprintf(stderr, "Can't open parent %s\n", parent); 127: return (-1); 128: } 129: vsdev = win_getnewwindow(); 130: win_setlink(vsdev, WL_PARENT, win_fdtonumber(pfd)); 131: win_insert(vsdev); 132: close(pfd); 133: } 134: else { 135: /* Running alone */ 136: vsdev = win_screennew(&sc); 137: } 138: return (vsdev); 139: } 140: 141: /* Do sun specific initialization */ 142: #ifdef notdef 143: static int pid; 144: #define XTERM "xterm" 145: static char *args[] = { 146: XTERM, 147: "=80x24+30+30", 148: "-C", 149: "-n", 150: "console", 151: 0, 152: }; 153: 154: #include <sys/wait.h> 155: 156: static SigChildHandler() 157: { 158: register int dead; 159: union wait status; 160: 161: while ((dead = wait3(&status, WNOHANG, NULL)) > 0) { 162: if (dead == pid) { 163: exit(0); 164: } 165: } 166: } 167: 168: static StartShell() 169: { 170: signal(SIGCHLD, SigChildHandler); 171: if ((pid = fork()) == 0) { 172: { 173: register int i = getdtablesize(); 174: 175: while (--i >= 0) { 176: close(i); 177: } 178: } 179: open("/dev/null", 2, 0); 180: dup(0); 181: dup(0); 182: { 183: /* Copy the environment for Setenv */ 184: extern char **environ; 185: register int i = 0; 186: char **envnew; 187: 188: while (environ[i] != NULL) 189: i++; 190: 191: envnew = (char **) malloc(sizeof(char *) * (i + 1)); 192: for (; i >= 0; i--) 193: envnew[i] = environ[i]; 194: environ = envnew; 195: } 196: { 197: #define HOSTNAMESIZE 128 198: char DisplayName[HOSTNAMESIZE]; 199: 200: gethostname(DisplayName, HOSTNAMESIZE); 201: strcat(DisplayName, ":0"); 202: Setenv("DISPLAY=", DisplayName); 203: #undef HOSTNAMESIZE 204: } 205: execvp(XTERM, args); 206: _exit(1); 207: } 208: } 209: #endif 210: 211: InitDisplay (info) 212: register DEVICE *info; 213: { 214: register int i; 215: static vsCursor vsc; 216: static vsBox vsm; 217: static vsEventQueue vsq = { 218: NULL, 219: 0, 220: 0, 221: 0, 222: }; 223: struct screen sc; 224: 225: win_screenget(vsdev, &sc); 226: info->height = sc.scr_rect.r_height; 227: info->width = sc.scr_rect.r_width; 228: if (parent) { 229: /* running under "overview" */ 230: win_setrect(vsdev, &sc.scr_rect); 231: } 232: { 233: struct fbtype fbt; 234: int fd = open(sc.scr_fbname, O_RDWR, 0); 235: 236: if (fd < 0 || ioctl(fd, FBIOGTYPE, &fbt) < 0) { 237: if (fd < 0) 238: fprintf(stderr, "Can't open fb %s\n", sc.scr_fbname); 239: else 240: fprintf(stderr, "Can't FBIOGTYPE on %s\n", sc.scr_fbname); 241: return (-1); 242: } 243: close(fd); 244: info->id = fbt.fb_type + SUN_BASE; 245: info->planes = fbt.fb_depth; 246: info->entries = fbt.fb_cmsize; 247: } 248: Display = pw_open(vsdev); 249: PixRect = Display->pw_pixrect; 250: pw_reversevideo(Display,0,1); 251: { 252: struct inputmask im; 253: 254: input_imnull(&im); 255: im.im_flags = IM_ASCII | IM_META | IM_NEGEVENT; 256: win_setinputcodebit(&im, LOC_MOVE); 257: win_setinputcodebit(&im, MS_LEFT); 258: win_setinputcodebit(&im, MS_MIDDLE); 259: win_setinputcodebit(&im, MS_RIGHT); 260: win_setinputmask(vsdev, &im, NULL, WIN_NULLLINK); 261: } 262: if (fcntl(vsdev, F_SETFL, O_NDELAY) < 0) 263: return (-1); 264: { 265: /* Following struct cannot be included from win_cursor.h */ 266: struct cursor { 267: short cur_xhot, cur_yhot; /* offset of mouse position from shape*/ 268: int cur_function; /* relationship of shape to screen */ 269: struct pixrect *cur_shape; /* memory image to use */ 270: int flags; /* various options */ 271: 272: short horiz_hair_thickness; /* horizontal crosshair height */ 273: int horiz_hair_op; /* drawing op */ 274: int horiz_hair_color; /* color */ 275: short horiz_hair_length; /* width */ 276: short horiz_hair_gap; /* gap */ 277: 278: short vert_hair_thickness; /* vertical crosshair width */ 279: int vert_hair_op; /* drawing op */ 280: int vert_hair_color; /* color */ 281: short vert_hair_length; /* height */ 282: short vert_hair_gap; /* gap */ 283: } cs; 284: static struct pixrect pr; 285: 286: cs.cur_xhot = cs.cur_yhot = cs.cur_function = 0; 287: cs.flags = 0; 288: cs.cur_shape = ≺ 289: pr.pr_size.x = pr.pr_size.y = 0; 290: win_setcursor(vsdev, &cs); 291: win_setmouseposition(vsdev, info->width >> 1, info->height >> 1); 292: } 293: info->mouse = &vsc; 294: info->mbox = &vsm; 295: info->queue = &vsq; 296: Define_input_handler(InputReader); 297: SetUpInvPix(); 298: CurrentDevice = info; 299: #ifdef notdef 300: StartShell(); 301: #endif 302: return (0); 303: } 304: 305: /* Check if display is dead */ 306: 307: DisplayDead () 308: { 309: return(0); 310: } 311: 312: /* the presumption here is that only one Allocate_space call is made/request */ 313: 314: #define ABUFSIZE 3072 315: static char ABuffer[3072]; /* random size buffer for allocate space */ 316: caddr_t AllocateSpace (size) 317: register int size; 318: { 319: if (size < ABUFSIZE) return(ABuffer); 320: errno = ENOMEM; 321: return (NULL); 322: } 323: 324: /* XXX - should be static data */ 325: SetUpInvPix() 326: { 327: register int i; 328: 329: for (i = 255; i >= 0; i--) { 330: register int j = 1, k = 128, l = 8; 331: 332: while (l--) { 333: if ((i & j) != 0) 334: InvPix[i] |= k; 335: j <<= 1; 336: k >>= 1; 337: } 338: } 339: } 340: 341: #ifdef notdef 342: Setenv (var, value) 343: /* 344: sets the value of var to be arg in the Unix 4.2 BSD environment env. 345: Var should end with '='. 346: (bindings are of the form "var=value") 347: This procedure assumes the memory for the first level of environ 348: was allocated using malloc. 349: */ 350: register char *var, *value; 351: { 352: extern char **environ; 353: register int index = 0; 354: 355: while (environ[index] != NULL) { 356: if (strncmp(environ[index], var, strlen(var)) == 0) { 357: /* found it */ 358: environ[index] = (char *) malloc(strlen(var) + strlen(value)); 359: strcpy(environ[index], var); 360: strcat(environ[index], value); 361: return; 362: } 363: index++; 364: } 365: 366: if ((environ = (char **) realloc(environ, sizeof(char *) * 367: (index + 2))) == NULL) { 368: fprintf(stderr, "Setenv: malloc out of memory\n"); 369: exit(1); 370: } 371: 372: environ[index] = (char *) malloc(strlen(var) + strlen(value)); 373: strcpy(environ[index], var); 374: strcat(environ[index], value); 375: environ[++index] = NULL; 376: } 377: #endif 378: #endif sun