|
| 1 | +package com.kdroid.composetray.lib.linux |
| 2 | + |
| 3 | +import com.kdroid.composetray.utils.NativeLibraryLoader |
| 4 | + |
| 5 | +/** |
| 6 | + * JNI bridge to the native Linux tray library (libLinuxTray.so). |
| 7 | + * Replaces the previous JNA/Go-based approach with a pure C + sd-bus implementation. |
| 8 | + * Follows the same patterns as MacNativeBridge. |
| 9 | + */ |
| 10 | +internal object LinuxNativeBridge { |
| 11 | + |
| 12 | + init { |
| 13 | + NativeLibraryLoader.load("LinuxTray", LinuxNativeBridge::class.java) |
| 14 | + } |
| 15 | + |
| 16 | + // -- Lifecycle --------------------------------------------------------------- |
| 17 | + |
| 18 | + /** Create a tray instance. Returns a native handle (pointer as long). */ |
| 19 | + @JvmStatic external fun nativeCreate(iconBytes: ByteArray?, tooltip: String?): Long |
| 20 | + |
| 21 | + /** Start the D-Bus event loop (blocks until nativeQuit is called). */ |
| 22 | + @JvmStatic external fun nativeRun(handle: Long): Int |
| 23 | + |
| 24 | + /** Signal the event loop to stop. Thread-safe. */ |
| 25 | + @JvmStatic external fun nativeQuit(handle: Long) |
| 26 | + |
| 27 | + /** Destroy the tray and release all resources. Call after nativeRun returns. */ |
| 28 | + @JvmStatic external fun nativeDestroy(handle: Long) |
| 29 | + |
| 30 | + // -- Tray properties --------------------------------------------------------- |
| 31 | + |
| 32 | + @JvmStatic external fun nativeSetIcon(handle: Long, iconBytes: ByteArray) |
| 33 | + @JvmStatic external fun nativeSetTitle(handle: Long, title: String?) |
| 34 | + @JvmStatic external fun nativeSetTooltip(handle: Long, tooltip: String?) |
| 35 | + |
| 36 | + // -- Callbacks --------------------------------------------------------------- |
| 37 | + |
| 38 | + @JvmStatic external fun nativeSetClickCallback(handle: Long, callback: Runnable?) |
| 39 | + @JvmStatic external fun nativeSetRClickCallback(handle: Long, callback: Runnable?) |
| 40 | + |
| 41 | + /** Register a per-menu-item callback. The callback is keyed by menuId. */ |
| 42 | + @JvmStatic external fun nativeSetMenuItemCallback(handle: Long, menuId: Int, callback: Runnable?) |
| 43 | + |
| 44 | + // -- Click position ---------------------------------------------------------- |
| 45 | + |
| 46 | + /** Writes [x, y] into outXY. */ |
| 47 | + @JvmStatic external fun nativeGetLastClickXY(handle: Long, outXY: IntArray) |
| 48 | + |
| 49 | + // -- Menu management --------------------------------------------------------- |
| 50 | + |
| 51 | + @JvmStatic external fun nativeResetMenu(handle: Long) |
| 52 | + @JvmStatic external fun nativeAddMenuItem(handle: Long, title: String?, tooltip: String?): Int |
| 53 | + @JvmStatic external fun nativeAddMenuItemCheckbox(handle: Long, title: String?, tooltip: String?, checked: Boolean): Int |
| 54 | + @JvmStatic external fun nativeAddSeparator(handle: Long) |
| 55 | + @JvmStatic external fun nativeAddSubMenuItem(handle: Long, parentId: Int, title: String?, tooltip: String?): Int |
| 56 | + @JvmStatic external fun nativeAddSubMenuItemCheckbox(handle: Long, parentId: Int, title: String?, tooltip: String?, checked: Boolean): Int |
| 57 | + @JvmStatic external fun nativeAddSubSeparator(handle: Long, parentId: Int) |
| 58 | + |
| 59 | + // -- Per-item operations ----------------------------------------------------- |
| 60 | + |
| 61 | + @JvmStatic external fun nativeItemSetTitle(handle: Long, id: Int, title: String?): Int |
| 62 | + @JvmStatic external fun nativeItemEnable(handle: Long, id: Int) |
| 63 | + @JvmStatic external fun nativeItemDisable(handle: Long, id: Int) |
| 64 | + @JvmStatic external fun nativeItemShow(handle: Long, id: Int) |
| 65 | + @JvmStatic external fun nativeItemHide(handle: Long, id: Int) |
| 66 | + @JvmStatic external fun nativeItemCheck(handle: Long, id: Int) |
| 67 | + @JvmStatic external fun nativeItemUncheck(handle: Long, id: Int) |
| 68 | + @JvmStatic external fun nativeItemSetIcon(handle: Long, id: Int, iconBytes: ByteArray) |
| 69 | +} |
0 commit comments