jdk/src/solaris/classes/sun/awt/X11/XAWTXSettings.java
author darcy
Thu, 13 Mar 2014 12:40:27 -0700
changeset 23647 41d22f2dbeb5
parent 23010 6dadb192ad81
child 24538 25bf8153fbfe
permissions -rw-r--r--
8033712: Fix more serial lint warnings in sun.awt Reviewed-by: alanb, serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18178
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
   * This code is ported to XAWT from MAWT based on awt_mgrsel.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
   * and XSettings.java code written originally by Valeriy Ushakov
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
   * Author : Bino George
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.XSettings;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    38
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class XAWTXSettings extends XSettings implements XMSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    45
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /* The maximal length of the property data. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final long MAX_LENGTH = 1000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    XMSelection settings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public XAWTXSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        initXSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    void initXSettings() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    58
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    59
            log.fine("Initializing XAWT XSettings");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    60
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        settings = new XMSelection("_XSETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        settings.addSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        initPerScreenXSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        settings.removeSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public void ownerDeath(int screen, XMSelection sel, long deadOwner) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    71
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    72
            log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    73
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    78
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    79
            log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen );
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    80
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    84
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    85
            log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    86
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        updateXSettings(screen,owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    void initPerScreenXSettings() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    91
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    92
            log.fine("Updating Per XSettings changes");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    93
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * As toolkit cannot yet cope with per-screen desktop properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * only report XSETTINGS changes on the default screen.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         * should be "good enough" for most cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Map updatedSettings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            long display = XToolkit.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            int screen = (int) XlibWrapper.DefaultScreen(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            updatedSettings = getUpdatedSettings(settings.getOwner(screen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // we must not  invoke this under Awt Lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private void updateXSettings(int screen, long owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        final Map updatedSettings = getUpdatedSettings(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // this method is called under awt lock and usually on toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // but parseXSettings() causes public code execution, so we need to transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // this to EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        EventQueue.invokeLater( new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                ((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private Map getUpdatedSettings(final long owner) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   127
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   128
            log.fine("owner =" + owner);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   129
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (0 == owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Map settings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        false, xSettingsPropertyAtom.getAtom() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   140
                int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   142
                if (status != XConstants.Success || getter.getData() == 0) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   143
                    if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   144
                        log.fine("OH OH : getter failed  status = " + status );
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   145
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    settings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                long ptr = getter.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   151
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   152
                    log.fine("noItems = " + getter.getNumberOfItems());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   153
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                byte array[] = Native.toBytes(ptr,getter.getNumberOfItems());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                if (array != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    settings = update(array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return settings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}