summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstderr64 <stderr64@null.net>2026-01-25 20:21:29 +0200
committerstderr64 <stderr64@null.net>2026-01-25 20:21:29 +0200
commitedd4da8c8ba0b8e3da7a144d89a299896f62c473 (patch)
treeee779f82aa7154f4e16816bad1cd5650173a6c7d
parent16d1d814fb686a78565e6be66f02de383fc039bd (diff)
downloaddwmtimestatus-edd4da8c8ba0b8e3da7a144d89a299896f62c473.tar.gz
dwmtimestatus-edd4da8c8ba0b8e3da7a144d89a299896f62c473.tar.zst
Even better initialization of structs
-rw-r--r--dwmtimestatus.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/dwmtimestatus.c b/dwmtimestatus.c
index 044e9e7..d61b074 100644
--- a/dwmtimestatus.c
+++ b/dwmtimestatus.c
@@ -22,13 +22,8 @@ struct status{
};
struct sigaction *s_act = NULL;
-struct status current_status = {0};
-XTextProperty status_props = {
- .value = (unsigned char*)&current_status.status,
- .encoding = XA_STRING,
- .format = 8,
- .nitems = 0
-};
+struct status *current_status_ptr = NULL;
+XTextProperty *status_props_ptr = NULL;
void sighandler( int si_code, siginfo_t *si_info, void *si_adr ){
int exit_status = EXIT_SUCCESS;
@@ -40,13 +35,12 @@ void sighandler( int si_code, siginfo_t *si_info, void *si_adr ){
{
fprintf( stdout, "Received signal %i, exiting\n", si_code );
}
- if ( current_status.dpy != NULL ){
- if ( XCloseDisplay(current_status.dpy) == BadGC )
+ if ( current_status_ptr->dpy != NULL ){
+ if ( XCloseDisplay(current_status_ptr->dpy) == BadGC )
fputs( "XCloseDisplay returned BadGC error\n", stderr );
- current_status.dpy = NULL;
+ current_status_ptr->dpy = NULL;
}
- memset( (void*)&current_status, 0, sizeof(struct status) );
- memset( (void*)&status_props, 0, sizeof(XTextProperty) );
+ memset( (void*)status_props_ptr, 0, sizeof(*status_props_ptr) );
free( s_act );
s_act = NULL;
exit( exit_status );
@@ -107,7 +101,14 @@ int main( int argc, char **args ){
assert( sigaction(SIGINT, (const struct sigaction*)s_act, NULL) != -1 );
assert( sigaction(SIGTERM, (const struct sigaction*)s_act, NULL) != -1 );
assert( sigaction(SIGPIPE, (const struct sigaction*)s_act, NULL) != -1 );
+ struct status current_status = {0};
memset( (void*)&current_status, 0, sizeof(struct status) );
+ XTextProperty status_props = {
+ .value = (unsigned char*)&current_status.status,
+ .encoding = XA_STRING,
+ .format = 8,
+ .nitems = 0
+ };
const char *optstring = "i:d:f:";
int opt_char = 0;
while ( (opt_char = getopt(argc, args, optstring)) != -1 ){
@@ -129,6 +130,8 @@ int main( int argc, char **args ){
}
}
current_status.root = DefaultRootWindow( current_status.dpy );
+ current_status_ptr = &current_status;
+ status_props_ptr = &status_props;
status_update_loop( &current_status, &status_props );
exit( EXIT_SUCCESS );
}