aboutsummaryrefslogtreecommitdiffstats
path: root/swaylock/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/main.c')
-rw-r--r--swaylock/main.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index d1384c6f..86dfd577 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -21,6 +21,7 @@
21#include "pool-buffer.h" 21#include "pool-buffer.h"
22#include "cairo.h" 22#include "cairo.h"
23#include "log.h" 23#include "log.h"
24#include "loop.h"
24#include "readline.h" 25#include "readline.h"
25#include "stringop.h" 26#include "stringop.h"
26#include "util.h" 27#include "util.h"
@@ -633,13 +634,9 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
633 } 634 }
634 break; 635 break;
635 case 'v': 636 case 'v':
636#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE 637 fprintf(stdout, "swaylock version " SWAY_VERSION "\n");
637 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", 638 exit(EXIT_SUCCESS);
638 SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); 639 break;
639#else
640 fprintf(stdout, "version unknown\n");
641#endif
642 return 1;
643 case LO_BS_HL_COLOR: 640 case LO_BS_HL_COLOR:
644 if (state) { 641 if (state) {
645 state->args.colors.bs_highlight = parse_color(optarg); 642 state->args.colors.bs_highlight = parse_color(optarg);
@@ -844,6 +841,10 @@ static int load_config(char *path, struct swaylock_state *state,
844 841
845static struct swaylock_state state; 842static struct swaylock_state state;
846 843
844static void display_in(int fd, short mask, void *data) {
845 wl_display_dispatch(state.display);
846}
847
847int main(int argc, char **argv) { 848int main(int argc, char **argv) {
848 wlr_log_init(WLR_DEBUG, NULL); 849 wlr_log_init(WLR_DEBUG, NULL);
849 initialize_pw_backend(); 850 initialize_pw_backend();
@@ -903,7 +904,11 @@ int main(int argc, char **argv) {
903 wl_list_init(&state.surfaces); 904 wl_list_init(&state.surfaces);
904 state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); 905 state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
905 state.display = wl_display_connect(NULL); 906 state.display = wl_display_connect(NULL);
906 assert(state.display); 907 if (!state.display) {
908 sway_abort("Unable to connect to the compositor. "
909 "If your compositor is running, check or set the "
910 "WAYLAND_DISPLAY environment variable.");
911 }
907 912
908 struct wl_registry *registry = wl_display_get_registry(state.display); 913 struct wl_registry *registry = wl_display_get_registry(state.display);
909 wl_registry_add_listener(registry, &registry_listener, &state); 914 wl_registry_add_listener(registry, &registry_listener, &state);
@@ -946,9 +951,14 @@ int main(int argc, char **argv) {
946 daemonize(); 951 daemonize();
947 } 952 }
948 953
954 state.eventloop = loop_create();
955 loop_add_fd(state.eventloop, wl_display_get_fd(state.display), POLL_IN,
956 display_in, NULL);
957
949 state.run_display = true; 958 state.run_display = true;
950 while (wl_display_dispatch(state.display) != -1 && state.run_display) { 959 while (state.run_display) {
951 // This space intentionally left blank 960 wl_display_flush(state.display);
961 loop_poll(state.eventloop);
952 } 962 }
953 963
954 free(state.args.font); 964 free(state.args.font);