mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			82 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "labwc.h"
 | 
						|
 | 
						|
void xdg_surface_map(struct wl_listener *listener, void *data)
 | 
						|
{
 | 
						|
	/* Called when the surface is mapped, or ready to display on-screen. */
 | 
						|
	struct view *view = wl_container_of(listener, view, map);
 | 
						|
	view->mapped = true;
 | 
						|
	view->been_mapped = true;
 | 
						|
	view->surface = view->xdg_surface->surface;
 | 
						|
	focus_view(view, view->xdg_surface->surface);
 | 
						|
}
 | 
						|
 | 
						|
void xdg_surface_unmap(struct wl_listener *listener, void *data)
 | 
						|
{
 | 
						|
	struct view *view = wl_container_of(listener, view, unmap);
 | 
						|
	view->mapped = false;
 | 
						|
	view_focus_next_toplevel(view->server);
 | 
						|
}
 | 
						|
 | 
						|
void xdg_surface_destroy(struct wl_listener *listener, void *data)
 | 
						|
{
 | 
						|
	struct view *view = wl_container_of(listener, view, destroy);
 | 
						|
	wl_list_remove(&view->link);
 | 
						|
	free(view);
 | 
						|
}
 | 
						|
 | 
						|
void xdg_toplevel_request_move(struct wl_listener *listener, void *data)
 | 
						|
{
 | 
						|
	/* This event is raised when a client would like to begin an interactive
 | 
						|
	 * move, typically because the user clicked on their client-side
 | 
						|
	 * decorations. Note that a more sophisticated compositor should check
 | 
						|
	 * the provied serial against a list of button press serials sent to
 | 
						|
	 * this
 | 
						|
	 * client, to prevent the client from requesting this whenever they
 | 
						|
	 * want. */
 | 
						|
	struct view *view = wl_container_of(listener, view, request_move);
 | 
						|
	begin_interactive(view, TINYWL_CURSOR_MOVE, 0);
 | 
						|
}
 | 
						|
 | 
						|
void xdg_toplevel_request_resize(struct wl_listener *listener, void *data)
 | 
						|
{
 | 
						|
	/* This event is raised when a client would like to begin an interactive
 | 
						|
	 * resize, typically because the user clicked on their client-side
 | 
						|
	 * decorations. Note that a more sophisticated compositor should check
 | 
						|
	 * the provied serial against a list of button press serials sent to
 | 
						|
	 * this
 | 
						|
	 * client, to prevent the client from requesting this whenever they
 | 
						|
	 * want. */
 | 
						|
	struct wlr_xdg_toplevel_resize_event *event = data;
 | 
						|
	struct view *view = wl_container_of(listener, view, request_resize);
 | 
						|
	begin_interactive(view, TINYWL_CURSOR_RESIZE, event->edges);
 | 
						|
}
 | 
						|
 | 
						|
void xdg_surface_new(struct wl_listener *listener, void *data)
 | 
						|
{
 | 
						|
	struct server *server =
 | 
						|
		wl_container_of(listener, server, new_xdg_surface);
 | 
						|
	struct wlr_xdg_surface *xdg_surface = data;
 | 
						|
	if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
 | 
						|
		return;
 | 
						|
	}
 | 
						|
 | 
						|
	struct view *view = calloc(1, sizeof(struct view));
 | 
						|
	view->server = server;
 | 
						|
	view->type = LAB_XDG_SHELL_VIEW;
 | 
						|
	view->xdg_surface = xdg_surface;
 | 
						|
 | 
						|
	view->map.notify = xdg_surface_map;
 | 
						|
	wl_signal_add(&xdg_surface->events.map, &view->map);
 | 
						|
	view->unmap.notify = xdg_surface_unmap;
 | 
						|
	wl_signal_add(&xdg_surface->events.unmap, &view->unmap);
 | 
						|
	view->destroy.notify = xdg_surface_destroy;
 | 
						|
	wl_signal_add(&xdg_surface->events.destroy, &view->destroy);
 | 
						|
 | 
						|
	struct wlr_xdg_toplevel *toplevel = xdg_surface->toplevel;
 | 
						|
	view->request_move.notify = xdg_toplevel_request_move;
 | 
						|
	wl_signal_add(&toplevel->events.request_move, &view->request_move);
 | 
						|
	view->request_resize.notify = xdg_toplevel_request_resize;
 | 
						|
	wl_signal_add(&toplevel->events.request_resize, &view->request_resize);
 | 
						|
 | 
						|
	wl_list_insert(&server->views, &view->link);
 | 
						|
}
 |