mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Implement key binds to control virtual outputs (#1287)
Add actions `VirtualOutputAdd` and `VirtualOutputRemove`
This commit is contained in:
		
							parent
							
								
									e303281333
								
							
						
					
					
						commit
						111b955b53
					
				
					 5 changed files with 150 additions and 1 deletions
				
			
		
							
								
								
									
										63
									
								
								src/output.c
									
										
									
									
									
								
							
							
						
						
									
										63
									
								
								src/output.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -9,6 +9,8 @@
 | 
			
		|||
#define _POSIX_C_SOURCE 200809L
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <strings.h>
 | 
			
		||||
#include <wlr/backend/drm.h>
 | 
			
		||||
#include <wlr/backend/headless.h>
 | 
			
		||||
#include <wlr/types/wlr_buffer.h>
 | 
			
		||||
#include <wlr/types/wlr_drm_lease_v1.h>
 | 
			
		||||
#include <wlr/types/wlr_output.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -172,6 +174,12 @@ new_output_notify(struct wl_listener *listener, void *data)
 | 
			
		|||
	struct server *server = wl_container_of(listener, server, new_output);
 | 
			
		||||
	struct wlr_output *wlr_output = data;
 | 
			
		||||
 | 
			
		||||
	/* Name virtual output */
 | 
			
		||||
	if (wlr_output_is_headless(wlr_output) && server->headless.pending_output_name[0] != '\0') {
 | 
			
		||||
		wlr_output_set_name(wlr_output, server->headless.pending_output_name);
 | 
			
		||||
		server->headless.pending_output_name[0] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * We offer any display as available for lease, some apps like
 | 
			
		||||
	 * gamescope, want to take ownership of a display when they can
 | 
			
		||||
| 
						 | 
				
			
			@ -179,7 +187,7 @@ new_output_notify(struct wl_listener *listener, void *data)
 | 
			
		|||
	 * This is also useful for debugging the DRM parts of
 | 
			
		||||
	 * another compositor.
 | 
			
		||||
	 */
 | 
			
		||||
	if (server->drm_lease_manager) {
 | 
			
		||||
	if (server->drm_lease_manager && wlr_output_is_drm(wlr_output)) {
 | 
			
		||||
		wlr_drm_lease_v1_manager_offer_output(
 | 
			
		||||
			server->drm_lease_manager, wlr_output);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -746,3 +754,56 @@ handle_output_power_manager_set_mode(struct wl_listener *listener, void *data)
 | 
			
		|||
		break;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
output_add_virtual(struct server *server, const char *output_name)
 | 
			
		||||
{
 | 
			
		||||
	if (output_name) {
 | 
			
		||||
		/* Prevent creating outputs with the same name */
 | 
			
		||||
		struct output *output;
 | 
			
		||||
		wl_list_for_each(output, &server->outputs, link) {
 | 
			
		||||
			if (wlr_output_is_headless(output->wlr_output) &&
 | 
			
		||||
					!strcmp(output->wlr_output->name, output_name)) {
 | 
			
		||||
				wlr_log(WLR_DEBUG,
 | 
			
		||||
					"refusing to create virtual output with duplicate name");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		strncpy(server->headless.pending_output_name, output_name,
 | 
			
		||||
				sizeof(server->headless.pending_output_name));
 | 
			
		||||
	} else {
 | 
			
		||||
		server->headless.pending_output_name[0] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
	/*
 | 
			
		||||
	 * Setting it to (0, 0) here disallows changing resolution from tools like
 | 
			
		||||
	 * wlr-randr (returns error)
 | 
			
		||||
	 */
 | 
			
		||||
	wlr_headless_add_output(server->headless.backend, 1920, 1080);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
output_remove_virtual(struct server *server, const char *output_name)
 | 
			
		||||
{
 | 
			
		||||
	struct output *output;
 | 
			
		||||
	wl_list_for_each(output, &server->outputs, link) {
 | 
			
		||||
		if (wlr_output_is_headless(output->wlr_output)) {
 | 
			
		||||
			if (output_name) {
 | 
			
		||||
				/*
 | 
			
		||||
				 * Given virtual output name, find and destroy virtual output by
 | 
			
		||||
				 * that name.
 | 
			
		||||
				 */
 | 
			
		||||
				if (!strcmp(output->wlr_output->name, output_name)) {
 | 
			
		||||
					wlr_output_destroy(output->wlr_output);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				/*
 | 
			
		||||
				 * When virtual output name was no supplied by user, simply
 | 
			
		||||
				 * destroy the first virtual output found.
 | 
			
		||||
				 */
 | 
			
		||||
				wlr_output_destroy(output->wlr_output);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue