Skip to content

Commit d7b688b

Browse files
author
Niklas Voss
committed
Auto-reindent windows and linux C-code to comply with Objective-C Mac OS implementation
1 parent 0791af8 commit d7b688b

File tree

2 files changed

+158
-158
lines changed

2 files changed

+158
-158
lines changed

tray_linux.c

+39-39
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,58 @@ static AppIndicator *indicator = NULL;
99
static int loop_result = 0;
1010

1111
static void _tray_menu_cb(GtkMenuItem *item, gpointer data) {
12-
(void)item;
13-
struct tray_menu *m = (struct tray_menu *)data;
14-
m->cb(m);
12+
(void)item;
13+
struct tray_menu *m = (struct tray_menu *)data;
14+
m->cb(m);
1515
}
1616

1717
static GtkMenuShell *_tray_menu(struct tray_menu *m) {
18-
GtkMenuShell *menu = (GtkMenuShell *)gtk_menu_new();
19-
for (; m != NULL && m->text != NULL; m++) {
20-
GtkWidget *item;
21-
if (strcmp(m->text, "-") == 0) {
22-
item = gtk_separator_menu_item_new();
23-
} else {
24-
if (m->submenu != NULL) {
25-
item = gtk_menu_item_new_with_label(m->text);
26-
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),
27-
GTK_WIDGET(_tray_menu(m->submenu)));
28-
} else {
29-
item = gtk_check_menu_item_new_with_label(m->text);
30-
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), !!m->checked);
31-
}
32-
gtk_widget_set_sensitive(item, !m->disabled);
33-
if (m->cb != NULL) {
34-
g_signal_connect(item, "activate", G_CALLBACK(_tray_menu_cb), m);
35-
}
18+
GtkMenuShell *menu = (GtkMenuShell *)gtk_menu_new();
19+
for (; m != NULL && m->text != NULL; m++) {
20+
GtkWidget *item;
21+
if (strcmp(m->text, "-") == 0) {
22+
item = gtk_separator_menu_item_new();
23+
} else {
24+
if (m->submenu != NULL) {
25+
item = gtk_menu_item_new_with_label(m->text);
26+
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),
27+
GTK_WIDGET(_tray_menu(m->submenu)));
28+
} else {
29+
item = gtk_check_menu_item_new_with_label(m->text);
30+
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), !!m->checked);
31+
}
32+
gtk_widget_set_sensitive(item, !m->disabled);
33+
if (m->cb != NULL) {
34+
g_signal_connect(item, "activate", G_CALLBACK(_tray_menu_cb), m);
35+
}
36+
}
37+
gtk_widget_show(item);
38+
gtk_menu_shell_append(menu, item);
3639
}
37-
gtk_widget_show(item);
38-
gtk_menu_shell_append(menu, item);
39-
}
40-
return menu;
40+
return menu;
4141
}
4242

4343
int tray_init(struct tray *tray) {
44-
if (gtk_init_check(0, NULL) == FALSE) {
45-
return -1;
46-
}
47-
indicator = app_indicator_new(TRAY_APPINDICATOR_ID, tray->icon.data,
48-
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
49-
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
50-
tray_update(tray);
51-
return 0;
44+
if (gtk_init_check(0, NULL) == FALSE) {
45+
return -1;
46+
}
47+
indicator = app_indicator_new(TRAY_APPINDICATOR_ID, tray->icon.data,
48+
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
49+
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
50+
tray_update(tray);
51+
return 0;
5252
}
5353

5454
int tray_loop(int blocking) {
55-
gtk_main_iteration_do(blocking);
56-
return loop_result;
55+
gtk_main_iteration_do(blocking);
56+
return loop_result;
5757
}
5858

5959
void tray_update(struct tray *tray) {
60-
app_indicator_set_icon(indicator, tray->icon.data);
61-
// GTK is all about reference counting, so previous menu should be destroyed
62-
// here
63-
app_indicator_set_menu(indicator, GTK_MENU(_tray_menu(tray->menu)));
60+
app_indicator_set_icon(indicator, tray->icon.data);
61+
// GTK is all about reference counting, so previous menu should be destroyed
62+
// here
63+
app_indicator_set_menu(indicator, GTK_MENU(_tray_menu(tray->menu)));
6464
}
6565

6666
void tray_exit() { loop_result = -1; }

tray_windows.c

+119-119
Original file line numberDiff line numberDiff line change
@@ -13,145 +13,145 @@ static HWND hwnd;
1313
static HMENU hmenu = NULL;
1414

1515
static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam,
16-
LPARAM lparam) {
17-
switch (msg) {
18-
case WM_CLOSE:
19-
DestroyWindow(hwnd);
20-
return 0;
21-
case WM_DESTROY:
22-
PostQuitMessage(0);
23-
return 0;
24-
case WM_TRAY_CALLBACK_MESSAGE:
25-
if (lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
26-
POINT p;
27-
GetCursorPos(&p);
28-
SetForegroundWindow(hwnd);
29-
WORD cmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON |
30-
TPM_RETURNCMD | TPM_NONOTIFY,
31-
p.x, p.y, 0, hwnd, NULL);
32-
SendMessage(hwnd, WM_COMMAND, cmd, 0);
33-
return 0;
34-
}
35-
break;
36-
case WM_COMMAND:
37-
if (wparam >= ID_TRAY_FIRST) {
38-
MENUITEMINFO item = {
39-
.cbSize = sizeof(MENUITEMINFO), .fMask = MIIM_ID | MIIM_DATA,
40-
};
41-
if (GetMenuItemInfo(hmenu, wparam, FALSE, &item)) {
42-
struct tray_menu *menu = (struct tray_menu *)item.dwItemData;
43-
if (menu != NULL && menu->cb != NULL) {
44-
menu->cb(menu);
45-
}
46-
}
47-
return 0;
16+
LPARAM lparam) {
17+
switch (msg) {
18+
case WM_CLOSE:
19+
DestroyWindow(hwnd);
20+
return 0;
21+
case WM_DESTROY:
22+
PostQuitMessage(0);
23+
return 0;
24+
case WM_TRAY_CALLBACK_MESSAGE:
25+
if (lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
26+
POINT p;
27+
GetCursorPos(&p);
28+
SetForegroundWindow(hwnd);
29+
WORD cmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON |
30+
TPM_RETURNCMD | TPM_NONOTIFY,
31+
p.x, p.y, 0, hwnd, NULL);
32+
SendMessage(hwnd, WM_COMMAND, cmd, 0);
33+
return 0;
34+
}
35+
break;
36+
case WM_COMMAND:
37+
if (wparam >= ID_TRAY_FIRST) {
38+
MENUITEMINFO item = {
39+
.cbSize = sizeof(MENUITEMINFO), .fMask = MIIM_ID | MIIM_DATA,
40+
};
41+
if (GetMenuItemInfo(hmenu, wparam, FALSE, &item)) {
42+
struct tray_menu *menu = (struct tray_menu *)item.dwItemData;
43+
if (menu != NULL && menu->cb != NULL) {
44+
menu->cb(menu);
45+
}
46+
}
47+
return 0;
48+
}
49+
break;
4850
}
49-
break;
50-
}
51-
return DefWindowProc(hwnd, msg, wparam, lparam);
51+
return DefWindowProc(hwnd, msg, wparam, lparam);
5252
}
5353

5454
static HMENU _tray_menu(struct tray_menu *m, UINT *id) {
55-
HMENU hmenu = CreatePopupMenu();
56-
for (; m != NULL && m->text != NULL; m++, (*id)++) {
57-
if (strcmp(m->text, "-") == 0) {
58-
InsertMenu(hmenu, *id, MF_SEPARATOR, TRUE, "");
59-
} else {
60-
MENUITEMINFO item;
61-
memset(&item, 0, sizeof(item));
62-
item.cbSize = sizeof(MENUITEMINFO);
63-
item.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_DATA;
64-
item.fType = 0;
65-
item.fState = 0;
66-
if (m->submenu != NULL) {
67-
item.fMask = item.fMask | MIIM_SUBMENU;
68-
item.hSubMenu = _tray_menu(m->submenu, id);
69-
}
70-
if (m->disabled) {
71-
item.fState |= MFS_DISABLED;
72-
}
73-
if (m->checked) {
74-
item.fState |= MFS_CHECKED;
75-
}
76-
item.wID = *id;
77-
item.dwTypeData = m->text;
78-
item.dwItemData = (ULONG_PTR)m;
55+
HMENU hmenu = CreatePopupMenu();
56+
for (; m != NULL && m->text != NULL; m++, (*id)++) {
57+
if (strcmp(m->text, "-") == 0) {
58+
InsertMenu(hmenu, *id, MF_SEPARATOR, TRUE, "");
59+
} else {
60+
MENUITEMINFO item;
61+
memset(&item, 0, sizeof(item));
62+
item.cbSize = sizeof(MENUITEMINFO);
63+
item.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_DATA;
64+
item.fType = 0;
65+
item.fState = 0;
66+
if (m->submenu != NULL) {
67+
item.fMask = item.fMask | MIIM_SUBMENU;
68+
item.hSubMenu = _tray_menu(m->submenu, id);
69+
}
70+
if (m->disabled) {
71+
item.fState |= MFS_DISABLED;
72+
}
73+
if (m->checked) {
74+
item.fState |= MFS_CHECKED;
75+
}
76+
item.wID = *id;
77+
item.dwTypeData = m->text;
78+
item.dwItemData = (ULONG_PTR)m;
7979

80-
InsertMenuItem(hmenu, *id, TRUE, &item);
80+
InsertMenuItem(hmenu, *id, TRUE, &item);
81+
}
8182
}
82-
}
83-
return hmenu;
83+
return hmenu;
8484
}
8585

8686
int tray_init(struct tray *tray) {
87-
memset(&wc, 0, sizeof(wc));
88-
wc.cbSize = sizeof(WNDCLASSEX);
89-
wc.lpfnWndProc = _tray_wnd_proc;
90-
wc.hInstance = GetModuleHandle(NULL);
91-
wc.lpszClassName = WC_TRAY_CLASS_NAME;
92-
if (!RegisterClassEx(&wc)) {
93-
return -1;
94-
}
87+
memset(&wc, 0, sizeof(wc));
88+
wc.cbSize = sizeof(WNDCLASSEX);
89+
wc.lpfnWndProc = _tray_wnd_proc;
90+
wc.hInstance = GetModuleHandle(NULL);
91+
wc.lpszClassName = WC_TRAY_CLASS_NAME;
92+
if (!RegisterClassEx(&wc)) {
93+
return -1;
94+
}
9595

96-
hwnd = CreateWindowEx(0, WC_TRAY_CLASS_NAME, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0);
97-
if (hwnd == NULL) {
98-
return -1;
99-
}
100-
UpdateWindow(hwnd);
96+
hwnd = CreateWindowEx(0, WC_TRAY_CLASS_NAME, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0);
97+
if (hwnd == NULL) {
98+
return -1;
99+
}
100+
UpdateWindow(hwnd);
101101

102-
memset(&nid, 0, sizeof(nid));
103-
nid.cbSize = sizeof(NOTIFYICONDATA);
104-
nid.hWnd = hwnd;
105-
nid.uID = 0;
106-
nid.uFlags = NIF_ICON | NIF_MESSAGE;
107-
nid.uCallbackMessage = WM_TRAY_CALLBACK_MESSAGE;
108-
Shell_NotifyIcon(NIM_ADD, &nid);
102+
memset(&nid, 0, sizeof(nid));
103+
nid.cbSize = sizeof(NOTIFYICONDATA);
104+
nid.hWnd = hwnd;
105+
nid.uID = 0;
106+
nid.uFlags = NIF_ICON | NIF_MESSAGE;
107+
nid.uCallbackMessage = WM_TRAY_CALLBACK_MESSAGE;
108+
Shell_NotifyIcon(NIM_ADD, &nid);
109109

110-
tray_update(tray);
111-
return 0;
110+
tray_update(tray);
111+
return 0;
112112
}
113113

114114
int tray_loop(int blocking) {
115-
MSG msg;
116-
if (blocking) {
117-
GetMessage(&msg, NULL, 0, 0);
118-
} else {
119-
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
120-
}
121-
if (msg.message == WM_QUIT) {
122-
return -1;
123-
}
124-
TranslateMessage(&msg);
125-
DispatchMessage(&msg);
126-
return 0;
115+
MSG msg;
116+
if (blocking) {
117+
GetMessage(&msg, NULL, 0, 0);
118+
} else {
119+
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
120+
}
121+
if (msg.message == WM_QUIT) {
122+
return -1;
123+
}
124+
TranslateMessage(&msg);
125+
DispatchMessage(&msg);
126+
return 0;
127127
}
128128

129129
void tray_update(struct tray *tray) {
130-
HMENU prevmenu = hmenu;
131-
UINT id = ID_TRAY_FIRST;
132-
hmenu = _tray_menu(tray->menu, &id);
133-
SendMessage(hwnd, WM_INITMENUPOPUP, (WPARAM)hmenu, 0);
134-
HICON icon;
135-
ExtractIconEx(tray->icon.data, 0, NULL, &icon, 1);
136-
if (nid.hIcon) {
137-
DestroyIcon(nid.hIcon);
138-
}
139-
nid.hIcon = icon;
140-
Shell_NotifyIcon(NIM_MODIFY, &nid);
130+
HMENU prevmenu = hmenu;
131+
UINT id = ID_TRAY_FIRST;
132+
hmenu = _tray_menu(tray->menu, &id);
133+
SendMessage(hwnd, WM_INITMENUPOPUP, (WPARAM)hmenu, 0);
134+
HICON icon;
135+
ExtractIconEx(tray->icon.data, 0, NULL, &icon, 1);
136+
if (nid.hIcon) {
137+
DestroyIcon(nid.hIcon);
138+
}
139+
nid.hIcon = icon;
140+
Shell_NotifyIcon(NIM_MODIFY, &nid);
141141

142-
if (prevmenu != NULL) {
143-
DestroyMenu(prevmenu);
144-
}
142+
if (prevmenu != NULL) {
143+
DestroyMenu(prevmenu);
144+
}
145145
}
146146

147147
void tray_exit() {
148-
Shell_NotifyIcon(NIM_DELETE, &nid);
149-
if (nid.hIcon != 0) {
150-
DestroyIcon(nid.hIcon);
151-
}
152-
if (hmenu != 0) {
153-
DestroyMenu(hmenu);
154-
}
155-
PostQuitMessage(0);
156-
UnregisterClass(WC_TRAY_CLASS_NAME, GetModuleHandle(NULL));
148+
Shell_NotifyIcon(NIM_DELETE, &nid);
149+
if (nid.hIcon != 0) {
150+
DestroyIcon(nid.hIcon);
151+
}
152+
if (hmenu != 0) {
153+
DestroyMenu(hmenu);
154+
}
155+
PostQuitMessage(0);
156+
UnregisterClass(WC_TRAY_CLASS_NAME, GetModuleHandle(NULL));
157157
}

0 commit comments

Comments
 (0)