home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / MozillaWm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.4 KB  |  169 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* MozillaWm.c
  20.  *
  21.  * Mozilla Window Manager interface
  22.  *
  23.  * X11 window manager conventions do not support the window manager
  24.  * functionality required by Mozilla JavaScript 1.2 features for NetCaster.
  25.  */
  26.  
  27. #include "MozillaWm.h"
  28.  
  29. #define _MOZILLA_WM_VERSION "_MOZILLA_WM_VERSION"
  30. #define _MOZILLA_WM_HINTS "_MOZILLA_WM_HINTS"
  31.  
  32. /* Window Manager-only API */
  33. #ifdef MOZILLA_WM_I_AM_A_WINDOW_MANAGER
  34. /* set version of Mozilla WM API supported by window manager. */
  35. void
  36. MozillaWmSetWmVersion(Screen *screen,long wmVersion)
  37. {
  38.     Display *display=XDisplayOfScreen(screen);
  39.     Window root=XRootWindowOfScreen(screen);
  40.     Atom XA_MOZILLA_WM_VERSION=XInternAtom(display,_MOZILLA_WM_VERSION,False);
  41.     
  42.     XChangeProperty(display,
  43.                     root,
  44.                     XA_MOZILLA_WM_VERSION,
  45.                     XA_MOZILLA_WM_VERSION,
  46.                     32,
  47.                     PropModeReplace,
  48.                     (unsigned char *) &wmVersion,
  49.                     1);
  50. }
  51. #endif
  52.  
  53. /* general client API */
  54.  
  55. /* get version of Mozilla WM API supported by window manager for client's screen */
  56. long
  57. MozillaWmGetWmVersion(Screen *screen)
  58. {
  59.     Display *display=XDisplayOfScreen(screen);
  60.     Window root=XRootWindowOfScreen(screen);
  61.     Atom XA_MOZILLA_WM_VERSION=XInternAtom(display,_MOZILLA_WM_VERSION,False);
  62.     int retValue;
  63.     unsigned long outlength;
  64.     unsigned char *outpointer=NULL;
  65.     Atom type;
  66.     int format;
  67.     unsigned long bytes_left;
  68.  
  69.     long wmVersion=MOZILLA_WM_VERSION_INVALID;/* default to invalid version */
  70.  
  71.     retValue=XGetWindowProperty(display,
  72.                                 root,
  73.                                 XA_MOZILLA_WM_VERSION,
  74.                                 0,
  75.                                 10000000,
  76.                                 False,
  77.                                 AnyPropertyType,
  78.                                 &type,
  79.                                 &format,
  80.                                 &outlength,
  81.                                 &bytes_left,
  82.                                 &outpointer);
  83.     if (retValue == 0 &&
  84.         outpointer != NULL &&
  85.         outlength > 0 &&
  86.         format == 32) {
  87.         /* extract version number from property data */
  88.         wmVersion=((long*)outpointer)[0];
  89.     }
  90.     if (outpointer != NULL)
  91.         XFree((char*)outpointer);
  92.  
  93.     return wmVersion;
  94. }
  95.  
  96.  
  97. /* set Mozilla WM hint flags on shell window */
  98. void MozillaWmSetHints(Screen *screen, Window window, unsigned long hints)
  99. {
  100.     Display *display=XDisplayOfScreen(screen);
  101.     Atom XA_MOZILLA_WM_HINTS=XInternAtom(display,_MOZILLA_WM_HINTS,False);
  102.  
  103.     XChangeProperty(display,
  104.                     window,
  105.                     XA_MOZILLA_WM_HINTS,
  106.                     XA_MOZILLA_WM_HINTS,
  107.                     32,
  108.                     PropModeReplace,
  109.                     (unsigned char *) &hints,
  110.                     1);
  111.  
  112. }
  113.  
  114. /* add Mozilla WM hint flags to shell window */
  115. void MozillaWmAddHints(Screen *screen, Window window, unsigned long hints)
  116. {
  117.     unsigned long wmHints=MozillaWmGetHints(screen,window);
  118.     wmHints |= hints;
  119.     MozillaWmSetHints(screen,window,wmHints);
  120. }
  121.  
  122. /* remove Mozilla WM hint flags from shell window */
  123. void MozillaWmRemoveHints(Screen *screen, Window window, unsigned long hints)
  124. {
  125.     unsigned long wmHints=MozillaWmGetHints(screen,window);
  126.     wmHints &= ~hints;
  127.     MozillaWmSetHints(screen,window,wmHints);
  128. }
  129.  
  130. /* get Mozilla WM hint flags from shell window */
  131. unsigned long MozillaWmGetHints(Screen *screen, Window window)
  132. {
  133.     Display *display=XDisplayOfScreen(screen);
  134.     Atom XA_MOZILLA_WM_HINTS=XInternAtom(display,_MOZILLA_WM_HINTS,False);
  135.     int retValue;
  136.     unsigned long outlength;
  137.     unsigned char *outpointer=NULL;
  138.     Atom type;
  139.     int format;
  140.     unsigned long bytes_left;
  141.  
  142.     unsigned long wmHints=MOZILLA_WM_NONE; /* default to no flags */
  143.  
  144.     retValue=XGetWindowProperty(display,
  145.                                 window,
  146.                                 XA_MOZILLA_WM_HINTS,
  147.                                 0,
  148.                                 10000000,
  149.                                 False,
  150.                                 AnyPropertyType,
  151.                                 &type,
  152.                                 &format,
  153.                                 &outlength,
  154.                                 &bytes_left,
  155.                                 &outpointer);
  156.     if (retValue == 0 &&
  157.         outpointer != NULL &&
  158.         outlength > 0 &&
  159.         format == 32) {
  160.         /* extract flags from property data */
  161.         wmHints=((long*)outpointer)[0];
  162.     }
  163.     if (outpointer != NULL)
  164.         XFree((char*)outpointer);
  165.  
  166.     return wmHints;
  167. }
  168.  
  169.