Update of /cvsroot/netrek/client/cow In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv27795 Modified Files: x11window.c system.mk.in Log Message: add video mode change support Index: x11window.c =================================================================== RCS file: /cvsroot/netrek/client/cow/x11window.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- x11window.c 16 May 2006 12:59:38 -0000 1.8 +++ x11window.c 22 May 2006 13:11:21 -0000 1.9 @@ -4,6 +4,9 @@ * Kevin P. Smith 6/11/89 Much modified by Jerry Frain and Joe Young * * $Log$ + * Revision 1.9 2006/05/22 13:11:21 quozl + * add video mode change support + * * Revision 1.8 2006/05/16 12:59:38 quozl * tactical camera, based on Imlib2 * @@ -58,6 +61,11 @@ #include "teams.bitmap" #include "mapcursor.bitmap" #include "localcursor.bitmap" +#include "smessage.h" +#include "defaults.h" +#include "x11window.h" +#include "x11sprite.h" +#include "camera.h" #ifdef VMS void vms_event_window(void); @@ -225,8 +233,6 @@ None, }; -static XSizeHints wm_size_hint; - #ifdef WINDOWMAKER char **wm_argv; int wm_argc; @@ -264,35 +270,6 @@ #define WIN_MENU 3 #define WIN_SCROLL 4 -struct window - { - Window window; - int type; - char *data; - int mapped; - int width, height; - char *name; - W_Callback handle_keydown; - W_Callback handle_keyup; - W_Callback handle_button; - W_Callback handle_expose; - -#ifdef SHORT_PACKETS - int insensitive; -#endif - Cursor cursor; - }; - -struct scrollingWindow - { - int lines; - int updated; - int topline; - struct stringList *head; - struct stringList *tail; - struct stringList *index; - }; - static void scrollUp(struct window *win, int y); static void scrollDown(struct window *win, int y); static void scrollPosition(struct window *win, int y); @@ -405,7 +382,7 @@ abort(); } -pastebuffer(void) +void pastebuffer(void) { int nbytes, x; char *buff, c; @@ -456,19 +433,20 @@ fprintf(stderr, "I can't open your display, twink!\n"); terminate(1); } - /* tmp */ - /* XSynchronize(W_Display, True); */ - /* XSetErrorHandler(_myerror); */ - camera_set_display(W_Display); - W_Root = DefaultRootWindow(W_Display); + // uncomment this to synchronise display for testing + XSynchronize(W_Display, True); - W_Visual = DefaultVisual(W_Display, DefaultScreen(W_Display)); + // uncomment this to enable a fatal error handler + // XSetErrorHandler(_myerror); + W_Root = DefaultRootWindow(W_Display); + W_Visual = DefaultVisual(W_Display, DefaultScreen(W_Display)); W_Screen = DefaultScreen(W_Display); W_Colormap = DefaultColormap(W_Display, W_Screen); myroot.window = W_Root; myroot.type = WIN_GRAPH; + video_mode_begin(); GetFonts(); GetColors(); @@ -484,11 +462,12 @@ #ifdef BEEPLITE init_tts(); #endif + camera_set_display(W_Display); } /* Make sure the font will work, ie: that it fits in the 6x10 character cell * that we expect. */ -checkFont(XFontStruct * fontinfo, char *fontname) +void checkFont(XFontStruct * fontinfo, char *fontname) { #ifndef SMALL_SCREEN @@ -505,10 +484,10 @@ #endif } -GetFonts(void) +void GetFonts(void) { - Font regular, italic, bold, big, ind; - int i, j; + Font regular, italic, bold, big; + int i; XGCValues values; XFontStruct *fontinfo; char *fontname; @@ -665,17 +644,15 @@ {0x80, 0xa0, 0xb0, 0xc0, 0x00, 0x20, 0x40, 0x60}; -GetColors(void) +void GetColors(void) { int i, j; XGCValues values; - XColor foo, garbage; + XColor foo; int white, black; unsigned long pixel; char defaultstring[100]; char *defaults; - - char *colorname; unsigned long extracolors[COLORS]; XColor colordef; @@ -962,8 +939,7 @@ } } -W_Window -W_RenameWindow(struct window *window, char *str) +void W_RenameWindow(struct window *window, char *str) { XStoreName(W_Display, window->window, str); } @@ -1011,7 +987,7 @@ &attrs), WIN_GRAPH); if (strcmp(name, "netrek") == 0) { - camera_set_window(newwin->window, width, height); + camera_set_window(&newwin->window); } /* top window */ sz_hints = XAllocSizeHints(); @@ -1297,7 +1273,6 @@ #endif unsigned char ch; - int nchars, ind; struct window *win; #ifdef FUNCTION_KEYS @@ -1754,7 +1729,7 @@ W_FlushLineCaches(W_Window window) { Window win = W_Void2Window(window)->window; - register i; + int i; for (i = 0; i < NCOLORS; i++) { @@ -1919,7 +1894,6 @@ { struct icon *newicon; struct window *win; - int black, white; #ifdef DEBUG printf("Storing bitmap for %d (%d x %d)\n", window, width, height); @@ -2133,7 +2107,7 @@ return (NULL); } -addToHash(struct window * win) +void addToHash(struct window * win) { struct windowlist **new; @@ -2328,8 +2302,8 @@ #ifndef NO_COPYAREA else { - register struct stringList *item; - register y; + struct stringList *item; + int y; if (win->height > sw->updated) { @@ -2368,8 +2342,8 @@ struct window *win; struct scrollingWindow *sw; { - register x, y, h; - int savedlines, maxrow, thumbTop, thumbHeight, totalHeight, winheight; + int x, y, h; + int savedlines, maxrow, thumbTop, thumbHeight, totalHeight, winheight; /* * savedlines : Number of offscreen text lines, @@ -2444,7 +2418,7 @@ } #ifdef SHORT_PACKETS -W_SetSensitive(W_Window w, int v) +void W_SetSensitive(W_Window w, int v) { struct window *win = W_Void2Window(w); @@ -2524,7 +2498,7 @@ return (W_Window2Void(newwin)); } -redrawMenu(struct window * win) +void redrawMenu(struct window * win) { int count; @@ -2541,7 +2515,7 @@ } } -redrawMenuItem(struct window *win, int n) +void redrawMenuItem(struct window *win, int n) { struct menuItem *items; @@ -2560,10 +2534,9 @@ } } -changeMenuItem(struct window *win, int col, int n, char *str, int len, W_Color color) +void changeMenuItem(struct window *win, int col, int n, char *str, int len, W_Color color) { struct menuItem *items; - char *news; items = (struct menuItem *) win->data; @@ -3017,8 +2990,6 @@ static Cursor curs; Pixmap cursbits; Pixmap cursmask; - short *curdata; - short *maskdata; struct window *win; XColor whiteCol, blackCol; @@ -3124,7 +3095,7 @@ } -deleteWindow(struct window *window) +void deleteWindow(struct window *window) { struct windowlist **rm; struct windowlist *temp; @@ -3357,7 +3328,7 @@ return XParseGeometry(geom_default, x, y, (unsigned int *) width, (unsigned int *) height); } -checkParent(char *name, W_Window * parent) +void checkParent(char *name, W_Window * parent) { char *adefault; char buf[100]; @@ -3389,18 +3360,16 @@ } } -checkMapped(char *name) +int checkMapped(char *name) { - char *adefault; char buf[100]; sprintf(buf, "%s.mapped", name); return (booleanDefault(buf, 0)); } -checkMappedPref(char *name, int preferred) +int checkMappedPref(char *name, int preferred) { - char *adefault; char buf[100]; sprintf(buf, "%s.mapped", name); @@ -3428,7 +3397,7 @@ } } -findMouse(int *x, int *y) +void findMouse(int *x, int *y) { Window theRoot, theChild; int wX, wY, rootX, rootY, status; @@ -3475,7 +3444,7 @@ return 0; } -W_Flush(void) +void W_Flush(void) { XFlush(W_Display); } @@ -3487,7 +3456,7 @@ } #define MAKE_WINDOW_SETTER(name, part) \ - W_Callback name(W_Window w, W_Callback c) \ + void name(W_Window w, W_Callback c) \ { \ W_Void2Window(w)->part = c; \ } @@ -3556,7 +3525,7 @@ return (XEventsQueued(W_Display, QueuedAfterReading)); } -W_ReadEvents(void) +int W_ReadEvents(void) { XEvent event; static @@ -3698,14 +3667,14 @@ void W_EraseTTSText(W_Window window, int max_width, int y, int width) { - struct window *win = W_Void2Window(window); - register int x = (max_width - width) / 2; + // struct window *win = W_Void2Window(window); + int x = (max_width - width) / 2; if (x < 0) x = 4; y -= W_TTSTextHeight(); - W_ClearArea(w, x, y, width, W_TTSTextHeight()); + W_ClearArea(window, x, y, width, W_TTSTextHeight()); } void @@ -3719,7 +3688,7 @@ /* length of string */ { struct window *win = W_Void2Window(window); - register int x = (max_width - width) / 2; + int x = (max_width - width) / 2; if (x < 0) x = 4; @@ -3747,3 +3716,80 @@ } } #endif /* HAVE_XPM */ + +/* XFree86 VidMode X extension handling */ + +#include <X11/extensions/xf86vmode.h> + +XF86VidModeModeInfo **video_mode_list; +XF86VidModeModeInfo *video_mode_current; +int video_mode_dotclock, video_mode_list_size; + +/* restore video mode to known previous mode */ +void video_mode_end() +{ + if (video_mode_current != NULL) { + XF86VidModeSwitchToMode(W_Display, W_Screen, video_mode_current); + fprintf(stderr, "video_mode_begin: restored previous video mode\n"); + } +} + +/* set video mode to that preferred for game */ +void video_mode_begin() +{ + int major, minor, line; + XF86VidModeModeLine current; + + /* do not change mode if configuration setting requests no change */ + if (!booleanDefault("VideoModeChange", 1)) { + return; + } + + /* do not change if X server has no support for change */ + if (!XF86VidModeQueryVersion(W_Display, &major, &minor)) { + fprintf(stderr, "XFree86-VidMode X extension absent\n"); + return; + } + + /* obtain the current mode line and list of known mode lines */ + XF86VidModeGetModeLine(W_Display, W_Screen, &video_mode_dotclock, ¤t); + XF86VidModeGetAllModeLines(W_Display, W_Screen, + &video_mode_list_size, &video_mode_list); + + /* find the current mode within the list of known mode lines */ + video_mode_current = NULL; + for (line=0; line < video_mode_list_size; line++) { + XF86VidModeModeInfo *mode = video_mode_list[line]; + if (mode->hdisplay == current.hdisplay && + mode->vdisplay == current.vdisplay && + mode->dotclock == video_mode_dotclock && + mode->htotal == current.htotal && + mode->vtotal == current.vtotal && + mode->flags == current.flags) { + video_mode_current = mode; + } + } + + /* do not change if the current mode was not found */ + if (video_mode_current == NULL) { + fprintf(stderr, "video_mode_begin: this mode not found, " + "cannot switch back, so not switching\n"); + return; + } + + /* schedule a change-back at program end */ + atexit(video_mode_end); + + /* if there is a mode line for 1024x768 then use it */ + for (line=0; line < video_mode_list_size; line++) { + XF86VidModeModeInfo *mode = video_mode_list[line]; + if (mode->hdisplay == 1024 && mode->vdisplay == 768) { + XF86VidModeSwitchToMode(W_Display, W_Screen, mode); + fprintf(stderr, "video_mode_begin: changed to 1024x768\n"); + return; + } + } + + /* mode was not changed, discard the scheduled change-back */ + video_mode_current = NULL; +} Index: system.mk.in =================================================================== RCS file: /cvsroot/netrek/client/cow/system.mk.in,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- system.mk.in 20 May 2006 08:12:54 -0000 1.9 +++ system.mk.in 22 May 2006 13:11:21 -0000 1.10 @@ -108,12 +108,12 @@ SHARED = $(SL_CFLAGS) INCDIRS = $(MPINC) $(INCS) CFLAGS = $(OPT) $($S) $(EXTRACFLAGS) $(SDL_CFLAGS) $(RSA_FLAGS) $(INCDIRS) -LFLAGS = $(EXTRALINKFLAGS) +LFLAGS = -g $(EXTRALINKFLAGS) LIBRARIES = $(LMP) $(LIBS) $(EXTRALIBS) $(SDL_LIBS) $(SDL_MIXER_LIBS) netrek: $(RSAOBJ) $(PMAKE) null $(ROBJ) $(MAINOBJ) $(INPUTOBJ) $(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ) cflags.c randomize $(CC) $(LFLAGS) -o netrek `./randomize $(ROBJ) $(RSAOBJ) $(INPUTOBJ) \ - $(MAINOBJ) $(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ)` $(LIBRARIES) -lImlib2 + $(MAINOBJ) $(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ)` $(LIBRARIES) -lXxf86vm -lImlib2 netrek.shared: done.libcow $(MAINOBJ) $(COWAPI) $(CC) $(LFLAGS) $(MAINOBJ) -L. -lcow $(LIBS) -o netrek.shared