home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
may94
/
util
/
edit
/
jade.lha
/
Jade
/
src
/
x11_display.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-19
|
6KB
|
230 lines
/* x11_display.c -- Initialisation for X11 window-system
Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
This file is part of Jade.
Jade is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Jade is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jade; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "jade.h"
#include "jade_protos.h"
#include <X11/Xutil.h>
#ifdef HAVE_UNIX
# include <sys/types.h>
# include <sys/time.h>
# include <fcntl.h>
#else
you lose
#endif
_PR void sys_usage(void);
_PR int initwinsys(int *, char ***);
_PR void killwinsys(void);
#ifdef HAVE_UNIX
_PR fd_set FdReadSet;
fd_set FdReadSet;
_PR void (*FdReadAction[])(int);
void (*FdReadAction[FD_SETSIZE])(int);
#endif
_PR Display *XDisplay;
_PR int XScreen;
_PR Colormap ColourMap;
_PR u_long XForePixel, XBackPixel;
_PR Atom Wm_Del_Win;
_PR char **Argv;
_PR int Argc;
Display *XDisplay;
int XScreen;
Colormap XColourMap;
u_long XForePixel, XBackPixel;
Atom Wm_Del_Win;
char **Argv;
int Argc;
static char *DisplayName = NULL;
static char *BgStr = "white";
static char *FgStr = "black";
static char *GeomStr = "80x24";
_PR VALUE DefFontStr;
VALUE DefFontStr = MKSTR(DEFAULT_FONT);
static char *ProgName;
static int
getxresources(void)
{
char *s;
if((s = XGetDefault(XDisplay, ProgName, "geometry"))
|| (s = XGetDefault(XDisplay, "Jade", "geometry")))
GeomStr = s;
if((s = XGetDefault(XDisplay, ProgName, "foreground"))
|| (s = XGetDefault(XDisplay, "Jade", "foreground")))
FgStr = s;
if((s = XGetDefault(XDisplay, ProgName, "background"))
|| (s = XGetDefault(XDisplay, "Jade", "background")))
BgStr = s;
if((s = XGetDefault(XDisplay, ProgName, "font"))
|| (s = XGetDefault(XDisplay, "Jade", "font")))
DefFontStr = valstrdup(s);
return(TRUE);
}
void
sys_usage(void)
{
fputs(
"where SYSTEM-OPTIONS are,\n"
" -display DISPLAY-NAME\n"
" -name NAME\n"
" -geometry WINDOW-GEOMETRY\n"
" -fg FOREGROUND-COLOUR\n"
" -bg BACKGROUND-COLOUR\n"
" -font FONT-NAME\n"
" -sync\n"
, stderr);
}
static int
getxoptions(int *argc_p, char ***argv_p)
{
int argc = *argc_p;
char **argv = *argv_p;
argc--;
argv++;
while((argc >= 1) && (**argv == '-'))
{
if(!strcmp("-sync", *argv))
XSynchronize(XDisplay, True);
else if(argc >= 2)
{
if(!strcmp("-display", *argv))
;
else if(!strcmp("-name", *argv))
;
else if(!strcmp("-geometry", *argv))
GeomStr = argv[1];
else if(!strcmp("-fg", *argv))
FgStr = argv[1];
else if(!strcmp("-bg", *argv))
BgStr = argv[1];
else if(!strcmp("-font", *argv))
DefFontStr = valstrdup(argv[1]);
else
break;
argc--; argv++;
}
else
break;
argc--; argv++;
}
*argc_p = argc;
*argv_p = argv;
return(TRUE);
}
static int
usexoptions(void)
{
int x, y, w, h;
int gflgs = XParseGeometry(GeomStr, &x, &y, &w, &h);
XColor tmpc;
if(gflgs & WidthValue)
DefDims[2] = w;
else
DefDims[2] = -1;
if(gflgs & HeightValue)
DefDims[3] = h;
else
DefDims[3] = -1;
/*
* need to use -ve values properly
*/
if(gflgs & XValue)
DefDims[0] = x;
else
DefDims[0] = -1;
if(gflgs & YValue)
DefDims[1] = y;
else
DefDims[1] = -1;
if(!XParseColor(XDisplay, XColourMap, FgStr, &tmpc))
fprintf(stderr, "error: invalid fg colour\n");
else if(!XAllocColor(XDisplay, XColourMap, &tmpc))
fprintf(stderr, "error: can't allocate fg colour\n");
else
XForePixel = tmpc.pixel;
if(!XParseColor(XDisplay, XColourMap, BgStr, &tmpc))
fprintf(stderr, "error: invalid bg colour\n");
else if(!XAllocColor(XDisplay, XColourMap, &tmpc))
fprintf(stderr, "error: can't allocate bg colour\n");
else
XBackPixel = tmpc.pixel;
return(TRUE);
}
int
initwinsys(int *argc_p, char ***argv_p)
{
int i;
Argv = *argv_p;
Argc = *argc_p;
ProgName = filepart(Argv[0]);
for(i = 1; i < Argc; i++)
{
/* These options have to be found *before* resources are looked
for. */
if(!strcmp("-display", Argv[i]) && (i+1 < Argc))
DisplayName = Argv[++i];
else if(!strcmp("-name", Argv[i]) && (i+1 < Argc))
ProgName = Argv[++i];
}
XDisplay = XOpenDisplay(DisplayName);
if(XDisplay)
{
#ifdef HAVE_UNIX
FD_ZERO(&FdReadSet);
/*
* close-on-exec = TRUE
*/
fcntl(ConnectionNumber(XDisplay), F_SETFD, 1);
FD_SET(ConnectionNumber(XDisplay), &FdReadSet);
/*
* Don't need to do this since the fact that the select() has returned
* means that the input Q is re-checked...
* ...although having thought about this it may be useful to do the
* below stuff so all events are processed before reading output from
* processes???
* FdReadAction[ConnectionNumber(XDisplay)] = readnextevent;
*/
#endif /* HAVE_UNIX */
XScreen = DefaultScreen(XDisplay);
XColourMap = DefaultColormap(XDisplay, XScreen);
if(getxresources() && getxoptions(argc_p, argv_p) && usexoptions())
{
Wm_Del_Win = XInternAtom(XDisplay, "WM_DELETE_WINDOW", False);
return(TRUE);
}
}
else
fprintf(stderr, "jade: can't open X connection\n");
return(FALSE);
}
void
killwinsys(void)
{
XCloseDisplay(XDisplay);
}