jdk/src/java.desktop/unix/native/libawt_xawt/xawt/awt_Taskbar.c
author azvegint
Thu, 24 Mar 2016 02:22:01 +0300
changeset 36903 addc2e9d4bd4
child 37711 972001566d66
permissions -rw-r--r--
8143227: Platform-Specific Desktop Features Reviewed-by: prr, serb
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
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
    63
static gboolean unity_load() {
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);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   100
    (*env)->CallStaticVoidMethod(env, jTaskbarCls, jTaskbarCallback, data,
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   101
            fp_dbusmenu_menuitem_property_get_int(mi, "toggle-state")
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   102
            ? JNI_FALSE
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   103
            : JNI_TRUE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   104
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   105
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   106
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   107
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   108
 * Method:    init
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   109
 * Signature: (Ljava/lang/String;)Z
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   110
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   111
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XTaskbarPeer_init
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   112
(JNIEnv *env, jclass cls, jstring jname) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   113
    jclass clazz;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   114
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   115
    jTaskbarCls = (*env)->NewGlobalRef(env, cls);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   116
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   117
    CHECK_NULL_RETURN(jTaskbarCallback =
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   118
            (*env)->GetStaticMethodID(env, cls, "menuItemCallback", "(Ljava/awt/MenuItem;)V"), JNI_FALSE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   119
    CHECK_NULL_RETURN(
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   120
            clazz = (*env)->FindClass(env, "java/awt/MenuItem"), JNI_FALSE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   121
    CHECK_NULL_RETURN(
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   122
            jMenuItemGetLabel = (*env)->GetMethodID(env, clazz, "getLabel", "()Ljava/lang/String;"), JNI_FALSE);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   123
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   124
    if (gtk2_load(env) && unity_load()) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   125
        const gchar* name = (*env)->GetStringUTFChars(env, jname, NULL);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   126
        if (name) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   127
            entry = fp_unity_launcher_entry_get_for_desktop_file(name);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   128
            (*env)->ReleaseStringUTFChars(env, jname, name);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   129
            return JNI_TRUE;
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
    return JNI_FALSE;
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
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   137
 * Method:    runloop
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   138
 * Signature: ()V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   139
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   140
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_runloop
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   141
(JNIEnv *env, jclass cls) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   142
    fp_gdk_threads_enter();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   143
    fp_gtk_main();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   144
    fp_gdk_threads_leave();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   145
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   146
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   147
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   148
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   149
 * Method:    setBadge
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   150
 * Signature: (JZ)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   151
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   152
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setBadge
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   153
(JNIEnv *env, jobject obj, jlong value, jboolean visible) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   154
    fp_gdk_threads_enter();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   155
    fp_unity_launcher_entry_set_count(entry, value);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   156
    fp_unity_launcher_entry_set_count_visible(entry, visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   157
    DbusmenuMenuitem* m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   158
    if (m = fp_unity_launcher_entry_get_quicklist(entry)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   159
        fp_unity_launcher_entry_set_quicklist(entry, m);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   160
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   161
    fp_gdk_threads_leave();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   162
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   163
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   164
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   165
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   166
 * Method:    setUrgent
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   167
 * Signature: (Z)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   168
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   169
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setUrgent
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   170
(JNIEnv *env, jobject obj, jboolean urgent) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   171
    fp_gdk_threads_enter();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   172
    fp_unity_launcher_entry_set_urgent(entry, urgent);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   173
    DbusmenuMenuitem* m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   174
    if (m = fp_unity_launcher_entry_get_quicklist(entry)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   175
        fp_unity_launcher_entry_set_quicklist(entry, m);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   176
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   177
    fp_gdk_threads_leave();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   178
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   179
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   180
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   181
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   182
 * Method:    updateProgress
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   183
 * Signature: (DZ)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   184
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   185
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_updateProgress
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   186
(JNIEnv *env, jobject obj, jdouble value, jboolean visible) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   187
    fp_gdk_threads_enter();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   188
    fp_unity_launcher_entry_set_progress(entry, value);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   189
    fp_unity_launcher_entry_set_progress_visible(entry, visible);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   190
    DbusmenuMenuitem* m;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   191
    if (m = fp_unity_launcher_entry_get_quicklist(entry)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   192
        fp_unity_launcher_entry_set_quicklist(entry, m);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   193
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   194
    fp_gdk_threads_leave();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   195
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   196
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   197
void deleteGlobalRef(gpointer data) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   198
    JNIEnv* env = (JNIEnv*) JNU_GetEnv(jvm, JNI_VERSION_1_2);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   199
    (*env)->DeleteGlobalRef(env, data);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   200
}
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   201
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   202
void fill_menu(JNIEnv *env, jobjectArray items) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   203
    int index;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   204
    jsize length = (*env)->GetArrayLength(env, items);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   205
    for (index = 0; index < length; index++) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   206
        jobject elem = (*env)->GetObjectArrayElement(env, items, index);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   207
        if ((*env)->ExceptionCheck(env)) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   208
            break;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   209
        }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   210
        elem = (*env)->NewGlobalRef(env, elem);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   211
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   212
        globalRefs = fp_g_list_append(globalRefs, elem);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   213
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   214
        jstring jlabel = (jstring) (*env)->CallObjectMethod(env, elem, jMenuItemGetLabel);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   215
        if (!(*env)->ExceptionCheck(env) && jlabel) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   216
            const gchar* label = (*env)->GetStringUTFChars(env, jlabel, NULL);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   217
            if (label) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   218
                DbusmenuMenuitem* mi = fp_dbusmenu_menuitem_new();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   219
                if (!strcmp(label, "-")) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   220
                    fp_dbusmenu_menuitem_property_set(mi, "type", "separator");
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   221
                } else {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   222
                    fp_dbusmenu_menuitem_property_set(mi, "label", label);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   223
                }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   224
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   225
                (*env)->ReleaseStringUTFChars(env, jlabel, label);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   226
                fp_dbusmenu_menuitem_child_append(menu, mi);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   227
                fp_g_signal_connect(mi, "item_activated", G_CALLBACK(callback), elem);
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
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   233
/*
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   234
 * Class:     sun_awt_X11_XTaskbarPeer
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   235
 * Method:    setNativeMenu
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   236
 * Signature: ([Ljava/awt/MenuItem;)V
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   237
 */
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   238
JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setNativeMenu
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   239
(JNIEnv *env, jobject obj, jobjectArray items) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   240
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   241
    fp_gdk_threads_enter();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   242
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   243
    if (!menu) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   244
        menu = fp_dbusmenu_menuitem_new();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   245
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   246
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   247
    fp_unity_launcher_entry_set_quicklist(entry, menu);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   248
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   249
    GList* list = fp_dbusmenu_menuitem_take_children(menu);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   250
    fp_g_list_free_full(list, fp_g_object_unref);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   251
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   252
    fp_g_list_free_full(globalRefs, deleteGlobalRef);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   253
    globalRefs = NULL;
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   254
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   255
    if (items) {
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   256
        fill_menu(env, items);
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   257
    }
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   258
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   259
    fp_gdk_threads_leave();
addc2e9d4bd4 8143227: Platform-Specific Desktop Features
azvegint
parents:
diff changeset
   260
}