Skip to content

Commit f739cf0

Browse files
Sven PüschelSven Püschel
authored andcommitted
format all source files
Format all source files with clang-format using the following comamnd: clang-format -i **/*.c *.c **/*.h *.h
1 parent ac8589d commit f739cf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+14470
-13352
lines changed

dunstify.c

Lines changed: 148 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
#include <gdk-pixbuf/gdk-pixbuf.h>
12
#include <glib.h>
23
#include <libnotify/notify.h>
34
#include <locale.h>
45
#include <stdbool.h>
56
#include <stdlib.h>
67
#include <string.h>
7-
#include <gdk-pixbuf/gdk-pixbuf.h>
88

99
static gchar *appname = "dunstify";
1010
static gchar *summary = NULL;
@@ -25,25 +25,107 @@ static guint32 close_id = 0;
2525
static gboolean block = false;
2626
static gchar **rest = NULL;
2727

28-
static GOptionEntry entries[] =
29-
{
30-
{ "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, "Name of your application", "NAME" },
31-
{ "urgency", 'u', 0, G_OPTION_ARG_STRING, &urgency_str, "The urgency of this notification", "URG" },
32-
{ "hints", 'h', 0, G_OPTION_ARG_STRING_ARRAY, &hint_strs, "User specified hints", "HINT" },
33-
{ "action", 'A', 0, G_OPTION_ARG_STRING_ARRAY, &action_strs, "Actions the user can invoke", "ACTION" },
34-
{ "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "The time in milliseconds until the notification expires", "TIMEOUT" },
35-
{ "icon", 'i', 0, G_OPTION_ARG_STRING, &icon, "An icon that should be displayed with the notification", "ICON" },
36-
{ "raw_icon", 'I', 0, G_OPTION_ARG_STRING, &raw_icon_path, "Path to the icon to be sent as raw image data", "RAW_ICON"},
37-
{ "category", 'c', 0, G_OPTION_ARG_STRING, &category, "The category of this notification", "TYPE" },
38-
{ "capabilities", 0, 0, G_OPTION_ARG_NONE, &capabilities, "Print the server capabilities and exit", NULL },
39-
{ "serverinfo", 's', 0, G_OPTION_ARG_NONE, &serverinfo, "Print server information and exit", NULL },
40-
{ "printid", 'p', 0, G_OPTION_ARG_NONE, &printid, "Print id, which can be used to update/replace this notification", NULL },
41-
{ "replace", 'r', 0, G_OPTION_ARG_INT, &replace_id, "Set id of this notification.", "ID" },
42-
{ "close", 'C', 0, G_OPTION_ARG_INT, &close_id, "Close the notification with the specified ID", "ID" },
43-
{ "block", 'b', 0, G_OPTION_ARG_NONE, &block, "Block until notification is closed and print close reason", NULL },
44-
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &rest, NULL, NULL },
45-
{ NULL }
46-
};
28+
static GOptionEntry entries[] = {
29+
{"appname",
30+
'a',
31+
0,
32+
G_OPTION_ARG_STRING,
33+
&appname,
34+
"Name of your application",
35+
"NAME"},
36+
{"urgency",
37+
'u',
38+
0,
39+
G_OPTION_ARG_STRING,
40+
&urgency_str,
41+
"The urgency of this notification",
42+
"URG"},
43+
{"hints",
44+
'h',
45+
0,
46+
G_OPTION_ARG_STRING_ARRAY,
47+
&hint_strs,
48+
"User specified hints",
49+
"HINT"},
50+
{"action",
51+
'A',
52+
0,
53+
G_OPTION_ARG_STRING_ARRAY,
54+
&action_strs,
55+
"Actions the user can invoke",
56+
"ACTION"},
57+
{"timeout",
58+
't',
59+
0,
60+
G_OPTION_ARG_INT,
61+
&timeout,
62+
"The time in milliseconds until the notification expires",
63+
"TIMEOUT"},
64+
{"icon",
65+
'i',
66+
0,
67+
G_OPTION_ARG_STRING,
68+
&icon,
69+
"An icon that should be displayed with the notification",
70+
"ICON"},
71+
{"raw_icon",
72+
'I',
73+
0,
74+
G_OPTION_ARG_STRING,
75+
&raw_icon_path,
76+
"Path to the icon to be sent as raw image data",
77+
"RAW_ICON"},
78+
{"category",
79+
'c',
80+
0,
81+
G_OPTION_ARG_STRING,
82+
&category,
83+
"The category of this notification",
84+
"TYPE"},
85+
{"capabilities",
86+
0,
87+
0,
88+
G_OPTION_ARG_NONE,
89+
&capabilities,
90+
"Print the server capabilities and exit",
91+
NULL},
92+
{"serverinfo",
93+
's',
94+
0,
95+
G_OPTION_ARG_NONE,
96+
&serverinfo,
97+
"Print server information and exit",
98+
NULL},
99+
{"printid",
100+
'p',
101+
0,
102+
G_OPTION_ARG_NONE,
103+
&printid,
104+
"Print id, which can be used to update/replace this notification",
105+
NULL},
106+
{"replace",
107+
'r',
108+
0,
109+
G_OPTION_ARG_INT,
110+
&replace_id,
111+
"Set id of this notification.",
112+
"ID"},
113+
{"close",
114+
'C',
115+
0,
116+
G_OPTION_ARG_INT,
117+
&close_id,
118+
"Close the notification with the specified ID",
119+
"ID"},
120+
{"block",
121+
'b',
122+
0,
123+
G_OPTION_ARG_NONE,
124+
&block,
125+
"Block until notification is closed and print close reason",
126+
NULL},
127+
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &rest, NULL, NULL},
128+
{NULL}};
47129

48130
void die(int exit_value)
49131
{
@@ -74,10 +156,11 @@ void print_serverinfo(void)
74156
exit(1);
75157
}
76158

77-
g_print("name:%s\nvendor:%s\nversion:%s\nspec_version:%s\n", name,
78-
vendor,
79-
version,
80-
spec_version);
159+
g_print("name:%s\nvendor:%s\nversion:%s\nspec_version:%s\n",
160+
name,
161+
vendor,
162+
version,
163+
spec_version);
81164
}
82165

83166
/*
@@ -98,7 +181,8 @@ char *get_argv(char *argv[], int index)
98181
}
99182

100183
/* Count the number of arguments in argv excluding the terminator "--" */
101-
int count_args(char *argv[], int argc) {
184+
int count_args(char *argv[], int argc)
185+
{
102186
for (int i = 0; i < argc; i++) {
103187
if (strcmp(argv[i], "--") == 0)
104188
return argc - 1;
@@ -114,7 +198,7 @@ void parse_commandline(int argc, char *argv[])
114198

115199
context = g_option_context_new("SUMMARY [BODY]");
116200
g_option_context_add_main_entries(context, entries, NULL);
117-
if (!g_option_context_parse(context, &argc, &argv, &error)){
201+
if (!g_option_context_parse(context, &argc, &argv, &error)) {
118202
g_printerr("Invalid commandline: %s\n", error->message);
119203
exit(1);
120204
}
@@ -143,8 +227,8 @@ void parse_commandline(int argc, char *argv[])
143227
body = g_strcompress(rest[1]);
144228

145229
if (rest[2] != NULL) {
146-
g_printerr("Too many arguments!\n");
147-
die(1);
230+
g_printerr("Too many arguments!\n");
231+
die(1);
148232
}
149233
}
150234
}
@@ -156,25 +240,19 @@ void parse_commandline(int argc, char *argv[])
156240

157241
if (urgency_str) {
158242
switch (urgency_str[0]) {
159-
case 'l':
160-
case 'L':
161-
case '0':
162-
urgency = NOTIFY_URGENCY_LOW;
163-
break;
164-
case 'n':
165-
case 'N':
166-
case '1':
167-
urgency = NOTIFY_URGENCY_NORMAL;
168-
break;
169-
case 'c':
170-
case 'C':
171-
case '2':
172-
urgency = NOTIFY_URGENCY_CRITICAL;
173-
break;
174-
default:
175-
g_printerr("Unknown urgency: %s\n", urgency_str);
176-
g_printerr("Assuming normal urgency\n");
177-
break;
243+
case 'l':
244+
case 'L':
245+
case '0': urgency = NOTIFY_URGENCY_LOW; break;
246+
case 'n':
247+
case 'N':
248+
case '1': urgency = NOTIFY_URGENCY_NORMAL; break;
249+
case 'c':
250+
case 'C':
251+
case '2': urgency = NOTIFY_URGENCY_CRITICAL; break;
252+
default:
253+
g_printerr("Unknown urgency: %s\n", urgency_str);
254+
g_printerr("Assuming normal urgency\n");
255+
break;
178256
}
179257
}
180258
}
@@ -209,8 +287,9 @@ void add_action(NotifyNotification *n, char *str)
209287
char *action = str;
210288
char *label = strchr(str, ',');
211289

212-
if (!label || *(label+1) == '\0') {
213-
g_printerr("Malformed action. Expected \"action,label\", got \"%s\"", str);
290+
if (!label || *(label + 1) == '\0') {
291+
g_printerr("Malformed action. Expected \"action,label\", got \"%s\"",
292+
str);
214293
return;
215294
}
216295

@@ -224,15 +303,17 @@ void add_hint(NotifyNotification *n, char *str)
224303
{
225304
char *type = str;
226305
char *name = strchr(str, ':');
227-
if (!name || *(name+1) == '\0') {
228-
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str);
306+
if (!name || *(name + 1) == '\0') {
307+
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"",
308+
str);
229309
return;
230310
}
231311
*name = '\0';
232312
name++;
233313
char *value = strchr(name, ':');
234-
if (!value || *(value+1) == '\0') {
235-
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str);
314+
if (!value || *(value + 1) == '\0') {
315+
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"",
316+
str);
236317
return;
237318
}
238319
*value = '\0';
@@ -249,19 +330,21 @@ void add_hint(NotifyNotification *n, char *str)
249330
if (h_byte < 0 || h_byte > 0xFF)
250331
g_printerr("Not a byte: \"%s\"", value);
251332
else
252-
notify_notification_set_hint_byte(n, name, (guchar) h_byte);
333+
notify_notification_set_hint_byte(n, name, (guchar)h_byte);
253334
} else
254-
g_printerr("Malformed hint. Expected a type of int, double, string or byte, got %s\n", type);
335+
g_printerr("Malformed hint. Expected a type of int, double, string or "
336+
"byte, got %s\n",
337+
type);
255338
}
256339

257340
int main(int argc, char *argv[])
258341
{
259342
setlocale(LC_ALL, "");
260343
g_set_prgname(argv[0]);
261344

262-
#if !GLIB_CHECK_VERSION(2,35,0)
263-
g_type_init();
264-
#endif
345+
#if !GLIB_CHECK_VERSION(2, 35, 0)
346+
g_type_init();
347+
#endif
265348

266349
parse_commandline(argc, argv);
267350

@@ -283,14 +366,14 @@ int main(int argc, char *argv[])
283366
GError *err = NULL;
284367

285368
if (raw_icon_path) {
286-
GdkPixbuf *raw_icon = gdk_pixbuf_new_from_file(raw_icon_path, &err);
369+
GdkPixbuf *raw_icon = gdk_pixbuf_new_from_file(raw_icon_path, &err);
287370

288-
if(err) {
289-
g_printerr("Unable to get raw icon: %s\n", err->message);
290-
die(1);
291-
}
371+
if (err) {
372+
g_printerr("Unable to get raw icon: %s\n", err->message);
373+
die(1);
374+
}
292375

293-
notify_notification_set_image_from_pixbuf(n, raw_icon);
376+
notify_notification_set_image_from_pixbuf(n, raw_icon);
294377
}
295378

296379
if (close_id > 0) {
@@ -324,7 +407,6 @@ int main(int argc, char *argv[])
324407
add_hint(n, hint_strs[i]);
325408
}
326409

327-
328410
notify_notification_show(n, &err);
329411
if (err) {
330412
g_printerr("Unable to send notification: %s\n", err->message);
@@ -339,7 +421,7 @@ int main(int argc, char *argv[])
339421
if (block || action_strs)
340422
g_main_loop_run(l);
341423

342-
g_object_unref(G_OBJECT (n));
424+
g_object_unref(G_OBJECT(n));
343425

344426
die(0);
345427
}

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
int main(int argc, char *argv[])
44
{
5-
return dunst_main(argc, argv);
5+
return dunst_main(argc, argv);
66
}
77
/* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */

0 commit comments

Comments
 (0)