Index: xc/ChangeLog =================================================================== RCS file: /cvs/xorg/xc/ChangeLog,v retrieving revision 1.808 diff -u -2 -0 -r1.808 ChangeLog --- xc/ChangeLog 11 Mar 2005 16:23:00 -0000 1.808 +++ xc/ChangeLog 11 Mar 2005 21:11:25 -0000 @@ -1,21 +1,34 @@ 2005-03-11 Roland Mainz + * xc/programs/twm/Imakefile + * xc/programs/twm/twm.c + * xc/programs/xdpyinfo/xdpyinfo.c + bugzilla #=2705 (https://bugs.freedesktop.org/show_bug.cgi?id==2705) + attachment #xxx (https://bugs.freedesktop.org/attachment.cgi?id=xxx) + Make twm ignore print screens to avoid that users accidentally warp + on a non-video screen (which are not visible on any monitor) when + the Xserver has both video and print screens. + (This includes also a small cleanup of xdpyinfo where parts of the + print screen test code comes from) + Patch by Julien Lafon (MIT/X.org license). + +2005-03-11 Roland Mainz * xc/programs/twm/add_window.c * xc/programs/twm/cursor.c * xc/programs/twm/events.c * xc/programs/twm/gc.c * xc/programs/twm/gram.y * xc/programs/twm/iconmgr.c * xc/programs/twm/icons.c * xc/programs/twm/list.c * xc/programs/twm/menus.c * xc/programs/twm/parse.c * xc/programs/twm/resize.c * xc/programs/twm/twm.c * xc/programs/twm/util.c bugzilla #2566 (https://bugs.freedesktop.org/show_bug.cgi?id=2566) attachment #2083 (https://bugs.freedesktop.org/attachment.cgi?id=2083) ANSI-fy twm window manager code. The conversion preserves the comments which annotate variables and function arguments (these have been moved into doxygen(esque?) "stubs" above each function. Patch by Mike Owens . Index: xc/programs/twm/Imakefile =================================================================== RCS file: /cvs/xorg/xc/programs/twm/Imakefile,v retrieving revision 1.3 diff -u -2 -0 -r1.3 Imakefile --- xc/programs/twm/Imakefile 21 Jul 2004 07:31:10 -0000 1.3 +++ xc/programs/twm/Imakefile 11 Mar 2005 21:11:42 -0000 @@ -1,40 +1,44 @@ XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:54:05 cpqbld Exp $ XCOMM $XFree86: xc/programs/twm/Imakefile,v 3.14 2002/10/08 20:54:04 keithp Exp $ XORGREL = XOrgReleaseString XORGREL_DEF = -DXORG_RELEASE="\"$(XORGREL)\"" #if HasMkstemp MKTMP_DEFINES = -DHAS_MKSTEMP #endif +#if BuildXprintLib + XPRINT_DEFINES = -DXPRINT + XPRINTLIBS = $(XPLIB) +#endif YFLAGS = -d DEPLIBS = $(DEPXMULIB) $(DEPXTOOLLIB) XkbClientDepLibs $(DEPXLIB) -LOCAL_LIBRARIES = $(XMULIB) $(XTOOLLIB) XkbClientLibs $(XLIB) +LOCAL_LIBRARIES = $(XMULIB) $(XTOOLLIB) XkbClientLibs $(XPRINTLIBS) $(XLIB) LINTLIBS = $(LINTXMU) $(LINTXTOOLLIB) $(LINTXLIB) DEFINES = $(SIGNAL_DEFINES) $(MKTMP_DEFINES) XkbClientDefines \ - $(XORGREL_DEF) $(VENDOR_DEFINES) + $(XPRINT_DEFINES) $(XORGREL_DEF) $(VENDOR_DEFINES) SRCS = gram.c lex.c deftwmrc.c add_window.c gc.c list.c twm.c \ parse.c menus.c events.c resize.c util.c version.c iconmgr.c \ cursor.c icons.c session.c OBJS = gram.o lex.o deftwmrc.o add_window.o gc.o list.o twm.o \ parse.o menus.o events.o resize.o util.o version.o iconmgr.o \ cursor.o icons.o session.o all:: SpecialCObjectRule(parse,$(_NOOP_),'-DSYSTEM_INIT_FILE="$(TWMDIR)/system.twmrc"') #if !HasPutenv SpecialCObjectRule(util,$(_NOOP_),-DNOPUTENV XkbClientDefines) #endif LexFile(lex) YaccFile(gram,$(YFLAGS)) Index: xc/programs/twm/twm.c =================================================================== RCS file: /cvs/xorg/xc/programs/twm/twm.c,v retrieving revision 1.3 diff -u -2 -0 -r1.3 twm.c --- xc/programs/twm/twm.c 11 Mar 2005 16:23:00 -0000 1.3 +++ xc/programs/twm/twm.c 11 Mar 2005 21:11:42 -0000 @@ -1,24 +1,25 @@ /*****************************************************************************/ /* Copyright 1989, 1998 The Open Group +Copyright 2005 Hitachi, Ltd. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. @@ -39,75 +40,80 @@ /** in publicity pertaining to distribution of the software without **/ /** specific, written prior permission. **/ /** **/ /** EVANS & SUTHERLAND DISCLAIMs ALL WARRANTIES WITH REGARD **/ /** TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- **/ /** ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND **/ /** BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM- **/ /** AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/ /** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/ /** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ /*********************************************************************** * * $Xorg: twm.c,v 1.5 2001/02/09 02:05:37 xorgcvs Exp $ * * twm - "Tom's Window Manager" * - * 27-Oct-87 Thomas E. LaStrange File created - * 10-Oct-90 David M. Sternlicht Storing saved colors on root + * 27-Oct-1987 Thomas E. LaStrange File created + * 10-Oct-1990 David M. Sternlicht Storing saved colors on root + * 19-Feb-2005 Julien Lafon Handle print screens for unified Xserver ***********************************************************************/ /* $XFree86: xc/programs/twm/twm.c,v 3.13 2003/04/21 08:15:10 herrb Exp $ */ #include #include #include #include "twm.h" #include "iconmgr.h" #include "add_window.h" #include "gc.h" #include "parse.h" #include "version.h" #include "menus.h" #include "events.h" #include "util.h" #include "gram.h" #include "screen.h" #include "parse.h" #include "session.h" #include #include #include #include #include #include +#ifdef XPRINT +#include +#endif /* XPRINT */ XtAppContext appContext; /* Xt application context */ XtSignalId si; Display *dpy = NULL; /* which display are we talking to */ Window ResizeWindow; /* the window we are resizing */ int MultiScreen = TRUE; /* try for more than one screen? */ +int NoPrintscreens = False; /* ignore special handling of print screens? */ int NumScreens; /* number of screens in ScreenList */ int HasShape; /* server supports shape extension? */ int ShapeEventBase, ShapeErrorBase; int HasSync; /* server supports SYNC extension? */ int SyncEventBase, SyncErrorBase; ScreenInfo **ScreenList; /* structures for each screen */ ScreenInfo *Scr = NULL; /* the cur and prev screens */ int PreviousScreen; /* last screen that we were on */ int FirstScreen; /* TRUE ==> first screen of display */ Bool PrintErrorMessages = False; /* controls error messages */ static int RedirectError; /* TRUE ==> another window manager running */ static int TwmErrorHandler ( Display *dpy, XErrorEvent *event ); /* for settting RedirectError */ static int CatchRedirectError ( Display *dpy, XErrorEvent *event ); /* for everything else */ static SIGNAL_T sigHandler(int); char Info[INFO_LINES][INFO_SIZE]; /* info strings to print */ int InfoLines; char *InitFile = NULL; Cursor UpperLeftCursor; /* upper Left corner cursor */ Cursor RightButt; @@ -146,100 +152,152 @@ Atom TwmAtoms[11]; Bool use_fontset; /* use XFontSet-related functions or not */ /* don't change the order of these strings */ static char* atom_names[11] = { "_MIT_PRIORITY_COLORS", "WM_CHANGE_STATE", "WM_STATE", "WM_COLORMAP_WINDOWS", "WM_PROTOCOLS", "WM_TAKE_FOCUS", "WM_SAVE_YOURSELF", "WM_DELETE_WINDOW", "SM_CLIENT_ID", "WM_CLIENT_LEADER", "WM_WINDOW_ROLE" }; +#ifdef XPRINT +/* |hasExtension()| and |IsPrintScreen()| have been stolen from + * xc/programs/xdpyinfo/xdpyinfo.c */ +static +Bool hasExtension(Display *dpy, char *extname) +{ + int num_extensions, + i; + char **extensions; + extensions = XListExtensions(dpy, &num_extensions); + for (i = 0; i < num_extensions && + (strcmp(extensions[i], extname) != 0); i++); + XFreeExtensionList(extensions); + return i != num_extensions; +} + +static +Bool IsPrintScreen(Screen *s) +{ + Display *dpy = XDisplayOfScreen(s); + int i; + + /* Check whether this is a screen of a print DDX */ + if (hasExtension(dpy, XP_PRINTNAME)) { + Screen **pscreens; + int pscrcount; + + pscreens = XpQueryScreens(dpy, &pscrcount); + for( i = 0 ; (i < pscrcount) && pscreens ; i++ ) { + if (s == pscreens[i]) { + return True; + } + } + XFree(pscreens); + } + return False; +} +#endif /* XPRINT */ + /*********************************************************************** * * Procedure: * main - start of twm * *********************************************************************** */ int main(int argc, char *argv[]) { Window root, parent, *children; unsigned int nchildren; int i, j; char *display_name = NULL; unsigned long valuemask; /* mask for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */ int numManaged, firstscrn, lastscrn, scrnum; int zero = 0; char *restore_filename = NULL; char *client_id = NULL; char *loc; ProgramName = argv[0]; Argc = argc; Argv = argv; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'd': /* -display dpy */ + if (strcmp(&argv[i][1], "display")) goto usage; if (++i >= argc) goto usage; display_name = argv[i]; continue; case 's': /* -single */ MultiScreen = FALSE; continue; +#ifdef XPRINT + case 'n': /* -noprint */ + if (strcmp(&argv[i][1], "noprint")) goto usage; + NoPrintscreens = True; + continue; +#endif /* XPRINT */ case 'f': /* -file twmrcfilename */ if (++i >= argc) goto usage; InitFile = argv[i]; continue; case 'v': /* -verbose */ PrintErrorMessages = True; continue; case 'c': /* -clientId */ + if (strcmp(&argv[i][1], "clientId")) goto usage; if (++i >= argc) goto usage; client_id = argv[i]; continue; case 'r': /* -restore */ + if (strcmp(&argv[i][1], "restore")) goto usage; if (++i >= argc) goto usage; restore_filename = argv[i]; continue; case 'q': /* -quiet */ PrintErrorMessages = False; continue; } } usage: fprintf (stderr, - "usage: %s [-display dpy] [-f file] [-s] [-q] [-v] [-clientId id] [-restore file]\n", + "usage: %s [-display dpy] [-f file] [-s] [-q] [-v]" +#ifdef XPRINT + " [-noprint]" +#endif /* XPRINT */ + " [-clientId id] [-restore file]\n", ProgramName); exit (1); } loc = setlocale(LC_ALL, ""); if (!loc || !strcmp(loc, "C") || !strcmp(loc, "POSIX") || !XSupportsLocale()) { use_fontset = False; } else { use_fontset = True; } #define newhandler(sig) \ if (signal (sig, SIG_IGN) != SIG_IGN) (void) signal (sig, sigHandler) newhandler (SIGINT); newhandler (SIGHUP); newhandler (SIGQUIT); newhandler (SIGTERM); @@ -313,55 +371,66 @@ else { firstscrn = lastscrn = DefaultScreen(dpy); } InfoLines = 0; /* for simplicity, always allocate NumScreens ScreenInfo struct pointers */ ScreenList = (ScreenInfo **) calloc (NumScreens, sizeof (ScreenInfo *)); if (ScreenList == NULL) { fprintf (stderr, "%s: Unable to allocate memory for screen list, exiting.\n", ProgramName); exit (1); } numManaged = 0; PreviousScreen = DefaultScreen(dpy); FirstScreen = TRUE; for (scrnum = firstscrn ; scrnum <= lastscrn; scrnum++) { +#ifdef XPRINT + /* Ignore print screens to avoid that users accidentally warp on a + * print screen (which are not visible on video displays) */ + if ((!NoPrintscreens) && IsPrintScreen(XScreenOfDisplay(dpy, scrnum))) + { + fprintf (stderr, "%s: skipping print screen %d\n", + ProgramName, scrnum); + continue; + } +#endif /* XPRINT */ + /* Make sure property priority colors is empty */ XChangeProperty (dpy, RootWindow(dpy, scrnum), _XA_MIT_PRIORITY_COLORS, XA_CARDINAL, 32, PropModeReplace, NULL, 0); RedirectError = FALSE; XSetErrorHandler(CatchRedirectError); XSelectInput(dpy, RootWindow (dpy, scrnum), ColormapChangeMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask); XSync(dpy, 0); XSetErrorHandler(TwmErrorHandler); if (RedirectError) { - fprintf (stderr, "%s: another window manager is already running", + fprintf (stderr, "%s: another window manager is already running.", ProgramName); if (MultiScreen && NumScreens > 0) fprintf(stderr, " on screen %d?\n", scrnum); else fprintf(stderr, "?\n"); continue; } numManaged ++; /* Note: ScreenInfo struct is calloc'ed to initialize to zero. */ Scr = ScreenList[scrnum] = (ScreenInfo *) calloc(1, sizeof(ScreenInfo)); if (Scr == NULL) { fprintf (stderr, "%s: unable to allocate memory for ScreenInfo structure for screen %d.\n", ProgramName, scrnum); continue; } @@ -582,42 +651,42 @@ " 8888 x 8888 ", 13); valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity); attributes.bit_gravity = NorthWestGravity; Scr->SizeWindow = XCreateWindow (dpy, Scr->Root, 0, 0, (unsigned int) Scr->SizeStringWidth, (unsigned int) (Scr->SizeFont.height + SIZE_VINDENT*2), (unsigned int) BW, 0, (unsigned int) CopyFromParent, (Visual *) CopyFromParent, valuemask, &attributes); XUngrabServer(dpy); FirstScreen = FALSE; Scr->FirstTime = FALSE; } /* for */ if (numManaged == 0) { if (MultiScreen && NumScreens > 0) - fprintf (stderr, "%s: unable to find any unmanaged screens\n", - ProgramName); + fprintf (stderr, "%s: unable to find any unmanaged %sscreens.\n", + ProgramName, NoPrintscreens?"":"video "); exit (1); } (void) ConnectToSessionManager (client_id); RestartPreviousState = False; HandlingEvents = TRUE; InitEvents(); HandleEvents(); exit(0); } /** * initialize twm variables */ void InitVariables() { FreeList(&Scr->BorderColorL); FreeList(&Scr->IconBorderColorL); Index: xc/programs/xdpyinfo/xdpyinfo.c =================================================================== RCS file: /cvs/xorg/xc/programs/xdpyinfo/xdpyinfo.c,v retrieving revision 1.7 diff -u -2 -0 -r1.7 xdpyinfo.c --- xc/programs/xdpyinfo/xdpyinfo.c 2 Sep 2004 05:50:38 -0000 1.7 +++ xc/programs/xdpyinfo/xdpyinfo.c 11 Mar 2005 21:11:43 -0000 @@ -1,27 +1,28 @@ /* * $Xorg: xdpyinfo.c,v 1.5 2001/02/09 02:05:41 xorgcvs Exp $ * * xdpyinfo - print information about X display connecton * * Copyright 1988, 1998 The Open Group +Copyright 2005 Hitachi, Ltd. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. @@ -326,100 +327,113 @@ break; } printf (" visual:\n"); printf (" visual id: 0x%lx\n", vip->visualid); printf (" class: %s\n", class); printf (" depth: %d plane%s\n", vip->depth, vip->depth == 1 ? "" : "s"); if (vip->class == TrueColor || vip->class == DirectColor) printf (" available colormap entries: %d per subfield\n", vip->colormap_size); else printf (" available colormap entries: %d\n", vip->colormap_size); printf (" red, green, blue masks: 0x%lx, 0x%lx, 0x%lx\n", vip->red_mask, vip->green_mask, vip->blue_mask); printf (" significant bits in color specification: %d bits\n", vip->bits_per_rgb); } +/* xc/programs/twm/twm.c has a copy of |hasExtension()|, please + * keep both versions in sync... */ static Bool hasExtension(Display *dpy, char *extname) { int num_extensions, i; char **extensions; extensions = XListExtensions(dpy, &num_extensions); for (i = 0; i < num_extensions && (strcmp(extensions[i], extname) != 0); i++); XFreeExtensionList(extensions); return i != num_extensions; } +/* xc/programs/twm/twm.c has a copy of |IsPrintScreen()|, please + * keep both versions in sync... */ +static +Bool IsPrintScreen(Screen *s) +{ + Display *dpy = XDisplayOfScreen(s); + int i; + + /* Check whether this is a screen of a print DDX */ + if (hasExtension(dpy, XP_PRINTNAME)) { + Screen **pscreens; + int pscrcount; + + pscreens = XpQueryScreens(dpy, &pscrcount); + for( i = 0 ; (i < pscrcount) && pscreens ; i++ ) { + if (s == pscreens[i]) { + return True; + } + } + XFree(pscreens); + } + return False; +} static void print_screen_info(Display *dpy, int scr) { Screen *s = ScreenOfDisplay (dpy, scr); /* opaque structure */ XVisualInfo viproto; /* fill in for getting info */ XVisualInfo *vip; /* retured info */ int nvi; /* number of elements returned */ int i; /* temp variable: iterator */ char eventbuf[80]; /* want 79 chars per line + nul */ static char *yes = "YES", *no = "NO", *when = "WHEN MAPPED"; double xres, yres; int ndepths = 0, *depths = NULL; unsigned int width, height; - Bool isPrintScreen = False; + Bool isPrintScreen = False; /* Initalise this if |INCLUDE_XPRINT_SUPPORT| is not set */ /* * there are 2.54 centimeters to an inch; so there are 25.4 millimeters. * * dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch)) * = N pixels / (M inch / 25.4) * = N * 25.4 pixels / M inch */ xres = ((((double) DisplayWidth(dpy,scr)) * 25.4) / ((double) DisplayWidthMM(dpy,scr))); yres = ((((double) DisplayHeight(dpy,scr)) * 25.4) / ((double) DisplayHeightMM(dpy,scr))); printf ("\n"); printf ("screen #%d:\n", scr); #ifdef INCLUDE_XPRINT_SUPPORT /* Check whether this is a screen of a print DDX */ - if (hasExtension(dpy, XP_PRINTNAME)) { - Screen **pscreens; - int pscrcount; - - pscreens = XpQueryScreens(dpy, &pscrcount); - for( i = 0 ; (i < pscrcount) && pscreens ; i++ ) { - if (scr == (int)XScreenNumberOfScreen(pscreens[i])) { - isPrintScreen = True; - break; - } - } - XFree(pscreens); - } + isPrintScreen = IsPrintScreen(s); printf (" print screen: %s\n", isPrintScreen?"yes":"no"); #endif /* INCLUDE_XPRINT_SUPPORT */ if (isPrintScreen) { /* Print resolution is set on a per-printer basis (per-document * or per-page), the screen itself has no "default" resolution */ printf (" maximum dimensions: %dx%d pixels\n", XDisplayWidth (dpy, scr), XDisplayHeight (dpy, scr)); } else { printf (" dimensions: %dx%d pixels (%dx%d millimeters)\n", XDisplayWidth (dpy, scr), XDisplayHeight (dpy, scr), XDisplayWidthMM(dpy, scr), XDisplayHeightMM (dpy, scr)); printf (" resolution: %dx%d dots per inch\n", (int) (xres + 0.5), (int) (yres + 0.5)); } depths = XListDepths (dpy, scr, &ndepths); if (!depths) ndepths = 0; printf (" depths (%d): ", ndepths);