summaryrefslogtreecommitdiff
path: root/src/wlclock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wlclock.c')
-rw-r--r--src/wlclock.c370
1 files changed, 184 insertions, 186 deletions
diff --git a/src/wlclock.c b/src/wlclock.c
index 3aed505..7257f3d 100644
--- a/src/wlclock.c
+++ b/src/wlclock.c
@@ -25,55 +25,54 @@
#include"surface.h"
#include"colour.h"
+struct Wlclock_context context = {0};
+
static void registry_handle_global (void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
{
- struct Wlclock *clock = (struct Wlclock *)data;
-
if (! strcmp(interface, wl_compositor_interface.name))
{
- clocklog(clock, 2, "[main] Get wl_compositor.\n");
- clock->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4);
+ clocklog(2, "[main] Get wl_compositor.\n");
+ context.compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4);
}
if (! strcmp(interface, wl_subcompositor_interface.name))
{
- clocklog(clock, 2, "[main] Get wl_subcompositor.\n");
- clock->subcompositor = wl_registry_bind(registry, name,
+ clocklog(2, "[main] Get wl_subcompositor.\n");
+ context.subcompositor = wl_registry_bind(registry, name,
&wl_subcompositor_interface, 1);
}
else if (! strcmp(interface, wl_shm_interface.name))
{
- clocklog(clock, 2, "[main] Get wl_shm.\n");
- clock->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
+ clocklog(2, "[main] Get wl_shm.\n");
+ context.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
}
else if (! strcmp(interface, zwlr_layer_shell_v1_interface.name))
{
- clocklog(clock, 2, "[main] Get zwlr_layer_shell_v1.\n");
- clock->layer_shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
+ clocklog(2, "[main] Get zwlr_layer_shell_v1.\n");
+ context.layer_shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
}
else if (! strcmp(interface, zxdg_output_manager_v1_interface.name))
{
- clocklog(clock, 2, "[main] Get zxdg_output_manager_v1.\n");
- clock->xdg_output_manager = wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, 3);
+ clocklog(2, "[main] Get zxdg_output_manager_v1.\n");
+ context.xdg_output_manager = wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, 3);
}
else if (! strcmp(interface, wl_output_interface.name))
{
- if (! create_output(data, registry, name, interface, version))
+ if (! create_output(registry, name, interface, version))
goto error;
}
return;
error:
- clock->loop = false;
- clock->ret = EXIT_FAILURE;
+ context.loop = false;
+ context.ret = EXIT_FAILURE;
}
static void registry_handle_global_remove (void *data,
struct wl_registry *registry, uint32_t name)
{
- struct Wlclock *clock = (struct Wlclock *)data;
- clocklog(clock, 1, "[main] Global remove.\n");
- destroy_output(get_output_from_global_name(clock, name));
+ clocklog(1, "[main] Global remove.\n");
+ destroy_output(get_output_from_global_name(name));
}
static const struct wl_registry_listener registry_listener = {
@@ -86,51 +85,51 @@ static bool capability_test (void *ptr, const char *name)
{
if ( ptr != NULL )
return true;
- clocklog(NULL, 0, "ERROR: Wayland compositor does not support %s.\n", name);
+ clocklog(0, "ERROR: Wayland compositor does not support %s.\n", name);
return false;
}
-static bool init_wayland (struct Wlclock *clock)
+static bool init_wayland (void)
{
- clocklog(clock, 1, "[main] Init Wayland.\n");
+ clocklog(1, "[main] Init Wayland.\n");
/* Connect to Wayland server. */
- clocklog(clock, 2, "[main] Connecting to server.\n");
- if ( NULL == (clock->display = wl_display_connect(NULL)) )
+ clocklog(2, "[main] Connecting to server.\n");
+ if ( NULL == (context.display = wl_display_connect(NULL)) )
{
- clocklog(NULL, 0, "ERROR: Can not connect to a Wayland server.\n");
+ clocklog(0, "ERROR: Can not connect to a Wayland server.\n");
return false;
}
/* Get registry and add listeners. */
- clocklog(clock, 2, "[main] Get wl_registry.\n");
- if ( NULL == (clock->registry = wl_display_get_registry(clock->display)) )
+ clocklog(2, "[main] Get wl_registry.\n");
+ if ( NULL == (context.registry = wl_display_get_registry(context.display)) )
{
- clocklog(NULL, 0, "ERROR: Can not get registry.\n");
+ clocklog(0, "ERROR: Can not get registry.\n");
return false;
}
- wl_registry_add_listener(clock->registry, &registry_listener, clock);
+ wl_registry_add_listener(context.registry, &registry_listener, NULL);
/* Allow registry listeners to catch up. */
- if ( wl_display_roundtrip(clock->display) == -1 )
+ if ( wl_display_roundtrip(context.display) == -1 )
{
- clocklog(NULL, 0, "ERROR: Roundtrip failed.\n");
+ clocklog(0, "ERROR: Roundtrip failed.\n");
return false;
}
/* Testing compatibilities. */
- if (! capability_test(clock->compositor, "wl_compositor"))
+ if (! capability_test(context.compositor, "wl_compositor"))
return false;
- if (! capability_test(clock->shm, "wl_shm"))
+ if (! capability_test(context.shm, "wl_shm"))
return false;
- if (! capability_test(clock->layer_shell, "zwlr_layer_shell"))
+ if (! capability_test(context.layer_shell, "zwlr_layer_shell"))
return false;
- if (! capability_test(clock->xdg_output_manager, "xdg_output_manager"))
+ if (! capability_test(context.xdg_output_manager, "xdg_output_manager"))
return false;
- clocklog(clock, 2, "[main] Catching up on output configuration.\n");
+ clocklog(2, "[main] Catching up on output configuration.\n");
struct Wlclock_output *op;
- wl_list_for_each(op, &clock->outputs, link)
+ wl_list_for_each(op, &context.outputs, link)
if ( ! op->configured && ! configure_output(op) )
return false;
@@ -138,27 +137,27 @@ static bool init_wayland (struct Wlclock *clock)
}
/* Finish him! */
-static void finish_wayland (struct Wlclock *clock)
+static void finish_wayland (void)
{
- if ( clock->display == NULL )
+ if ( context.display == NULL )
return;
- clocklog(clock, 1, "[main] Finish Wayland.\n");
+ clocklog(1, "[main] Finish Wayland.\n");
- destroy_all_outputs(clock);
+ destroy_all_outputs();
- clocklog(clock, 2, "[main] Destroying Wayland objects.\n");
- if ( clock->layer_shell != NULL )
- zwlr_layer_shell_v1_destroy(clock->layer_shell);
- if ( clock->compositor != NULL )
- wl_compositor_destroy(clock->compositor);
- if ( clock->shm != NULL )
- wl_shm_destroy(clock->shm);
- if ( clock->registry != NULL )
- wl_registry_destroy(clock->registry);
+ clocklog(2, "[main] Destroying Wayland objects.\n");
+ if ( context.layer_shell != NULL )
+ zwlr_layer_shell_v1_destroy(context.layer_shell);
+ if ( context.compositor != NULL )
+ wl_compositor_destroy(context.compositor);
+ if ( context.shm != NULL )
+ wl_shm_destroy(context.shm);
+ if ( context.registry != NULL )
+ wl_registry_destroy(context.registry);
- clocklog(clock, 2, "[main] Diconnecting from server.\n");
- wl_display_disconnect(clock->display);
+ clocklog(2, "[main] Diconnecting from server.\n");
+ wl_display_disconnect(context.display);
}
static int count_args (int index, int argc, char *argv[])
@@ -175,7 +174,7 @@ static int count_args (int index, int argc, char *argv[])
return args;
}
-static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
+static bool handle_command_flags (int argc, char *argv[])
{
enum
{
@@ -239,8 +238,8 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
" --namespace Namespace of the layer surface.\n"
" --no-input Let inputs surface pass trough the layer surface.\n"
" --output The output which the clock will be displayed.\n"
- " --position Set the position of the clock.\n"
- " --size Size of the clock.\n"
+ " --position Set the position of the context.\n"
+ " --size Size of the context.\n"
" --snap Let the hour hand snap to the next position instead of slowly progressing.\n"
"\n";
@@ -251,44 +250,44 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
{
case 'h':
fputs(usage, stderr);
- clock->ret = EXIT_SUCCESS;
+ context.ret = EXIT_SUCCESS;
return false;
case 'v':
- clock->verbosity++;
+ context.verbosity++;
break;
case 'V':
fputs("wlclock version " VERSION "\n", stderr);
- clock->ret = EXIT_SUCCESS;
+ context.ret = EXIT_SUCCESS;
return false;
case POSITION:
if (! strcmp(optarg, "center"))
- clock->anchor = 0;
+ context.anchor = 0;
else if (! strcmp(optarg, "top"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
else if (! strcmp(optarg, "right"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
else if (! strcmp(optarg, "bottom"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
else if (! strcmp(optarg, "left"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
else if (! strcmp(optarg, "top-left"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
else if (! strcmp(optarg, "top-right"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
else if (! strcmp(optarg, "bottom-left"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
else if (! strcmp(optarg, "bottom-right"))
- clock->anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
+ context.anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
else
{
- clocklog(NULL, 0, "ERROR: Unrecognized position \"%s\".\n"
+ clocklog(0, "ERROR: Unrecognized position \"%s\".\n"
"INFO: Possible positisions are 'center', "
"'top', 'right', 'bottom', 'left', "
"'top-right', 'top-left', 'bottom-right', 'bottom-left'.\n",
@@ -299,76 +298,76 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
break;
case BACKGROUND_COLOUR:
- if (! colour_from_string(&clock->background_colour, optarg))
+ if (! colour_from_string(&context.background_colour, optarg))
return false;
break;
case BORDER_COLOUR:
- if (! colour_from_string(&clock->border_colour, optarg))
+ if (! colour_from_string(&context.border_colour, optarg))
return false;
break;
case BORDER_SIZE:
args = count_args(optind, argc, argv);
if ( args == 1 )
- clock->border_top = clock->border_right =
- clock->border_bottom = clock->border_left =
+ context.border_top = context.border_right =
+ context.border_bottom = context.border_left =
atoi(optarg);
else if ( args == 4 )
{
- clock->border_top = atoi(argv[optind-1]);
- clock->border_right = atoi(argv[optind]);
- clock->border_bottom = atoi(argv[optind+1]);
- clock->border_left = atoi(argv[optind+2]);
+ context.border_top = atoi(argv[optind-1]);
+ context.border_right = atoi(argv[optind]);
+ context.border_bottom = atoi(argv[optind+1]);
+ context.border_left = atoi(argv[optind+2]);
optind += 3; /* Tell getopt() to skip three argv fields. */
}
else
{
- clocklog(NULL, 0, "ERROR: Border configuration "
+ clocklog(0, "ERROR: Border configuration "
"requires one or four arguments.\n");
return false;
}
- if ( clock->border_top < 0 || clock->border_right < 0
- || clock->border_bottom < 0 || clock->border_left < 0 )
+ if ( context.border_top < 0 || context.border_right < 0
+ || context.border_bottom < 0 || context.border_left < 0 )
{
- clocklog(NULL, 0, "ERROR: Borders may not be smaller than zero.\n");
+ clocklog(0, "ERROR: Borders may not be smaller than zero.\n");
return false;
}
break;
case CLOCK_COLOUR:
- if (! colour_from_string(&clock->clock_colour, optarg))
+ if (! colour_from_string(&context.clock_colour, optarg))
return false;
break;
case MARKING_WIDTH:
- clock->marking_width = atoi(optarg);
- if ( clock->marking_width < 0 )
+ context.marking_width = atoi(optarg);
+ if ( context.marking_width < 0 )
{
- clocklog(NULL, 0, "ERROR: Marking width may not be smaller than zero.\n");
+ clocklog(0, "ERROR: Marking width may not be smaller than zero.\n");
return false;
}
break;
case HAND_WIDTH:
- clock->hand_width = atoi(optarg);
- if ( clock->hand_width < 0 )
+ context.hand_width = atoi(optarg);
+ if ( context.hand_width < 0 )
{
- clocklog(NULL, 0, "ERROR: Hand width may not be smaller than zero.\n");
+ clocklog(0, "ERROR: Hand width may not be smaller than zero.\n");
return false;
}
break;
case EXCLUSIVE_ZONE:
if (is_boolean_true(optarg))
- clock->exclusive_zone = 1;
+ context.exclusive_zone = 1;
else if (is_boolean_false(optarg))
- clock->exclusive_zone = 0;
+ context.exclusive_zone = 0;
else if (! strcmp(optarg, "stationary"))
- clock->exclusive_zone = -1;
+ context.exclusive_zone = -1;
else
{
- clocklog(NULL, 0, "ERROR: Unrecognized exclusive zone option \"%s\".\n"
+ clocklog(0, "ERROR: Unrecognized exclusive zone option \"%s\".\n"
"INFO: Possible options are 'true', "
"'false' and 'stationary'.\n", optarg);
return false;
@@ -377,16 +376,16 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
case LAYER:
if (! strcmp(optarg, "overlay"))
- clock->layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
+ context.layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
else if (! strcmp(optarg, "top"))
- clock->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
+ context.layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
else if (! strcmp(optarg, "bottom"))
- clock->layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
+ context.layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
else if (! strcmp(optarg, "background"))
- clock->layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
+ context.layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
else
{
- clocklog(NULL, 0, "ERROR: Unrecognized layer \"%s\".\n"
+ clocklog(0, "ERROR: Unrecognized layer \"%s\".\n"
"INFO: Possible layers are 'overlay', "
"'top', 'bottom', and 'background'.\n", optarg);
return false;
@@ -396,84 +395,84 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
case MARGIN:
args = count_args(optind, argc, argv);
if ( args == 1 )
- clock->margin_top = clock->margin_right =
- clock->margin_bottom = clock->margin_left =
+ context.margin_top = context.margin_right =
+ context.margin_bottom = context.margin_left =
atoi(optarg);
else if ( args == 4 )
{
- clock->margin_top = atoi(argv[optind-1]);
- clock->margin_right = atoi(argv[optind]);
- clock->margin_bottom = atoi(argv[optind+1]);
- clock->margin_left = atoi(argv[optind+2]);
+ context.margin_top = atoi(argv[optind-1]);
+ context.margin_right = atoi(argv[optind]);
+ context.margin_bottom = atoi(argv[optind+1]);
+ context.margin_left = atoi(argv[optind+2]);
optind += 3; /* Tell getopt() to skip three argv fields. */
}
else
{
- clocklog(NULL, 0, "ERROR: Margin configuration "
+ clocklog(0, "ERROR: Margin configuration "
"requires one or four arguments.\n");
return false;
}
- if ( clock->margin_top < 0 || clock->margin_right < 0
- || clock->margin_bottom < 0 || clock->margin_left < 0 )
+ if ( context.margin_top < 0 || context.margin_right < 0
+ || context.margin_bottom < 0 || context.margin_left < 0 )
{
- clocklog(NULL, 0, "ERROR: Margins may not be smaller than zero.\n");
+ clocklog(0, "ERROR: Margins may not be smaller than zero.\n");
return false;
}
break;
case NAMEPSACE:
- set_string(&clock->namespace, optarg);
+ set_string(&context.namespace, optarg);
break;
case NO_INPUT:
- clock->input = false;
+ context.input = false;
break;
case SNAP:
- clock->snap = true;
+ context.snap = true;
break;
case OUTPUT:
if ( ! strcmp("all", optarg) || ! strcmp("*", optarg) )
- free_if_set(clock->output);
+ free_if_set(context.output);
else
- set_string(&clock->output, optarg);
+ set_string(&context.output, optarg);
break;
case CORNER_RADIUS:
args = count_args(optind, argc, argv);
if ( args == 1 )
- clock->radius_top_left = clock->radius_top_right =
- clock->radius_bottom_right = clock->radius_bottom_left =
+ context.radius_top_left = context.radius_top_right =
+ context.radius_bottom_right = context.radius_bottom_left =
atoi(optarg);
else if ( args == 4 )
{
- clock->radius_top_left = atoi(argv[optind-1]);
- clock->radius_top_right = atoi(argv[optind]);
- clock->radius_bottom_right = atoi(argv[optind+1]);
- clock->radius_bottom_left = atoi(argv[optind+2]);
+ context.radius_top_left = atoi(argv[optind-1]);
+ context.radius_top_right = atoi(argv[optind]);
+ context.radius_bottom_right = atoi(argv[optind+1]);
+ context.radius_bottom_left = atoi(argv[optind+2]);
optind += 3; /* Tell getopt() to skip three argv fields. */
}
else
{
- clocklog(NULL, 0, "ERROR: Radius configuration "
+ clocklog(0, "ERROR: Radius configuration "
"requires one or four arguments.\n");
return false;
}
- if ( clock->radius_top_left < 0 || clock->radius_top_right < 0
- || clock->radius_bottom_right < 0 || clock->radius_bottom_left < 0 )
+ if ( context.radius_top_left < 0 || context.radius_top_right < 0
+ || context.radius_bottom_right < 0 || context.radius_bottom_left < 0 )
{
- clocklog(NULL, 0, "ERROR: Radii may not be smaller than zero.\n");
+ clocklog(0, "ERROR: Radii may not be smaller than zero.\n");
return false;
}
break;
case SIZE:
- clock->dimensions.center_size = atoi(optarg);
- if ( clock->dimensions.center_size <= 10 )
+ context.dimensions.center_size = atoi(optarg);
+ if ( context.dimensions.center_size <= 10 )
{
- clocklog(NULL, 0, "ERROR: Unreasonably small size \"%d\".\n",
- clock->dimensions.center_size);
+ clocklog(0, "ERROR: Unreasonably small size \"%d\".\n",
+ context.dimensions.center_size);
return false;
}
break;
@@ -492,10 +491,10 @@ static time_t get_timeout (void)
return ((now / 60 * 60 ) + 60 - now) * 1000;
}
-static void clock_run (struct Wlclock *clock)
+static void clock_run ()
{
- clocklog(clock, 1, "[main] Starting loop.\n");
- clock->ret = EXIT_SUCCESS;
+ clocklog(1, "[main] Starting loop.\n");
+ context.ret = EXIT_SUCCESS;
struct pollfd fds[2] = { 0 };
size_t wayland_fd = 0;
@@ -507,9 +506,9 @@ static void clock_run (struct Wlclock *clock)
#endif
fds[wayland_fd].events = POLLIN;
- if ( -1 == (fds[wayland_fd].fd = wl_display_get_fd(clock->display)) )
+ if ( -1 == (fds[wayland_fd].fd = wl_display_get_fd(context.display)) )
{
- clocklog(NULL, 0, "ERROR: Unable to open Wayland display fd.\n");
+ clocklog(0, "ERROR: Unable to open Wayland display fd.\n");
goto error;
}
@@ -524,26 +523,26 @@ static void clock_run (struct Wlclock *clock)
sigaddset(&mask, SIGUSR2);
if ( sigprocmask(SIG_BLOCK, &mask, NULL) == -1 )
{
- clocklog(NULL, 0, "ERROR: sigprocmask() failed.\n");
+ clocklog(0, "ERROR: sigprocmask() failed.\n");
goto error;
}
fds[signal_fd].events = POLLIN;
if ( -1 == (fds[signal_fd].fd = signalfd(-1, &mask, 0)) )
{
- clocklog(NULL, 0, "ERROR: Unable to open signal fd.\n"
+ clocklog(0, "ERROR: Unable to open signal fd.\n"
"ERROR: signalfd: %s\n", strerror(errno));
goto error;
}
#endif
- while (clock->loop)
+ while (context.loop)
{
/* Flush Wayland events. */
errno = 0;
do {
- if ( wl_display_flush(clock->display) == 1 && errno != EAGAIN )
+ if ( wl_display_flush(context.display) == 1 && errno != EAGAIN )
{
- clocklog(NULL, 0, "ERROR: wl_display_flush: %s\n",
+ clocklog(0, "ERROR: wl_display_flush: %s\n",
strerror(errno));
break;
}
@@ -553,24 +552,24 @@ static void clock_run (struct Wlclock *clock)
if ( ret == 0 ) /* Timeout -> update clock hands. */
{
- update_all_hands(clock);
+ update_all_hands();
continue;
}
else if ( ret < 0 )
{
- clocklog(NULL, 0, "ERROR: poll: %s\n", strerror(errno));
+ clocklog(0, "ERROR: poll: %s\n", strerror(errno));
continue;
}
/* Wayland events */
- if ( fds[wayland_fd].revents & POLLIN && wl_display_dispatch(clock->display) == -1 )
+ if ( fds[wayland_fd].revents & POLLIN && wl_display_dispatch(context.display) == -1 )
{
- clocklog(NULL, 0, "ERROR: wl_display_flush: %s\n", strerror(errno));
+ clocklog(0, "ERROR: wl_display_flush: %s\n", strerror(errno));
goto error;
}
- if ( fds[wayland_fd].revents & POLLOUT && wl_display_flush(clock->display) == -1 )
+ if ( fds[wayland_fd].revents & POLLOUT && wl_display_flush(context.display) == -1 )
{
- clocklog(NULL, 0, "ERROR: wl_display_flush: %s\n", strerror(errno));
+ clocklog(0, "ERROR: wl_display_flush: %s\n", strerror(errno));
goto error;
}
@@ -581,24 +580,24 @@ static void clock_run (struct Wlclock *clock)
if ( read(fds[signal_fd].fd, &fdsi, sizeof(struct signalfd_siginfo))
!= sizeof(struct signalfd_siginfo) )
{
- clocklog(NULL, 0, "ERROR: Can not read signal info.\n");
+ clocklog(0, "ERROR: Can not read signal info.\n");
goto error;
}
if ( fdsi.ssi_signo == SIGINT || fdsi.ssi_signo == SIGQUIT || fdsi.ssi_signo == SIGTERM )
{
- clocklog(clock, 1, "[main] Received SIGINT, SIGQUIT or SIGTERM; Exiting.\n");
+ clocklog(1, "[main] Received SIGINT, SIGQUIT or SIGTERM; Exiting.\n");
goto exit;
}
else if ( fdsi.ssi_signo == SIGUSR1 || fdsi.ssi_signo == SIGUSR2 )
- clocklog(clock, 1, "[main] Received SIGUSR; Ignoring.\n");
+ clocklog(1, "[main] Received SIGUSR; Ignoring.\n");
}
#endif
}
return;
error:
- clock->ret = EXIT_FAILURE;
+ context.ret = EXIT_FAILURE;
#ifdef HANDLE_SIGNALS
exit:
if ( fds[signal_fd].fd != -1 )
@@ -611,57 +610,56 @@ exit:
int main (int argc, char *argv[])
{
- struct Wlclock clock = { 0 };
- wl_list_init(&clock.outputs);
- clock.ret = EXIT_FAILURE;
- clock.loop = true;
- clock.verbosity = 0;
-
- clock.dimensions.center_size = 165; /* About the size of xclock, at least on my machine. */
- clock.exclusive_zone = -1;
- clock.input = true;
- clock.snap = false;
- clock.layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
- clock.anchor = 0; /* Center */
- set_string(&clock.namespace, "wlclock");
- clock.border_bottom = clock.border_top
- = clock.border_left = clock.border_right = 1;
- clock.radius_bottom_left = clock.radius_bottom_right
- = clock.radius_top_left = clock.radius_top_right = 0;
- clock.margin_bottom = clock.margin_top
- = clock.margin_left = clock.margin_right = 0;
- clock.marking_width = 1;
- clock.hand_width = 0;
- colour_from_string(&clock.background_colour, "#FFFFFF");
- colour_from_string(&clock.border_colour, "#000000");
- colour_from_string(&clock.clock_colour, "#000000");
-
- if (! handle_command_flags(&clock, argc, argv))
+ wl_list_init(&context.outputs);
+ context.ret = EXIT_FAILURE;
+ context.loop = true;
+ context.verbosity = 0;
+
+ context.dimensions.center_size = 165; /* About the size of xclock, at least on my machine. */
+ context.exclusive_zone = -1;
+ context.input = true;
+ context.snap = false;
+ context.layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
+ context.anchor = 0; /* Center */
+ set_string(&context.namespace, "wlclock");
+ context.border_bottom = context.border_top
+ = context.border_left = context.border_right = 1;
+ context.radius_bottom_left = context.radius_bottom_right
+ = context.radius_top_left = context.radius_top_right = 0;
+ context.margin_bottom = context.margin_top
+ = context.margin_left = context.margin_right = 0;
+ context.marking_width = 1;
+ context.hand_width = 0;
+ colour_from_string(&context.background_colour, "#FFFFFF");
+ colour_from_string(&context.border_colour, "#000000");
+ colour_from_string(&context.clock_colour, "#000000");
+
+ if (! handle_command_flags(argc, argv))
goto exit;
- clock.dimensions.w = clock.dimensions.center_size
- + clock.border_left + clock.border_right;
- clock.dimensions.h = clock.dimensions.center_size
- + clock.border_top + clock.border_bottom;
- clock.dimensions.center_x = clock.border_left;
- clock.dimensions.center_y = clock.border_top;
+ context.dimensions.w = context.dimensions.center_size
+ + context.border_left + context.border_right;
+ context.dimensions.h = context.dimensions.center_size
+ + context.border_top + context.border_bottom;
+ context.dimensions.center_x = context.border_left;
+ context.dimensions.center_y = context.border_top;
- clocklog(&clock, 1, "[main] wlclock: version=%s\n"
+ clocklog(1, "[main] wlclock: version=%s\n"
"[main] Default dimensions: size=%d cx=%d cy=%d w=%d h=%d\n",
- VERSION, clock.dimensions.center_size,
- clock.dimensions.center_x, clock.dimensions.center_y,
- clock.dimensions.w, clock.dimensions.h);
+ VERSION, context.dimensions.center_size,
+ context.dimensions.center_x, context.dimensions.center_y,
+ context.dimensions.w, context.dimensions.h);
- if (! init_wayland(&clock))
+ if (! init_wayland())
goto exit;
- clock_run(&clock);
+ clock_run();
exit:
- finish_wayland(&clock);
- free_if_set(clock.output);
- free_if_set(clock.namespace);
- return clock.ret;
+ finish_wayland();
+ free_if_set(context.output);
+ free_if_set(context.namespace);
+ return context.ret;
}