diff --git a/comp/src/gb.dbus.trayicon/.project b/comp/src/gb.dbus.trayicon/.project index 826cbd69c..095aa2666 100644 --- a/comp/src/gb.dbus.trayicon/.project +++ b/comp/src/gb.dbus.trayicon/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 # Compiled with Gambas 3.8.90 Title=Tray icons using the new DBus protocol -Startup=FTest +Startup=Main Version=3.8.90 VersionFile=1 Component=gb.image diff --git a/comp/src/gb.dbus.trayicon/.src/Main.module b/comp/src/gb.dbus.trayicon/.src/Main.module index a268ff0fc..69de8d469 100644 --- a/comp/src/gb.dbus.trayicon/.src/Main.module +++ b/comp/src/gb.dbus.trayicon/.src/Main.module @@ -50,6 +50,7 @@ Public Sub Main() ' File.Save(Application.Path &/ "default.bin", String@(hImage.Data, hImage.W * hImage.H * SizeOf(gb.Integer))) DBus.Debug = True + DBus.Unique = True FTest.Show End diff --git a/comp/src/gb.dbus.trayicon/.startup b/comp/src/gb.dbus.trayicon/.startup index 6bfa16fc8..b1368ab02 100644 --- a/comp/src/gb.dbus.trayicon/.startup +++ b/comp/src/gb.dbus.trayicon/.startup @@ -1,4 +1,4 @@ -FTest +Main Tray icons using the new DBus protocol 0 0 diff --git a/gb.dbus/src/gb.dbus/.src/DBus.class b/gb.dbus/src/gb.dbus/.src/DBus.class index 8aa823f97..7ef01e225 100644 --- a/gb.dbus/src/gb.dbus/.src/DBus.class +++ b/gb.dbus/src/gb.dbus/.src/DBus.class @@ -7,9 +7,11 @@ Inherits _DBus Static Property Name As String Static Public _ApplicationCache As New Collection Static Property Read Null As Object +Static Property Unique As Boolean Static Private $sAppName As String Static Private $iRegisterCount As Integer +Static Private $bUnique As Boolean Static Public Sub _get((Application) As String) As DBusApplication @@ -71,7 +73,13 @@ Static Public Sub _RegisterApplication(hConnection As DBusConnection) As String If IsNull(hConnection.Tag) Then sName = Name_Read() - hConnection._RequestName(sName) + If hConnection._RequestName(sName, True) Then + If $bUnique Then + Error.Raise("Unique application is already registered") + Else + Error.Raise("Application is already registered") + Endif + Endif hConnection.Tag = sName Endif Inc $iRegisterCount @@ -91,8 +99,13 @@ End Static Private Function Name_Read() As String + Dim sName As String + If $sAppName Then Return $sAppName - Return "org.gambas." & _Normalize(Application.Name, True, "-_") + + sName = "org.gambas." & _Normalize(Application.Name, True, "-_") + If Not $bUnique Then sName &= "-" & CStr(Application.Handle) + Return sName End @@ -138,3 +151,15 @@ Static Public Sub _HasSystemTray() As Boolean Try Return DBus["org.kde.StatusNotifierWatcher"]["/StatusNotifierWatcher", "org.kde.StatusNotifierWatcher"].IsStatusNotifierHostRegistered End + +Static Private Function Unique_Read() As Boolean + + Return $bUnique + +End + +Static Private Sub Unique_Write(Value As Boolean) + + $bUnique = Value + +End diff --git a/gb.dbus/src/helper.c b/gb.dbus/src/helper.c index 0351ba3cd..b6774fabd 100644 --- a/gb.dbus/src/helper.c +++ b/gb.dbus/src/helper.c @@ -1265,7 +1265,7 @@ bool DBUS_register(DBusConnection *connection, const char *name, bool unique) dbus_error_init(&error); - //fprintf(stderr, "DBUS_register: %s\n", name); + //fprintf(stderr, "DBUS_register: %s / unique = %d\n", name, unique); ret = dbus_bus_request_name(connection, name, unique ? DBUS_NAME_FLAG_DO_NOT_QUEUE : 0, &error);