1
+ #include <ctype.h>
2
+ #include <errno.h>
3
+ #include <inttypes.h>
4
+ #include <stdarg.h>
5
+ #include <stdint.h>
1
6
#include <stdio.h>
2
7
#include <stdlib.h>
3
- #include <stdint.h>
4
- #include <inttypes.h>
5
8
#include <string.h>
6
- #include <unistd.h>
7
- #include <errno.h>
8
9
#include <sys/socket.h>
9
10
#include <sys/un.h>
11
+ #include <unistd.h>
10
12
#include <yajl/yajl_gen.h>
11
- #include <ctype.h>
12
- #include <stdarg.h>
13
13
14
14
#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
18
19
19
20
#define IPC_EVENT_TAG_CHANGE "tag_change_event"
20
21
#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)
123
124
free (* reply );
124
125
return -2 ;
125
126
} else if (n == -1 ) {
126
- if (errno == EINTR || errno == EAGAIN )
127
- continue ;
127
+ if (errno == EINTR || errno == EAGAIN ) continue ;
128
128
free (* reply );
129
129
return -1 ;
130
130
}
@@ -145,8 +145,7 @@ read_socket(IPCMessageType *msg_type, uint32_t *msg_size, char **msg)
145
145
146
146
if (ret < 0 ) {
147
147
// Try again (non-fatal error)
148
- if (ret == -1 && (errno == EINTR || errno == EAGAIN ))
149
- continue ;
148
+ if (ret == -1 && (errno == EINTR || errno == EAGAIN )) continue ;
150
149
151
150
fprintf (stderr , "Error receiving response from socket. " );
152
151
fprintf (stderr , "The connection might have been lost.\n" );
@@ -198,10 +197,7 @@ static int
198
197
send_message (IPCMessageType msg_type , uint32_t msg_size , uint8_t * msg )
199
198
{
200
199
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 };
205
201
206
202
size_t header_size = sizeof (dwm_ipc_header_t );
207
203
size_t total_size = header_size + msg_size ;
@@ -298,6 +294,7 @@ run_command(const char *name, char *args[], int argc)
298
294
// "command": "<name>",
299
295
// "args": [ ... ]
300
296
// }
297
+ // clang-format off
301
298
YMAP (
302
299
YSTR ("command" ); YSTR (name );
303
300
YSTR ("args" ); YARR (
@@ -314,6 +311,7 @@ run_command(const char *name, char *args[], int argc)
314
311
}
315
312
)
316
313
)
314
+ // clang-format on
317
315
318
316
yajl_gen_get_buf (gen , & msg , & msg_size );
319
317
@@ -364,9 +362,11 @@ get_dwm_client(Window win)
364
362
// {
365
363
// "client_window_id": "<win>"
366
364
// }
365
+ // clang-format off
367
366
YMAP (
368
367
YSTR ("client_window_id" ); YINT (win );
369
368
)
369
+ // clang-format on
370
370
371
371
yajl_gen_get_buf (gen , & msg , & msg_size );
372
372
@@ -392,10 +392,12 @@ subscribe(const char *event)
392
392
// "event": "<event>",
393
393
// "action": "subscribe"
394
394
// }
395
+ // clang-format off
395
396
YMAP (
396
397
YSTR ("event" ); YSTR (event );
397
398
YSTR ("action" ); YSTR ("subscribe" );
398
399
)
400
+ // clang-format on
399
401
400
402
yajl_gen_get_buf (gen , & msg , & msg_size );
401
403
@@ -409,7 +411,7 @@ subscribe(const char *event)
409
411
}
410
412
411
413
static void
412
- usage_error (const char * prog_name , const char * format , ...)
414
+ usage_error (const char * prog_name , const char * format , ...)
413
415
{
414
416
va_list args ;
415
417
va_start (args , format );
@@ -440,10 +442,10 @@ print_usage(const char *name)
440
442
puts (" get_dwm_client <window_id> Get dwm client proprties" );
441
443
puts ("" );
442
444
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 );
447
449
puts ("" );
448
450
puts (" help Display this message" );
449
451
puts ("" );
@@ -452,10 +454,9 @@ print_usage(const char *name)
452
454
int
453
455
main (int argc , char * argv [])
454
456
{
455
- const char * prog_name = argv [0 ];
457
+ const char * prog_name = argv [0 ];
456
458
// 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" );
459
460
460
461
connect_to_socket ();
461
462
if (sock_fd == -1 ) {
@@ -468,8 +469,7 @@ main(int argc, char *argv[])
468
469
print_usage (prog_name );
469
470
return 0 ;
470
471
} 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" );
473
473
// Command name
474
474
char * command = argv [i ];
475
475
// Command arguments are everything after command name
@@ -499,8 +499,7 @@ main(int argc, char *argv[])
499
499
return 0 ;
500
500
} else if (strcmp (argv [i ], "subscribe" ) == 0 ) {
501
501
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 ]);
504
503
} else
505
504
usage_error (prog_name , "Expected event name" );
506
505
// Keep listening for events forever
0 commit comments