mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	SnapToRegion: Add SnapToRegion action
This commit is contained in:
		
							parent
							
								
									9d3e309a22
								
							
						
					
					
						commit
						96a591297d
					
				
					 3 changed files with 43 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -30,4 +30,6 @@ void regions_init(struct server *server, struct seat *seat);
 | 
			
		|||
void regions_update(struct output *output);
 | 
			
		||||
void regions_destroy(struct wl_list *regions);
 | 
			
		||||
 | 
			
		||||
struct region *regions_from_name(const char *region_name, struct output *output);
 | 
			
		||||
 | 
			
		||||
#endif /* __LABWC_REGIONS_H */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										27
									
								
								src/action.c
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								src/action.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
#include "debug.h"
 | 
			
		||||
#include "labwc.h"
 | 
			
		||||
#include "menu/menu.h"
 | 
			
		||||
#include "regions.h"
 | 
			
		||||
#include "ssd.h"
 | 
			
		||||
#include "view.h"
 | 
			
		||||
#include "workspaces.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -58,6 +59,7 @@ enum action_type {
 | 
			
		|||
	ACTION_TYPE_RESIZE,
 | 
			
		||||
	ACTION_TYPE_GO_TO_DESKTOP,
 | 
			
		||||
	ACTION_TYPE_SEND_TO_DESKTOP,
 | 
			
		||||
	ACTION_TYPE_SNAP_TO_REGION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const char *action_names[] = {
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +87,7 @@ const char *action_names[] = {
 | 
			
		|||
	"Resize",
 | 
			
		||||
	"GoToDesktop",
 | 
			
		||||
	"SendToDesktop",
 | 
			
		||||
	"SnapToRegion",
 | 
			
		||||
	NULL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +114,9 @@ action_arg_from_xml_node(struct action *action, char *nodename, char *content)
 | 
			
		|||
	} else if (!strcmp(nodename, "to.action")) {
 | 
			
		||||
		/* GoToDesktop, SendToDesktop */
 | 
			
		||||
		action_arg_add_str(action, NULL, content);
 | 
			
		||||
	} else if (!strcmp(nodename, "region.action")) {
 | 
			
		||||
		/* SnapToRegion */
 | 
			
		||||
		action_arg_add_str(action, NULL, content);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -418,6 +424,27 @@ actions_run(struct view *activator, struct server *server,
 | 
			
		|||
				}
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case ACTION_TYPE_SNAP_TO_REGION:
 | 
			
		||||
			if (!arg) {
 | 
			
		||||
				wlr_log(WLR_ERROR, "Missing argument for SnapToRegion");
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
			if (!view) {
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
			struct output *output = view->output;
 | 
			
		||||
			if (!output) {
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
			const char *region_name = action_str_from_arg(arg);
 | 
			
		||||
			struct region *region = regions_from_name(region_name, output);
 | 
			
		||||
			if (region) {
 | 
			
		||||
				view_snap_to_region(view, region,
 | 
			
		||||
					/*store_natural_geometry*/ true);
 | 
			
		||||
			} else {
 | 
			
		||||
				wlr_log(WLR_ERROR, "Invalid SnapToRegion id: '%s'", region_name);
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case ACTION_TYPE_NONE:
 | 
			
		||||
			break;
 | 
			
		||||
		case ACTION_TYPE_INVALID:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,6 +25,20 @@ regions_init(struct server *server, struct seat *seat)
 | 
			
		|||
	/* To be filled later */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct region *
 | 
			
		||||
regions_from_name(const char *region_name, struct output *output)
 | 
			
		||||
{
 | 
			
		||||
	assert(region_name);
 | 
			
		||||
	assert(output);
 | 
			
		||||
	struct region *region;
 | 
			
		||||
	wl_list_for_each(region, &output->regions, link) {
 | 
			
		||||
		if (!strcmp(region->name, region_name)) {
 | 
			
		||||
			return region;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
regions_update(struct output *output)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue