Page 1 of 1

Linux Notifications (e.g. like Windows tray balloons)

Posted: Fri Apr 24, 2015 7:11 am
by Opcode
I am wondering if there's an easy way (that doesn't require a ton of code) to display notifications on Linux. A prime example would be Ubuntu has "toast-like" notifications that are usually found on Windows 8 applications. Is there an easy (simple) way of triggering notifications that will work across distributions? It doesn't need to work across all of them although Ubuntu and its derivatives and maybe distributions like Arch. I'm using the following code for throwing balloon notifications on Windows and am curious if the same can be done on Linux with a similar amount of code.

Modified for example.

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  
  Structure NOTIFYICONDATA_v6
    cbSize.l
    hWnd.l
    uID.l
    uFlags.l
    uCallbackMessage.l
    hIcon.l
    szTip.s{128}
    dwState.l
    dwStateMask.l
    szInfo.s{256}
    StructureUnion
      uTimeout.l
      uVersion.l
    EndStructureUnion
    szInfoTitle.s{64}
    dwInfoFlags.l
    guidItem.GUID
    hBalloonIcon.l
  EndStructure
  
  Procedure.i WindowShowBalloonTip(Window.i, TrayIcon.i, Title.s, Message.s, Timeout.l = 3000)
    
    Protected Result.i = #False, Balloon.NOTIFYICONDATA_v6
    
    If OSVersion() >= #PB_OS_Windows_2000
      If IsSysTrayIcon(TrayIcon)
        Balloon\hWnd        = WindowID(Window)
        Balloon\uID         = TrayIcon
        Balloon\uFlags      = #NIF_INFO
        Balloon\dwState     = #NIS_SHAREDICON
        Balloon\szInfoTitle = Title
        Balloon\szInfo      = Message
        Balloon\uTimeout    = Timeout
        Balloon\dwInfoFlags = #NIIF_NOSOUND | #NIIF_INFO
        Balloon\cbSize      = SizeOf(NOTIFYICONDATA_v6)
        Result = Shell_NotifyIcon_(#NIM_MODIFY, Balloon)
      EndIf
    EndIf
    
    ProcedureReturn Result
    
  EndProcedure
  
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
  
  ; Linux variant
  
CompilerEndIf

Re: Linux Notifications (e.g. like Windows tray balloons)

Posted: Fri Apr 24, 2015 8:52 am
by ts-soft

Re: Linux Notifications (e.g. like Windows tray balloons)

Posted: Sat Apr 25, 2015 11:12 am
by Oma
Hi,

for Linux you could try this short one:
(needs libnotify-bin)

Code: Select all

;Options:
;--urgency=low, --urgency=normal, --urgency=critical
;--expire-time=ms
;--icon=StockIcon-Name OR IconFilename
;  with --urgency=critical  you have to click for hiding (on most systems)

Global nSummary.s= "My Application"
Global nBody.s   = "A Desktop-Notification with 'notify-send'" + "\n" + "and a 2. line"
Global nIcon.s   = "--icon=dialog-information --urgency=normal --expire-time=5000"

If Not RunProgram("notify-send", #DQUOTE$ + nSummary  + #DQUOTE$ + " " + #DQUOTE$ + nBody + #DQUOTE$ + nIcon, "")
	Debug "'notify-send' not available!"
	Debug "install: sudo apt-get install libnotify-bin"
EndIf
Cheers, Charly