All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.purejava.appindicator.GObject Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
package org.purejava.appindicator;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;

import static org.purejava.appindicator.app_indicator_h.g_signal_connect_object;

public final class GObject {

    /**
     * This is similar to g_signal_connect_data(), but uses a closure which ensures that the gobject stays alive during the call to c_handler by temporarily adding a reference count to gobject.
     * When the gobject is destroyed the signal handler will be automatically disconnected. Note that this is not currently threadsafe (ie: emitting a signal while gobject is being destroyed in another thread is not safe).
     * @param instance       The instance to connect to.
     * @param detailedSignal A string of the form “signal-name::detail”.
     * @param cHandler       The GCallback to connect.
     * @param gobject        The object to pass as data to c_handler. The argument can be NULL.
     * @param connectFlags   A combination of GConnectFlags.
     * @return The handler id.
     */
    public static long signalConnectObject(MemorySegment instance, String detailedSignal, MemorySegment cHandler, MemorySegment gobject, int connectFlags) {
        if (null != instance
            && null!= detailedSignal
            && null != cHandler) {
            try (var arena = Arena.ofConfined()) {
                return g_signal_connect_object(instance, arena.allocateFrom(detailedSignal), cHandler, gobject, connectFlags);
            }
        } else {
            return -1;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy