Commit 12e79be0 authored by Serge A. Zaitsev's avatar Serge A. Zaitsev

changed formatting

parent fad5f0d8
...@@ -5,33 +5,31 @@ ...@@ -5,33 +5,31 @@
static struct tray tray; static struct tray tray;
static void hello_cb(struct tray_menu *item) { static void hello_cb(struct tray_menu *item) {
printf("hello cb\n"); printf("hello cb\n");
if (strcmp(tray.icon, "indicator-messages") == 0) { if (strcmp(tray.icon, "indicator-messages") == 0) {
tray.icon = "indicator-messages-new"; tray.icon = "indicator-messages-new";
} else { } else {
tray.icon = "indicator-messages"; tray.icon = "indicator-messages";
} }
tray_update(&tray); tray_update(&tray);
} }
static void quit_cb(struct tray_menu *item) { static void quit_cb(struct tray_menu *item) {
printf("quit cb\n"); printf("quit cb\n");
tray_exit(); tray_exit();
} }
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[]) {
tray_init(&tray); tray_init(&tray);
while (tray_loop(1) == 0) { while (tray_loop(1) == 0) {
printf("iteration\n"); printf("iteration\n");
} }
return 0; return 0;
} }
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
struct tray_menu; struct tray_menu;
struct tray { struct tray {
char *icon; char *icon;
char *tooltip; char *tooltip;
struct tray_menu *menu; struct tray_menu *menu;
}; };
struct tray_menu { struct tray_menu {
char *icon; char *icon;
char *text; /* label */ char *text; /* label */
int flags; int flags;
void (*cb)(struct tray_menu *); void (*cb)(struct tray_menu *);
void *context; void *context;
}; };
static void tray_update(struct tray *tray); static void tray_update(struct tray *tray);
...@@ -31,45 +31,43 @@ static AppIndicator *indicator = NULL; ...@@ -31,45 +31,43 @@ 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);
} }
static int tray_init(struct tray *tray) { static int tray_init(struct tray *tray) {
if (gtk_init_check(0, NULL) == FALSE) { if (gtk_init_check(0, NULL) == FALSE) {
return -1; return -1;
} }
indicator = app_indicator_new(TRAY_APPINDICATOR_ID, tray->icon, indicator = app_indicator_new(TRAY_APPINDICATOR_ID, tray->icon,
APP_INDICATOR_CATEGORY_APPLICATION_STATUS); APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE); app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
tray_update(tray); tray_update(tray);
return 0; return 0;
} }
static int tray_loop(int blocking) { static int tray_loop(int blocking) {
gtk_main_iteration_do(blocking); gtk_main_iteration_do(blocking);
return loop_result; return loop_result;
} }
static void tray_update(struct tray *tray) { static void tray_update(struct tray *tray) {
struct tray_menu *m; struct tray_menu *m;
app_indicator_set_icon(indicator, tray->icon); app_indicator_set_icon(indicator, tray->icon);
GtkMenuShell *gtk_menu = (GtkMenuShell *)gtk_menu_new(); GtkMenuShell *gtk_menu = (GtkMenuShell *)gtk_menu_new();
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++) {
GtkWidget *item = gtk_menu_item_new_with_label(m->text); GtkWidget *item = gtk_menu_item_new_with_label(m->text);
gtk_widget_show(item); gtk_widget_show(item);
gtk_menu_shell_append(GTK_MENU_SHELL(gtk_menu), item); gtk_menu_shell_append(GTK_MENU_SHELL(gtk_menu), item);
if (m->cb != NULL) { if (m->cb != NULL) {
g_signal_connect(item, "activate", G_CALLBACK(_tray_menu_cb), m); g_signal_connect(item, "activate", G_CALLBACK(_tray_menu_cb), m);
} }
} }
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; ...@@ -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) { ...@@ -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];
...@@ -113,9 +111,9 @@ static int tray_loop(int blocking) { ...@@ -113,9 +111,9 @@ static int tray_loop(int blocking) {
NSEvent *event; NSEvent *event;
NSDate *until = (blocking ? [NSDate distantFuture] : [NSDate distantPast]); NSDate *until = (blocking ? [NSDate distantFuture] : [NSDate distantPast]);
event = [NSApp nextEventMatchingMask:NSAnyEventMask event = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:until untilDate:until
inMode:NSDefaultRunLoopMode inMode:NSDefaultRunLoopMode
dequeue:YES]; dequeue:YES];
if (event) { if (event) {
[NSApp sendEvent:event]; [NSApp sendEvent:event];
} }
...@@ -131,12 +129,11 @@ static void tray_update(struct tray *tray) { ...@@ -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) { ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment