23
23
24
24
/* Refresh interval in seconds */
25
25
const unsigned int refresh = 5 ;
26
+ const char * mpd_host = "/home/helm/Music/.mpd/socket" ;
27
+ const unsigned int mpd_port = 0 ; /* Unnecessary when used with UNIX socket. */
26
28
27
29
#define CUC (var ) (const unsigned char *)var
28
30
@@ -64,7 +66,9 @@ static int stdin_end_map(void *context);
64
66
static inline int round_float_to_int (float f );
65
67
static char * size_to_human_readable (double n );
66
68
static char * get_kernel_string (void );
69
+ static struct passwd * get_passwd (void );
67
70
static char * get_user (void );
71
+ static char * get_user_home (void );
68
72
static char * get_ram_usage (void );
69
73
static char * get_datetime (bool fuzzy );
70
74
static char * get_disk_free (const char * mount );
@@ -212,21 +216,39 @@ get_kernel_string(void)
212
216
return strdup (u .release );
213
217
}
214
218
219
+ static struct passwd *
220
+ get_passwd (void )
221
+ {
222
+ uid_t uid ;
223
+
224
+ uid = geteuid ();
225
+ return getpwuid (uid );
226
+ }
227
+
215
228
static char *
216
229
get_user (void )
217
230
{
218
- uid_t uid ;
219
231
struct passwd * pw ;
220
232
221
- uid = geteuid ();
222
- pw = getpwuid (uid );
223
- if (pw == NULL ) {
233
+ if (!(pw = get_passwd ())) {
224
234
return NULL ;
225
235
}
226
236
227
237
return strdup (pw -> pw_name );
228
238
}
229
239
240
+ static char *
241
+ get_user_home (void )
242
+ {
243
+ struct passwd * pw ;
244
+
245
+ if (!(pw = get_passwd ())) {
246
+ return NULL ;
247
+ }
248
+
249
+ return strdup (pw -> pw_dir );
250
+ }
251
+
230
252
static char *
231
253
get_ram_usage (void )
232
254
{
@@ -297,14 +319,13 @@ get_datetime(bool fuzzy)
297
319
return NULL ;
298
320
}
299
321
if (!strftime (secondarytimestring , sizeof (datestring ), "%H:%M" , now )) {
300
- printf ("foo\n" );
301
322
free (secondarytimestring );
302
323
return NULL ;
303
324
}
304
325
}
305
326
306
327
307
- size_t len = strnlen (datestring , sizeof (datestring )- 1 + strlen (secondarytimestring ) + strlen (" " ) + 1 ;
328
+ size_t len = strnlen (datestring , sizeof (datestring )- 1 ) + strlen (secondarytimestring ) + strlen (" " ) + 1 ;
308
329
timestring = malloc (len );
309
330
if (!timestring ) {
310
331
free (secondarytimestring );
@@ -370,7 +391,7 @@ get_uptime(void)
370
391
static struct mpd_connection *
371
392
mpd_connect (void )
372
393
{
373
- struct mpd_connection * connection = mpd_connection_new ("/home/helm/Music/.mpd/socket" , 0 , 0 );
394
+ struct mpd_connection * connection = mpd_connection_new (mpd_host , mpd_port , 0 );
374
395
if (connection == NULL ) {
375
396
return NULL ;
376
397
}
@@ -479,10 +500,17 @@ static char *
479
500
get_free_storage (void )
480
501
{
481
502
char * freestring ;
503
+ char * home_directory ;
482
504
char * home , * root ;
483
505
484
- home = get_disk_free ("/home/helm" );
506
+ home_directory = get_user_home ();
507
+ if (home_directory == NULL ) {
508
+ return NULL ;
509
+ }
510
+
511
+ home = get_disk_free (home_directory );
485
512
if (home == NULL ) {
513
+ free (home_directory );
486
514
return NULL ;
487
515
}
488
516
root = get_disk_free ("/" );
@@ -495,6 +523,7 @@ get_free_storage(void)
495
523
snprintf (freestring , 64 , "~/:%s /:%s" , home , root );
496
524
}
497
525
526
+ free (home_directory );
498
527
free (home );
499
528
free (root );
500
529
return freestring ;
@@ -665,7 +694,7 @@ main(void)
665
694
char input_event_buf [256 ];
666
695
667
696
ret = read (fds [0 ].fd , input_event_buf , sizeof (input_event_buf ));
668
- parse_click_event (buf , ret );
697
+ parse_click_event (input_event_buf , ret );
669
698
}
670
699
}
671
700
0 commit comments