jdk/src/java.desktop/unix/classes/sun/awt/X11/XTaskbarPeer.java
author ssadetsky
Mon, 25 Apr 2016 15:37:31 +0300
changeset 37711 972001566d66
parent 37550 c8252b8fea3d
child 39854 28eb438b1368
permissions -rw-r--r--
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux Reviewed-by: prr, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     1
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     4
 *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    10
 *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    15
 * accompanied this code).
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    16
 *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    20
 *
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    23
 * questions.
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    24
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    25
package sun.awt.X11;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    26
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    27
import java.awt.MenuItem;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    28
import java.awt.PopupMenu;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    29
import java.awt.Taskbar.Feature;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    30
import java.awt.peer.TaskbarPeer;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    31
import java.awt.event.ActionEvent;
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
    32
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
    33
import sun.awt.UNIXToolkit;
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    34
import java.security.AccessController;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    35
import sun.security.action.GetPropertyAction;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    36
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    37
final class XTaskbarPeer implements TaskbarPeer {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    38
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    39
    private static boolean nativeLibraryLoaded = false;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    40
    private static boolean initExecuted = false;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    41
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    42
    private PopupMenu menu = null;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    43
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    44
    private static void initWithLock() {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    45
        XToolkit.awtLock();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    46
        try {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    47
            if (!initExecuted) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    48
                String dname = AccessController.doPrivileged(
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    49
                                new GetPropertyAction("java.desktop.appName", ""));
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
    50
                nativeLibraryLoaded = init(dname,
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
    51
                        UNIXToolkit.getEnabledGtkVersion().ordinal(),
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
    52
                        UNIXToolkit.isGtkVerbose());
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    53
                if (nativeLibraryLoaded) {
37550
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 36903
diff changeset
    54
                    Thread t = new Thread(null, () -> { runloop(); },
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 36903
diff changeset
    55
                                          "TaskBar", 0, false);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    56
                    t.setDaemon(true);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    57
                    t.start();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    58
                }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    59
            }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    60
        } finally {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    61
            initExecuted = true;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    62
            XToolkit.awtUnlock();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    63
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    64
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    65
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    66
    XTaskbarPeer() {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    67
        initWithLock();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    68
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    69
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    70
    static boolean isTaskbarSupported() {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    71
        initWithLock();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    72
        return nativeLibraryLoaded;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    73
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    74
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    75
    @Override
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    76
    public boolean isSupported(Feature feature) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    77
        switch (feature) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    78
            case ICON_BADGE_NUMBER:
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    79
            case MENU:
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    80
            case PROGRESS_VALUE:
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    81
            case USER_ATTENTION:
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    82
                return true;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    83
            default:
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    84
                return false;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    85
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    86
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    87
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    88
    @Override
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    89
    public void setProgressValue(int value) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    90
        boolean visible
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    91
                = value >= 0
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    92
                && value <= 100;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    93
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    94
        double v = visible
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    95
                ? (double) value / 100
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    96
                : 0d;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    97
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    98
        updateProgress(v, visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    99
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   100
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   101
    @Override
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   102
    public void setIconBadge(String badge) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   103
        boolean visible = false;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   104
        long val = 0;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   105
        if (badge != null) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   106
            try {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   107
                val = Long.parseLong(badge);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   108
                visible = true;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   109
            } catch (NumberFormatException e) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   110
            }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   111
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   112
        setBadge(val, visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   113
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   114
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   115
    @Override
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   116
    public PopupMenu getMenu() {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   117
        return menu;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   118
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   119
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   120
    @Override
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   121
    public synchronized void setMenu(PopupMenu m) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   122
        this.menu = m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   123
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   124
        if (menu != null && menu.getItemCount() > 0) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   125
            int msize = menu.getItemCount();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   126
            MenuItem[] items = new MenuItem[msize];
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   127
            for (int i = 0; i < msize; i++) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   128
                items[i] = menu.getItem(i);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   129
            }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   130
            setNativeMenu(items);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   131
        } else {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   132
            setNativeMenu(null);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   133
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   134
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   135
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   136
    @Override
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   137
    public void requestUserAttention(boolean enabled, boolean critical) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   138
        setUrgent(enabled);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   139
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   140
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   141
    private static void menuItemCallback(MenuItem mi) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   142
        if (mi != null) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   143
            ActionEvent ae = new ActionEvent(mi, ActionEvent.ACTION_PERFORMED,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   144
                    mi.getActionCommand());
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   145
            try {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   146
                XToolkit.awtLock();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   147
                XToolkit.postEvent(XToolkit.targetToAppContext(ae.getSource()), ae);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   148
            } finally {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   149
                XToolkit.awtUnlock();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   150
            }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   151
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   152
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   153
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
   154
    private static native boolean init(String name, int version,
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37550
diff changeset
   155
                                                               boolean verbose);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   156
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   157
    private static native void runloop();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   158
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   159
    private native void setBadge(long value, boolean visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   160
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   161
    private native void updateProgress(double value, boolean visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   162
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   163
    private native void setUrgent(boolean urgent);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   164
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   165
    private native void setNativeMenu(MenuItem[] items);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   166
}