Skip to content
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

(4/5) Multiple Issues: Fix intersections after mouse button release #183

Merged
merged 46 commits into from
Oct 6, 2019
Merged
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6fcd6ad
(1/5) Multiple issues: Prep
felix-andreas Aug 27, 2019
c96e543
snap widgets after mouse button release
felix-andreas Aug 27, 2019
f37971b
close gaps after mouse button release
felix-andreas Aug 27, 2019
27fa510
check intersections after mouse button release
felix-andreas Aug 27, 2019
b4adae3
Merge branch 'master' into 1_of_5_prep_for_multiple_issues
Sep 24, 2019
00053df
Merge branch 'master' into 3_of_5_close_gaps_after_mouse_button_release
Sep 24, 2019
c627436
Merge branch 'master' into 4_of_5_fix_intersections_after_mouse_butto…
Sep 24, 2019
4310d3d
don't pass event as parameter
felix-andreas Sep 24, 2019
bacaf98
simplify event connection
felix-andreas Sep 24, 2019
87edff8
Merge branch 'master' into 2_of_5_snap_monitors_after_mouse_button_re…
felix-andreas Sep 24, 2019
70aaaa0
Merge branch '1_of_5_prep_for_multiple_issues' into 2_of_5_snap_monit…
felix-andreas Sep 24, 2019
99b3969
Merge branch '2_of_5_snap_monitors_after_mouse_button_release' of git…
felix-andreas Sep 24, 2019
3a29a0f
spelling: snapping
felix-andreas Sep 24, 2019
1c9e8ea
Merge branch '2_of_5_snap_monitors_after_mouse_button_release' into 3…
felix-andreas Sep 24, 2019
c471a5b
add blank line for linter
felix-andreas Sep 24, 2019
f4f6d57
Merge branch '3_of_5_close_gaps_after_mouse_button_release' of github…
felix-andreas Sep 24, 2019
05c535f
Merge branch '3_of_5_close_gaps_after_mouse_button_release' into 4_of…
felix-andreas Sep 24, 2019
2ef6b0e
add geometry label
felix-andreas Sep 24, 2019
5ad0884
Revert "add geometry label"
felix-andreas Sep 24, 2019
832bcae
add spaces for struct initialization
felix-andreas Sep 24, 2019
a159dd7
Merge branch '3_of_5_close_gaps_after_mouse_button_release' into 4_of…
felix-andreas Sep 24, 2019
7e86ebf
Merge branch 'master' into 2_of_5_snap_monitors_after_mouse_button_re…
felix-andreas Sep 24, 2019
b666631
Merge branch 'master' into 3_of_5_close_gaps_after_mouse_button_release
felix-andreas Sep 24, 2019
66c509f
Merge branch 'master' into 4_of_5_fix_intersections_after_mouse_butto…
felix-andreas Sep 24, 2019
1e07fea
remove space in comment
felix-andreas Sep 25, 2019
f92d8d1
Merge branch 'master' into 2_of_5_snap_monitors_after_mouse_button_re…
felix-andreas Sep 25, 2019
0a91ba9
Merge branch 'master' into 4_of_5_fix_intersections_after_mouse_butto…
Sep 26, 2019
f4b3b6c
Merge branch 'master' into 2_of_5_snap_monitors_after_mouse_button_re…
Sep 26, 2019
f383ba1
Merge branch 'master' into 3_of_5_close_gaps_after_mouse_button_release
Sep 26, 2019
ded0d2a
lint: add empty line
felix-andreas Sep 27, 2019
df9efcb
rename variable to be more explanatory
felix-andreas Sep 27, 2019
5052fa1
make minimum widget offset a const
felix-andreas Sep 27, 2019
07436e2
Merge branch '2_of_5_snap_monitors_after_mouse_button_release' of git…
felix-andreas Sep 27, 2019
86d962f
Merge branch '3_of_5_close_gaps_after_mouse_button_release' of github…
felix-andreas Sep 27, 2019
bd766f2
Merge branch '2_of_5_snap_monitors_after_mouse_button_release' into 3…
felix-andreas Sep 27, 2019
3460154
rename variables for clarity
felix-andreas Sep 27, 2019
b52624d
Merge branch '2_of_5_snap_monitors_after_mouse_button_release' into 3…
felix-andreas Sep 27, 2019
451352c
lint
felix-andreas Sep 28, 2019
78a6f4c
Merge branch '2_of_5_snap_monitors_after_mouse_button_release' into 3…
felix-andreas Sep 28, 2019
84675dd
lint: add space
felix-andreas Sep 28, 2019
def3390
lint: add correct space
felix-andreas Sep 28, 2019
20b9006
Merge branch '3_of_5_close_gaps_after_mouse_button_release' into 4_of…
felix-andreas Sep 28, 2019
59f7aab
Merge branch 'master' into 4_of_5_fix_intersections_after_mouse_butto…
Sep 29, 2019
4ded1a8
Revert "Merge branch 'master' into 4_of_5_fix_intersections_after_mou…
felix-andreas Sep 29, 2019
43c9fb8
Merge branch 'master' into 4_of_5_fix_intersections_after_mouse_butto…
kgrubb Oct 3, 2019
c53a39b
Merge branch 'master' into 4_of_5_fix_intersections_after_mouse_butto…
Oct 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 38 additions & 54 deletions src/Widgets/DisplaysOverlay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
reorder_overlay (display_widget, -1);
display_widget.delta_x = (int) (diff_x / current_ratio);
display_widget.delta_y = (int) (diff_y / current_ratio);
check_intersects (display_widget);
display_widget.queue_resize_no_redraw ();
}

private void close_gaps () {
Expand Down Expand Up @@ -350,64 +350,48 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
});
}

public void check_intersects (DisplayWidget source_display_widget) {
int orig_x, orig_y, src_x, src_y, src_width, src_height;
source_display_widget.get_geometry (out orig_x, out orig_y, out src_width, out src_height);
src_x = orig_x + source_display_widget.delta_x;
src_y = orig_y + source_display_widget.delta_y;
Gdk.Rectangle src_rect = {src_x, src_y, src_width, src_height};
get_children ().foreach ((child) => {
if (child is DisplayWidget) {
var display_widget = (DisplayWidget) child;
if (display_widget == source_display_widget) {
return;
}
// If widget is intersects with any other widgets -> move other widgets to fix intersection
public void check_intersects (DisplayWidget source_display_widget, int level = 0, int distance_x = 0, int distance_y = 0) {
if (level > 10) {
warning ("Maximum level of recursion reached! Could not fix intersects!");
return;
}

int x, y, width, height;
display_widget.get_geometry (out x, out y, out width, out height);
Gdk.Rectangle test_rect = {x, y, width, height};
Gdk.Rectangle intersection;
if (src_rect.intersect (test_rect, out intersection)) {
if (intersection.height == src_height) {
// on the left side
if (intersection.x <= x + width/2) {
source_display_widget.delta_x = x - (orig_x + src_width);
// on the right side
} else {
source_display_widget.delta_x = x - orig_x + width;
}
} else if (intersection.width == src_width) {
// on the bottom side
if (intersection.y <= y + height/2) {
source_display_widget.delta_y = y - (orig_y + src_height);
} else {
// on the upper side
source_display_widget.delta_y = y - orig_y + height;
}
int source_x, source_y, source_width, source_height;
source_display_widget.get_geometry (out source_x, out source_y, out source_width, out source_height);
Gdk.Rectangle src_rect = { source_x, source_y, source_width, source_height };

foreach (var child in get_children ()) {
if (!(child is DisplayWidget) || (DisplayWidget) child == source_display_widget) {
continue;
}

var other_display_widget = (DisplayWidget) child;
int other_x, other_y, other_width, other_height;
other_display_widget.get_geometry (out other_x, out other_y, out other_width, out other_height);
Gdk.Rectangle test_rect = { other_x, other_y, other_width, other_height };
if (src_rect.intersect (test_rect, null)) {
if (level == 0) {
var distance_left = source_x - other_x - other_width;
var distance_right = source_x - other_x + source_width;
var distance_top = source_y - other_y - other_height;
var distance_bottom = source_y - other_y + source_height;
var test_distance_x = distance_right < -distance_left ? distance_right : distance_left;
var test_distance_y = distance_bottom < -distance_top ? distance_bottom : distance_top;

// if distance to upper egde == distance lower edge, move horizontally
if (test_distance_x.abs () <= test_distance_y.abs () || distance_top == -distance_bottom) {
distance_x = test_distance_x;
} else {
if (intersection.width < intersection.height) {
// on the left side
if (intersection.x <= x + width/2) {
source_display_widget.delta_x = x - (orig_x + src_width);
// on the right side
} else {
source_display_widget.delta_x = x - orig_x + width;
}
} else {
// on the bottom side
if (intersection.y <= y + height/2) {
source_display_widget.delta_y = y - (orig_y + src_height);
} else {
// on the upper side
source_display_widget.delta_y = y - orig_y + height;
}
}
distance_y = test_distance_y;
}
}
}
});

source_display_widget.queue_resize_no_redraw ();
other_display_widget.set_geometry (other_x + distance_x, other_y + distance_y, other_width, other_height);
other_display_widget.queue_resize_no_redraw ();
check_intersects (other_display_widget, level + 1, distance_x, distance_y);
}
}
}

public void snap_edges (DisplayWidget last_moved) {
Expand Down