PB v6.1X Raspberry PI ChangeSysTrayIcon

Post bugreports for the Linux version here
User avatar
mk-soft
Always Here
Always Here
Posts: 6242
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

PB v6.1X Raspberry PI ChangeSysTrayIcon

Post by mk-soft »

Raspberry PI lxpanel only:

If you change the systray icon, it is not always displayed. Only after repeated selection.

But if I change to the copy of the icon, it is also displayed immediately.

Maybe a sequence problem (because I don't know this internally from PB)
1. New icon not yet written to /tmp
2. Or previous icon deleted too early.

Info: Since the background is not deleted, I switch the systray once to passive and then to active

Testcode

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

If Not InitAppIndicatorLibrary()
  MessageRequester("Stop", "Error open library 'libappindicator3.so'", #PB_MessageRequester_Error)
  End
EndIf

;-TOP

Procedure SysTrayID(SysTray)
  Protected *SysTray.Integer
  *SysTray = IsSysTrayIcon(SysTray)
  If *SysTray
    ProcedureReturn *SysTray\i
  EndIf
EndProcedure

UsePNGImageDecoder()

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  Protected theme_icon_path.s, icon1, icon2
  Protected tmp_icon_path.s, icon_file.s, id
  
  theme_icon_path = #PB_Compiler_Home + "examples/sources/Data/ToolBar/"
  icon1 = LoadImage(0, theme_icon_path + "Properties.png")
  icon2 = LoadImage(1, theme_icon_path + "Delete.png")
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 300, 200, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    CreatePopupMenu(1)
    MenuItem(1, "Active")
    MenuItem(2, "Attention")
    MenuBar()
    MenuItem(99, "Exit")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Systray
    AddSysTrayIcon(1, WindowID(0), icon1)
    SysTrayIconToolTip(1, "ABC")
    SysTrayIconMenu(1, MenuID(1))
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ;- Test: copy icons
    id = SysTrayID(1)
    ChangeSysTrayIcon(1, icon2)
    tmp_icon_path = PeekS(app_indicator_get_icon_theme_path(id), -1, #PB_UTF8) + #PS$
    icon_file = tmp_icon_path + PeekS(app_indicator_get_icon(id), -1, #PB_UTF8) + ".png"
    CopyFile(icon_file, tmp_icon_path + "myicon2.png")
    ChangeSysTrayIcon(1, icon1)
    tmp_icon_path = PeekS(app_indicator_get_icon_theme_path(id), -1, #PB_UTF8) + #PS$
    icon_file = tmp_icon_path + PeekS(app_indicator_get_icon(id), -1, #PB_UTF8) + ".png"
    CopyFile(icon_file, tmp_icon_path +"myicon1.png")
    
    app_indicator_set_icon_full(id, "myicon1", #Null$)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 1
              app_indicator_set_status(SysTrayID(1), #APP_INDICATOR_STATUS_PASSIVE)
              ; test
              ;ChangeSysTrayIcon(1, icon1)
              app_indicator_set_icon_full(id, "myicon1", #Null$)
              ;
              app_indicator_set_status(SysTrayID(1), #APP_INDICATOR_STATUS_ACTIVE)
              
            Case 2
              app_indicator_set_status(SysTrayID(1), #APP_INDICATOR_STATUS_PASSIVE)
              ; test
              ;ChangeSysTrayIcon(1, icon2)
              app_indicator_set_icon_full(id, "myicon2", #Null$)
              ;
              app_indicator_set_status(SysTrayID(1), #APP_INDICATOR_STATUS_ACTIVE)
              
            Case 99
              Break
          EndSelect 
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
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: 6242
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB v6.1X Raspberry PI ChangeSysTrayIcon

Post by mk-soft »

Not work with PB v6.12 LTS :cry:
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