Skip to content

Commit a935137

Browse files
committed
Add .clang-format and clang-format everything
Don't clang-format types.h. It is meant to be a copy of the type definitions in dwm.c and for some reason dwm.c uses tabs for that. Also don't format any files not added by the patch to avoid patch compatability issues.
1 parent 44cfa83 commit a935137

9 files changed

+198
-167
lines changed

.clang-format

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
Language: Cpp
3+
Standard: Cpp11
4+
BasedOnStyle: Google
5+
ColumnLimit: 80
6+
BreakBeforeBraces: Linux
7+
IndentWidth: 2
8+
AlwaysBreakAfterReturnType: AllDefinitions
9+
AlignEscapedNewlines: Right
10+
---

IPCClient.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
#include <sys/epoll.h>
1+
#include "IPCClient.h"
2+
23
#include <string.h>
4+
#include <sys/epoll.h>
35

4-
#include "IPCClient.h"
56
#include "util.h"
67

7-
IPCClient*
8+
IPCClient *
89
ipc_client_new(int fd)
910
{
10-
IPCClient* c = (IPCClient*)malloc(sizeof(IPCClient));
11+
IPCClient *c = (IPCClient *)malloc(sizeof(IPCClient));
1112

1213
if (c == NULL) return NULL;
1314

@@ -49,15 +50,12 @@ ipc_list_remove_client(IPCClientList *list, IPCClient *c)
4950
IPCClient *cprev = c->prev;
5051
IPCClient *cnext = c->next;
5152

52-
if (cprev != NULL)
53-
cprev->next = c->next;
54-
if (cnext != NULL)
55-
cnext->prev = c->prev;
56-
if (c == *list)
57-
*list = c->next;
53+
if (cprev != NULL) cprev->next = c->next;
54+
if (cnext != NULL) cnext->prev = c->prev;
55+
if (c == *list) *list = c->next;
5856
}
5957

60-
IPCClient*
58+
IPCClient *
6159
ipc_list_get_client(IPCClientList list, int fd)
6260
{
6361
for (IPCClient *c = list; c; c = c->next) {

IPCClient.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef IPC_CLIENT_H_
22
#define IPC_CLIENT_H_
33

4+
#include <stdio.h>
45
#include <stdlib.h>
56
#include <sys/epoll.h>
6-
#include <stdio.h>
77

88
typedef struct IPCClient IPCClient;
99
/**
10-
* This structure contains the details of an IPC Client and pointers for a linked
11-
* list
10+
* This structure contains the details of an IPC Client and pointers for a
11+
* linked list
1212
*/
1313
struct IPCClient {
1414
int fd;
@@ -22,7 +22,7 @@ struct IPCClient {
2222
IPCClient *prev;
2323
};
2424

25-
typedef IPCClient* IPCClientList;
25+
typedef IPCClient *IPCClientList;
2626

2727
/**
2828
* Allocate memory for new IPCClient with the specified file descriptor and
@@ -32,7 +32,7 @@ typedef IPCClient* IPCClientList;
3232
*
3333
* @return Address to allocated IPCClient struct
3434
*/
35-
IPCClient* ipc_client_new(int fd);
35+
IPCClient *ipc_client_new(int fd);
3636

3737
/**
3838
* Add an IPC Client to the specified list
@@ -56,7 +56,6 @@ void ipc_list_remove_client(IPCClientList *list, IPCClient *c);
5656
* @param list List to remove the client from
5757
* @param fd File descriptor of the IPCClient
5858
*/
59-
IPCClient* ipc_list_get_client(IPCClientList list, int fd);
60-
61-
#endif // IPC_CLIENT_H_
59+
IPCClient *ipc_list_get_client(IPCClientList list, int fd);
6260

61+
#endif // IPC_CLIENT_H_

dwm-msg.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
#include <ctype.h>
2+
#include <errno.h>
3+
#include <inttypes.h>
4+
#include <stdarg.h>
5+
#include <stdint.h>
16
#include <stdio.h>
27
#include <stdlib.h>
3-
#include <stdint.h>
4-
#include <inttypes.h>
58
#include <string.h>
6-
#include <unistd.h>
7-
#include <errno.h>
89
#include <sys/socket.h>
910
#include <sys/un.h>
11+
#include <unistd.h>
1012
#include <yajl/yajl_gen.h>
11-
#include <ctype.h>
12-
#include <stdarg.h>
1313

1414
#define IPC_MAGIC "DWM-IPC"
15-
#define IPC_MAGIC_ARR \
16-
{ 'D', 'W', 'M', '-', 'I', 'P', 'C' }
17-
#define IPC_MAGIC_LEN 7 // Not including null char
15+
// clang-format off
16+
#define IPC_MAGIC_ARR { 'D', 'W', 'M', '-', 'I', 'P', 'C' }
17+
// clang-format on
18+
#define IPC_MAGIC_LEN 7 // Not including null char
1819

1920
#define IPC_EVENT_TAG_CHANGE "tag_change_event"
2021
#define IPC_EVENT_CLIENT_FOCUS_CHANGE "client_focus_change_event"
@@ -123,8 +124,7 @@ recv_message(uint8_t *msg_type, uint32_t *reply_size, uint8_t **reply)
123124
free(*reply);
124125
return -2;
125126
} else if (n == -1) {
126-
if (errno == EINTR || errno == EAGAIN)
127-
continue;
127+
if (errno == EINTR || errno == EAGAIN) continue;
128128
free(*reply);
129129
return -1;
130130
}
@@ -145,8 +145,7 @@ read_socket(IPCMessageType *msg_type, uint32_t *msg_size, char **msg)
145145

146146
if (ret < 0) {
147147
// Try again (non-fatal error)
148-
if (ret == -1 && (errno == EINTR || errno == EAGAIN))
149-
continue;
148+
if (ret == -1 && (errno == EINTR || errno == EAGAIN)) continue;
150149

151150
fprintf(stderr, "Error receiving response from socket. ");
152151
fprintf(stderr, "The connection might have been lost.\n");
@@ -198,10 +197,7 @@ static int
198197
send_message(IPCMessageType msg_type, uint32_t msg_size, uint8_t *msg)
199198
{
200199
dwm_ipc_header_t header = {
201-
.magic = IPC_MAGIC_ARR,
202-
.size = msg_size,
203-
.type = msg_type
204-
};
200+
.magic = IPC_MAGIC_ARR, .size = msg_size, .type = msg_type};
205201

206202
size_t header_size = sizeof(dwm_ipc_header_t);
207203
size_t total_size = header_size + msg_size;
@@ -298,6 +294,7 @@ run_command(const char *name, char *args[], int argc)
298294
// "command": "<name>",
299295
// "args": [ ... ]
300296
// }
297+
// clang-format off
301298
YMAP(
302299
YSTR("command"); YSTR(name);
303300
YSTR("args"); YARR(
@@ -314,6 +311,7 @@ run_command(const char *name, char *args[], int argc)
314311
}
315312
)
316313
)
314+
// clang-format on
317315

318316
yajl_gen_get_buf(gen, &msg, &msg_size);
319317

@@ -364,9 +362,11 @@ get_dwm_client(Window win)
364362
// {
365363
// "client_window_id": "<win>"
366364
// }
365+
// clang-format off
367366
YMAP(
368367
YSTR("client_window_id"); YINT(win);
369368
)
369+
// clang-format on
370370

371371
yajl_gen_get_buf(gen, &msg, &msg_size);
372372

@@ -392,10 +392,12 @@ subscribe(const char *event)
392392
// "event": "<event>",
393393
// "action": "subscribe"
394394
// }
395+
// clang-format off
395396
YMAP(
396397
YSTR("event"); YSTR(event);
397398
YSTR("action"); YSTR("subscribe");
398399
)
400+
// clang-format on
399401

400402
yajl_gen_get_buf(gen, &msg, &msg_size);
401403

@@ -409,7 +411,7 @@ subscribe(const char *event)
409411
}
410412

411413
static void
412-
usage_error(const char *prog_name, const char* format, ...)
414+
usage_error(const char *prog_name, const char *format, ...)
413415
{
414416
va_list args;
415417
va_start(args, format);
@@ -440,10 +442,10 @@ print_usage(const char *name)
440442
puts(" get_dwm_client <window_id> Get dwm client proprties");
441443
puts("");
442444
puts(" subscribe [events...] Subscribe to specified events");
443-
puts(" Options: "IPC_EVENT_TAG_CHANGE",");
444-
puts(" "IPC_EVENT_LAYOUT_CHANGE",");
445-
puts(" "IPC_EVENT_CLIENT_FOCUS_CHANGE",");
446-
puts(" "IPC_EVENT_MONITOR_FOCUS_CHANGE);
445+
puts(" Options: " IPC_EVENT_TAG_CHANGE ",");
446+
puts(" " IPC_EVENT_LAYOUT_CHANGE ",");
447+
puts(" " IPC_EVENT_CLIENT_FOCUS_CHANGE ",");
448+
puts(" " IPC_EVENT_MONITOR_FOCUS_CHANGE);
447449
puts("");
448450
puts(" help Display this message");
449451
puts("");
@@ -452,10 +454,9 @@ print_usage(const char *name)
452454
int
453455
main(int argc, char *argv[])
454456
{
455-
const char* prog_name = argv[0];
457+
const char *prog_name = argv[0];
456458
// Need at least command argument
457-
if (argc < 2)
458-
usage_error(prog_name, "Expected an argument, got none");
459+
if (argc < 2) usage_error(prog_name, "Expected an argument, got none");
459460

460461
connect_to_socket();
461462
if (sock_fd == -1) {
@@ -468,8 +469,7 @@ main(int argc, char *argv[])
468469
print_usage(prog_name);
469470
return 0;
470471
} else if (strcmp(argv[i], "run_command") == 0) {
471-
if (++i >= argc)
472-
usage_error(prog_name, "No command specified");
472+
if (++i >= argc) usage_error(prog_name, "No command specified");
473473
// Command name
474474
char *command = argv[i];
475475
// Command arguments are everything after command name
@@ -499,8 +499,7 @@ main(int argc, char *argv[])
499499
return 0;
500500
} else if (strcmp(argv[i], "subscribe") == 0) {
501501
if (++i < argc) {
502-
for (int j = i; j < argc; j++)
503-
subscribe(argv[j]);
502+
for (int j = i; j < argc; j++) subscribe(argv[j]);
504503
} else
505504
usage_error(prog_name, "Expected event name");
506505
// Keep listening for events forever

ipc-client.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#include <unistd.h>
1010

1111
#define IPC_MAGIC "DWM-IPC"
12-
#define IPC_MAGIC_ARR \
13-
{ 'D', 'W', 'M', '-', 'I', 'P', 'C' }
14-
#define IPC_MAGIC_LEN 7 // Not including null char
12+
// clang-format off
13+
#define IPC_MAGIC_ARR { 'D', 'W', 'M', '-', 'I', 'P', 'C' }
14+
// clang-format on
15+
#define IPC_MAGIC_LEN 7 // Not including null char
1516

1617
typedef enum IPCMessageType {
1718
IPC_TYPE_RUN_COMMAND = 0,
@@ -40,9 +41,10 @@ typedef struct dwm_ipc_header {
4041
uint8_t type;
4142
} __attribute((packed)) dwm_ipc_header_t;
4243

43-
44-
static int ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size,
45-
uint8_t **reply) {
44+
static int
45+
ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size,
46+
uint8_t **reply)
47+
{
4648
uint32_t read_bytes = 0;
4749
const int32_t to_read = sizeof(dwm_ipc_header_t);
4850
char header[to_read];
@@ -103,8 +105,7 @@ static int ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size,
103105
} else if (n == -1) {
104106
// TODO: Should we return and wait for another epoll event?
105107
// This would require saving the partial read in some way.
106-
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
107-
continue;
108+
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue;
108109
free(*reply);
109110
return -1;
110111
}
@@ -115,7 +116,9 @@ static int ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size,
115116
return 0;
116117
}
117118

118-
int main(int argc, char *argv[]) {
119+
int
120+
main(int argc, char *argv[])
121+
{
119122
struct sockaddr_un addr;
120123

121124
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -138,16 +141,14 @@ int main(int argc, char *argv[]) {
138141
" \"args\": [ 1 ]\n"
139142
"}";*/
140143
char *msg =
141-
"{\n"
142-
" \"event\": \"layout_change_event\",\n"
143-
" \"action\": \"subscribe\"\n"
144-
"}";
144+
"{\n"
145+
" \"event\": \"layout_change_event\",\n"
146+
" \"action\": \"subscribe\"\n"
147+
"}";
145148

146-
dwm_ipc_header_t msg_header = {
147-
.magic = IPC_MAGIC_ARR,
148-
.type = IPC_TYPE_SUBSCRIBE,
149-
.size = strlen(msg) + 1
150-
};
149+
dwm_ipc_header_t msg_header = {.magic = IPC_MAGIC_ARR,
150+
.type = IPC_TYPE_SUBSCRIBE,
151+
.size = strlen(msg) + 1};
151152

152153
uint8_t buffer[sizeof(dwm_ipc_header_t) + msg_header.size];
153154
memcpy(buffer, &msg_header, sizeof(dwm_ipc_header_t));
@@ -167,4 +168,3 @@ int main(int argc, char *argv[]) {
167168
printf("%s\n", reply);
168169
}
169170
}
170-

0 commit comments

Comments
 (0)