0N/A/*
2362N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A /*
0N/A * This code is ported to XAWT from MAWT based on awt_mgrsel.c
0N/A * and XSettings.java code written originally by Valeriy Ushakov
0N/A * Author : Bino George
0N/A */
0N/A
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.util.*;
0N/Aimport java.awt.*;
0N/Aimport sun.awt.XSettings;
1696N/Aimport sun.util.logging.PlatformLogger;
0N/A
0N/A
0N/Aclass XAWTXSettings extends XSettings implements XMSelectionListener {
0N/A
0N/A private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS");
0N/A
1696N/A private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings");
0N/A
0N/A /* The maximal length of the property data. */
0N/A public static final long MAX_LENGTH = 1000000;
0N/A
0N/A XMSelection settings;
0N/A
0N/A public XAWTXSettings() {
0N/A initXSettings();
0N/A
0N/A }
0N/A
0N/A void initXSettings() {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Initializing XAWT XSettings");
0N/A settings = new XMSelection("_XSETTINGS");
0N/A settings.addSelectionListener(this);
0N/A initPerScreenXSettings();
0N/A }
0N/A
0N/A void dispose() {
0N/A settings.removeSelectionListener(this);
0N/A }
0N/A
0N/A public void ownerDeath(int screen, XMSelection sel, long deadOwner) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen);
0N/A }
0N/A
0N/A
0N/A public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen );
0N/A }
0N/A
0N/A public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) {
0N/A log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event);
0N/A updateXSettings(screen,owner);
0N/A }
0N/A
0N/A void initPerScreenXSettings() {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Updating Per XSettings changes");
0N/A
0N/A /*
0N/A * As toolkit cannot yet cope with per-screen desktop properties,
0N/A * only report XSETTINGS changes on the default screen. This
0N/A * should be "good enough" for most cases.
0N/A */
0N/A
0N/A Map updatedSettings = null;
0N/A XToolkit.awtLock();
0N/A try {
0N/A long display = XToolkit.getDisplay();
0N/A int screen = (int) XlibWrapper.DefaultScreen(display);
0N/A updatedSettings = getUpdatedSettings(settings.getOwner(screen));
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A // we must not invoke this under Awt Lock
0N/A ((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings);
0N/A }
0N/A
0N/A private void updateXSettings(int screen, long owner) {
0N/A final Map updatedSettings = getUpdatedSettings(owner);
0N/A // this method is called under awt lock and usually on toolkit thread
0N/A // but parseXSettings() causes public code execution, so we need to transfer
0N/A // this to EDT
0N/A EventQueue.invokeLater( new Runnable() {
0N/A public void run() {
0N/A ((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings);
0N/A }
0N/A });
0N/A }
0N/A
0N/A private Map getUpdatedSettings(final long owner) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("owner =" + owner);
0N/A if (0 == owner) {
0N/A return null;
0N/A }
0N/A
0N/A Map settings = null;
0N/A try {
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH,
0N/A false, xSettingsPropertyAtom.getAtom() );
0N/A try {
1216N/A int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
0N/A
216N/A if (status != XConstants.Success || getter.getData() == 0) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("OH OH : getter failed status = " + status );
0N/A settings = null;
0N/A }
0N/A
0N/A long ptr = getter.getData();
0N/A
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("noItems = " + getter.getNumberOfItems());
0N/A byte array[] = Native.toBytes(ptr,getter.getNumberOfItems());
0N/A if (array != null) {
0N/A settings = update(array);
0N/A }
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A catch (Exception e) {
0N/A e.printStackTrace();
0N/A }
0N/A return settings;
0N/A }
0N/A
0N/A
0N/A
0N/A}