pkg://mpeg_wdgt2.0b.tar.gz:88693/Xroutines.c
downloads
#include "video.h"
extern Window window;
extern int ditherType;;
#ifdef SH_MEM
int gXErrorFlag = 0;
int HandleXError(dpy, event)
Display *dpy;
XErrorEvent *event;
{
gXErrorFlag = 1;
return 0;
}
void InstallXErrorHandler()
{
int HandleXError();
XSetErrorHandler(HandleXError);
XFlush(display);
}
void DeInstallXErrorHandler()
{
XSetErrorHandler(NULL);
XFlush(display);
}
#endif
/*
*--------------------------------------------------------------
*
* ResizeDisplay --
*
* Resizes display window.
*
* Results:
* None.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
void ResizeDisplay(w, h)
int w, h;
{
if (ditherType == NO_DITHER) return;
XResizeWindow(display, window, w, h);
XFlush(display);
}
/*
*--------------------------------------------------------------
*
* MakeWindow --
*
* Create X Window
*
* Results:
* Read the code.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
#ifdef SH_MEM
int CompletionType = -1;
#endif
void
MakeWindow(name)
char *name;
{
XSizeHints hint;
unsigned int fg, bg;
char *hello = "MPEG Play";
int screen;
Window CreateFullColorWindow();
if (ditherType == NO_DITHER) return;
display = XOpenDisplay(name);
if (display == NULL) {
fprintf(stderr, "Can not open display\n");
exit(-2);
}
#ifdef SH_MEM
if(shmemFlag)
CompletionType = XShmGetEventBase(display) + ShmCompletion;
#endif
screen = DefaultScreen (display);
/* Fill in hint structure */
hint.x = 200;
hint.y = 300;
hint.width = 150;
hint.height = 150;
hint.flags = PPosition | PSize;
/* Get some colors */
bg = WhitePixel (display, screen);
fg = BlackPixel (display, screen);
/* Make the window */
if (ditherType == FULL_COLOR_DITHER) {
window = CreateFullColorWindow (display, hint.x, hint.y, hint.width, hint.height);
if (window == 0) {
fprintf (stderr, "-color option only valid on full color display\n");
exit (-1);
}
} else if (ditherType == MONO_DITHER || ditherType == MONO_THRESHOLD ||
ditherType == MONO_FS4_DITHER || ditherType == HALFTONE_DITHER) {
window = XCreateSimpleWindow (display,
DefaultRootWindow (display),
hint.x, hint.y,
hint.width, hint.height,
4, fg, bg);
} else {
XVisualInfo vinfo;
if (!XMatchVisualInfo (display, screen, 8, PseudoColor,
&vinfo)) {
if (!XMatchVisualInfo(display, screen, 8, GrayScale,
&vinfo)) {
fprintf(stderr, "-requires 8 bit display\n");
exit(-1);
}
}
window = XCreateSimpleWindow (display,
DefaultRootWindow (display),
hint.x, hint.y,
hint.width, hint.height,
4, fg, bg);
}
XSelectInput(display, window, StructureNotifyMask);
/* Tell other applications about this window */
XSetStandardProperties (display, window, hello, hello, None, NULL, 0, &hint);
/* Map window. */
XMapWindow(display, window);
/* Wait for map. */
while(1) {
XEvent xev;
XNextEvent(display, &xev);
if(xev.type == MapNotify && xev.xmap.event == window)
break;
}
XSelectInput(display, window, NoEventMask);
}