src/java.desktop/unix/native/libawt_xawt/xawt/awt_Taskbar.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
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
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    26
#include <dlfcn.h>
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    27
#include "jvm_md.h"
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    28
#include <setjmp.h>
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    29
#include <string.h>
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    30
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    31
#include "jni_util.h"
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    32
#include "awt_Taskbar.h"
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    33
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    34
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    35
extern JavaVM *jvm;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    36
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    37
#define NO_SYMBOL_EXCEPTION 1
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    38
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    39
#define UNITY_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("unity", "9")
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    40
#define UNITY_LIB JNI_LIB_NAME("unity")
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    41
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    42
static jmp_buf j;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    43
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    44
static void *unity_libhandle = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    45
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    46
static DbusmenuMenuitem* menu = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    47
UnityLauncherEntry* entry = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    48
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    49
static jclass jTaskbarCls = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    50
static jmethodID jTaskbarCallback = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    51
static jmethodID jMenuItemGetLabel = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    52
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    53
GList* globalRefs = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    54
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    55
static void* dl_symbol(const char* name) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    56
    void* result = dlsym(unity_libhandle, name);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    57
    if (!result)
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    58
        longjmp(j, NO_SYMBOL_EXCEPTION);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    59
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    60
    return result;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    61
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    62
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    63
static gboolean unity_load(void) {
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    64
    unity_libhandle = dlopen(UNITY_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    65
    if (unity_libhandle == NULL) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    66
        unity_libhandle = dlopen(UNITY_LIB, RTLD_LAZY | RTLD_LOCAL);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    67
        if (unity_libhandle == NULL) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    68
            return FALSE;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    69
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    70
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    71
    if (setjmp(j) == 0) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    72
        fp_unity_launcher_entry_get_for_desktop_file = dl_symbol("unity_launcher_entry_get_for_desktop_file");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    73
        fp_unity_launcher_entry_set_count = dl_symbol("unity_launcher_entry_set_count");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    74
        fp_unity_launcher_entry_set_count_visible = dl_symbol("unity_launcher_entry_set_count_visible");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    75
        fp_unity_launcher_entry_set_urgent = dl_symbol("unity_launcher_entry_set_urgent");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    76
        fp_unity_launcher_entry_set_progress = dl_symbol("unity_launcher_entry_set_progress");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    77
        fp_unity_launcher_entry_set_progress_visible = dl_symbol("unity_launcher_entry_set_progress_visible");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    78
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    79
        fp_dbusmenu_menuitem_new = dl_symbol("dbusmenu_menuitem_new");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    80
        fp_dbusmenu_menuitem_property_set = dl_symbol("dbusmenu_menuitem_property_set");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    81
        fp_dbusmenu_menuitem_property_set_int = dl_symbol("dbusmenu_menuitem_property_set_int");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    82
        fp_dbusmenu_menuitem_property_get_int = dl_symbol("dbusmenu_menuitem_property_get_int");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    83
        fp_dbusmenu_menuitem_property_set = dl_symbol("dbusmenu_menuitem_property_set");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    84
        fp_dbusmenu_menuitem_child_append = dl_symbol("dbusmenu_menuitem_child_append");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    85
        fp_dbusmenu_menuitem_child_delete = dl_symbol("dbusmenu_menuitem_child_delete");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    86
        fp_dbusmenu_menuitem_take_children = dl_symbol("dbusmenu_menuitem_take_children");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    87
        fp_dbusmenu_menuitem_foreach = dl_symbol("dbusmenu_menuitem_foreach");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    88
        fp_unity_launcher_entry_set_quicklist = dl_symbol("unity_launcher_entry_set_quicklist");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    89
        fp_unity_launcher_entry_get_quicklist = dl_symbol("unity_launcher_entry_get_quicklist");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    90
    } else {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    91
        dlclose(unity_libhandle);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    92
        unity_libhandle = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    93
        return FALSE;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    94
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    95
    return TRUE;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    96
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    97
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    98
void callback(DbusmenuMenuitem* mi, guint ts, jobject data) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    99
    JNIEnv* env = (JNIEnv*) JNU_GetEnv(jvm, JNI_VERSION_1_2);
41797
901aa8f0c2ee 8153526: [Unity] Taskbar.getTaskbar().setMenu(null) doesn't remove menu
azvegint
parents: 37711
diff changeset
   100
    (*env)->CallStaticVoidMethod(env, jTaskbarCls, jTaskbarCallback, data);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   101
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   102
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   103
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   104
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   105
 * Method:    init
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   106
 * Signature: (Ljava/lang/String;)Z
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   107
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   108
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XTaskbarPeer_init
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   109
(JNIEnv *env, jclass cls, jstring jname, jint version, jboolean verbose) {
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   110
    jclass clazz;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   111
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   112
    jTaskbarCls = (*env)->NewGlobalRef(env, cls);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   113
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   114
    CHECK_NULL_RETURN(jTaskbarCallback =
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   115
            (*env)->GetStaticMethodID(env, cls, "menuItemCallback", "(Ljava/awt/MenuItem;)V"), JNI_FALSE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   116
    CHECK_NULL_RETURN(
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   117
            clazz = (*env)->FindClass(env, "java/awt/MenuItem"), JNI_FALSE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   118
    CHECK_NULL_RETURN(
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   119
            jMenuItemGetLabel = (*env)->GetMethodID(env, clazz, "getLabel", "()Ljava/lang/String;"), JNI_FALSE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   120
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   121
    if (gtk_load(env, version, verbose) && unity_load()) {
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   122
        const gchar* name = (*env)->GetStringUTFChars(env, jname, NULL);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   123
        if (name) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   124
            entry = fp_unity_launcher_entry_get_for_desktop_file(name);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   125
            (*env)->ReleaseStringUTFChars(env, jname, name);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   126
            return JNI_TRUE;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   127
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   128
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   129
    return JNI_FALSE;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   130
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   131
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   132
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   133
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   134
 * Method:    runloop
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   135
 * Signature: ()V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   136
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   137
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_runloop
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   138
(JNIEnv *env, jclass cls) {
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   139
    gtk->gdk_threads_enter();
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   140
    gtk->gtk_main();
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   141
    gtk->gdk_threads_leave();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   142
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   143
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   144
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   145
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   146
 * Method:    setBadge
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   147
 * Signature: (JZ)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   148
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   149
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setBadge
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   150
(JNIEnv *env, jobject obj, jlong value, jboolean visible) {
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   151
    gtk->gdk_threads_enter();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   152
    fp_unity_launcher_entry_set_count(entry, value);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   153
    fp_unity_launcher_entry_set_count_visible(entry, visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   154
    DbusmenuMenuitem* m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   155
    if (m = fp_unity_launcher_entry_get_quicklist(entry)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   156
        fp_unity_launcher_entry_set_quicklist(entry, m);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   157
    }
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   158
    gtk->gdk_threads_leave();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   159
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   160
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   161
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   162
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   163
 * Method:    setUrgent
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   164
 * Signature: (Z)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   165
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   166
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setUrgent
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   167
(JNIEnv *env, jobject obj, jboolean urgent) {
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   168
    gtk->gdk_threads_enter();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   169
    fp_unity_launcher_entry_set_urgent(entry, urgent);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   170
    DbusmenuMenuitem* m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   171
    if (m = fp_unity_launcher_entry_get_quicklist(entry)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   172
        fp_unity_launcher_entry_set_quicklist(entry, m);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   173
    }
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   174
    gtk->gdk_threads_leave();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   175
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   176
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   177
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   178
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   179
 * Method:    updateProgress
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   180
 * Signature: (DZ)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   181
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   182
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_updateProgress
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   183
(JNIEnv *env, jobject obj, jdouble value, jboolean visible) {
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   184
    gtk->gdk_threads_enter();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   185
    fp_unity_launcher_entry_set_progress(entry, value);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   186
    fp_unity_launcher_entry_set_progress_visible(entry, visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   187
    DbusmenuMenuitem* m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   188
    if (m = fp_unity_launcher_entry_get_quicklist(entry)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   189
        fp_unity_launcher_entry_set_quicklist(entry, m);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   190
    }
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   191
    gtk->gdk_threads_leave();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   192
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   193
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   194
void deleteGlobalRef(gpointer data) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   195
    JNIEnv* env = (JNIEnv*) JNU_GetEnv(jvm, JNI_VERSION_1_2);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   196
    (*env)->DeleteGlobalRef(env, data);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   197
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   198
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   199
void fill_menu(JNIEnv *env, jobjectArray items) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   200
    int index;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   201
    jsize length = (*env)->GetArrayLength(env, items);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   202
    for (index = 0; index < length; index++) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   203
        jobject elem = (*env)->GetObjectArrayElement(env, items, index);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   204
        if ((*env)->ExceptionCheck(env)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   205
            break;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   206
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   207
        elem = (*env)->NewGlobalRef(env, elem);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   208
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   209
        globalRefs = gtk->g_list_append(globalRefs, elem);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   210
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   211
        jstring jlabel = (jstring) (*env)->CallObjectMethod(env, elem, jMenuItemGetLabel);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   212
        if (!(*env)->ExceptionCheck(env) && jlabel) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   213
            const gchar* label = (*env)->GetStringUTFChars(env, jlabel, NULL);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   214
            if (label) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   215
                DbusmenuMenuitem* mi = fp_dbusmenu_menuitem_new();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   216
                if (!strcmp(label, "-")) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   217
                    fp_dbusmenu_menuitem_property_set(mi, "type", "separator");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   218
                } else {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   219
                    fp_dbusmenu_menuitem_property_set(mi, "label", label);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   220
                }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   221
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   222
                (*env)->ReleaseStringUTFChars(env, jlabel, label);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   223
                fp_dbusmenu_menuitem_child_append(menu, mi);
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   224
                gtk->g_signal_connect_data(mi, "item_activated",
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   225
                                           G_CALLBACK(callback), elem, NULL, 0);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   226
            }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   227
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   228
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   229
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   230
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   231
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   232
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   233
 * Method:    setNativeMenu
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   234
 * Signature: ([Ljava/awt/MenuItem;)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   235
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   236
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setNativeMenu
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   237
(JNIEnv *env, jobject obj, jobjectArray items) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   238
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   239
    gtk->gdk_threads_enter();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   240
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   241
    if (!menu) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   242
        menu = fp_dbusmenu_menuitem_new();
41797
901aa8f0c2ee 8153526: [Unity] Taskbar.getTaskbar().setMenu(null) doesn't remove menu
azvegint
parents: 37711
diff changeset
   243
        fp_unity_launcher_entry_set_quicklist(entry, menu);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   244
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   245
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   246
    GList* list = fp_dbusmenu_menuitem_take_children(menu);
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   247
    gtk->g_list_free_full(list, gtk->g_object_unref);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   248
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   249
    gtk->g_list_free_full(globalRefs, deleteGlobalRef);
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   250
    globalRefs = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   251
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   252
    if (items) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   253
        fill_menu(env, items);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   254
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   255
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 36903
diff changeset
   256
    gtk->gdk_threads_leave();
36903
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   257
}