mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	resistance: only resist "entry" into another window space
This commit is contained in:
		
							parent
							
								
									2262851237
								
							
						
					
					
						commit
						8a0f1f9355
					
				
					 4 changed files with 33 additions and 26 deletions
				
			
		| 
						 | 
					@ -66,6 +66,7 @@ struct edge {
 | 
				
			||||||
 * @target: position to which the moving edge will be moved
 | 
					 * @target: position to which the moving edge will be moved
 | 
				
			||||||
 * @oppose: opposing edge of encountered region
 | 
					 * @oppose: opposing edge of encountered region
 | 
				
			||||||
 * @align: aligned edge of encountered region
 | 
					 * @align: aligned edge of encountered region
 | 
				
			||||||
 | 
					 * @lesser: true if the moving edge is top or left, false otherwise
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This function will be used by edge_find_neighbors and edge_find_outputs to
 | 
					 * This function will be used by edge_find_neighbors and edge_find_outputs to
 | 
				
			||||||
 * validate and select the "best" output or neighbor edge against which a
 | 
					 * validate and select the "best" output or neighbor edge against which a
 | 
				
			||||||
| 
						 | 
					@ -92,7 +93,7 @@ struct edge {
 | 
				
			||||||
 * update the value of *best accordingly.
 | 
					 * update the value of *best accordingly.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
typedef void (*edge_validator_t)(int *best, struct edge current,
 | 
					typedef void (*edge_validator_t)(int *best, struct edge current,
 | 
				
			||||||
	struct edge target, struct edge oppose, struct edge align);
 | 
						struct edge target, struct edge oppose, struct edge align, bool lesser);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void edges_initialize(struct border *edges);
 | 
					void edges_initialize(struct border *edges);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -90,11 +90,13 @@ validate_single_region_edge(int *valid_edge,
 | 
				
			||||||
	 * the region borders for aligned edges only.
 | 
						 * the region borders for aligned edges only.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool lesser = direction == VIEW_EDGE_LEFT || direction == VIEW_EDGE_UP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	validator(valid_edge,
 | 
						validator(valid_edge,
 | 
				
			||||||
		build_edge(view, direction, 0),
 | 
							build_edge(view, direction, 0),
 | 
				
			||||||
		build_edge(target, direction, 0),
 | 
							build_edge(target, direction, 0),
 | 
				
			||||||
		build_edge(region, view_edge_invert(direction), 0),
 | 
							build_edge(region, view_edge_invert(direction), 0),
 | 
				
			||||||
		build_edge(region, direction, rc.gap));
 | 
							build_edge(region, direction, rc.gap), lesser);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -132,11 +134,13 @@ validate_single_output_edge(int *valid_edge,
 | 
				
			||||||
		.left = INT_MIN,
 | 
							.left = INT_MIN,
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool lesser = direction == VIEW_EDGE_LEFT || direction == VIEW_EDGE_UP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	validator(valid_edge,
 | 
						validator(valid_edge,
 | 
				
			||||||
		build_edge(view, direction, 0),
 | 
							build_edge(view, direction, 0),
 | 
				
			||||||
		build_edge(target, direction, 0),
 | 
							build_edge(target, direction, 0),
 | 
				
			||||||
		build_edge(region, direction, 0),
 | 
							build_edge(region, direction, 0),
 | 
				
			||||||
		build_edge(unbounded, direction, 0));
 | 
							build_edge(unbounded, direction, 0), lesser);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,12 +11,11 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
check_edge(int *next, struct edge current, struct edge target,
 | 
					check_edge(int *next, struct edge current, struct edge target,
 | 
				
			||||||
		struct edge oppose, struct edge align, int tolerance)
 | 
							struct edge oppose, struct edge align, int tolerance, bool lesser)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int cur = current.offset;
 | 
						int cur = current.offset;
 | 
				
			||||||
	int tgt = target.offset;
 | 
						int tgt = target.offset;
 | 
				
			||||||
	int opp = oppose.offset;
 | 
						int opp = oppose.offset;
 | 
				
			||||||
	int aln = align.offset;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Ignore non-moving edges */
 | 
						/* Ignore non-moving edges */
 | 
				
			||||||
	if (cur == tgt) {
 | 
						if (cur == tgt) {
 | 
				
			||||||
| 
						 | 
					@ -39,9 +38,28 @@ check_edge(int *next, struct edge current, struct edge target,
 | 
				
			||||||
	/* Direction of motion for the edge */
 | 
						/* Direction of motion for the edge */
 | 
				
			||||||
	const bool decreasing = tgt < cur;
 | 
						const bool decreasing = tgt < cur;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Motion resists "entry" into the space of another window, but never
 | 
				
			||||||
 | 
						 * resist leaving it. Without edge attraction, this only happens when
 | 
				
			||||||
 | 
						 * the "leading" edge of a motion (top edge upward, bottom edge
 | 
				
			||||||
 | 
						 * downward, left edge leftward, right edge rightward) encounters an
 | 
				
			||||||
 | 
						 * opposing edge. If the motion is not of a leading edge, there is no
 | 
				
			||||||
 | 
						 * need to check for any resistance.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * However, if there is attraction, a "trailing" edge of a motion (top
 | 
				
			||||||
 | 
						 * edge downward, bottom edge upward, left edge rightward, right edge
 | 
				
			||||||
 | 
						 * leftward) may be grabbed by the opposing edge of another window as
 | 
				
			||||||
 | 
						 * it passes. Hence, trailing edges still need to be tested in
 | 
				
			||||||
 | 
						 * attractive cases.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (tolerance >= 0 && lesser != decreasing) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Check the opposing edge */
 | 
						/* Check the opposing edge */
 | 
				
			||||||
	bool valid = false;
 | 
						bool valid = false;
 | 
				
			||||||
	if (decreasing) {
 | 
						if (decreasing) {
 | 
				
			||||||
 | 
							/* Check for decreasing movement across opposing edge */
 | 
				
			||||||
		const int lo = clipped_sub(opp, abs(tolerance));
 | 
							const int lo = clipped_sub(opp, abs(tolerance));
 | 
				
			||||||
		const int hi = clipped_sub(opp, MIN(tolerance, 0));
 | 
							const int hi = clipped_sub(opp, MIN(tolerance, 0));
 | 
				
			||||||
		valid = tgt >= lo && tgt < hi && cur >= opp;
 | 
							valid = tgt >= lo && tgt < hi && cur >= opp;
 | 
				
			||||||
| 
						 | 
					@ -55,38 +73,22 @@ check_edge(int *next, struct edge current, struct edge target,
 | 
				
			||||||
	if (valid && edges_traverse_edge(current, target, oppose)) {
 | 
						if (valid && edges_traverse_edge(current, target, oppose)) {
 | 
				
			||||||
		*next = edge_get_best(*next, opp, decreasing);
 | 
							*next = edge_get_best(*next, opp, decreasing);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Check the aligned edge */
 | 
					 | 
				
			||||||
	valid = false;
 | 
					 | 
				
			||||||
	if (decreasing) {
 | 
					 | 
				
			||||||
		const int lo = clipped_sub(aln, abs(tolerance));
 | 
					 | 
				
			||||||
		const int hi = clipped_sub(aln, MIN(tolerance, 0));
 | 
					 | 
				
			||||||
		valid = tgt >= lo && tgt < hi && cur >= aln;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		const int lo = clipped_add(aln, MIN(tolerance, 0));
 | 
					 | 
				
			||||||
		const int hi = clipped_add(aln, abs(tolerance));
 | 
					 | 
				
			||||||
		valid = tgt > lo && tgt <= hi && cur <= aln;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (valid && edges_traverse_edge(current, target, align)) {
 | 
					 | 
				
			||||||
		*next = edge_get_best(*next, aln, decreasing);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
check_edge_output(int *next, struct edge current, struct edge target,
 | 
					check_edge_output(int *next, struct edge current, struct edge target,
 | 
				
			||||||
		struct edge oppose, struct edge align)
 | 
							struct edge oppose, struct edge align, bool lesser)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	check_edge(next, current, target,
 | 
						check_edge(next, current, target,
 | 
				
			||||||
		oppose, align, rc.screen_edge_strength);
 | 
							oppose, align, rc.screen_edge_strength, lesser);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
check_edge_window(int *next, struct edge current, struct edge target,
 | 
					check_edge_window(int *next, struct edge current, struct edge target,
 | 
				
			||||||
		struct edge oppose, struct edge align)
 | 
							struct edge oppose, struct edge align, bool lesser)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	check_edge(next, current, target,
 | 
						check_edge(next, current, target,
 | 
				
			||||||
		oppose, align, rc.window_edge_strength);
 | 
							oppose, align, rc.window_edge_strength, lesser);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
check_edge(int *next, struct edge current, struct edge target,
 | 
					check_edge(int *next, struct edge current, struct edge target,
 | 
				
			||||||
		struct edge oppose, struct edge align)
 | 
							struct edge oppose, struct edge align, bool lesser)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int cur = current.offset;
 | 
						int cur = current.offset;
 | 
				
			||||||
	int tgt = target.offset;
 | 
						int tgt = target.offset;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue