home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / internal / 2071 next >
Encoding:
Text File  |  1992-12-21  |  9.0 KB  |  284 lines

  1. Newsgroups: comp.unix.internals
  2. Path: sparky!uunet!mcsun!ub4b!sunbim!usenet
  3. From: km@barco.be
  4. Subject:  Colormaps in OW 3
  5. Message-ID: <1992Dec21.084734.26053@sunbim.be>
  6. Sender: usenet@sunbim.be (user news)
  7. Reply-To: km@barco.be
  8. Organization: Barco 
  9. Date: Mon, 21 Dec 92 08:47:34 GMT
  10. Lines: 272
  11.  
  12. hi ,
  13. We have a problem with colormaps on a SUN Sparcstation 2 (SUN OS 4.1.2)
  14. We have an application which requires that the user can define his own
  15. gammafunction in the colormap.  At startup of the X-server he therefor
  16. would like to have possible previous stored settings reloaded.
  17.  
  18. In fact it all boils down to the problem that at startup of the XSERVER
  19. (xnews) we want to install our own colormap so that other newly created
  20. Xclients also inherit this colormap-ID. We have written a small test-
  21. program (which we sent you at the end of this mail) which installs a user-
  22. defined colormap. To see clearly when our colormap gets loaded we have
  23. taken a copy of the Default Colormap and made the red, green and blue
  24. values equal, which gives some kind of gray-scale effect. However we have
  25. the problem that when new Xclients are started, they keep on using the old
  26. (initial default) colormap...
  27.  
  28. In fact even when we use XSetWindowColormap to set the colormap of the root
  29. window, new clients keep on using the 'default startup' colormap. If we use
  30. the DefaultColormap-macro we keep on getting the old initial colormap-ID.
  31. And it is probably so that new xclients, (for instance xterm, xclock a.s.o.)
  32. are using this DefaultColormap-macro to set their own window-colormap. so
  33. they are not aware of our new colormap.
  34.  
  35. Is there a way to solve the above mentioned problem ?
  36.  
  37. Furthermore :
  38.  
  39. a. In theory, above problem has nothing to do with the OpenLookWindowManager.
  40.    The OLWM is just a 'special' client, that performs some house-keeping. 
  41.    Altough I have one question about this. Suppose one uses XSetWindow-
  42.    Colormap to set the colormap of the root-window to a user-defined one,
  43.    together with the colormap of the window created in the program, and 
  44.    the OLWM is running in ColorFollowsMouse mode. If one moves the mouse-
  45.    pointer above the newly created window the OLWM installs the user-defined
  46.    colormap (as it is supposed to do).  However if one moves the mouse-pointer
  47.    to the root-window the OLWM does NOT install the user-defined colormap.
  48.    Hence, if one uses xwininfo to check the colormap ID of the ROOT-window
  49.    one gets the userdefined colormap ID...
  50.    Is there any explanation for this ?
  51.  
  52. b. If one assumes the same situation as above, it means we have a program 
  53.    running and we use the CTRL-L2 key to lock our user-defined colormap.
  54.    If one then clicks on the RIGHT-MOUSE-BUTTON to get for instance the
  55.    root-menu, then the OLWM switches back in the default-colormap ?
  56.    Can one avoid this ?
  57.  
  58. c. Also is there a possibility to perform the CTRL-L2 (LockColorMap function)
  59.    from within a program ?  Because the program that is to install our user-
  60.    defined colormap should run as a deamon, and should possibly have no visi-
  61.    ble window on the screen.  At that moment it isn't any lobger possible to
  62.    use the CTRL-L2 ...
  63.  
  64. d. Also if we use the XSetStandardColormap (XSetRGBColormap) function to set
  65.    the XA_RGB_DEFAULT_MAP,XA_RGB_BEST_MAP... properties all behavior stays
  66.    the same. I assume this is normal, because in fact these STANDARD Color-
  67.    maps have nothing to do with the DEFAULT colormap. The concept of STANDARD 
  68.    colormaps is only to make life easier when one wants to share colors 
  69.    between Xclients. Is this right ?  
  70.  
  71.  
  72.  
  73. We've got really stuck...  Could anyone please give me some hints or give us
  74. your opinion on the situation.  We are not sure if it is even possible to force
  75. the xnews X-server to use a user-defined colormap at startup ...
  76.  
  77. Thank you very much in advance.
  78. Kind Regards.
  79.  
  80.  
  81. Kurt MICHELS
  82.  
  83. R&D Department
  84. BARCO N.V.
  85. BELGIUM
  86.  
  87. E-mail : km@barco.be
  88. Tel    : 32 56 233 368
  89. Fax    : 32 56 233 332
  90.  
  91.  
  92.  
  93.  
  94. --------------------------------------------------
  95.  
  96. /* File : INIT.C  */
  97.  
  98. /*
  99. This program allocates the entire colormap, ALL applications are
  100. forced to use only this colormap.  Of course they can install 
  101. themselves a total new colormap ... (this one can never avoid).
  102. It can be used as daemon, because if one omits the XMapWindow
  103. function, then nothing is displayed on the screen.
  104.  
  105. This program can easily be extented to read-in a colormap from a
  106. file which was stored in some format...
  107. */
  108.  
  109.  
  110. #include <X11/Xlib.h>
  111. #include <X11/Xutil.h>
  112. #include <X11/Xatom.h>
  113. #include <stdio.h>
  114. #include <X11/keysymdef.h>
  115.  
  116. #define     MYMAXCOLORS    256
  117.  
  118.  
  119. void main()
  120.   {
  121.   Display     *display;
  122.   Window     win;
  123.   Window    rootwin;
  124.   Window    windowlist[10];
  125.   XWindowAttributes     attributes;
  126.  
  127.   int         defaultscreen;
  128.   char         dummy;
  129.    
  130.   unsigned int width, height, x, y; 
  131.   unsigned int borderwidth = 4;       
  132.   unsigned int display_width, display_height;
  133.  
  134.   XEvent     report;
  135.   XEvent     CTRL2Event;
  136.   XKeyEvent    CTRL2KeyEvent;
  137.   Visual     *defaultvisual;
  138.  
  139.  
  140.   /**************** ADDED FOR COLOR-MANAGEMENT *********************/
  141.  
  142.   int        i;
  143.   int        myplane_masks[1];
  144.   int        mypixelvalues[MYMAXCOLORS];
  145.   Colormap    mycolormap;
  146.   Colormap    defaultmap;
  147.  
  148.   XStandardColormap    standardcolormap;
  149.   XColor        mycolors[MYMAXCOLORS];
  150.   XColor        origcolors[MYMAXCOLORS];
  151.   XColor        origcolor;
  152.   XColor        newcolor;
  153.     
  154.   /******************************************************************/
  155.  
  156.   display = XOpenDisplay(NULL);
  157.   /* XGrabServer(display);   */
  158.  
  159.   defaultscreen      = DefaultScreen(display);
  160.   defaultvisual      = DefaultVisual(display, defaultscreen);
  161.   defaultmap         = DefaultColormap(display, defaultscreen);
  162.   rootwin         = RootWindow(display,defaultscreen); 
  163.  
  164.  
  165.   XGetStandardColormap(display, rootwin, &standardcolormap, XA_RGB_DEFAULT_MAP);
  166.   printf("Standard Colormap ID : 0x%lx\n ", standardcolormap.colormap);
  167.   printf("Default  Colormap ID : 0x%lx\n ",defaultmap);
  168.  
  169.   display_width  = DisplayWidth (display, defaultscreen);
  170.   display_height = DisplayHeight(display, defaultscreen);
  171.  
  172.   x = display_width/3;
  173.   y = display_height/3;
  174.   width = display_width/3;
  175.   height = display_height/4;
  176.  
  177.   win = XCreateSimpleWindow(display, rootwin,
  178.                 x, y, width, height, borderwidth,
  179.                 BlackPixel(display,defaultscreen),
  180.                 WhitePixel(display,defaultscreen));
  181.  
  182.   mycolormap = XCreateColormap (display, win, defaultvisual, AllocAll);
  183.   XAllocColorCells (display, mycolormap, False, myplane_masks, 0, mypixelvalues, MYMAXCOLORS);
  184.  
  185.   for ( i=0; i < MYMAXCOLORS; i++) origcolors[i].pixel=i;
  186.   XQueryColors     (display, defaultmap, origcolors, MYMAXCOLORS);
  187.   for ( i=0; i < MYMAXCOLORS; i++) { origcolors[i].red = origcolors[i].blue; origcolors[i].green = origcolors[i].blue; };
  188.  
  189.   XStoreColors (display, mycolormap, origcolors, MYMAXCOLORS);
  190.   XSetWindowColormap (display, win, mycolormap);
  191.  
  192.  
  193.   /* Probably not necessary, because the Window Manager should do this ... */ 
  194.   XInstallColormap (display, mycolormap);                                                                   
  195.  
  196.  
  197.   /* XSetCloseDownMode(display, RetainPermanent);     */
  198.   /* XUngrabServer(display);                          */
  199.  
  200.   XSelectInput (display, win, ExposureMask | StructureNotifyMask | ColormapNotify | KeyPressMask); 
  201.  
  202.   XSetStandardProperties(display, win, "INIT", "INIT", NULL, NULL, NULL, NULL);
  203.   XMapWindow(display, win);
  204.  
  205.    XFlush(display);
  206.  
  207.  
  208.   /* Possibly needed for the OpenLookWindowManager                     */
  209.  
  210.   /*
  211.  
  212.   printf("If we are running in ColorLockedMode then if a client     \n");
  213.   printf("changes the WM_COLORMAP_WINDOWS property the OLWM should  \n");
  214.   printf("have to respond with installing the first Window in the   \n");
  215.   printf("list named by WM_COLORMAP_WINDOWS ...                     \n");
  216.  
  217.   printf("CONTINUE ... ");
  218.   getchar(&dummy);
  219.   printf("\n");
  220.  
  221.   windowlist[0] = win;
  222.   windowlist[1] = rootwin;
  223.   XSetWMColormapWindows (display, win, windowlist, 2);
  224.   XSetWMColormapWindows (display, rootwin, windowlist, 2);
  225.  
  226.   */
  227.  
  228.  
  229.   /* Neccessary, because in the CALITALK program we are going to get    */
  230.   /* the colormapID of this initial colormap, via the attributes of     */
  231.   /* the ROOTWINDOW, so this ROOTWINDOW does also need to have our      */
  232.   /* user-defined colormap !                                            */
  233.  
  234.   XSetWindowColormap (display, rootwin, mycolormap);   
  235.  
  236.   /*
  237.   CTRL2KeyEvent.type         = KeyPress;
  238.   CTRL2KeyEvent.send_event     = True;
  239.   CTRL2KeyEvent.display        = display;
  240.   CTRL2KeyEvent.window        = win;
  241.   CTRL2KeyEvent.root        = rootwin;
  242.   CTRL2KeyEvent.state        = ControlMask;
  243.   CTRL2KeyEvent.keycode        = 84;  
  244.  
  245.   CTRL2Event.type     = KeyPress;
  246.   CTRL2Event.xkey    = CTRL2KeyEvent;  
  247.   
  248.  
  249.   XSendEvent(display, win, False, KeyPress, CTRL2Event);
  250.   */
  251.  
  252.   XSync(display,False);
  253.   XFlush(display);
  254.  
  255.   while (1)
  256.     {
  257.     XNextEvent(display, &report);
  258.  
  259.     switch (report.type)
  260.        {
  261.        case KeyPress:
  262.           printf("\nOK KeyPress Event Received !!\n");
  263.           printf("KeyCode : %d\n",report.xkey.keycode);
  264.  
  265.           report.xkey.keycode = 70;
  266.  
  267.           /*
  268.           XSendEvent(display, win, True, NULL, report);
  269.           */
  270.  
  271.           XFlush(display);
  272.  
  273.           break;
  274.        default:
  275.            break;
  276.        } 
  277.     }
  278.   }
  279.  .
  280.  
  281.  
  282.  
  283.  
  284.