aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/swaybar/bar.h15
-rw-r--r--include/swaybar/status_line.h4
-rw-r--r--sway/tree/container.c17
-rw-r--r--swaybar/bar.c17
-rw-r--r--swaybar/i3bar.c32
-rw-r--r--swaybar/render.c4
-rw-r--r--swaylock/main.c187
7 files changed, 201 insertions, 75 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index af478f33..f1ff25b2 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -16,11 +16,24 @@ struct swaybar_pointer {
16 int x, y; 16 int x, y;
17}; 17};
18 18
19enum x11_button {
20 NONE,
21 LEFT,
22 MIDDLE,
23 RIGHT,
24 SCROLL_UP,
25 SCROLL_DOWN,
26 SCROLL_LEFT,
27 SCROLL_RIGHT,
28 BACK,
29 FORWARD,
30};
31
19struct swaybar_hotspot { 32struct swaybar_hotspot {
20 struct wl_list link; 33 struct wl_list link;
21 int x, y, width, height; 34 int x, y, width, height;
22 void (*callback)(struct swaybar_output *output, 35 void (*callback)(struct swaybar_output *output,
23 int x, int y, uint32_t button, void *data); 36 int x, int y, enum x11_button button, void *data);
24 void (*destroy)(void *data); 37 void (*destroy)(void *data);
25 void *data; 38 void *data;
26}; 39};
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h
index bf12a842..2eaf8140 100644
--- a/include/swaybar/status_line.h
+++ b/include/swaybar/status_line.h
@@ -72,7 +72,9 @@ bool status_handle_readable(struct status_line *status);
72void status_line_free(struct status_line *status); 72void status_line_free(struct status_line *status);
73bool i3bar_handle_readable(struct status_line *status); 73bool i3bar_handle_readable(struct status_line *status);
74void i3bar_block_send_click(struct status_line *status, 74void i3bar_block_send_click(struct status_line *status,
75 struct i3bar_block *block, int x, int y, uint32_t button); 75 struct i3bar_block *block, int x, int y, enum x11_button button);
76void i3bar_block_free(struct i3bar_block *block); 76void i3bar_block_free(struct i3bar_block *block);
77enum x11_button wl_button_to_x11_button(uint32_t button);
78enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value);
77 79
78#endif 80#endif
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 3f9d701a..02384199 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -199,16 +199,23 @@ static struct sway_container *container_workspace_destroy(
199 return NULL; 199 return NULL;
200 } 200 }
201 201
202 // Do not destroy this if it's the last workspace on this output
203 struct sway_container *output = container_parent(workspace, C_OUTPUT); 202 struct sway_container *output = container_parent(workspace, C_OUTPUT);
204 if (output && output->children->length == 1) { 203
204 // If we're destroying the output, it will be NULL here. Return the root so
205 // that it doesn't appear that the workspace has refused to be destoyed,
206 // which would leave it in a broken state with no parent.
207 if (output == NULL) {
208 return &root_container;
209 }
210
211 // Do not destroy this if it's the last workspace on this output
212 if (output->children->length == 1) {
205 return NULL; 213 return NULL;
206 } 214 }
207 215
208 wlr_log(WLR_DEBUG, "destroying workspace '%s'", workspace->name); 216 wlr_log(WLR_DEBUG, "destroying workspace '%s'", workspace->name);
209 217
210 struct sway_container *parent = workspace->parent; 218 if (!workspace_is_empty(workspace)) {
211 if (!workspace_is_empty(workspace) && output) {
212 // Move children to a different workspace on this output 219 // Move children to a different workspace on this output
213 struct sway_container *new_workspace = NULL; 220 struct sway_container *new_workspace = NULL;
214 for (int i = 0; i < output->children->length; i++) { 221 for (int i = 0; i < output->children->length; i++) {
@@ -230,7 +237,7 @@ static struct sway_container *container_workspace_destroy(
230 } 237 }
231 } 238 }
232 239
233 return parent; 240 return output;
234} 241}
235 242
236static struct sway_container *container_output_destroy( 243static struct sway_container *container_output_destroy(
diff --git a/swaybar/bar.c b/swaybar/bar.c
index f03c5aea..94bc48bc 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -147,7 +147,7 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
147 && x < hotspot->x + hotspot->width 147 && x < hotspot->x + hotspot->width
148 && y < hotspot->y + hotspot->height) { 148 && y < hotspot->y + hotspot->height) {
149 hotspot->callback(output, pointer->x, pointer->y, 149 hotspot->callback(output, pointer->x, pointer->y,
150 button, hotspot->data); 150 wl_button_to_x11_button(button), hotspot->data);
151 } 151 }
152 } 152 }
153} 153}
@@ -155,11 +155,26 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
155static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, 155static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
156 uint32_t time, uint32_t axis, wl_fixed_t value) { 156 uint32_t time, uint32_t axis, wl_fixed_t value) {
157 struct swaybar *bar = data; 157 struct swaybar *bar = data;
158 struct swaybar_pointer *pointer = &bar->pointer;
158 struct swaybar_output *output = bar->pointer.current; 159 struct swaybar_output *output = bar->pointer.current;
159 if (!sway_assert(output, "axis with no active output")) { 160 if (!sway_assert(output, "axis with no active output")) {
160 return; 161 return;
161 } 162 }
162 163
164 struct swaybar_hotspot *hotspot;
165 wl_list_for_each(hotspot, &output->hotspots, link) {
166 double x = pointer->x * output->scale;
167 double y = pointer->y * output->scale;
168 if (x >= hotspot->x
169 && y >= hotspot->y
170 && x < hotspot->x + hotspot->width
171 && y < hotspot->y + hotspot->height) {
172 hotspot->callback(output, pointer->x, pointer->y,
173 wl_axis_to_x11_button(axis, value), hotspot->data);
174 return;
175 }
176 }
177
163 double amt = wl_fixed_to_double(value); 178 double amt = wl_fixed_to_double(value);
164 if (amt == 0.0) { 179 if (amt == 0.0) {
165 return; 180 return;
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 26f073c8..78b183ad 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -1,5 +1,6 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <json-c/json.h> 2#include <json-c/json.h>
3#include <linux/input-event-codes.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <string.h> 5#include <string.h>
5#include <unistd.h> 6#include <unistd.h>
@@ -192,7 +193,7 @@ bool i3bar_handle_readable(struct status_line *status) {
192} 193}
193 194
194void i3bar_block_send_click(struct status_line *status, 195void i3bar_block_send_click(struct status_line *status,
195 struct i3bar_block *block, int x, int y, uint32_t button) { 196 struct i3bar_block *block, int x, int y, enum x11_button button) {
196 wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); 197 wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)");
197 if (!block->name || !status->i3bar_state.click_events) { 198 if (!block->name || !status->i3bar_state.click_events) {
198 return; 199 return;
@@ -215,3 +216,32 @@ void i3bar_block_send_click(struct status_line *status,
215 } 216 }
216 json_object_put(event_json); 217 json_object_put(event_json);
217} 218}
219
220enum x11_button wl_button_to_x11_button(uint32_t button) {
221 switch (button) {
222 case BTN_LEFT:
223 return LEFT;
224 case BTN_MIDDLE:
225 return MIDDLE;
226 case BTN_RIGHT:
227 return RIGHT;
228 case BTN_SIDE:
229 return BACK;
230 case BTN_EXTRA:
231 return FORWARD;
232 default:
233 return NONE;
234 }
235}
236
237enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
238 switch (axis) {
239 case WL_POINTER_AXIS_VERTICAL_SCROLL:
240 return wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
241 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
242 return wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
243 default:
244 wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll");
245 return NONE;
246 }
247}
diff --git a/swaybar/render.c b/swaybar/render.c
index 909b56f4..d210e25a 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -109,7 +109,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
109} 109}
110 110
111static void block_hotspot_callback(struct swaybar_output *output, 111static void block_hotspot_callback(struct swaybar_output *output,
112 int x, int y, uint32_t button, void *data) { 112 int x, int y, enum x11_button button, void *data) {
113 struct i3bar_block *block = data; 113 struct i3bar_block *block = data;
114 struct status_line *status = output->bar->status; 114 struct status_line *status = output->bar->status;
115 i3bar_block_send_click(status, block, x, y, button); 115 i3bar_block_send_click(status, block, x, y, button);
@@ -349,7 +349,7 @@ static const char *strip_workspace_number(const char *ws_name) {
349} 349}
350 350
351static void workspace_hotspot_callback(struct swaybar_output *output, 351static void workspace_hotspot_callback(struct swaybar_output *output,
352 int x, int y, uint32_t button, void *data) { 352 int x, int y, enum x11_button button, void *data) {
353 ipc_send_workspace_command(output->bar, (const char *)data); 353 ipc_send_workspace_command(output->bar, (const char *)data);
354} 354}
355 355
diff --git a/swaylock/main.c b/swaylock/main.c
index ae5b86b9..668a8742 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -345,22 +345,25 @@ static void load_image(char *arg, struct swaylock_state *state) {
345 image->path = strdup(arg); 345 image->path = strdup(arg);
346 } 346 }
347 347
348 bool exists = false; 348 struct swaylock_image *iter_image, *temp;
349 struct swaylock_image *iter_image; 349 wl_list_for_each_safe(iter_image, temp, &state->images, link) {
350 wl_list_for_each(iter_image, &state->images, link) {
351 if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) { 350 if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) {
352 exists = true; 351 if (image->output_name) {
352 wlr_log(WLR_DEBUG,
353 "Replacing image defined for output %s with %s",
354 image->output_name, image->path);
355 } else {
356 wlr_log(WLR_DEBUG, "Replacing default image with %s",
357 image->path);
358 }
359 wl_list_remove(&iter_image->link);
360 free(iter_image->cairo_surface);
361 free(iter_image->output_name);
362 free(iter_image->path);
363 free(iter_image);
353 break; 364 break;
354 } 365 }
355 } 366 }
356 if (exists) {
357 if (image->output_name) {
358 wlr_log(WLR_ERROR, "Multiple images defined for output %s",
359 image->output_name);
360 } else {
361 wlr_log(WLR_ERROR, "Multiple default images defined");
362 }
363 }
364 367
365 // Bash doesn't replace the ~ with $HOME if the output name is supplied 368 // Bash doesn't replace the ~ with $HOME if the output name is supplied
366 wordexp_t p; 369 wordexp_t p;
@@ -420,7 +423,7 @@ enum line_mode {
420}; 423};
421 424
422static int parse_options(int argc, char **argv, struct swaylock_state *state, 425static int parse_options(int argc, char **argv, struct swaylock_state *state,
423 enum line_mode *line_mode) { 426 enum line_mode *line_mode, char **config_path) {
424 enum long_option_codes { 427 enum long_option_codes {
425 LO_BS_HL_COLOR = 256, 428 LO_BS_HL_COLOR = 256,
426 LO_FONT, 429 LO_FONT,
@@ -572,38 +575,58 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
572 } 575 }
573 switch (c) { 576 switch (c) {
574 case 'C': 577 case 'C':
575 // Config file. This will have already been handled so just ignore. 578 if (config_path) {
579 *config_path = strdup(optarg);
580 }
576 break; 581 break;
577 case 'c': 582 case 'c':
578 state->args.colors.background = parse_color(optarg); 583 if (state) {
579 state->args.mode = BACKGROUND_MODE_SOLID_COLOR; 584 state->args.colors.background = parse_color(optarg);
585 state->args.mode = BACKGROUND_MODE_SOLID_COLOR;
586 }
580 break; 587 break;
581 case 'e': 588 case 'e':
582 state->args.ignore_empty = true; 589 if (state) {
590 state->args.ignore_empty = true;
591 }
583 break; 592 break;
584 case 'f': 593 case 'f':
585 state->args.daemonize = true; 594 if (state) {
595 state->args.daemonize = true;
596 }
586 break; 597 break;
587 case 'i': 598 case 'i':
588 load_image(optarg, state); 599 if (state) {
600 load_image(optarg, state);
601 }
589 break; 602 break;
590 case 'n': 603 case 'n':
591 *line_mode = LM_INSIDE; 604 if (line_mode) {
605 *line_mode = LM_INSIDE;
606 }
592 break; 607 break;
593 case 'r': 608 case 'r':
594 *line_mode = LM_RING; 609 if (line_mode) {
610 *line_mode = LM_RING;
611 }
595 break; 612 break;
596 case 's': 613 case 's':
597 state->args.mode = parse_background_mode(optarg); 614 if (state) {
598 if (state->args.mode == BACKGROUND_MODE_INVALID) { 615 state->args.mode = parse_background_mode(optarg);
599 return 1; 616 if (state->args.mode == BACKGROUND_MODE_INVALID) {
617 return 1;
618 }
600 } 619 }
601 break; 620 break;
602 case 't': 621 case 't':
603 state->args.mode = BACKGROUND_MODE_TILE; 622 if (state) {
623 state->args.mode = BACKGROUND_MODE_TILE;
624 }
604 break; 625 break;
605 case 'u': 626 case 'u':
606 state->args.show_indicator = false; 627 if (state) {
628 state->args.show_indicator = false;
629 }
607 break; 630 break;
608 case 'v': 631 case 'v':
609#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE 632#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
@@ -612,73 +635,117 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
612#else 635#else
613 fprintf(stdout, "version unknown\n"); 636 fprintf(stdout, "version unknown\n");
614#endif 637#endif
615 return 0; 638 return 1;
616 case LO_BS_HL_COLOR: 639 case LO_BS_HL_COLOR:
617 state->args.colors.bs_highlight = parse_color(optarg); 640 if (state) {
641 state->args.colors.bs_highlight = parse_color(optarg);
642 }
618 break; 643 break;
619 case LO_FONT: 644 case LO_FONT:
620 free(state->args.font); 645 if (state) {
621 state->args.font = strdup(optarg); 646 free(state->args.font);
647 state->args.font = strdup(optarg);
648 }
622 break; 649 break;
623 case LO_IND_RADIUS: 650 case LO_IND_RADIUS:
624 state->args.radius = strtol(optarg, NULL, 0); 651 if (state) {
652 state->args.radius = strtol(optarg, NULL, 0);
653 }
625 break; 654 break;
626 case LO_IND_THICKNESS: 655 case LO_IND_THICKNESS:
627 state->args.thickness = strtol(optarg, NULL, 0); 656 if (state) {
657 state->args.thickness = strtol(optarg, NULL, 0);
658 }
628 break; 659 break;
629 case LO_INSIDE_COLOR: 660 case LO_INSIDE_COLOR:
630 state->args.colors.inside.input = parse_color(optarg); 661 if (state) {
662 state->args.colors.inside.input = parse_color(optarg);
663 }
631 break; 664 break;
632 case LO_INSIDE_CLEAR_COLOR: 665 case LO_INSIDE_CLEAR_COLOR:
633 state->args.colors.inside.cleared = parse_color(optarg); 666 if (state) {
667 state->args.colors.inside.cleared = parse_color(optarg);
668 }
634 break; 669 break;
635 case LO_INSIDE_VER_COLOR: 670 case LO_INSIDE_VER_COLOR:
636 state->args.colors.inside.verifying = parse_color(optarg); 671 if (state) {
672 state->args.colors.inside.verifying = parse_color(optarg);
673 }
637 break; 674 break;
638 case LO_INSIDE_WRONG_COLOR: 675 case LO_INSIDE_WRONG_COLOR:
639 state->args.colors.inside.wrong = parse_color(optarg); 676 if (state) {
677 state->args.colors.inside.wrong = parse_color(optarg);
678 }
640 break; 679 break;
641 case LO_KEY_HL_COLOR: 680 case LO_KEY_HL_COLOR:
642 state->args.colors.key_highlight = parse_color(optarg); 681 if (state) {
682 state->args.colors.key_highlight = parse_color(optarg);
683 }
643 break; 684 break;
644 case LO_LINE_COLOR: 685 case LO_LINE_COLOR:
645 state->args.colors.line.input = parse_color(optarg); 686 if (state) {
687 state->args.colors.line.input = parse_color(optarg);
688 }
646 break; 689 break;
647 case LO_LINE_CLEAR_COLOR: 690 case LO_LINE_CLEAR_COLOR:
648 state->args.colors.line.cleared = parse_color(optarg); 691 if (state) {
692 state->args.colors.line.cleared = parse_color(optarg);
693 }
649 break; 694 break;
650 case LO_LINE_VER_COLOR: 695 case LO_LINE_VER_COLOR:
651 state->args.colors.line.verifying = parse_color(optarg); 696 if (state) {
697 state->args.colors.line.verifying = parse_color(optarg);
698 }
652 break; 699 break;
653 case LO_LINE_WRONG_COLOR: 700 case LO_LINE_WRONG_COLOR:
654 state->args.colors.line.wrong = parse_color(optarg); 701 if (state) {
702 state->args.colors.line.wrong = parse_color(optarg);
703 }
655 break; 704 break;
656 case LO_RING_COLOR: 705 case LO_RING_COLOR:
657 state->args.colors.ring.input = parse_color(optarg); 706 if (state) {
707 state->args.colors.ring.input = parse_color(optarg);
708 }
658 break; 709 break;
659 case LO_RING_CLEAR_COLOR: 710 case LO_RING_CLEAR_COLOR:
660 state->args.colors.ring.cleared = parse_color(optarg); 711 if (state) {
712 state->args.colors.ring.cleared = parse_color(optarg);
713 }
661 break; 714 break;
662 case LO_RING_VER_COLOR: 715 case LO_RING_VER_COLOR:
663 state->args.colors.ring.verifying = parse_color(optarg); 716 if (state) {
717 state->args.colors.ring.verifying = parse_color(optarg);
718 }
664 break; 719 break;
665 case LO_RING_WRONG_COLOR: 720 case LO_RING_WRONG_COLOR:
666 state->args.colors.ring.wrong = parse_color(optarg); 721 if (state) {
722 state->args.colors.ring.wrong = parse_color(optarg);
723 }
667 break; 724 break;
668 case LO_SEP_COLOR: 725 case LO_SEP_COLOR:
669 state->args.colors.separator = parse_color(optarg); 726 if (state) {
727 state->args.colors.separator = parse_color(optarg);
728 }
670 break; 729 break;
671 case LO_TEXT_COLOR: 730 case LO_TEXT_COLOR:
672 state->args.colors.text.input = parse_color(optarg); 731 if (state) {
732 state->args.colors.text.input = parse_color(optarg);
733 }
673 break; 734 break;
674 case LO_TEXT_CLEAR_COLOR: 735 case LO_TEXT_CLEAR_COLOR:
675 state->args.colors.text.cleared = parse_color(optarg); 736 if (state) {
737 state->args.colors.text.cleared = parse_color(optarg);
738 }
676 break; 739 break;
677 case LO_TEXT_VER_COLOR: 740 case LO_TEXT_VER_COLOR:
678 state->args.colors.text.verifying = parse_color(optarg); 741 if (state) {
742 state->args.colors.text.verifying = parse_color(optarg);
743 }
679 break; 744 break;
680 case LO_TEXT_WRONG_COLOR: 745 case LO_TEXT_WRONG_COLOR:
681 state->args.colors.text.wrong = parse_color(optarg); 746 if (state) {
747 state->args.colors.text.wrong = parse_color(optarg);
748 }
682 break; 749 break;
683 default: 750 default:
684 fprintf(stderr, "%s", usage); 751 fprintf(stderr, "%s", usage);
@@ -759,7 +826,7 @@ static int load_config(char *path, struct swaylock_state *state,
759 char flag[strlen(line) + 3]; 826 char flag[strlen(line) + 3];
760 sprintf(flag, "--%s", line); 827 sprintf(flag, "--%s", line);
761 char *argv[] = {"swaylock", flag}; 828 char *argv[] = {"swaylock", flag};
762 int result = parse_options(2, argv, state, line_mode); 829 int result = parse_options(2, argv, state, line_mode, NULL);
763 if (result != 0) { 830 if (result != 0) {
764 free(line); 831 free(line);
765 fclose(config); 832 fclose(config);
@@ -789,18 +856,10 @@ int main(int argc, char **argv) {
789 wlr_log_init(WLR_DEBUG, NULL); 856 wlr_log_init(WLR_DEBUG, NULL);
790 857
791 char *config_path = NULL; 858 char *config_path = NULL;
792 static struct option long_options[] = { 859 int result = parse_options(argc, argv, NULL, NULL, &config_path);
793 {"config", required_argument, NULL, 'C'}, 860 if (result != 0) {
794 {0, 0, 0, 0}, 861 free(config_path);
795 }; 862 return result;
796 while (1) {
797 int c = getopt_long(argc, argv, "C:", long_options, NULL);
798 if (c == -1) {
799 break;
800 } else if (c == 'C') {
801 config_path = strdup(optarg);
802 break;
803 }
804 } 863 }
805 if (!config_path) { 864 if (!config_path) {
806 config_path = get_config_path(); 865 config_path = get_config_path();
@@ -817,7 +876,7 @@ int main(int argc, char **argv) {
817 876
818 if (argc > 1) { 877 if (argc > 1) {
819 wlr_log(WLR_DEBUG, "Parsing CLI Args"); 878 wlr_log(WLR_DEBUG, "Parsing CLI Args");
820 int result = parse_options(argc, argv, &state, &line_mode); 879 int result = parse_options(argc, argv, &state, &line_mode, NULL);
821 if (result != 0) { 880 if (result != 0) {
822 return result; 881 return result;
823 } 882 }