Not work on Raspberry Bookworm (Linux 12) Wayland !?
Works with Raspberry Bookworm (Linux 12) X11
Update v1.01.1
- Complete import library functions
- New example
Update v1.01.2
- Example change active icon
Update v1.01.4
- Fix menu event
- Update example
Update v1.01.5
- Optimize NewAppIndicator
Update v1.01.6
- Added FreeAppIndicator
Code: Select all
;-TOP
; Comment : Linux AppIndicator
; Author : mk-soft
; Version : v1.01.6
; Create : 18.12.2023
; Update : 23.06.2024
; Package : sudo apt-get install libappindicator3-1 (If not installed)
; Devel : sudo apt-get install libappindicator3-dev
; Doc : sudo apt-get install libayatana-appindicator-doc
; Link : https://www.purebasic.fr/english/viewtopic.php?t=82948
Enumeration
#APP_INDICATOR_CATEGORY_APPLICATION_STATUS
#APP_INDICATOR_CATEGORY_COMMUNICATIONS
#APP_INDICATOR_CATEGORY_SYSTEM_SERVICES
#APP_INDICATOR_CATEGORY_HARDWARE
#APP_INDICATOR_CATEGORY_OTHER
EndEnumeration
Enumeration
#APP_INDICATOR_STATUS_PASSIVE
#APP_INDICATOR_STATUS_ACTIVE
#APP_INDICATOR_STATUS_ATTENTION
EndEnumeration
#APP_INDICATOR_SIGNAL_NEW_ICON = "new-icon"
#APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON = "new-attention-icon"
#APP_INDICATOR_SIGNAL_NEW_STATUS = "new-status"
#APP_INDICATOR_SIGNAL_NEW_LABEL = "new-label"
#APP_INDICATOR_SIGNAL_CONNECTION_CHANGED = "connection-changed"
#APP_INDICATOR_SIGNAL_NEW_ICON_THEME_PATH = "new-icon-theme-path"
#APP_INDICATOR_SIGNAL_SCROLL_EVENT = "scroll-event"
Macro _dq_
"
EndMacro
Macro LIBFUNC(_libFunction_, _library_=lib)
Global _libFunction_._libFunction_ = GetFunction(_library_, _dq_#_libFunction_#_dq_)
CompilerIf #PB_Compiler_Debugger
If _libfunction_ = 0
Debug "Error: Invalid Library Function '" + _dq_#_libFunction_#_dq_ + "'"
CallDebugger
EndIf
CompilerEndIf
EndMacro
PrototypeC app_indicator_get_type()
PrototypeC app_indicator_new(id.p-utf8, icon_name.p-utf8, category)
PrototypeC app_indicator_new_with_path(id.p-utf8, icon_name.p-utf8, category, icon_theme_path.p-utf8)
PrototypeC app_indicator_set_status(appindicator, status)
PrototypeC app_indicator_set_attention_icon_full(appindicator, icon_name.p-utf8, icon_desc.p-utf8);
PrototypeC app_indicator_set_icon_full(appindicator, icon_name.p-utf8, icon_desc.p-utf8) ;
PrototypeC app_indicator_set_icon_theme_path(appindicator, icon_theme_path.p-utf8)
PrototypeC app_indicator_set_menu(appindicator, *gtkmenu)
PrototypeC app_indicator_set_title(appindicator, title.p-utf8)
PrototypeC app_indicator_set_label(appindicator, label.p-utf8, guide.p-utf8)
PrototypeC app_indicator_set_ordering_index(appindicator, ordering_index)
PrototypeC app_indicator_set_secondary_activate_target(appindicator, *menuitem)
;
PrototypeC app_indicator_get_id(appindicator) ; const *gchar
PrototypeC app_indicator_get_category(appindicator)
PrototypeC app_indicator_get_status(appindicator)
PrototypeC app_indicator_get_icon(appindicator) ; const *gchar
PrototypeC app_indicator_get_icon_desc(appindicator) ; const *gchar
PrototypeC app_indicator_get_icon_theme_path(appindicator) ; const *gchar
PrototypeC app_indicator_get_attention_icon(appindicator) ; const *gchar
PrototypeC app_indicator_get_attention_icon_desc(appindicator) ; const *gchar
PrototypeC app_indicator_get_menu(appindicator) ; GtkMenu
PrototypeC app_indicator_get_title(appindicator) ; const *gchar
PrototypeC app_indicator_get_label(appindicator) ; const *gchar
PrototypeC app_indicator_get_label_guide(appindicator) ; const *gchar
PrototypeC app_indicator_get_ordering_index(appindicator)
PrototypeC app_indicator_get_secondary_activate_target(appindicator) ; *menuitem (gtkwidget)
PrototypeC app_indicator_build_menu_from_desktop(appindicator, desktop_file.p-utf8, desktop_profile.p-utf8)
Procedure InitAppIndicatorLibrary()
Protected lib
lib = OpenLibrary(#PB_Any, "libappindicator3.so")
If lib
LIBFUNC(app_indicator_get_type)
LIBFUNC(app_indicator_new)
LIBFUNC(app_indicator_new_with_path)
LIBFUNC(app_indicator_set_status)
LIBFUNC(app_indicator_set_icon_full);
LIBFUNC(app_indicator_set_attention_icon_full)
LIBFUNC(app_indicator_set_icon_theme_path)
LIBFUNC(app_indicator_set_menu)
LIBFUNC(app_indicator_set_title)
LIBFUNC(app_indicator_set_label)
LIBFUNC(app_indicator_set_ordering_index)
LIBFUNC(app_indicator_set_secondary_activate_target)
LIBFUNC(app_indicator_get_id)
LIBFUNC(app_indicator_get_category)
LIBFUNC(app_indicator_get_status)
LIBFUNC(app_indicator_get_icon)
LIBFUNC(app_indicator_get_icon_desc)
LIBFUNC(app_indicator_get_icon_theme_path)
LIBFUNC(app_indicator_get_attention_icon)
LIBFUNC(app_indicator_get_attention_icon_desc)
LIBFUNC(app_indicator_get_menu)
LIBFUNC(app_indicator_get_title)
LIBFUNC(app_indicator_get_label)
LIBFUNC(app_indicator_get_label_guide)
LIBFUNC(app_indicator_get_ordering_index)
LIBFUNC(app_indicator_get_secondary_activate_target)
LIBFUNC(app_indicator_build_menu_from_desktop)
Else
Debug "Error open library 'libappindicator3.so'"
EndIf
ProcedureReturn lib
EndProcedure
; ----
Structure udtMenuPB
*gtkmenu
*gtkwindow
data1.i
data2.i
EndStructure
Procedure NewAppIndicator(Menu, WindowID, IconThemePath.s, Icon.s, AttentionIcon.s = "")
Protected appindicator, *menu.udtMenuPB
appindicator = app_indicator_new_with_path("pb-client-0x" + Hex(WindowID),
Icon,
#APP_INDICATOR_CATEGORY_APPLICATION_STATUS,
IconThemePath)
; Small delay for first start. Sometime not visible
Delay(10)
If appindicator
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE);
*menu = IsMenu(Menu)
If *menu
*menu\gtkwindow = WindowID
app_indicator_set_menu(appindicator, *menu\gtkmenu)
EndIf
If AttentionIcon
app_indicator_set_attention_icon_full(appindicator, AttentionIcon, #Null$)
EndIf
EndIf
ProcedureReturn appindicator
EndProcedure
Procedure FreeAppIndicator(AppIndicator)
g_object_unref_(AppIndicator)
EndProcedure
; ****
CompilerIf #PB_Compiler_IsMainFile
If Not InitAppIndicatorLibrary()
MessageRequester("Stop", "Error open library 'libappindicator3.so'", #PB_MessageRequester_Error)
End
EndIf
; ----
ProcedureC signal_appindicator_scroll_event(appindicator, steps, direction, user_data)
Select direction
Case #GDK_SCROLL_UP
Debug "Scroll Up: " + steps
Case #GDK_SCROLL_DOWN
Debug "Scroll Down: " + steps
EndSelect
EndProcedure
; ----
Procedure Main()
Protected appindicator, icon_path.s
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 300, 200, "Example AppIndicator", #PB_Window_SystemMenu)
CreatePopupMenu(1)
MenuItem(1, "Passiv")
MenuItem(2, "Active New")
MenuItem(3, "Active Copy")
MenuItem(4, "Active Paste")
MenuBar()
MenuItem(5, "Attention")
MenuBar()
MenuItem(99, "Exit")
icon_path = #PB_Compiler_Home + "examples/sources/Data/ToolBar/"
appindicator = NewAppIndicator(1, WindowID(0), icon_path, "New", "Delete")
app_indicator_set_title(appindicator, "Example Title")
app_indicator_set_label(appindicator, "Example Label", "")
ButtonGadget(0, 10, 10, 120, 25, "Set Active")
g_signal_connect_(appindicator, #APP_INDICATOR_SIGNAL_SCROLL_EVENT, @signal_appindicator_scroll_event(), 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
Case 1
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_PASSIVE)
Case 2
app_indicator_set_icon_full(appindicator, "New", #Null$)
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE)
Case 3
app_indicator_set_icon_full(appindicator, "Copy", #Null$)
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE)
Case 4
app_indicator_set_icon_full(appindicator, "Paste", #Null$)
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE)
Case 5
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ATTENTION)
Case 99
Break
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE)
EndSelect
EndSelect
ForEver
FreeAppIndicator(appindicator)
EndIf
EndProcedure : Main()
CompilerEndIf