src/solaris/classes/sun/awt/X11/XAWTXSettings.java

Print this page




  38 import sun.util.logging.PlatformLogger;
  39 
  40 
  41 class XAWTXSettings extends XSettings implements XMSelectionListener {
  42 
  43     private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS");
  44 
  45     private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings");
  46 
  47     /* The maximal length of the property data. */
  48     public static final long MAX_LENGTH = 1000000;
  49 
  50     XMSelection settings;
  51 
  52     public XAWTXSettings() {
  53         initXSettings();
  54 
  55     }
  56 
  57     void initXSettings() {
  58         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Initializing XAWT XSettings");


  59         settings = new XMSelection("_XSETTINGS");
  60         settings.addSelectionListener(this);
  61         initPerScreenXSettings();
  62     }
  63 
  64     void dispose() {
  65         settings.removeSelectionListener(this);
  66     }
  67 
  68     public void ownerDeath(int screen, XMSelection sel, long deadOwner) {
  69         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen);


  70     }
  71 
  72 
  73     public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {
  74         if (log.isLoggable(PlatformLogger.FINE)) log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen );


  75     }
  76 
  77     public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) {

  78         log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event);

  79         updateXSettings(screen,owner);
  80     }
  81 
  82     void initPerScreenXSettings() {
  83         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Updating Per XSettings changes");


  84 
  85         /*
  86          * As toolkit cannot yet cope with per-screen desktop properties,
  87          * only report XSETTINGS changes on the default screen.  This
  88          * should be "good enough" for most cases.
  89          */
  90 
  91         Map updatedSettings = null;
  92         XToolkit.awtLock();
  93         try {
  94             long display = XToolkit.getDisplay();
  95             int screen = (int) XlibWrapper.DefaultScreen(display);
  96             updatedSettings = getUpdatedSettings(settings.getOwner(screen));
  97         } finally {
  98             XToolkit.awtUnlock();
  99         }
 100         // we must not  invoke this under Awt Lock
 101         ((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings);
 102     }
 103 
 104     private void updateXSettings(int screen, long owner) {
 105         final Map updatedSettings = getUpdatedSettings(owner);
 106         // this method is called under awt lock and usually on toolkit thread
 107         // but parseXSettings() causes public code execution, so we need to transfer
 108         // this to EDT
 109         EventQueue.invokeLater( new Runnable() {
 110             public void run() {
 111                 ((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings);
 112             }
 113         });
 114     }
 115 
 116     private Map getUpdatedSettings(final long owner) {
 117         if (log.isLoggable(PlatformLogger.FINE)) log.fine("owner =" + owner);


 118         if (0 == owner) {
 119             return null;
 120         }
 121 
 122         Map settings = null;
 123         try {
 124             WindowPropertyGetter getter =
 125                 new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH,
 126                         false, xSettingsPropertyAtom.getAtom() );
 127             try {
 128                 int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 129 
 130                 if (status != XConstants.Success || getter.getData() == 0) {
 131                     if (log.isLoggable(PlatformLogger.FINE)) log.fine("OH OH : getter failed  status = " + status );


 132                     settings = null;
 133                 }
 134 
 135                 long ptr = getter.getData();
 136 
 137                 if (log.isLoggable(PlatformLogger.FINE)) log.fine("noItems = " + getter.getNumberOfItems());


 138                 byte array[] = Native.toBytes(ptr,getter.getNumberOfItems());
 139                 if (array != null) {
 140                     settings = update(array);
 141                 }
 142             } finally {
 143                 getter.dispose();
 144             }
 145         }
 146         catch (Exception e) {
 147             e.printStackTrace();
 148         }
 149         return settings;
 150     }
 151 
 152 
 153 
 154 }


  38 import sun.util.logging.PlatformLogger;
  39 
  40 
  41 class XAWTXSettings extends XSettings implements XMSelectionListener {
  42 
  43     private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS");
  44 
  45     private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings");
  46 
  47     /* The maximal length of the property data. */
  48     public static final long MAX_LENGTH = 1000000;
  49 
  50     XMSelection settings;
  51 
  52     public XAWTXSettings() {
  53         initXSettings();
  54 
  55     }
  56 
  57     void initXSettings() {
  58         if (log.isLoggable(PlatformLogger.FINE)) {
  59             log.fine("Initializing XAWT XSettings");
  60         }
  61         settings = new XMSelection("_XSETTINGS");
  62         settings.addSelectionListener(this);
  63         initPerScreenXSettings();
  64     }
  65 
  66     void dispose() {
  67         settings.removeSelectionListener(this);
  68     }
  69 
  70     public void ownerDeath(int screen, XMSelection sel, long deadOwner) {
  71         if (log.isLoggable(PlatformLogger.FINE)) {
  72             log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen);
  73         }
  74     }
  75 
  76 
  77     public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {
  78         if (log.isLoggable(PlatformLogger.FINE)) {
  79             log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen );
  80         }
  81     }
  82 
  83     public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) {
  84         if (log.isLoggable(PlatformLogger.FINE)) {
  85             log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event);
  86         }
  87         updateXSettings(screen,owner);
  88     }
  89 
  90     void initPerScreenXSettings() {
  91         if (log.isLoggable(PlatformLogger.FINE)) {
  92             log.fine("Updating Per XSettings changes");
  93         }
  94 
  95         /*
  96          * As toolkit cannot yet cope with per-screen desktop properties,
  97          * only report XSETTINGS changes on the default screen.  This
  98          * should be "good enough" for most cases.
  99          */
 100 
 101         Map updatedSettings = null;
 102         XToolkit.awtLock();
 103         try {
 104             long display = XToolkit.getDisplay();
 105             int screen = (int) XlibWrapper.DefaultScreen(display);
 106             updatedSettings = getUpdatedSettings(settings.getOwner(screen));
 107         } finally {
 108             XToolkit.awtUnlock();
 109         }
 110         // we must not  invoke this under Awt Lock
 111         ((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings);
 112     }
 113 
 114     private void updateXSettings(int screen, long owner) {
 115         final Map updatedSettings = getUpdatedSettings(owner);
 116         // this method is called under awt lock and usually on toolkit thread
 117         // but parseXSettings() causes public code execution, so we need to transfer
 118         // this to EDT
 119         EventQueue.invokeLater( new Runnable() {
 120             public void run() {
 121                 ((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings);
 122             }
 123         });
 124     }
 125 
 126     private Map getUpdatedSettings(final long owner) {
 127         if (log.isLoggable(PlatformLogger.FINE)) {
 128             log.fine("owner =" + owner);
 129         }
 130         if (0 == owner) {
 131             return null;
 132         }
 133 
 134         Map settings = null;
 135         try {
 136             WindowPropertyGetter getter =
 137                 new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH,
 138                         false, xSettingsPropertyAtom.getAtom() );
 139             try {
 140                 int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 141 
 142                 if (status != XConstants.Success || getter.getData() == 0) {
 143                     if (log.isLoggable(PlatformLogger.FINE)) {
 144                         log.fine("OH OH : getter failed  status = " + status );
 145                     }
 146                     settings = null;
 147                 }
 148 
 149                 long ptr = getter.getData();
 150 
 151                 if (log.isLoggable(PlatformLogger.FINE)) {
 152                     log.fine("noItems = " + getter.getNumberOfItems());
 153                 }
 154                 byte array[] = Native.toBytes(ptr,getter.getNumberOfItems());
 155                 if (array != null) {
 156                     settings = update(array);
 157                 }
 158             } finally {
 159                 getter.dispose();
 160             }
 161         }
 162         catch (Exception e) {
 163             e.printStackTrace();
 164         }
 165         return settings;
 166     }
 167 
 168 
 169 
 170 }