summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Mykyta Holubakha <hilobakho@gmail.com>2016-05-07 20:49:51 +0300
committerLibravatar Mykyta Holubakha <hilobakho@gmail.com>2016-05-07 20:49:51 +0300
commit0423c41a0f9f8f84bde80e664e59e33e3b05e3d4 (patch)
tree0f168f873158653f9d42fb94c591b1d2e6450cd7
parentMerge pull request #638 from neosilky/memleak (diff)
downloadsway-0423c41a0f9f8f84bde80e664e59e33e3b05e3d4.tar.gz
sway-0423c41a0f9f8f84bde80e664e59e33e3b05e3d4.tar.zst
sway-0423c41a0f9f8f84bde80e664e59e33e3b05e3d4.zip
Implemented configurable floating scroll behavior
-rw-r--r--include/config.h11
-rw-r--r--sway/commands.c43
-rw-r--r--sway/config.c4
-rw-r--r--sway/handlers.c10
4 files changed, 63 insertions, 5 deletions
diff --git a/include/config.h b/include/config.h
index 8e5e33c3..6bd09151 100644
--- a/include/config.h
+++ b/include/config.h
@@ -167,10 +167,9 @@ enum edge_border_types {
167}; 167};
168 168
169enum floating_scroll_behavior { 169enum floating_scroll_behavior {
170 FSB_GAPS_OUTER, /**< Adjust outer gaps */ 170 FSB_GAPS_OUTER, /**< Adjust outer gaps */
171 FSB_GAPS_INNER /**< Adjust inner gaps */ 171 FSB_GAPS_INNER, /**< Adjust inner gaps */
172 // Note: in the future I expect to see more things you can do with the scroll 172 FSB_CUSTOM /**< Perform a user-defined action */
173 // wheel than maniuplating gaps
174}; 173};
175 174
176/** 175/**
@@ -191,7 +190,9 @@ struct sway_config {
191 uint32_t floating_mod; 190 uint32_t floating_mod;
192 uint32_t dragging_key; 191 uint32_t dragging_key;
193 uint32_t resizing_key; 192 uint32_t resizing_key;
194 enum floating_scroll_behavior floating_scroll; // TODO: command to set this 193 enum floating_scroll_behavior floating_scroll;
194 char *fsb_up;
195 char *fsb_down;
195 enum swayc_layouts default_orientation; 196 enum swayc_layouts default_orientation;
196 enum swayc_layouts default_layout; 197 enum swayc_layouts default_layout;
197 char *font; 198 char *font;
diff --git a/sway/commands.c b/sway/commands.c
index 9b0356c4..a4fcde78 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -58,6 +58,7 @@ static sway_cmd cmd_exec_always;
58static sway_cmd cmd_exit; 58static sway_cmd cmd_exit;
59static sway_cmd cmd_floating; 59static sway_cmd cmd_floating;
60static sway_cmd cmd_floating_mod; 60static sway_cmd cmd_floating_mod;
61static sway_cmd cmd_floating_scroll;
61static sway_cmd cmd_focus; 62static sway_cmd cmd_focus;
62static sway_cmd cmd_focus_follows_mouse; 63static sway_cmd cmd_focus_follows_mouse;
63static sway_cmd cmd_font; 64static sway_cmd cmd_font;
@@ -705,6 +706,47 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
705 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 706 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
706} 707}
707 708
709static struct cmd_results *cmd_floating_scroll(int argc, char **argv) {
710 struct cmd_results *error = NULL;
711 if ((error = checkarg(argc, "floating_scroll", EXPECTED_AT_LEAST, 1))) {
712 return error;
713 }
714 if (!strcasecmp("behavior", argv[0])) {
715 if (argc < 2) {
716 error = cmd_results_new(CMD_INVALID, "floating_scroll", "Insufficient parameters given");
717 return error;
718 }
719 if (!strcasecmp("gaps_inner", argv[1])) {
720 config->floating_scroll = FSB_GAPS_INNER;
721 } else if (!strcasecmp("gaps_outer", argv[1])) {
722 config->floating_scroll = FSB_GAPS_OUTER;
723 } else if (!strcasecmp("custom", argv[1])) {
724 config->floating_scroll = FSB_CUSTOM;
725 } else {
726 error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown behavior: '%s'", argv[1]);
727 return error;
728 }
729 } else if (!strcasecmp("up", argv[0])) {
730 free(config->fsb_up);
731 if (argc < 2) {
732 config->fsb_up = strdup("");
733 } else {
734 config->fsb_up = join_args(argv + 1, argc - 1);
735 }
736 } else if (!strcasecmp("down", argv[0])) {
737 free(config->fsb_down);
738 if (argc < 2) {
739 config->fsb_down = strdup("");
740 } else {
741 config->fsb_down = join_args(argv + 1, argc - 1);
742 }
743 } else {
744 error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown command: '%s'", argv[0]);
745 return error;
746 }
747 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
748}
749
708static struct cmd_results *cmd_focus(int argc, char **argv) { 750static struct cmd_results *cmd_focus(int argc, char **argv) {
709 if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file."); 751 if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file.");
710 struct cmd_results *error = NULL; 752 struct cmd_results *error = NULL;
@@ -2377,6 +2419,7 @@ static struct cmd_handler handlers[] = {
2377 { "exit", cmd_exit }, 2419 { "exit", cmd_exit },
2378 { "floating", cmd_floating }, 2420 { "floating", cmd_floating },
2379 { "floating_modifier", cmd_floating_mod }, 2421 { "floating_modifier", cmd_floating_mod },
2422 { "floating_scroll", cmd_floating_scroll },
2380 { "focus", cmd_focus }, 2423 { "focus", cmd_focus },
2381 { "focus_follows_mouse", cmd_focus_follows_mouse }, 2424 { "focus_follows_mouse", cmd_focus_follows_mouse },
2382 { "font", cmd_font }, 2425 { "font", cmd_font },
diff --git a/sway/config.c b/sway/config.c
index 237d8996..15aed11b 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -131,6 +131,8 @@ void free_config(struct sway_config *config) {
131 list_free(config->active_bar_modifiers); 131 list_free(config->active_bar_modifiers);
132 free_flat_list(config->config_chain); 132 free_flat_list(config->config_chain);
133 free(config->font); 133 free(config->font);
134 free(config->fsb_up);
135 free(config->fsb_down);
134 free(config); 136 free(config);
135} 137}
136 138
@@ -160,6 +162,8 @@ static void config_defaults(struct sway_config *config) {
160 config->dragging_key = M_LEFT_CLICK; 162 config->dragging_key = M_LEFT_CLICK;
161 config->resizing_key = M_RIGHT_CLICK; 163 config->resizing_key = M_RIGHT_CLICK;
162 config->floating_scroll = FSB_GAPS_INNER; 164 config->floating_scroll = FSB_GAPS_INNER;
165 config->fsb_up = strdup("");
166 config->fsb_down = strdup("");
163 config->default_layout = L_NONE; 167 config->default_layout = L_NONE;
164 config->default_orientation = L_NONE; 168 config->default_orientation = L_NONE;
165 config->font = strdup("monospace 10"); 169 config->font = strdup("monospace 10");
diff --git a/sway/handlers.c b/sway/handlers.c
index b82456e2..23c9985e 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -743,6 +743,16 @@ bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modi
743 arrange_windows(&root_container, -1, -1); 743 arrange_windows(&root_container, -1, -1);
744 break; 744 break;
745 } 745 }
746 case FSB_CUSTOM:
747 {
748 int amount = (int)_amount[0];
749 if (amount > 0) {
750 handle_command(config->fsb_up);
751 } else if (amount < 0) {
752 handle_command(config->fsb_down);
753 }
754 break;
755 }
746 } 756 }
747 } 757 }
748 return EVENT_PASSTHROUGH; 758 return EVENT_PASSTHROUGH;