mirror of
https://github.com/swaywm/sway.git
synced 2026-03-20 05:34:28 -04:00
Implement configurable wrapping on bar ws scroll
This commit is contained in:
parent
a9767ad2f7
commit
3bb880bf20
8 changed files with 72 additions and 4 deletions
|
|
@ -96,6 +96,37 @@ static void mouse_button_notify(struct window *window, int x, int y,
|
|||
static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
|
||||
sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down");
|
||||
|
||||
if (!swaybar.config->wrap_scroll) {
|
||||
// Find output this window lives on
|
||||
int i;
|
||||
struct output *output;
|
||||
for (i = 0; i < swaybar.outputs->length; ++i) {
|
||||
output = swaybar.outputs->items[i];
|
||||
if (output->window == window) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sway_assert(i != swaybar.outputs->length, "Unknown window in scroll event")) {
|
||||
return;
|
||||
}
|
||||
int focused = -1;
|
||||
for (i = 0; i < output->workspaces->length; ++i) {
|
||||
struct workspace *ws = output->workspaces->items[i];
|
||||
if (ws->focused) {
|
||||
focused = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sway_assert(focused != -1, "Scroll wheel event received on inactive output")) {
|
||||
return;
|
||||
}
|
||||
if ((focused == 0 && direction == SCROLL_UP) ||
|
||||
(focused == output->workspaces->length - 1 && direction == SCROLL_DOWN)) {
|
||||
// Do not wrap
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output";
|
||||
ipc_send_workspace_command(workspace_name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ struct config *init_config() {
|
|||
config->sep_symbol = NULL;
|
||||
config->strip_workspace_numbers = false;
|
||||
config->binding_mode_indicator = true;
|
||||
config->wrap_scroll = false;
|
||||
config->workspace_buttons = true;
|
||||
config->all_outputs = false;
|
||||
config->outputs = create_list();
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ void ipc_send_workspace_command(const char *workspace_name) {
|
|||
static void ipc_parse_config(struct config *config, const char *payload) {
|
||||
json_object *bar_config = json_tokener_parse(payload);
|
||||
json_object *tray_output, *mode, *hidden_bar, *position, *status_command;
|
||||
json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers;
|
||||
json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers;
|
||||
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
|
||||
json_object *markup;
|
||||
json_object_object_get_ex(bar_config, "tray_output", &tray_output);
|
||||
|
|
@ -29,6 +29,7 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
|||
json_object_object_get_ex(bar_config, "status_command", &status_command);
|
||||
json_object_object_get_ex(bar_config, "font", &font);
|
||||
json_object_object_get_ex(bar_config, "bar_height", &bar_height);
|
||||
json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll);
|
||||
json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons);
|
||||
json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers);
|
||||
json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator);
|
||||
|
|
@ -65,6 +66,10 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
|||
config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator);
|
||||
}
|
||||
|
||||
if (wrap_scroll) {
|
||||
config->wrap_scroll = json_object_get_boolean(wrap_scroll);
|
||||
}
|
||||
|
||||
if (workspace_buttons) {
|
||||
config->workspace_buttons = json_object_get_boolean(workspace_buttons);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue