mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #935 from thejan2009/wrap-focus-change
Wrap focus change
This commit is contained in:
		
						commit
						02dc4142c0
					
				
					 5 changed files with 46 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -106,6 +106,7 @@ sway_cmd cmd_focus;
 | 
			
		|||
sway_cmd cmd_focus_follows_mouse;
 | 
			
		||||
sway_cmd cmd_font;
 | 
			
		||||
sway_cmd cmd_for_window;
 | 
			
		||||
sway_cmd cmd_force_focus_wrapping;
 | 
			
		||||
sway_cmd cmd_fullscreen;
 | 
			
		||||
sway_cmd cmd_gaps;
 | 
			
		||||
sway_cmd cmd_hide_edge_borders;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -211,6 +211,7 @@ struct sway_config {
 | 
			
		|||
	// Flags
 | 
			
		||||
	bool focus_follows_mouse;
 | 
			
		||||
	bool mouse_warping;
 | 
			
		||||
	bool force_focus_wrapping;
 | 
			
		||||
	bool active;
 | 
			
		||||
	bool failed;
 | 
			
		||||
	bool reloading;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -171,6 +171,7 @@ static struct cmd_handler handlers[] = {
 | 
			
		|||
	{ "focus", cmd_focus },
 | 
			
		||||
	{ "focus_follows_mouse", cmd_focus_follows_mouse },
 | 
			
		||||
	{ "font", cmd_font },
 | 
			
		||||
	{ "force_focus_wrapping", cmd_force_focus_wrapping },
 | 
			
		||||
	{ "for_window", cmd_for_window },
 | 
			
		||||
	{ "fullscreen", cmd_fullscreen },
 | 
			
		||||
	{ "gaps", cmd_gaps },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								sway/commands/force_focus_wrapping.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								sway/commands/force_focus_wrapping.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
#include <string.h>
 | 
			
		||||
#include "sway/commands.h"
 | 
			
		||||
 | 
			
		||||
struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) {
 | 
			
		||||
	struct cmd_results *error = NULL;
 | 
			
		||||
	if ((error = checkarg(argc, "force_focus_wrapping", EXPECTED_EQUAL_TO, 1))) {
 | 
			
		||||
		return error;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config->force_focus_wrapping = !strcasecmp(argv[0], "yes");
 | 
			
		||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1084,13 +1084,17 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
 | 
			
		|||
		return container->fullscreen;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	swayc_t *wrap_candidate = NULL;
 | 
			
		||||
	while (true) {
 | 
			
		||||
		// Test if we can even make a difference here
 | 
			
		||||
		bool can_move = false;
 | 
			
		||||
		int diff = 0;
 | 
			
		||||
		if (parent->type == C_ROOT) {
 | 
			
		||||
			sway_log(L_DEBUG, "Moving between outputs");
 | 
			
		||||
			swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true);
 | 
			
		||||
			if (!output || output == container) {
 | 
			
		||||
				return wrap_candidate;
 | 
			
		||||
			}
 | 
			
		||||
			sway_log(L_DEBUG, "Moving between outputs");
 | 
			
		||||
			return get_swayc_in_output_direction(output, dir);
 | 
			
		||||
		} else {
 | 
			
		||||
			if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1108,8 +1112,31 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
 | 
			
		|||
 | 
			
		||||
		if (can_move) {
 | 
			
		||||
			int desired = index_child(container) + diff;
 | 
			
		||||
			if (container->is_floating || desired < 0 || desired >= parent->children->length) {
 | 
			
		||||
			if (container->is_floating) {
 | 
			
		||||
				if (desired < 0) {
 | 
			
		||||
					wrap_candidate = parent->floating->items[parent->floating->length-1];
 | 
			
		||||
				} else if (desired >= parent->floating->length){
 | 
			
		||||
					wrap_candidate = parent->floating->items[0];
 | 
			
		||||
				} else {
 | 
			
		||||
					wrap_candidate = parent->floating->items[desired];
 | 
			
		||||
				}
 | 
			
		||||
				if (wrap_candidate) {
 | 
			
		||||
					wlc_view_bring_to_front(wrap_candidate->handle);
 | 
			
		||||
				}
 | 
			
		||||
				return wrap_candidate;
 | 
			
		||||
			} else if (desired < 0 || desired >= parent->children->length) {
 | 
			
		||||
				can_move = false;
 | 
			
		||||
				int len = parent->children->length;
 | 
			
		||||
				if (!wrap_candidate && len > 1) {
 | 
			
		||||
					if (desired < 0) {
 | 
			
		||||
						wrap_candidate = parent->children->items[len-1];
 | 
			
		||||
					} else {
 | 
			
		||||
						wrap_candidate = parent->children->items[0];
 | 
			
		||||
					}
 | 
			
		||||
					if (config->force_focus_wrapping) {
 | 
			
		||||
						return wrap_candidate;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				return parent->children->items[desired];
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -1118,8 +1145,8 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
 | 
			
		|||
			container = parent;
 | 
			
		||||
			parent = parent->parent;
 | 
			
		||||
			if (!parent || container == limit) {
 | 
			
		||||
				// Nothing we can do
 | 
			
		||||
				return NULL;
 | 
			
		||||
				// wrapping is the last chance
 | 
			
		||||
				return wrap_candidate;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue