Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XAWTXSettings.java
32288 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* This code is ported to XAWT from MAWT based on awt_mgrsel.c27* and XSettings.java code written originally by Valeriy Ushakov28* Author : Bino George29*/303132package sun.awt.X11;3334import java.util.*;35import java.awt.*;36import sun.awt.XSettings;37import sun.util.logging.PlatformLogger;383940class XAWTXSettings extends XSettings implements XMSelectionListener {4142private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS");4344private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings");4546/* The maximal length of the property data. */47public static final long MAX_LENGTH = 1000000;4849XMSelection settings;5051public XAWTXSettings() {52initXSettings();5354}5556void initXSettings() {57if (log.isLoggable(PlatformLogger.Level.FINE)) {58log.fine("Initializing XAWT XSettings");59}60settings = new XMSelection("_XSETTINGS");61settings.addSelectionListener(this);62initPerScreenXSettings();63}6465void dispose() {66settings.removeSelectionListener(this);67}6869public void ownerDeath(int screen, XMSelection sel, long deadOwner) {70if (log.isLoggable(PlatformLogger.Level.FINE)) {71log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen);72}73}747576public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {77if (log.isLoggable(PlatformLogger.Level.FINE)) {78log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen );79}80}8182public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) {83if (log.isLoggable(PlatformLogger.Level.FINE)) {84log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event);85}86updateXSettings(screen,owner);87}8889void initPerScreenXSettings() {90if (log.isLoggable(PlatformLogger.Level.FINE)) {91log.fine("Updating Per XSettings changes");92}9394/*95* As toolkit cannot yet cope with per-screen desktop properties,96* only report XSETTINGS changes on the default screen. This97* should be "good enough" for most cases.98*/99100Map updatedSettings = null;101XToolkit.awtLock();102try {103long display = XToolkit.getDisplay();104int screen = (int) XlibWrapper.DefaultScreen(display);105updatedSettings = getUpdatedSettings(settings.getOwner(screen));106} finally {107XToolkit.awtUnlock();108}109// we must not invoke this under Awt Lock110((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings);111}112113private void updateXSettings(int screen, long owner) {114final Map updatedSettings = getUpdatedSettings(owner);115// this method is called under awt lock and usually on toolkit thread116// but parseXSettings() causes public code execution, so we need to transfer117// this to EDT118EventQueue.invokeLater( new Runnable() {119public void run() {120((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings);121}122});123}124125private Map getUpdatedSettings(final long owner) {126if (log.isLoggable(PlatformLogger.Level.FINE)) {127log.fine("owner =" + owner);128}129if (0 == owner) {130return null;131}132133Map settings = null;134try {135WindowPropertyGetter getter =136new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH,137false, xSettingsPropertyAtom.getAtom() );138try {139int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());140141if (status != XConstants.Success || getter.getData() == 0) {142if (log.isLoggable(PlatformLogger.Level.FINE)) {143log.fine("OH OH : getter failed status = " + status );144}145settings = null;146}147148long ptr = getter.getData();149150if (log.isLoggable(PlatformLogger.Level.FINE)) {151log.fine("noItems = " + getter.getNumberOfItems());152}153byte array[] = Native.toBytes(ptr,getter.getNumberOfItems());154if (array != null) {155settings = update(array);156}157} finally {158getter.dispose();159}160}161catch (Exception e) {162e.printStackTrace();163}164return settings;165}166167168169}170171172