All Projects → zserge → Tray

zserge / Tray

Licence: mit
Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Tray

Wxwidgets
wxWidgets is a free and open source cross-platform C++ framework for writing advanced GUI applications using native controls.
Stars: ✭ 3,994 (+1424.43%)
Mutual labels:  cross-platform, gtk
Eiskaltdcpp
File sharing program using DC and ADC protocols
Stars: ✭ 277 (+5.73%)
Mutual labels:  cross-platform, gtk
Mednaffe
A front-end (GUI) for mednafen emulator
Stars: ✭ 200 (-23.66%)
Mutual labels:  cross-platform, gtk
Rednotebook
RedNotebook is a cross-platform journal
Stars: ✭ 336 (+28.24%)
Mutual labels:  cross-platform, gtk
Nigui
Cross-platform desktop GUI toolkit written in Nim
Stars: ✭ 430 (+64.12%)
Mutual labels:  cross-platform, gtk
Gtk Fortran
A GTK / Fortran binding
Stars: ✭ 171 (-34.73%)
Mutual labels:  cross-platform, gtk
Systemtray
Cross-platform SystemTray support for Swing/AWT, GtkStatusIcon, and AppIndicator on Java 8+
Stars: ✭ 253 (-3.44%)
Mutual labels:  cross-platform, gtk
tasks
Synced tasks and reminders on elementary OS
Stars: ✭ 79 (-69.85%)
Mutual labels:  gtk
pdftag
A simple metadata editor for PDFs for Linux and Windows
Stars: ✭ 48 (-81.68%)
Mutual labels:  gtk
csak
Cartel Swiss Army Knife for Android devices - easy to use toolkit for Android devices
Stars: ✭ 18 (-93.13%)
Mutual labels:  gtk
switchboard-plug-display
Switchboard Displays Plug
Stars: ✭ 14 (-94.66%)
Mutual labels:  gtk
Abrus-gtk-theme
Abrus is a stylish Design theme for GTK 3, GTK 2 and Gnome-Shell etc.
Stars: ✭ 25 (-90.46%)
Mutual labels:  gtk
wingpanel-indicator-network
Wingpanel Network Indicator
Stars: ✭ 22 (-91.6%)
Mutual labels:  gtk
ordne
A Simple Pomodoro Timer for Elementary OS
Stars: ✭ 13 (-95.04%)
Mutual labels:  gtk
Jcolor
An easy syntax to format your strings with colored fonts and backgrounds.
Stars: ✭ 255 (-2.67%)
Mutual labels:  cross-platform
kiwi
A graphical UI framework on top of PyGTK
Stars: ✭ 24 (-90.84%)
Mutual labels:  gtk
Megaglest Source
MegaGlest real-time strategy game engine (cross-platform, 3-d)
Stars: ✭ 259 (-1.15%)
Mutual labels:  cross-platform
rnote
A simple drawing application to create handwritten notes.
Stars: ✭ 1,538 (+487.02%)
Mutual labels:  gtk
principles
Remember Dieter Rams' ten principles of good design on elementary OS
Stars: ✭ 38 (-85.5%)
Mutual labels:  gtk
scalaui
Scala Native GUI framework based on libui
Stars: ✭ 56 (-78.63%)
Mutual labels:  gtk

Tray

Cross-platform, single header, super tiny C99 implementation of a system tray icon with a popup menu.

Works well on:

  • Linux/Gtk (libappindicator)
  • Windows XP or newer (shellapi.h)
  • MacOS (Cocoa/AppKit)

There is also a stub implementation that returns errors on attempt to create a tray menu.

Setup

Before you can compile tray, you'll need to add an environment definition before the line where you include tray.h.

For Windows:

#include <stdio.h>
#include <string.h>

#define TRAY_WINAPI 1

#include "tray.h"
...

For Linux:

#include <stdio.h>
#include <string.h>

#define TRAY_APPINDICATOR 1

#include "tray.h"
...

For Mac:

#include <stdio.h>
#include <string.h>

#define TRAY_APPKIT 1

#include "tray.h"
...

Demo

The included example .c files can be compiled based on your environment.

For example, to compile and run the program on Windows:

$> gcc example_windows.c [Enter]

This will compile and build a.out. To run it:

$> a [Enter]

Example

struct tray tray = {
    .icon = "icon.png",
    .menu = (struct tray_menu[]){{"Toggle me", 0, 0, toggle_cb, NULL},
                                 {"-", 0, 0, NULL, NULL},
                                 {"Quit", 0, 0, quit_cb, NULL},
                                 {NULL, 0, 0, NULL, NULL}},
};

void toggle_cb(struct tray_menu *item) {
	item->checked = !item->checked;
	tray_update(&tray);
}

void quit_cb(struct tray_menu *item) {
  tray_exit();
}

...

tray_init(&tray);
while (tray_loop(1) == 0);
tray_exit();

API

Tray structure defines an icon and a menu. Menu is a NULL-terminated array of items. Menu item defines menu text, menu checked and disabled (grayed) flags and a callback with some optional context pointer.

struct tray {
  char *icon;
  struct tray_menu *menu;
};

struct tray_menu {
  char *text;
  int disabled;
  int checked;

  void (*cb)(struct tray_menu *);
  void *context;

  struct tray_menu *submenu;
};
  • int tray_init(struct tray *) - creates tray icon. Returns -1 if tray icon/menu can't be created.
  • void tray_update(struct tray *) - updates tray icon and menu.
  • int tray_loop(int blocking) - runs one iteration of the UI loop. Returns -1 if tray_exit() has been called.
  • void tray_exit() - terminates UI loop.

All functions are meant to be called from the UI thread only.

Menu arrays must be terminated with a NULL item, e.g. the last item in the array must have text field set to NULL.

Roadmap

  • [x] Cross-platform tray icon
  • [x] Cross-platform tray popup menu
  • [x] Separators in the menu
  • [x] Disabled/enabled menu items
  • [x] Checked/unchecked menu items
  • [x] Nested menus
  • [ ] Icons for menu items
  • [x] Rewrite ObjC code in C using ObjC Runtime (now ObjC code breaks many linters and static analyzers)
  • [ ] Call GTK code using dlopen/dlsym (to make binaries run safely if Gtk libraries are not available)

License

This software is distributed under MIT license, so feel free to integrate it in your commercial products.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].