SNI/DBus tray support (#15189)
Build (All) / Create test plan (push) Has been cancelled
Build (All) / level1 (push) Has been cancelled
Build (All) / level2 (push) Has been cancelled

This commit is contained in:
eafton
2026-04-10 14:11:38 -07:00
committed by GitHub
parent 4aa0a6e2bf
commit 8c024f4f3a
10 changed files with 2659 additions and 584 deletions
+87
View File
@@ -22,6 +22,82 @@
#include "./SDL_list.h"
// Append
bool SDL_ListAppend(SDL_ListNode **head, void *ent)
{
SDL_ListNode *cursor;
SDL_ListNode *node;
if (!head) {
return false;
}
node = (SDL_ListNode *)SDL_malloc(sizeof(*node));
if (!node) {
return false;
}
node->entry = ent;
node->next = NULL;
if (*head) {
cursor = *head;
while (cursor->next) {
cursor = cursor->next;
}
cursor->next = node;
} else {
*head = node;
}
return true;
}
bool SDL_ListInsertAtPosition(SDL_ListNode **head, int pos, void *ent)
{
SDL_ListNode *cursor;
SDL_ListNode *node;
int i;
if (pos == -1) {
return SDL_ListAppend(head, ent);
}
if (!pos) {
node = (SDL_ListNode *)SDL_malloc(sizeof(*node));
if (!node) {
return false;
}
node->entry = ent;
if (*head) {
node->next = *head;
} else {
node->next = NULL;
}
*head = node;
}
cursor = *head;
for (i = 1; i < pos - 1 && cursor; i++) {
cursor = cursor->next;
}
if (!cursor) {
return SDL_ListAppend(head, ent);
}
node = (SDL_ListNode *)SDL_malloc(sizeof(*node));
if (!node) {
return false;
}
node->entry = ent;
node->next = cursor->next;
cursor->next = node;
return true;
}
// Push
bool SDL_ListAdd(SDL_ListNode **head, void *ent)
{
@@ -84,3 +160,14 @@ void SDL_ListClear(SDL_ListNode **head)
SDL_free(tmp);
}
}
int SDL_ListCountEntries(SDL_ListNode **head)
{
SDL_ListNode *node;
int count = 0;
for (node = *head; node; node = node->next) {
++count;
}
return count;
}
+3
View File
@@ -28,9 +28,12 @@ typedef struct SDL_ListNode
struct SDL_ListNode *next;
} SDL_ListNode;
bool SDL_ListAppend(SDL_ListNode **head, void *ent);
bool SDL_ListInsertAtPosition(SDL_ListNode **head, int pos, void *ent);
bool SDL_ListAdd(SDL_ListNode **head, void *ent);
void SDL_ListPop(SDL_ListNode **head, void **ent);
void SDL_ListRemove(SDL_ListNode **head, void *ent);
void SDL_ListClear(SDL_ListNode **head);
int SDL_ListCountEntries(SDL_ListNode **head);
#endif // SDL_list_h_
+64
View File
@@ -0,0 +1,64 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_menu_h_
#define SDL_menu_h_
#include "./SDL_list.h"
typedef enum SDL_MenuItemType
{
SDL_MENU_ITEM_TYPE_NORMAL,
SDL_MENU_ITEM_TYPE_SEPERATOR,
SDL_MENU_ITEM_TYPE_CHECKBOX
} SDL_MenuItemType;
typedef enum SDL_MenuItemFlags
{
SDL_MENU_ITEM_FLAGS_NONE = 0,
SDL_MENU_ITEM_FLAGS_DISABLED = 1 << 0,
SDL_MENU_ITEM_FLAGS_CHECKED = 1 << 1,
SDL_MENU_ITEM_FLAGS_BAR_ITEM = 1 << 2
} SDL_MenuItemFlags;
/* Do not create this struct directly, users of this structure like the DBUSMENU layer use extended versions of it which need to be allocated by specfic functions. */
/* This struct is meant to be in an SDL_List just like sub_menu */
typedef struct SDL_MenuItem
{
/* Basic properties */
const char *utf8;
SDL_MenuItemType type;
SDL_MenuItemFlags flags;
/* Callback */
void *cb_data;
void (*cb)(struct SDL_MenuItem *, void *);
/* Submenu, set to NULL if none */
SDL_ListNode *sub_menu;
/* User data slots */
void *udata;
void *udata2;
void *udata3;
} SDL_MenuItem;
#endif // SDL_menu_h_
+1076 -12
View File
File diff suppressed because one or more lines are too long
+26 -2
View File
@@ -28,14 +28,20 @@
#define SDL_USE_LIBDBUS 1
#include <dbus/dbus.h>
#include "../../SDL_list.h"
#include "../../SDL_menu.h"
#ifndef DBUS_TIMEOUT_USE_DEFAULT
#define DBUS_TIMEOUT_USE_DEFAULT -1
#endif
#ifndef DBUS_TIMEOUT_INFINITE
#define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff)
#define DBUS_TIMEOUT_INFINITE ((int)0x7fffffff)
#endif
#ifndef DBUS_TYPE_UNIX_FD
#define DBUS_TYPE_UNIX_FD ((int) 'h')
#define DBUS_TYPE_UNIX_FD ((int)'h')
#endif
#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
#endif
typedef struct SDL_DBusContext
@@ -95,6 +101,15 @@ typedef struct SDL_DBusContext
void (*free_string_array)(char **);
void (*shutdown)(void);
/* New symbols for SNI and menu export */
int (*bus_request_name)(DBusConnection *, const char *, unsigned int, DBusError *);
dbus_bool_t (*message_is_method_call)(DBusMessage *, const char *, const char *);
DBusMessage *(*message_new_error)(DBusMessage *, const char *, const char *);
DBusMessage *(*message_new_method_return)(DBusMessage *);
dbus_bool_t (*message_iter_append_fixed_array)(DBusMessageIter *, int, const void *, int);
void (*message_iter_get_fixed_array)(DBusMessageIter *, void *, int *);
dbus_bool_t (*connection_unregister_object_path)(DBusConnection *, const char *);
dbus_bool_t (*connection_get_object_path_data)(DBusConnection *, const char *, void **);
} SDL_DBusContext;
extern void SDL_DBus_Init(void);
@@ -128,6 +143,15 @@ extern char **SDL_DBus_DocumentsPortalRetrieveFiles(const char *key, int *files_
extern int SDL_DBus_CameraPortalRequestAccess(void);
// Menu export functions
#define SDL_DBUS_UPDATE_MENU_FLAGS_NONE 0
extern SDL_MenuItem *SDL_DBus_CreateMenuItem(void);
extern const char *SDL_DBus_ExportMenu(SDL_DBusContext *ctx, DBusConnection *conn, SDL_ListNode *menu);
extern void SDL_DBus_UpdateMenu(SDL_DBusContext *ctx, DBusConnection *conn, SDL_ListNode *menu, const char *path, void (*cb)(SDL_ListNode *, const char *, void *), void *cbdata, unsigned char flags);
extern void SDL_DBus_RegisterMenuOpenCallback(SDL_ListNode *menu, bool (*cb)(SDL_ListNode *, void *), void *cbdata);
extern void SDL_DBus_TransferMenuItemProperties(SDL_MenuItem *src, SDL_MenuItem *dst);
extern void SDL_DBus_RetractMenu(SDL_DBusContext *ctx, DBusConnection *conn, const char **path);
#endif // HAVE_DBUS_DBUS_H
#endif // SDL_dbus_h_
+6 -2
View File
@@ -20,11 +20,10 @@
*/
#include "SDL_internal.h"
#include "../video/SDL_sysvideo.h"
#include "../events/SDL_events_c.h"
#include "../video/SDL_sysvideo.h"
#include "SDL_tray_utils.h"
static int active_trays = 0;
void SDL_RegisterTray(SDL_Tray *tray)
@@ -91,3 +90,8 @@ bool SDL_HasActiveTrays(void)
{
return (active_trays > 0);
}
int SDL_GetActiveTrayCount(void)
{
return active_trays;
}
+1
View File
@@ -26,3 +26,4 @@ extern void SDL_RegisterTray(SDL_Tray *tray);
extern void SDL_UnregisterTray(SDL_Tray *tray);
extern void SDL_CleanupTrays(void);
extern bool SDL_HasActiveTrays(void);
extern int SDL_GetActiveTrayCount(void);
File diff suppressed because one or more lines are too long
+138 -568
View File
File diff suppressed because it is too large Load Diff
+81
View File
@@ -0,0 +1,81 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifndef SDL_unixtray_h_
#define SDL_unixtray_h_
#include "../../core/linux/SDL_dbus.h"
#include "../SDL_tray_utils.h"
typedef struct SDL_TrayDriver
{
const char *name;
unsigned int count;
SDL_Tray *(*CreateTray)(struct SDL_TrayDriver *, SDL_PropertiesID);
void (*DestroyTray)(SDL_Tray *);
void (*UpdateTray)(SDL_Tray *);
void (*SetTrayIcon)(SDL_Tray *, SDL_Surface *);
void (*SetTrayTooltip)(SDL_Tray *, const char *);
SDL_TrayMenu *(*CreateTrayMenu)(SDL_Tray *);
SDL_TrayEntry *(*InsertTrayEntryAt)(SDL_TrayMenu *, int, const char *, SDL_TrayEntryFlags);
SDL_TrayMenu *(*CreateTraySubmenu)(SDL_TrayEntry *);
SDL_TrayMenu *(*GetTraySubmenu)(SDL_TrayEntry *);
SDL_TrayEntry **(*GetTrayEntries)(SDL_TrayMenu *, int *);
void (*RemoveTrayEntry)(SDL_TrayEntry *);
void (*SetTrayEntryLabel)(SDL_TrayEntry *, const char *);
const char *(*GetTrayEntryLabel)(SDL_TrayEntry *);
void (*SetTrayEntryChecked)(SDL_TrayEntry *, bool);
void (*ClickTrayEntry)(SDL_TrayEntry *);
bool (*GetTrayEntryChecked)(SDL_TrayEntry *);
void (*SetTrayEntryEnabled)(SDL_TrayEntry *, bool);
bool (*GetTrayEntryEnabled)(SDL_TrayEntry *);
void (*SetTrayEntryCallback)(SDL_TrayEntry *, SDL_TrayCallback, void *);
void (*DestroyDriver)(struct SDL_TrayDriver *);
} SDL_TrayDriver;
struct SDL_TrayMenu
{
SDL_Tray *parent_tray;
SDL_TrayEntry *parent_entry;
};
struct SDL_TrayEntry
{
SDL_TrayMenu *parent;
};
struct SDL_Tray
{
SDL_TrayDriver *driver;
SDL_TrayMenu *menu;
};
#ifdef SDL_USE_LIBDBUS
extern SDL_TrayDriver *SDL_Tray_CreateDBusDriver(void);
#endif
#endif // SDL_unixtray_h_