Linux AppIndicator (Systray replacement)

Linux specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5216
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Linux AppIndicator (Systray replacement)

Post by mk-soft »

Testet with Mint Linux LMDE 6 and Raspberry Bullseye (Linux 11)

Not work on Raspberry Bookworm (Linux 12) !?

Update v1.01.1
- Complete import library functions
- New example

Code: Select all

;-TOP

; Comment   : Linux AppIndicator
; Author    : mk-soft
; Version   : v1.01.1
; Create    : 18.12.2023
; 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

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

CompilerIf #PB_Compiler_IsMainFile
  
  If Not InitAppIndicatorLibrary()
    MessageRequester("Stop", "Error open library 'libappindicator3.so'", #PB_MessageRequester_Error)
    End
  EndIf
  
  ; ----
  
  Procedure NewAppIndicator(MenuID)
    Protected appindicator, theme_icon_path.s
    
    appindicator = app_indicator_new("pb-example-simple-client", "indicator-messages", #APP_INDICATOR_CATEGORY_APPLICATION_STATUS)
    theme_icon_path = #PB_Compiler_Home + "examples/sources/Data/ToolBar"
    
    ; Small delay for first start. Sometime not visible
    Delay(10)
    
    If appindicator
      app_indicator_set_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE);
      app_indicator_set_menu(appindicator, MenuID)
      app_indicator_set_title(appindicator, "Example Inidcator")
      app_indicator_set_icon_theme_path(appindicator, theme_icon_path)
      app_indicator_set_icon_full(appindicator, "Properties", "")
      app_indicator_set_attention_icon_full(appindicator, "Delete", "")
    EndIf
    ProcedureReturn appindicator
  EndProcedure
  
  ; ----
  
  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
    
    If OpenWindow(0, #PB_Ignore, #PB_Ignore, 300, 200, "Example AppIndicator", #PB_Window_SystemMenu)
      
      CreatePopupMenu(1)
      MenuItem(1, "Passiv")
      MenuItem(2, "Active")
      MenuItem(3, "Attention")
      MenuBar()
      MenuItem(99, "Exit")
      
      appindicator = NewAppIndicator(MenuID(1))
      
      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_status(appindicator, #APP_INDICATOR_STATUS_ACTIVE)
              Case 3
                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
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf
Last edited by mk-soft on Mon Dec 18, 2023 5:46 pm, edited 3 times in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 16451
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: AppIndicator (Systray) not work on Raspberry

Post by Fred »

That's insteresting, I started already rewritting the SysTray lib for Linux using AppIndicator and now you say it doesn't work on Raspberry ? :shock:
User avatar
mk-soft
Always Here
Always Here
Posts: 5216
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: AppIndicator (Systray) not work on Raspberry

Post by mk-soft »

I have tested my code again with Linux 11 Arm64 (bullseye).
It works with warnings

Arm64 (bullseye)
[22:58:42] Warte auf den Start des Executable...
[22:58:42] Executable-Typ: Linux - arm64 (64bit, Unicode)
[22:58:42] Executable gestartet.
[22:58:43] [WARNING] AppIndicator.pb (Zeile: 96)
[22:58:43] [WARNING] Gdk (CRITICAL): gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed
x86/x64 Mint Linux (bullseye)
[00:29:19] Warte auf den Start des Executable...
[00:29:19] Executable-Typ: Linux - x86 (32bit, Unicode)
[00:29:19] Executable gestartet.
[00:29:27] [WARNING] Zeile: 95
[00:29:27] [WARNING] GLib-GObject (CRITICAL): g_object_get_data: assertion 'G_IS_OBJECT (object)' failed
[00:29:27] Die Programmausführung ist abgeschlossen.
I will reinstall Linux 12 Arm64 (bookworm) this weekend.
Arm32 won't work for now, because with the last update Linux 11 and Linux 12 unfortunately BindEvent and BindGadgetEvent don't work anymore.

Small Tip for RaspBerry OS:
SSD: EMTEC Portable SSD X210 (128gb)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5216
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Linux AppIndicator (Systray replacement)

Post by mk-soft »

Update v1.01.1
- Complete import library functions
- New example
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5216
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Linux AppIndicator (Systray replacement)

Post by mk-soft »

Report:

The icons are displayed under Raspberry Bullseye, but are not displayed correctly when the icon is changed.
The icons are not displayed under Raspberry Bookwork, although the icon menu is accessible.

Under Intel Linux 12 (Mint Linux LMDE 6) the AppIndicator works.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply