forked from Yadciel/c_tray
changed formatting
This commit is contained in:
@@ -21,11 +21,9 @@ static void quit_cb(struct tray_menu *item) {
|
|||||||
|
|
||||||
static struct tray tray = {
|
static struct tray tray = {
|
||||||
.icon = "indicator-messages-new",
|
.icon = "indicator-messages-new",
|
||||||
.menu = (struct tray_menu[]){
|
.menu = (struct tray_menu[]){{NULL, "Hello", 0, hello_cb, NULL},
|
||||||
{NULL, "Hello", 0, hello_cb, NULL},
|
|
||||||
{NULL, "Quit", 0, quit_cb, NULL},
|
{NULL, "Quit", 0, quit_cb, NULL},
|
||||||
{NULL, NULL, 0, NULL, NULL}
|
{NULL, NULL, 0, NULL, NULL}},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|||||||
27
tray.h
27
tray.h
@@ -31,7 +31,7 @@ static AppIndicator *indicator = NULL;
|
|||||||
static int loop_result = 0;
|
static int loop_result = 0;
|
||||||
|
|
||||||
static void _tray_menu_cb(GtkMenuItem *item, gpointer data) {
|
static void _tray_menu_cb(GtkMenuItem *item, gpointer data) {
|
||||||
struct tray_menu *m = (struct tray_menu *) data;
|
struct tray_menu *m = (struct tray_menu *)data;
|
||||||
m->cb(m);
|
m->cb(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +67,7 @@ static void tray_update(struct tray *tray) {
|
|||||||
app_indicator_set_menu(indicator, GTK_MENU(gtk_menu));
|
app_indicator_set_menu(indicator, GTK_MENU(gtk_menu));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tray_exit() {
|
static void tray_exit() { loop_result = -1; }
|
||||||
loop_result = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(TRAY_APPKIT)
|
#elif defined(TRAY_APPKIT)
|
||||||
|
|
||||||
@@ -80,13 +78,13 @@ static NSStatusBar *statusBar;
|
|||||||
static id statusItem;
|
static id statusItem;
|
||||||
static id statusBarButton;
|
static id statusBarButton;
|
||||||
|
|
||||||
@interface Tray : NSObject<NSApplicationDelegate>
|
@interface Tray : NSObject <NSApplicationDelegate>
|
||||||
- (void) menuCallback: (id) sender;
|
- (void)menuCallback:(id)sender;
|
||||||
@end
|
@end
|
||||||
@implementation Tray
|
@implementation Tray
|
||||||
- (void) menuCallback: (id) sender {
|
- (void)menuCallback:(id)sender {
|
||||||
struct tray_menu *m = (struct tray_menu *)
|
struct tray_menu *m =
|
||||||
[[sender representedObject] pointerValue];
|
(struct tray_menu *)[[sender representedObject] pointerValue];
|
||||||
m->cb(m);
|
m->cb(m);
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
@@ -96,7 +94,7 @@ static int tray_init(struct tray *tray) {
|
|||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
Tray *trayDelegate = [Tray new];
|
Tray *trayDelegate = [Tray new];
|
||||||
[NSApp setDelegate: trayDelegate];
|
[NSApp setDelegate:trayDelegate];
|
||||||
|
|
||||||
statusBar = [NSStatusBar systemStatusBar];
|
statusBar = [NSStatusBar systemStatusBar];
|
||||||
statusItem = [statusBar statusItemWithLength:NSVariableStatusItemLength];
|
statusItem = [statusBar statusItemWithLength:NSVariableStatusItemLength];
|
||||||
@@ -131,12 +129,11 @@ static void tray_update(struct tray *tray) {
|
|||||||
for (struct tray_menu *m = tray->menu; m != NULL && m->text != NULL; m++) {
|
for (struct tray_menu *m = tray->menu; m != NULL && m->text != NULL; m++) {
|
||||||
NSMenuItem *menuItem = [NSMenuItem alloc];
|
NSMenuItem *menuItem = [NSMenuItem alloc];
|
||||||
[menuItem autorelease];
|
[menuItem autorelease];
|
||||||
[menuItem
|
[menuItem initWithTitle:[NSString stringWithUTF8String:m->text]
|
||||||
initWithTitle: [NSString stringWithUTF8String: m->text]
|
|
||||||
action:@selector(menuCallback:)
|
action:@selector(menuCallback:)
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
[menuItem setEnabled:YES];
|
[menuItem setEnabled:YES];
|
||||||
[menuItem setRepresentedObject: [NSValue valueWithPointer:m]];
|
[menuItem setRepresentedObject:[NSValue valueWithPointer:m]];
|
||||||
|
|
||||||
[menu addItem:menuItem];
|
[menu addItem:menuItem];
|
||||||
|
|
||||||
@@ -146,9 +143,7 @@ static void tray_update(struct tray *tray) {
|
|||||||
[statusItem setMenu:menu];
|
[statusItem setMenu:menu];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tray_exit() {
|
static void tray_exit() { [NSApp terminate:NSApp]; }
|
||||||
[NSApp terminate:NSApp];
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(TRAY_WINAPI)
|
#elif defined(TRAY_WINAPI)
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user