{"id":13719557,"url":"https://github.com/zserge/tray","last_synced_at":"2025-04-04T18:08:46.393Z","repository":{"id":50439054,"uuid":"78437054","full_name":"zserge/tray","owner":"zserge","description":"Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu.","archived":false,"fork":false,"pushed_at":"2024-01-16T13:41:33.000Z","size":57,"stargazers_count":525,"open_issues_count":11,"forks_count":86,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-28T17:08:54.398Z","etag":null,"topics":["appindicator","cross-platform","gtk","tray-icon","tray-menu"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zserge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-09T14:40:06.000Z","updated_at":"2025-03-16T20:12:26.000Z","dependencies_parsed_at":"2024-10-24T16:44:23.047Z","dependency_job_id":"871413c4-1e05-4be3-9636-544f21ff280a","html_url":"https://github.com/zserge/tray","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Ftray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Ftray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Ftray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Ftray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zserge","download_url":"https://codeload.github.com/zserge/tray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226215,"owners_count":20904465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appindicator","cross-platform","gtk","tray-icon","tray-menu"],"created_at":"2024-08-03T01:00:51.531Z","updated_at":"2025-04-04T18:08:46.377Z","avatar_url":"https://github.com/zserge.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"Tray\n----\n\nCross-platform, single header, super tiny C99 implementation of a system tray icon with a popup menu.\n\nWorks well on:\n\n* Linux/Gtk (libappindicator)\n* Windows XP or newer (shellapi.h)\n* MacOS (Cocoa/AppKit)\n\nThere is also a stub implementation that returns errors on attempt to create a tray menu.\n\n# Setup\n\nBefore you can compile `tray`, you'll need to add an environment definition before the line where you include `tray.h`. \n\n**For Windows:**\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n\n#define TRAY_WINAPI 1\n\n#include \"tray.h\"\n...\n```\n\n**For Linux:**\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n\n#define TRAY_APPINDICATOR 1\n\n#include \"tray.h\"\n...\n```\n\n**For Mac:**\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n\n#define TRAY_APPKIT 1\n\n#include \"tray.h\"\n...\n```\n\n# Demo\n\nThe included example `.c` files can be compiled based on your environment.\n\nFor example, to compile and run the program on Windows: \n\n```shell\n$\u003e gcc example_windows.c [Enter]\n``` \n\nThis will compile and build `a.out`. To run it: \n\n```\n$\u003e a [Enter]\n```\n\n# Example\n\n```c\nstruct tray tray = {\n    .icon = \"icon.png\",\n    .menu = (struct tray_menu[]){{\"Toggle me\", 0, 0, toggle_cb, NULL},\n                                 {\"-\", 0, 0, NULL, NULL},\n                                 {\"Quit\", 0, 0, quit_cb, NULL},\n                                 {NULL, 0, 0, NULL, NULL}},\n};\n\nvoid toggle_cb(struct tray_menu *item) {\n\titem-\u003echecked = !item-\u003echecked;\n\ttray_update(\u0026tray);\n}\n\nvoid quit_cb(struct tray_menu *item) {\n  tray_exit();\n}\n\n...\n\ntray_init(\u0026tray);\nwhile (tray_loop(1) == 0);\ntray_exit();\n\n```\n\n# API\n\nTray structure defines an icon and a menu.\nMenu is a NULL-terminated array of items.\nMenu item defines menu text, menu checked and disabled (grayed) flags and a\ncallback with some optional context pointer.\n\n```c\nstruct tray {\n  char *icon;\n  struct tray_menu *menu;\n};\n\nstruct tray_menu {\n  char *text;\n  int disabled;\n  int checked;\n\n  void (*cb)(struct tray_menu *);\n  void *context;\n\n  struct tray_menu *submenu;\n};\n```\n\n* `int tray_init(struct tray *)` - creates tray icon. Returns -1 if tray icon/menu can't be created.\n* `void tray_update(struct tray *)` - updates tray icon and menu.\n* `int tray_loop(int blocking)` - runs one iteration of the UI loop. Returns -1 if `tray_exit()` has been called.\n* `void tray_exit()` - terminates UI loop.\n\nAll functions are meant to be called from the UI thread only.\n\nMenu arrays must be terminated with a NULL item, e.g. the last item in the\narray must have text field set to NULL.\n\n## Roadmap\n\n* [x] Cross-platform tray icon\n* [x] Cross-platform tray popup menu\n* [x] Separators in the menu\n* [x] Disabled/enabled menu items\n* [x] Checked/unchecked menu items\n* [x] Nested menus\n* [ ] Icons for menu items\n* [x] Rewrite ObjC code in C using ObjC Runtime (now ObjC code breaks many linters and static analyzers)\n* [ ] Call GTK code using dlopen/dlsym (to make binaries run safely if Gtk libraries are not available)\n\n## License\n\nThis software is distributed under [MIT license](http://www.opensource.org/licenses/mit-license.php),\n so feel free to integrate it in your commercial products.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Ftray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzserge%2Ftray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Ftray/lists"}