Skip to content

Commit

Permalink
New feature: adjust gaps with floating_mod+scroll
Browse files Browse the repository at this point in the history
I made this configurable but I didn't make the command for it. That's
left as an exercise to an eager contributor.

    mod_scroll_behavior [gaps inner|gaps outer]

Would merge implementions of more behaviors for mod+scroll, if anyone
has some neato ideas.
  • Loading branch information
ddevault committed Mar 30, 2016
1 parent 68f4f9b commit a128504
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ enum edge_border_types {
E_BOTH /**< hide vertical and horizontal edge borders */
};

enum floating_scroll_behavior {
FSB_GAPS_OUTER, /**< Adjust outer gaps */
FSB_GAPS_INNER /**< Adjust inner gaps */
// Note: in the future I expect to see more things you can do with the scroll
// wheel than maniuplating gaps
};

/**
* The configuration struct. The result of loading a config file.
*/
Expand All @@ -181,6 +188,7 @@ struct sway_config {
uint32_t floating_mod;
uint32_t dragging_key;
uint32_t resizing_key;
enum floating_scroll_behavior floating_scroll; // TODO: command to set this
enum swayc_layouts default_orientation;
enum swayc_layouts default_layout;
char *font;
Expand Down
1 change: 1 addition & 0 deletions sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static void config_defaults(struct sway_config *config) {
config->floating_mod = 0;
config->dragging_key = M_LEFT_CLICK;
config->resizing_key = M_RIGHT_CLICK;
config->floating_scroll = FSB_GAPS_INNER;
config->default_layout = L_NONE;
config->default_orientation = L_NONE;
config->font = strdup("monospace 10");
Expand Down
25 changes: 25 additions & 0 deletions sway/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,31 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
case M_SCROLL_DOWN:
break;
}
if (!(modifiers->mods ^ config->floating_mod) &&
(button == M_SCROLL_UP || button == M_SCROLL_DOWN)) {
switch (config->floating_scroll) {
case FSB_GAPS_INNER:
case FSB_GAPS_OUTER:
{
int amount = button == M_SCROLL_UP ? -1 : 1;
int i,j;
for (i = 0; i < root_container.children->length; ++i) {
swayc_t *op = root_container.children->items[i];
for (j = 0; j < op->children->length; ++j) {
swayc_t *ws = op->children->items[j];
// TODO: adjust outer gaps ws->gaps = 0;
if (config->floating_scroll == FSB_GAPS_INNER) {
container_map(ws, add_gaps, &amount);
} else {
ws->gaps += amount;
}
}
}
arrange_windows(&root_container, -1, -1);
break;
}
}
}

// get focused window and check if to change focus on mouse click
swayc_t *focused = get_focused_container(&root_container);
Expand Down

0 comments on commit a128504

Please sign in to comment.