src/java.desktop/unix/classes/sun/awt/X11/XMSelection.java
author itakiguchi
Tue, 30 Oct 2018 15:51:10 -0700
changeset 52528 edc729e2ee36
parent 52248 2e330da7cbf4
child 52987 468829d1983e
permissions -rw-r--r--
8211810: X11 Time stamp data should be unsigned Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, 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
   * 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
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    35
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class  XMSelection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * A method for a subsytem to express its interest in a certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * manager selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * If owner changes, the ownerChanged of the XMSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * will be called with the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * number and the new owning window when onwership is established, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * None if the owner is gone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Events in extra_mask are selected for on owning windows (exsiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * ones and on new owners when established) and otherEvent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * XMWSelectionListener will be called with the screen number and an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The function returns an array of current owners.  The size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * array is ScreenCount(awt_display).  The array is "owned" by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * module and should be considered by the caller as read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    58
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMSelection");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* Name of the selection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    String selectionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* list of listeners to be called for events */
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
    63
    Vector<XMSelectionListener> listeners;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /* X atom array (one per screen) for this selection */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
    66
    XAtom[] atoms;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /* Window ids of selection owners */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
    69
    long[] owners;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /* event mask to set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    long eventMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static int numScreens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static XAtom XA_MANAGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
    78
    static HashMap<Long, XMSelection> selectionMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        long display = XToolkit.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            numScreens = XlibWrapper.ScreenCount(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        XA_MANAGER = XAtom.get("MANAGER");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int screen = 0; screen < numScreens ; screen ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            initScreen(display,screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
    93
        selectionMap = new HashMap<>();
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
    static void initScreen(long display, final int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            long root = XlibWrapper.RootWindow(display,screen);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   100
            XlibWrapper.XSelectInput(display, root, XConstants.StructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            XToolkit.addEventDispatcher(root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                processRootEvent(ev, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public int getNumberOfScreens() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return numScreens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    void select(long extra_mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        eventMask = extra_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        for (int screen = 0; screen < numScreens ; screen ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            selectPerScreen(screen,extra_mask);
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
    void resetOwner(long owner, final int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            long display = XToolkit.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                setOwner(owner, screen);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   131
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   132
                    log.fine("New Selection Owner for screen " + screen + " = " + owner );
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   133
                }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   134
                XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | eventMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                XToolkit.addEventDispatcher(owner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                            public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                dispatchSelectionEvent(ev, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    void selectPerScreen(final int screen, long extra_mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                long display = XToolkit.getDisplay();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   153
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   154
                    log.fine("Grabbing XServer");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   155
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                XlibWrapper.XGrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    String selection_name = getName()+"_S"+screen;
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   160
                    if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   161
                        log.fine("Screen = " + screen + " selection name = " + selection_name);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   162
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    XAtom atom = XAtom.get(selection_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    selectionMap.put(Long.valueOf(atom.getAtom()),this); // add mapping from atom to the instance of XMSelection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    setAtom(atom,screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    long owner = XlibWrapper.XGetSelectionOwner(display, atom.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    if (owner != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        setOwner(owner, screen);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   169
                        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   170
                            log.fine("Selection Owner for screen " + screen + " = " + owner );
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   171
                        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   172
                        XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | extra_mask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        XToolkit.addEventDispatcher(owner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                        public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                            dispatchSelectionEvent(ev, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            finally {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   186
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   187
                    log.fine("UnGrabbing XServer");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   188
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                XlibWrapper.XUngrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    static boolean processClientMessage(XEvent xev, int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        XClientMessageEvent xce = xev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (xce.get_message_type() == XA_MANAGER.getAtom()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   200
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   201
                log.fine("client messags = " + xce);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   202
            }
52528
edc729e2ee36 8211810: X11 Time stamp data should be unsigned
itakiguchi
parents: 52248
diff changeset
   203
            long timestamp = xce.get_data(0) & 0xFFFFFFFFL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            long atom = xce.get_data(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            long owner = xce.get_data(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            long data = xce.get_data(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            XMSelection sel = getInstance(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (sel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                sel.resetOwner(owner,screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                sel.dispatchOwnerChangedEvent(xev,screen,owner,data, timestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    static  boolean processRootEvent(XEvent xev, int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        switch (xev.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   219
            case XConstants.ClientMessage: {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                return processClientMessage(xev, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    static XMSelection getInstance(long selection) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   230
        return selectionMap.get(Long.valueOf(selection));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Default constructor specifies PropertyChangeMask as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public XMSelection (String selname) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   239
        this(selname, XConstants.PropertyChangeMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
   /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    * Some users may not need to know about selection changes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    * just owner ship changes, They would specify a zero extra mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public XMSelection (String selname, long extraMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            selectionName = selname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            atoms = new XAtom[getNumberOfScreens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            owners = new long[getNumberOfScreens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        select(extraMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public synchronized void addSelectionListener(XMSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (listeners == null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   262
            listeners = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        listeners.add(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public synchronized void removeSelectionListener(XMSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (listeners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            listeners.remove(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   273
    synchronized Collection<XMSelectionListener> getListeners() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return listeners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    synchronized XAtom getAtom(int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (atoms != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return atoms[screen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    synchronized void setAtom(XAtom a, int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (atoms != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            atoms[screen] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    synchronized long getOwner(int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (owners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            return owners[screen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    synchronized void setOwner(long owner, int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (owners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            owners[screen] = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    synchronized String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return selectionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    synchronized void dispatchSelectionChanged( XPropertyEvent ev, int screen) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   309
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   310
            log.fine("Selection Changed : Screen = " + screen + "Event =" + ev);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   311
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (listeners != null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   313
            Iterator<XMSelectionListener> iter = listeners.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            while (iter.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   315
                XMSelectionListener disp = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                disp.selectionChanged(screen, this, ev.get_window(), ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    synchronized void dispatchOwnerDeath(XDestroyWindowEvent de, int screen) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   322
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   323
            log.fine("Owner dead : Screen = " + screen + "Event =" + de);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   324
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (listeners != null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   326
            Iterator<XMSelectionListener> iter = listeners.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            while (iter.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   328
                XMSelectionListener disp = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                disp.ownerDeath(screen, this, de.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    void dispatchSelectionEvent(XEvent xev, int screen) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   336
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   337
            log.fine("Event =" + xev);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   338
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   339
        if (xev.get_type() == XConstants.DestroyNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            XDestroyWindowEvent de = xev.get_xdestroywindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            dispatchOwnerDeath( de, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   343
        else if (xev.get_type() == XConstants.PropertyNotify)  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            XPropertyEvent xpe = xev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            dispatchSelectionChanged( xpe, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    synchronized void dispatchOwnerChangedEvent(XEvent ev, int screen, long owner, long data, long timestamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (listeners != null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   352
            Iterator<XMSelectionListener> iter = listeners.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            while (iter.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   354
                XMSelectionListener disp = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                disp.ownerChanged(screen,this, owner, data, timestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
}