-
Notifications
You must be signed in to change notification settings - Fork 70
Add mirror mode with Control key #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
axel-angel
wants to merge
2
commits into
emersion:master
Choose a base branch
from
axel-angel:feature-mirror-selection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,8 @@ static void move_seat(struct slurp_seat *seat, wl_fixed_t surface_x, | |
| if (seat->state->edit_anchor) { | ||
| current_selection->anchor_x += x - current_selection->x; | ||
| current_selection->anchor_y += y - current_selection->y; | ||
| current_selection->start_x += x - current_selection->x; | ||
| current_selection->start_y += y - current_selection->y; | ||
| } | ||
|
|
||
| current_selection->x = x; | ||
|
|
@@ -97,17 +99,36 @@ static void handle_active_selection_motion(struct slurp_seat *seat, struct slurp | |
| int32_t anchor_y = current_selection->anchor_y; | ||
| int32_t dist_x = current_selection->x - anchor_x; | ||
| int32_t dist_y = current_selection->y - anchor_y; | ||
| int32_t start_x = current_selection->start_x; | ||
| int32_t start_y = current_selection->start_y; | ||
|
|
||
| current_selection->has_selection = true; | ||
| // selection includes the seat and anchor positions | ||
| int32_t width = abs(dist_x) + 1; | ||
| int32_t height = abs(dist_y) + 1; | ||
| if (seat->state->aspect_ratio) { | ||
|
|
||
| int32_t width; | ||
| int32_t height; | ||
|
|
||
| if (seat->state->mirror_mode) { | ||
| width = 2 * abs(start_x - current_selection->x); | ||
| height = 2 * abs(start_y - current_selection->y); | ||
| } else { | ||
| // selection includes the seat and anchor positions | ||
| width = abs(dist_x) + 1; | ||
| height = abs(dist_y) + 1; | ||
| } | ||
|
|
||
| if (seat->state->aspect_ratio) { | ||
| width = max(width, height / seat->state->aspect_ratio); | ||
| height = max(height, width * seat->state->aspect_ratio); | ||
| } | ||
| current_selection->selection.x = dist_x > 0 ? anchor_x : anchor_x - (width - 1); | ||
| current_selection->selection.y = dist_y > 0 ? anchor_y : anchor_y - (height - 1); | ||
| if (seat->state->mirror_mode) { | ||
| int32_t delta_x = width / 2; | ||
| int32_t delta_y = height / 2; | ||
| current_selection->anchor_x = anchor_x = start_x - delta_x; | ||
| current_selection->anchor_y = anchor_y = start_y - delta_y; | ||
| } | ||
|
|
||
| current_selection->selection.x = dist_x > 0 || seat->state->mirror_mode ? anchor_x : anchor_x - (width - 1); | ||
| current_selection->selection.y = dist_y > 0 || seat->state->mirror_mode ? anchor_y : anchor_y - (height - 1); | ||
|
Comment on lines
+130
to
+131
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, the -1 offset when dist is negative may be required for mirror mode. We may need to structure the code a bit differently to write the code only once. PS: is the -1 to compensate the border? in that case we need to use state border_weight instead. |
||
| current_selection->selection.width = width; | ||
| current_selection->selection.height = height; | ||
| } | ||
|
|
@@ -209,8 +230,8 @@ static void handle_selection_start(struct slurp_seat *seat, | |
| state->running = false; | ||
| } | ||
| } else { | ||
| current_selection->anchor_x = current_selection->x; | ||
| current_selection->anchor_y = current_selection->y; | ||
| current_selection->start_x = current_selection->anchor_x = current_selection->x; | ||
| current_selection->start_y = current_selection->anchor_y = current_selection->y; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -313,6 +334,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, | |
| } | ||
| state->edit_anchor = true; | ||
| break; | ||
|
|
||
| case XKB_KEY_Shift_L: | ||
| case XKB_KEY_Shift_R: | ||
| if (!state->fixed_aspect_ratio) { | ||
|
|
@@ -322,6 +344,17 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, | |
| } | ||
| } | ||
| break; | ||
|
|
||
| case XKB_KEY_Control_L: | ||
| case XKB_KEY_Control_R: | ||
| state->mirror_mode = true; | ||
| if (state->resizing_selection) { | ||
| struct slurp_selection *current = slurp_seat_current_selection(seat); | ||
| current->start_x = current->anchor_x + round(current->selection.width / 2); | ||
| current->start_y = current->anchor_y + round(current->selection.height / 2); | ||
| recompute_selection(seat); | ||
| } | ||
| break; | ||
| } | ||
| break; | ||
|
|
||
|
|
@@ -333,7 +366,12 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, | |
| if (state->resizing_selection) { | ||
| recompute_selection(seat); | ||
| } | ||
| } | ||
| } else if (keysym == XKB_KEY_Control_L || keysym == XKB_KEY_Control_R) { | ||
| state->mirror_mode = false; | ||
| if (state->resizing_selection) { | ||
| recompute_selection(seat); | ||
| } | ||
| } | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -882,6 +920,7 @@ int main(int argc, char *argv[]) { | |
| .resizing_selection = false, | ||
| .fixed_aspect_ratio = false, | ||
| .aspect_ratio = 0, | ||
| .mirror_mode = false, | ||
| .font_family = FONT_FAMILY | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also include the +1 offset implemented below?