Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tray
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
tray
Commits
9a43cc0d
Commit
9a43cc0d
authored
Jan 09, 2017
by
Serge A. Zaitsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added readme
parent
fd9f32ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
README.md
README.md
+88
-0
No files found.
README.md
0 → 100644
View file @
9a43cc0d
Tray
----
Cross-platform, 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.
# Example
```
c
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.
```
c
struct
tray
{
char
*
icon
;
struct
tray_menu
*
menu
;
};
struct
tray_menu
{
char
*
text
;
int
disabled
;
int
checked
;
void
(
*
cb
)(
struct
tray_menu
*
);
void
*
context
;
};
```
*
`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.
## 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
[
]
Nested menus
[
]
Icons for menu items
[
]
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
](
http://www.opensource.org/licenses/mit-license.php
)
,
so feel free to integrate it in your commercial products.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment