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 19 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
53 changes: 30 additions & 23 deletions src/Widgets/DisplaysOverlay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public class Display.DisplaysOverlay : Gtk.Overlay {
private const int SNAP_LIMIT = int.MAX - 1;
private const int MINIMUM_WIDGET_OFFSET = 50;

public signal void configuration_changed (bool changed);

Expand Down Expand Up @@ -213,6 +214,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {

display_widget.show_all ();
display_widget.set_as_primary.connect (() => set_as_primary (display_widget.virtual_monitor));

display_widget.check_position.connect (() => {
check_intersects (display_widget);
close_gaps ();
Expand Down Expand Up @@ -281,7 +283,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
}

private void close_gaps () {
var display_widgets = new List<DisplayWidget>();
var display_widgets = new List<DisplayWidget> ();
foreach (var child in get_children ()) {
if (child is DisplayWidget) {
display_widgets.append ((DisplayWidget) child);
Expand Down Expand Up @@ -318,6 +320,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
return true;
}
}

return false;
}

Expand Down Expand Up @@ -414,7 +417,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
}

/******************************************************************************************
* Widget snapping is done by trying to snap a widget to other widgets called Anchors. *
* Widget snapping is done by trying to snap a widget to other widgets called Anchors. *
* It first calculates the distance between each anchor and the widget, and afterwards *
* snaps the widget to the closest edge/corner *
* *
Expand All @@ -436,40 +439,44 @@ public class Display.DisplaysOverlay : Gtk.Overlay {
widget_x += widget.delta_x;
widget_y += widget.delta_y;

int distance = int.MAX, distance_x = 0, distance_y = 0;
int shortest_distance = int.MAX, shortest_distance_x = 0, shortest_distance_y = 0;
foreach (var anchor in anchors) {
int anchor_x, anchor_y, anchor_width, anchor_height;
anchor.get_geometry (out anchor_x, out anchor_y, out anchor_width, out anchor_height);

var diff_x = anchor_x - widget_x;
var diff_y = anchor_y - widget_y;
var distance_left = diff_x + anchor_width;
var distance_right = diff_x - widget_width;
var distance_top = diff_y + anchor_height;
var distance_bottom = diff_y - widget_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;
var distance_origin_x = anchor_x - widget_x;
var distance_origin_y = anchor_y - widget_y;
var distance_left = distance_origin_x + anchor_width;
var distance_right = distance_origin_x - widget_width;
var distance_top = distance_origin_y + anchor_height;
var distance_bottom = distance_origin_y - widget_height;
var distance_widget_anchor_x = distance_right > -distance_left ? distance_right : distance_left;
var distance_widget_anchor_y = distance_bottom > -distance_top ? distance_bottom : distance_top;

// widget is between left and right edges of anchor, no horizontal movement needed
if (distance_left > 0 && distance_right < 0) {
test_distance_x = 0;
distance_widget_anchor_x = 0;
// widget is between top and bottom edges of anchor, no vertical movement needed
} else if (distance_top > 0 && distance_bottom < 0) {
test_distance_y = 0;
} else { // As diagonal monitors are not allowed, offset by 50px
if (test_distance_x.abs () >= test_distance_y.abs ()) {
test_distance_x += diff_x > 0 ? 50 : -50;
distance_widget_anchor_y = 0;
// widget is diagonal to anchor, as diagonal monitors are not allowed, offset by 50px (MINIMUM_WIDGET_OFFSET)
} else {
if (distance_widget_anchor_x.abs () >= distance_widget_anchor_y.abs ()) {
distance_widget_anchor_x += (distance_origin_x > 0 ? 1 : -1) * MINIMUM_WIDGET_OFFSET;
} else {
test_distance_y += diff_y > 0 ? 50 : -50;
distance_widget_anchor_y += (distance_origin_y > 0 ? 1 : -1) * MINIMUM_WIDGET_OFFSET;
}
}

var test_distance = test_distance_x * test_distance_x + test_distance_y * test_distance_y;
if (test_distance < distance) {
distance_x = test_distance_x;
distance_y = test_distance_y;
distance = test_distance;
var shortest_distance_candidate = distance_widget_anchor_x * distance_widget_anchor_x
+ distance_widget_anchor_y * distance_widget_anchor_y;
if (shortest_distance_candidate < shortest_distance) {
shortest_distance = shortest_distance_candidate;
shortest_distance_x = distance_widget_anchor_x;
shortest_distance_y = distance_widget_anchor_y;
}
}

widget.set_geometry (widget_x + distance_x, widget_y + distance_y, widget_width, widget_height);
widget.set_geometry (widget_x + shortest_distance_x, widget_y + shortest_distance_y, widget_width, widget_height);
}
}