Workspace code cleanup
This commit is contained in:
parent
3ad50f9627
commit
29c481da95
|
@ -202,9 +202,9 @@ void handle_output_manager_test(struct wl_listener *listener, void *data);
|
|||
void handle_output_power_manager_set_mode(struct wl_listener *listener,
|
||||
void *data);
|
||||
|
||||
void update_workspace_scroll_percent(int dx, int invert);
|
||||
void update_workspace_scroll_percent(struct sway_seat *seat, int dx, int invert);
|
||||
|
||||
void snap_workspace_scroll_percent(int dx, int invert);
|
||||
void snap_workspace_scroll_percent(struct sway_seat *seat);
|
||||
|
||||
struct sway_output_non_desktop *output_non_desktop_create(struct wlr_output *wlr_output);
|
||||
|
||||
|
|
|
@ -1105,19 +1105,7 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
|
|||
apply_output_config(oc, output);
|
||||
}
|
||||
|
||||
static void workspace_scroll_mark_dirty(struct sway_output *output) {
|
||||
output_damage_whole(output);
|
||||
transaction_commit_dirty();
|
||||
}
|
||||
|
||||
static void reset_workspace_scroll_percent(struct sway_output *output) {
|
||||
output->workspace_scroll_percent = 0;
|
||||
|
||||
workspace_scroll_mark_dirty(output);
|
||||
}
|
||||
|
||||
void update_workspace_scroll_percent(int dx, int invert) {
|
||||
struct sway_seat *seat = input_manager_get_default_seat();
|
||||
void update_workspace_scroll_percent(struct sway_seat *seat, int dx, int invert) {
|
||||
struct sway_workspace *focused_ws = seat_get_focused_workspace(seat);
|
||||
struct sway_output *output = focused_ws->output;
|
||||
|
||||
|
@ -1142,38 +1130,39 @@ void update_workspace_scroll_percent(int dx, int invert) {
|
|||
|
||||
// Limit the percent depending on if the workspace is the first/last or in
|
||||
// the middle somewhere.
|
||||
int min = -1, max = 1;
|
||||
float min = -1.0f, max = 1.0f;
|
||||
if (visible_index + 1 >= output->workspaces->length) {
|
||||
// NOTE: Can be adjusted in the future to wrap around workspaces
|
||||
max = 0;
|
||||
}
|
||||
if (visible_index == 0) {
|
||||
// NOTE: Can be adjusted in the future to wrap around workspaces
|
||||
min = 0;
|
||||
}
|
||||
output->workspace_scroll_percent = MIN(max, MAX(min, percent));
|
||||
|
||||
workspace_scroll_mark_dirty(output);
|
||||
output_damage_whole(output);
|
||||
transaction_commit_dirty();
|
||||
}
|
||||
|
||||
void snap_workspace_scroll_percent(int dx, int invert) {
|
||||
struct sway_seat *seat = input_manager_get_default_seat();
|
||||
void snap_workspace_scroll_percent(struct sway_seat *seat) {
|
||||
struct sway_workspace *focused_ws = seat_get_focused_workspace(seat);
|
||||
struct sway_output *output = focused_ws->output;
|
||||
|
||||
// TODO: Make the threshold configurable??
|
||||
const float THRESHOLD = 0.35;
|
||||
if (ABS(output->workspace_scroll_percent) <= THRESHOLD) {
|
||||
goto reset;
|
||||
if (fabs(output->workspace_scroll_percent) <= THRESHOLD) {
|
||||
goto reset_state;
|
||||
}
|
||||
|
||||
dx *= invert;
|
||||
|
||||
int dir = 0;
|
||||
if (dx < 0) {
|
||||
if (output->workspace_scroll_percent < 0) {
|
||||
dir = -1;
|
||||
} else if (dx > 0) {
|
||||
} else if (output->workspace_scroll_percent > 0) {
|
||||
dir = 1;
|
||||
} else {
|
||||
goto reset;
|
||||
// Skip setting workspace if the percentage is zero
|
||||
goto reset_state;
|
||||
}
|
||||
|
||||
int visible_index = list_find(output->workspaces, focused_ws);
|
||||
|
@ -1184,7 +1173,10 @@ void snap_workspace_scroll_percent(int dx, int invert) {
|
|||
workspace_switch(new_ws);
|
||||
seat_consider_warp_to_focus(seat);
|
||||
|
||||
reset:
|
||||
reset_state:
|
||||
// Reset the state
|
||||
reset_workspace_scroll_percent(output);
|
||||
output->workspace_scroll_percent = 0;
|
||||
|
||||
output_damage_whole(output);
|
||||
transaction_commit_dirty();
|
||||
}
|
||||
|
|
|
@ -1833,14 +1833,15 @@ static void render_container(struct sway_output *output,
|
|||
}
|
||||
|
||||
static void render_workspace(struct sway_output *output,
|
||||
pixman_region32_t *damage, struct sway_workspace *ws, bool focused) {
|
||||
pixman_region32_t *damage, struct sway_workspace *ws, bool focused,
|
||||
struct sway_workspace *other_ws) {
|
||||
struct sway_workspace *workspaces[2] = { ws, NULL };
|
||||
|
||||
if (output->workspace_scroll_percent < 0) {
|
||||
workspaces[0] = workspace_output_prev(ws);
|
||||
workspaces[0] = other_ws;
|
||||
workspaces[1] = ws;
|
||||
} else if (output->workspace_scroll_percent > 0) {
|
||||
workspaces[1] = workspace_output_next(ws);
|
||||
workspaces[1] = other_ws;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
@ -1918,7 +1919,7 @@ static void render_floating_container(struct sway_output *soutput,
|
|||
}
|
||||
|
||||
static void render_floating(struct sway_output *soutput,
|
||||
pixman_region32_t *damage) {
|
||||
pixman_region32_t *damage, struct sway_workspace *other_ws) {
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
|
||||
|
@ -1928,13 +1929,6 @@ static void render_floating(struct sway_output *soutput,
|
|||
}
|
||||
|
||||
struct sway_workspace *visible_ws = output->current.active_workspace;
|
||||
struct sway_workspace *other_ws = NULL;
|
||||
if (output->workspace_scroll_percent < 0) {
|
||||
other_ws = workspace_output_prev(visible_ws);
|
||||
} else {
|
||||
other_ws = workspace_output_next(visible_ws);
|
||||
}
|
||||
|
||||
for (int j = 0; j < output->current.workspaces->length; ++j) {
|
||||
struct sway_workspace *ws = output->current.workspaces->items[j];
|
||||
|
||||
|
@ -2186,8 +2180,8 @@ void output_render(struct sway_output *output, struct timespec *when,
|
|||
render_output_blur(output, damage);
|
||||
}
|
||||
|
||||
render_workspace(output, damage, workspace, workspace->current.focused);
|
||||
render_floating(output, damage);
|
||||
render_workspace(output, damage, workspace, workspace->current.focused, other_ws);
|
||||
render_floating(output, damage, other_ws);
|
||||
#if HAVE_XWAYLAND
|
||||
render_unmanaged(output, damage, &root->xwayland_unmanaged);
|
||||
#endif
|
||||
|
|
|
@ -1065,7 +1065,7 @@ static void handle_swipe_update(struct sway_seat *seat,
|
|||
struct sway_gesture_binding *current = gesture_binding_match(config->current_mode->gesture_bindings, &gesture, input);
|
||||
|
||||
int invert = gesture_workspace_swipe_command_parse(current->command);
|
||||
update_workspace_scroll_percent(seatop->gestures.dx, invert);
|
||||
update_workspace_scroll_percent(seat, seatop->gestures.dx, invert);
|
||||
} else {
|
||||
// ... otherwise forward to client
|
||||
struct sway_cursor *cursor = seat->cursor;
|
||||
|
@ -1100,8 +1100,7 @@ static void handle_swipe_end(struct sway_seat *seat,
|
|||
if (binding) {
|
||||
switch (binding->gesture.type) {
|
||||
case GESTURE_TYPE_WORKSPACE_SWIPE:;
|
||||
int invert = gesture_workspace_swipe_command_parse(binding->command);
|
||||
snap_workspace_scroll_percent(seatop->gestures.dx, invert);
|
||||
snap_workspace_scroll_percent(seat);
|
||||
break;
|
||||
default:
|
||||
gesture_binding_execute(seat, binding);
|
||||
|
|
Loading…
Reference in a new issue