parent
							
								
									28cedb5623
								
							
						
					
					
						commit
						a9cbfd950e
					
				| @ -1,47 +0,0 @@ | ||||
| #ifndef TYPES_WLR_XDG_SHELL_V6_H | ||||
| #define TYPES_WLR_XDG_SHELL_V6_H | ||||
| 
 | ||||
| #include <wayland-server-core.h> | ||||
| #include <wlr/types/wlr_xdg_shell_v6.h> | ||||
| #include "xdg-shell-unstable-v6-protocol.h" | ||||
| 
 | ||||
| struct wlr_xdg_positioner_v6_resource { | ||||
| 	struct wl_resource *resource; | ||||
| 	struct wlr_xdg_positioner_v6 attrs; | ||||
| }; | ||||
| 
 | ||||
| extern const struct wlr_surface_role xdg_toplevel_v6_surface_role; | ||||
| extern const struct wlr_surface_role xdg_popup_v6_surface_role; | ||||
| 
 | ||||
| uint32_t schedule_xdg_surface_v6_configure(struct wlr_xdg_surface_v6 *surface); | ||||
| struct wlr_xdg_surface_v6 *create_xdg_surface_v6( | ||||
| 	struct wlr_xdg_client_v6 *client, struct wlr_surface *surface, | ||||
| 	uint32_t id); | ||||
| void unmap_xdg_surface_v6(struct wlr_xdg_surface_v6 *surface); | ||||
| void destroy_xdg_surface_v6(struct wlr_xdg_surface_v6 *surface); | ||||
| void handle_xdg_surface_v6_commit(struct wlr_surface *wlr_surface); | ||||
| void handle_xdg_surface_v6_precommit(struct wlr_surface *wlr_surface); | ||||
| 
 | ||||
| void create_xdg_positioner_v6(struct wlr_xdg_client_v6 *client, uint32_t id); | ||||
| struct wlr_xdg_positioner_v6_resource *get_xdg_positioner_v6_from_resource( | ||||
| 	struct wl_resource *resource); | ||||
| 
 | ||||
| void create_xdg_popup_v6(struct wlr_xdg_surface_v6 *xdg_surface, | ||||
| 	struct wlr_xdg_surface_v6 *parent, | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner, int32_t id); | ||||
| void handle_xdg_surface_v6_popup_committed(struct wlr_xdg_surface_v6 *surface); | ||||
| struct wlr_xdg_popup_grab_v6 *get_xdg_shell_v6_popup_grab_from_seat( | ||||
| 	struct wlr_xdg_shell_v6 *shell, struct wlr_seat *seat); | ||||
| void destroy_xdg_popup_v6(struct wlr_xdg_surface_v6 *surface); | ||||
| 
 | ||||
| void create_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *xdg_surface, | ||||
| 	uint32_t id); | ||||
| void handle_xdg_surface_v6_toplevel_committed(struct wlr_xdg_surface_v6 *surface); | ||||
| void send_xdg_toplevel_v6_configure(struct wlr_xdg_surface_v6 *surface, | ||||
| 	struct wlr_xdg_surface_v6_configure *configure); | ||||
| void handle_xdg_toplevel_v6_ack_configure(struct wlr_xdg_surface_v6 *surface, | ||||
| 	struct wlr_xdg_surface_v6_configure *configure); | ||||
| bool compare_xdg_surface_v6_toplevel_state(struct wlr_xdg_toplevel_v6 *state); | ||||
| void destroy_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *surface); | ||||
| 
 | ||||
| #endif | ||||
| @ -1,375 +0,0 @@ | ||||
| /*
 | ||||
|  * This protocol is obsolete and will be removed in a future version. The | ||||
|  * recommended replacement is xdg-shell. | ||||
|  */ | ||||
| 
 | ||||
| /*
 | ||||
|  * This an unstable interface of wlroots. No guarantees are made regarding the | ||||
|  * future consistency of this API. | ||||
|  */ | ||||
| #ifndef WLR_USE_UNSTABLE | ||||
| #error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" | ||||
| #endif | ||||
| 
 | ||||
| #ifndef WLR_TYPES_WLR_XDG_SHELL_V6_H | ||||
| #define WLR_TYPES_WLR_XDG_SHELL_V6_H | ||||
| 
 | ||||
| #include <wayland-server-core.h> | ||||
| #include <wlr/types/wlr_box.h> | ||||
| #include <wlr/types/wlr_seat.h> | ||||
| #include "xdg-shell-unstable-v6-protocol.h" | ||||
| 
 | ||||
| /**
 | ||||
|  * An interface enabling clients to turn their wl_surfaces into windows in a | ||||
|  * desktop environment. | ||||
|  */ | ||||
| struct wlr_xdg_shell_v6 { | ||||
| 	struct wl_global *global; | ||||
| 	struct wl_list clients; | ||||
| 	struct wl_list popup_grabs; | ||||
| 	uint32_t ping_timeout; | ||||
| 
 | ||||
| 	struct wl_listener display_destroy; | ||||
| 
 | ||||
| 	struct { | ||||
| 		/**
 | ||||
| 		 * The `new_surface` event signals that a client has requested to | ||||
| 		 * create a new shell surface. At this point, the surface is ready to | ||||
| 		 * be configured but is not mapped or ready receive input events. The | ||||
| 		 * surface will be ready to be managed on the `map` event. | ||||
| 		 */ | ||||
| 		struct wl_signal new_surface; | ||||
| 		struct wl_signal destroy; | ||||
| 	} events; | ||||
| 
 | ||||
| 	void *data; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_client_v6 { | ||||
| 	struct wlr_xdg_shell_v6 *shell; | ||||
| 	struct wl_resource *resource; | ||||
| 	struct wl_client *client; | ||||
| 	struct wl_list surfaces; | ||||
| 
 | ||||
| 	struct wl_list link; // wlr_xdg_shell_v6::clients
 | ||||
| 
 | ||||
| 	uint32_t ping_serial; | ||||
| 	struct wl_event_source *ping_timer; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_positioner_v6 { | ||||
| 	struct wlr_box anchor_rect; | ||||
| 	enum zxdg_positioner_v6_anchor anchor; | ||||
| 	enum zxdg_positioner_v6_gravity gravity; | ||||
| 	enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment; | ||||
| 
 | ||||
| 	struct { | ||||
| 		int32_t width, height; | ||||
| 	} size; | ||||
| 
 | ||||
| 	struct { | ||||
| 		int32_t x, y; | ||||
| 	} offset; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_popup_v6 { | ||||
| 	struct wlr_xdg_surface_v6 *base; | ||||
| 	struct wl_list link; | ||||
| 
 | ||||
| 	struct wl_resource *resource; | ||||
| 	bool committed; | ||||
| 	struct wlr_xdg_surface_v6 *parent; | ||||
| 	struct wlr_seat *seat; | ||||
| 
 | ||||
| 	// Position of the popup relative to the upper left corner of the window
 | ||||
| 	// geometry of the parent surface
 | ||||
| 	struct wlr_box geometry; | ||||
| 
 | ||||
| 	struct wlr_xdg_positioner_v6 positioner; | ||||
| 
 | ||||
| 	struct wl_list grab_link; // wlr_xdg_popup_grab_v6::popups
 | ||||
| }; | ||||
| 
 | ||||
| // each seat gets a popup grab
 | ||||
| struct wlr_xdg_popup_grab_v6 { | ||||
| 	struct wl_client *client; | ||||
| 	struct wlr_seat_pointer_grab pointer_grab; | ||||
| 	struct wlr_seat_keyboard_grab keyboard_grab; | ||||
| 	struct wlr_seat_touch_grab touch_grab; | ||||
| 	struct wlr_seat *seat; | ||||
| 	struct wl_list popups; | ||||
| 	struct wl_list link; // wlr_xdg_shell_v6::popup_grabs
 | ||||
| 	struct wl_listener seat_destroy; | ||||
| }; | ||||
| 
 | ||||
| enum wlr_xdg_surface_v6_role { | ||||
| 	WLR_XDG_SURFACE_V6_ROLE_NONE, | ||||
| 	WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL, | ||||
| 	WLR_XDG_SURFACE_V6_ROLE_POPUP, | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_toplevel_v6_state { | ||||
| 	bool maximized, fullscreen, resizing, activated; | ||||
| 	uint32_t width, height; | ||||
| 	uint32_t max_width, max_height; | ||||
| 	uint32_t min_width, min_height; | ||||
| 
 | ||||
| 	// Since the fullscreen request may be made before the toplevel's surface
 | ||||
| 	// is mapped, this is used to store the requested fullscreen output (if
 | ||||
| 	// any) for wlr_xdg_toplevel_v6::client_pending.
 | ||||
| 	struct wlr_output *fullscreen_output; | ||||
| 	struct wl_listener fullscreen_output_destroy; | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
|  * An xdg-surface is a user interface element requiring management by the | ||||
|  * compositor. An xdg-surface alone isn't useful, a role should be assigned to | ||||
|  * it in order to map it. | ||||
|  * | ||||
|  * When a surface has a role and is ready to be displayed, the `map` event is | ||||
|  * emitted. When a surface should no longer be displayed, the `unmap` event is | ||||
|  * emitted. The `unmap` event is guaranteed to be emitted before the `destroy` | ||||
|  * event if the view is destroyed when mapped. | ||||
|  */ | ||||
| struct wlr_xdg_toplevel_v6 { | ||||
| 	struct wl_resource *resource; | ||||
| 	struct wlr_xdg_surface_v6 *base; | ||||
| 	struct wlr_xdg_surface_v6 *parent; | ||||
| 	bool added; | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_state client_pending; | ||||
| 	struct wlr_xdg_toplevel_v6_state server_pending; | ||||
| 	struct wlr_xdg_toplevel_v6_state last_acked; | ||||
| 	struct wlr_xdg_toplevel_v6_state current; | ||||
| 
 | ||||
| 	char *title; | ||||
| 	char *app_id; | ||||
| 
 | ||||
| 	struct { | ||||
| 		struct wl_signal request_maximize; | ||||
| 		struct wl_signal request_fullscreen; | ||||
| 		struct wl_signal request_minimize; | ||||
| 		struct wl_signal request_move; | ||||
| 		struct wl_signal request_resize; | ||||
| 		struct wl_signal request_show_window_menu; | ||||
| 		struct wl_signal set_parent; | ||||
| 		struct wl_signal set_title; | ||||
| 		struct wl_signal set_app_id; | ||||
| 	} events; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_surface_v6_configure { | ||||
| 	struct wl_list link; // wlr_xdg_surface_v6::configure_list
 | ||||
| 	uint32_t serial; | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_state *toplevel_state; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_surface_v6 { | ||||
| 	struct wlr_xdg_client_v6 *client; | ||||
| 	struct wl_resource *resource; | ||||
| 	struct wlr_surface *surface; | ||||
| 	struct wl_list link; // wlr_xdg_client_v6::surfaces
 | ||||
| 	enum wlr_xdg_surface_v6_role role; | ||||
| 
 | ||||
| 	union { | ||||
| 		struct wlr_xdg_toplevel_v6 *toplevel; | ||||
| 		struct wlr_xdg_popup_v6 *popup; | ||||
| 	}; | ||||
| 
 | ||||
| 	struct wl_list popups; // wlr_xdg_popup_v6::link
 | ||||
| 
 | ||||
| 	bool added, configured, mapped; | ||||
| 	uint32_t configure_serial; | ||||
| 	struct wl_event_source *configure_idle; | ||||
| 	uint32_t configure_next_serial; | ||||
| 	struct wl_list configure_list; | ||||
| 
 | ||||
| 	bool has_next_geometry; | ||||
| 	struct wlr_box next_geometry; | ||||
| 	struct wlr_box geometry; | ||||
| 
 | ||||
| 	struct wl_listener surface_destroy; | ||||
| 	struct wl_listener surface_commit; | ||||
| 
 | ||||
| 	struct { | ||||
| 		struct wl_signal destroy; | ||||
| 		struct wl_signal ping_timeout; | ||||
| 		struct wl_signal new_popup; | ||||
| 		/**
 | ||||
| 		 * The `map` event signals that the shell surface is ready to be | ||||
| 		 * managed by the compositor and rendered on the screen. At this point, | ||||
| 		 * the surface has configured its properties, has had the opportunity | ||||
| 		 * to bind to the seat to receive input events, and has a buffer that | ||||
| 		 * is ready to be rendered. You can now safely add this surface to a | ||||
| 		 * list of views. | ||||
| 		 */ | ||||
| 		struct wl_signal map; | ||||
| 		/**
 | ||||
| 		 * The `unmap` event signals that the surface is no longer in a state | ||||
| 		 * where it should be shown on the screen. This might happen if the | ||||
| 		 * surface no longer has a displayable buffer because either the | ||||
| 		 * surface has been hidden or is about to be destroyed. | ||||
| 		 */ | ||||
| 		struct wl_signal unmap; | ||||
| 	} events; | ||||
| 
 | ||||
| 	void *data; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_toplevel_v6_move_event { | ||||
| 	struct wlr_xdg_surface_v6 *surface; | ||||
| 	struct wlr_seat_client *seat; | ||||
| 	uint32_t serial; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_toplevel_v6_resize_event { | ||||
| 	struct wlr_xdg_surface_v6 *surface; | ||||
| 	struct wlr_seat_client *seat; | ||||
| 	uint32_t serial; | ||||
| 	uint32_t edges; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_toplevel_v6_set_fullscreen_event { | ||||
| 	struct wlr_xdg_surface_v6 *surface; | ||||
| 	bool fullscreen; | ||||
| 	struct wlr_output *output; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_toplevel_v6_show_window_menu_event { | ||||
| 	struct wlr_xdg_surface_v6 *surface; | ||||
| 	struct wlr_seat_client *seat; | ||||
| 	uint32_t serial; | ||||
| 	uint32_t x, y; | ||||
| }; | ||||
| 
 | ||||
| struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display); | ||||
| 
 | ||||
| /**
 | ||||
|  * Send a ping to the surface. If the surface does not respond in a reasonable | ||||
|  * amount of time, the ping_timeout event will be emitted. | ||||
|  */ | ||||
| void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface); | ||||
| 
 | ||||
| /**
 | ||||
|  * Request that this toplevel surface be the given size. Returns the associated | ||||
|  * configure serial. | ||||
|  */ | ||||
| uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, | ||||
| 		uint32_t width, uint32_t height); | ||||
| 
 | ||||
| /**
 | ||||
|  * Request that this toplevel surface show itself in an activated or deactivated | ||||
|  * state. Returns the associated configure serial. | ||||
|  */ | ||||
| uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool activated); | ||||
| 
 | ||||
| /**
 | ||||
|  * Request that this toplevel surface consider itself maximized or not | ||||
|  * maximized. Returns the associated configure serial. | ||||
|  */ | ||||
| uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool maximized); | ||||
| 
 | ||||
| /**
 | ||||
|  * Request that this toplevel surface consider itself fullscreen or not | ||||
|  * fullscreen. Returns the associated configure serial. | ||||
|  */ | ||||
| uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool fullscreen); | ||||
| 
 | ||||
| /**
 | ||||
|  * Request that this toplevel surface consider itself to be resizing or not | ||||
|  * resizing. Returns the associated configure serial. | ||||
|  */ | ||||
| uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool resizing); | ||||
| 
 | ||||
| /**
 | ||||
|  * Request that this xdg surface closes. | ||||
|  */ | ||||
| void wlr_xdg_surface_v6_send_close(struct wlr_xdg_surface_v6 *surface); | ||||
| 
 | ||||
| /**
 | ||||
|  * Find a surface within this xdg-surface tree at the given surface-local | ||||
|  * coordinates. Returns the surface and coordinates in the leaf surface | ||||
|  * coordinate system or NULL if no surface is found at that location. | ||||
|  */ | ||||
| struct wlr_surface *wlr_xdg_surface_v6_surface_at( | ||||
| 		struct wlr_xdg_surface_v6 *surface, double sx, double sy, | ||||
| 		double *sub_x, double *sub_y); | ||||
| 
 | ||||
| /**
 | ||||
|  * Get the geometry for this positioner based on the anchor rect, gravity, and | ||||
|  * size of this positioner. | ||||
|  */ | ||||
| struct wlr_box wlr_xdg_positioner_v6_get_geometry( | ||||
| 		struct wlr_xdg_positioner_v6 *positioner); | ||||
| 
 | ||||
| /**
 | ||||
|  * Get the anchor point for this popup in the toplevel parent's coordinate system. | ||||
|  */ | ||||
| void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, | ||||
| 		int *toplevel_sx, int *toplevel_sy); | ||||
| 
 | ||||
| /**
 | ||||
|  * Convert the given coordinates in the popup coordinate system to the toplevel | ||||
|  * surface coordinate system. | ||||
|  */ | ||||
| void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, | ||||
| 		int popup_sx, int popup_sy, int *toplevel_sx, int *toplevel_sy); | ||||
| 
 | ||||
| /**
 | ||||
|  * Set the geometry of this popup to unconstrain it according to its | ||||
|  * xdg-positioner rules. The box should be in the popup's root toplevel parent | ||||
|  * surface coordinate system. | ||||
|  */ | ||||
| void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, | ||||
| 		struct wlr_box *toplevel_sx_box); | ||||
| 
 | ||||
| /**
 | ||||
|   Invert the right/left anchor and gravity for this positioner. This can be | ||||
|   used to "flip" the positioner around the anchor rect in the x direction. | ||||
|  */ | ||||
| void wlr_positioner_v6_invert_x( | ||||
| 		struct wlr_xdg_positioner_v6 *positioner); | ||||
| 
 | ||||
| /**
 | ||||
|   Invert the top/bottom anchor and gravity for this positioner. This can be | ||||
|   used to "flip" the positioner around the anchor rect in the y direction. | ||||
|  */ | ||||
| void wlr_positioner_v6_invert_y( | ||||
| 		struct wlr_xdg_positioner_v6 *positioner); | ||||
| 
 | ||||
| bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface); | ||||
| 
 | ||||
| struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface( | ||||
| 		struct wlr_surface *surface); | ||||
| 
 | ||||
| /**
 | ||||
|  * Get the surface geometry. | ||||
|  * This is either the geometry as set by the client, or defaulted to the bounds | ||||
|  * of the surface + the subsurfaces (as specified by the protocol). | ||||
|  * | ||||
|  * The x and y value can be <0 | ||||
|  */ | ||||
| void wlr_xdg_surface_v6_get_geometry(struct wlr_xdg_surface_v6 *surface, struct wlr_box *box); | ||||
| 
 | ||||
| /**
 | ||||
|  * Call `iterator` on each surface and popup in the xdg-surface tree, with the | ||||
|  * surface's position relative to the root xdg-surface. The function is called | ||||
|  * from root to leaves (in rendering order). | ||||
|  */ | ||||
| void wlr_xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface, | ||||
| 	wlr_surface_iterator_func_t iterator, void *user_data); | ||||
| 
 | ||||
| /**
 | ||||
|  * Call `iterator` on each popup in the xdg-surface tree, with the popup's | ||||
|  * position relative to the root xdg-surface. The function is called from root | ||||
|  * to leaves (in rendering order). | ||||
|  */ | ||||
| void wlr_xdg_surface_v6_for_each_popup(struct wlr_xdg_surface_v6 *surface, | ||||
| 	wlr_surface_iterator_func_t iterator, void *user_data); | ||||
| 
 | ||||
| #endif | ||||
| @ -1,585 +0,0 @@ | ||||
| #include <assert.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include "types/wlr_xdg_shell_v6.h" | ||||
| #include "util/signal.h" | ||||
| 
 | ||||
| static struct wlr_xdg_surface_v6 *xdg_popup_grab_get_topmost( | ||||
| 		struct wlr_xdg_popup_grab_v6 *grab) { | ||||
| 	struct wlr_xdg_popup_v6 *popup; | ||||
| 	wl_list_for_each(popup, &grab->popups, grab_link) { | ||||
| 		return popup->base; | ||||
| 	} | ||||
| 
 | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| static void xdg_popup_grab_end(struct wlr_xdg_popup_grab_v6 *popup_grab) { | ||||
| 	struct wlr_xdg_popup_v6 *popup, *tmp; | ||||
| 	wl_list_for_each_safe(popup, tmp, &popup_grab->popups, grab_link) { | ||||
| 		zxdg_popup_v6_send_popup_done(popup->resource); | ||||
| 	} | ||||
| 
 | ||||
| 	wlr_seat_pointer_end_grab(popup_grab->seat); | ||||
| 	wlr_seat_keyboard_end_grab(popup_grab->seat); | ||||
| 	wlr_seat_touch_end_grab(popup_grab->seat); | ||||
| } | ||||
| 
 | ||||
| static void xdg_pointer_grab_enter(struct wlr_seat_pointer_grab *grab, | ||||
| 		struct wlr_surface *surface, double sx, double sy) { | ||||
| 	struct wlr_xdg_popup_grab_v6 *popup_grab = grab->data; | ||||
| 	if (wl_resource_get_client(surface->resource) == popup_grab->client) { | ||||
| 		wlr_seat_pointer_enter(grab->seat, surface, sx, sy); | ||||
| 	} else { | ||||
| 		wlr_seat_pointer_clear_focus(grab->seat); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void xdg_pointer_grab_clear_focus(struct wlr_seat_pointer_grab *grab) { | ||||
| 	wlr_seat_pointer_clear_focus(grab->seat); | ||||
| } | ||||
| 
 | ||||
| static void xdg_pointer_grab_motion(struct wlr_seat_pointer_grab *grab, | ||||
| 		uint32_t time, double sx, double sy) { | ||||
| 	wlr_seat_pointer_send_motion(grab->seat, time, sx, sy); | ||||
| } | ||||
| 
 | ||||
| static uint32_t xdg_pointer_grab_button(struct wlr_seat_pointer_grab *grab, | ||||
| 		uint32_t time, uint32_t button, uint32_t state) { | ||||
| 	uint32_t serial = | ||||
| 		wlr_seat_pointer_send_button(grab->seat, time, button, state); | ||||
| 	if (serial) { | ||||
| 		return serial; | ||||
| 	} else { | ||||
| 		xdg_popup_grab_end(grab->data); | ||||
| 		return 0; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void xdg_pointer_grab_axis(struct wlr_seat_pointer_grab *grab, | ||||
| 		uint32_t time, enum wlr_axis_orientation orientation, double value, | ||||
| 		int32_t value_discrete, enum wlr_axis_source source) { | ||||
| 	wlr_seat_pointer_send_axis(grab->seat, time, orientation, value, | ||||
| 		value_discrete, source); | ||||
| } | ||||
| 
 | ||||
| static void xdg_pointer_grab_frame(struct wlr_seat_pointer_grab *grab) { | ||||
| 	wlr_seat_pointer_send_frame(grab->seat); | ||||
| } | ||||
| 
 | ||||
| static void xdg_pointer_grab_cancel(struct wlr_seat_pointer_grab *grab) { | ||||
| 	xdg_popup_grab_end(grab->data); | ||||
| } | ||||
| 
 | ||||
| static const struct wlr_pointer_grab_interface xdg_pointer_grab_impl = { | ||||
| 	.enter = xdg_pointer_grab_enter, | ||||
| 	.clear_focus = xdg_pointer_grab_clear_focus, | ||||
| 	.motion = xdg_pointer_grab_motion, | ||||
| 	.button = xdg_pointer_grab_button, | ||||
| 	.cancel = xdg_pointer_grab_cancel, | ||||
| 	.axis = xdg_pointer_grab_axis, | ||||
| 	.frame = xdg_pointer_grab_frame, | ||||
| }; | ||||
| 
 | ||||
| static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab, | ||||
| 		struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, | ||||
| 		struct wlr_keyboard_modifiers *modifiers) { | ||||
| 	// keyboard focus should remain on the popup
 | ||||
| } | ||||
| 
 | ||||
| static void xdg_keyboard_grab_clear_focus(struct wlr_seat_keyboard_grab *grab) { | ||||
| 	// keyboard focus should remain on the popup
 | ||||
| } | ||||
| 
 | ||||
| static void xdg_keyboard_grab_key(struct wlr_seat_keyboard_grab *grab, | ||||
| 		uint32_t time, uint32_t key, uint32_t state) { | ||||
| 	wlr_seat_keyboard_send_key(grab->seat, time, key, state); | ||||
| } | ||||
| 
 | ||||
| static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab, | ||||
| 		struct wlr_keyboard_modifiers *modifiers) { | ||||
| 	wlr_seat_keyboard_send_modifiers(grab->seat, modifiers); | ||||
| } | ||||
| 
 | ||||
| static void xdg_keyboard_grab_cancel(struct wlr_seat_keyboard_grab *grab) { | ||||
| 	wlr_seat_pointer_end_grab(grab->seat); | ||||
| } | ||||
| 
 | ||||
| static const struct wlr_keyboard_grab_interface xdg_keyboard_grab_impl = { | ||||
| 	.enter = xdg_keyboard_grab_enter, | ||||
| 	.clear_focus = xdg_keyboard_grab_clear_focus, | ||||
| 	.key = xdg_keyboard_grab_key, | ||||
| 	.modifiers = xdg_keyboard_grab_modifiers, | ||||
| 	.cancel = xdg_keyboard_grab_cancel, | ||||
| }; | ||||
| 
 | ||||
| static uint32_t xdg_touch_grab_down(struct wlr_seat_touch_grab *grab, | ||||
| 		uint32_t time, struct wlr_touch_point *point) { | ||||
| 	struct wlr_xdg_popup_grab_v6 *popup_grab = grab->data; | ||||
| 
 | ||||
| 	if (wl_resource_get_client(point->surface->resource) != popup_grab->client) { | ||||
| 		xdg_popup_grab_end(grab->data); | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	return wlr_seat_touch_send_down(grab->seat, point->surface, time, | ||||
| 			point->touch_id, point->sx, point->sy); | ||||
| } | ||||
| 
 | ||||
| static void xdg_touch_grab_up(struct wlr_seat_touch_grab *grab, | ||||
| 		uint32_t time, struct wlr_touch_point *point) { | ||||
| 	wlr_seat_touch_send_up(grab->seat, time, point->touch_id); | ||||
| } | ||||
| 
 | ||||
| static void xdg_touch_grab_motion(struct wlr_seat_touch_grab *grab, | ||||
| 		uint32_t time, struct wlr_touch_point *point) { | ||||
| 	wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx, | ||||
| 		point->sy); | ||||
| } | ||||
| 
 | ||||
| static void xdg_touch_grab_enter(struct wlr_seat_touch_grab *grab, | ||||
| 		uint32_t time, struct wlr_touch_point *point) { | ||||
| } | ||||
| 
 | ||||
| static void xdg_touch_grab_cancel(struct wlr_seat_touch_grab *grab) { | ||||
| 	wlr_seat_touch_end_grab(grab->seat); | ||||
| } | ||||
| 
 | ||||
| static const struct wlr_touch_grab_interface xdg_touch_grab_impl = { | ||||
| 	.down = xdg_touch_grab_down, | ||||
| 	.up = xdg_touch_grab_up, | ||||
| 	.motion = xdg_touch_grab_motion, | ||||
| 	.enter = xdg_touch_grab_enter, | ||||
| 	.cancel = xdg_touch_grab_cancel | ||||
| }; | ||||
| 
 | ||||
| static void xdg_popup_grab_handle_seat_destroy( | ||||
| 		struct wl_listener *listener, void *data) { | ||||
| 	struct wlr_xdg_popup_grab_v6 *xdg_grab = | ||||
| 		wl_container_of(listener, xdg_grab, seat_destroy); | ||||
| 
 | ||||
| 	wl_list_remove(&xdg_grab->seat_destroy.link); | ||||
| 
 | ||||
| 	struct wlr_xdg_popup_v6 *popup, *next; | ||||
| 	wl_list_for_each_safe(popup, next, &xdg_grab->popups, grab_link) { | ||||
| 		destroy_xdg_surface_v6(popup->base); | ||||
| 	} | ||||
| 
 | ||||
| 	wl_list_remove(&xdg_grab->link); | ||||
| 	free(xdg_grab); | ||||
| } | ||||
| 
 | ||||
| struct wlr_xdg_popup_grab_v6 *get_xdg_shell_v6_popup_grab_from_seat( | ||||
| 		struct wlr_xdg_shell_v6 *shell, struct wlr_seat *seat) { | ||||
| 	struct wlr_xdg_popup_grab_v6 *xdg_grab; | ||||
| 	wl_list_for_each(xdg_grab, &shell->popup_grabs, link) { | ||||
| 		if (xdg_grab->seat == seat) { | ||||
| 			return xdg_grab; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_grab = calloc(1, sizeof(struct wlr_xdg_popup_grab_v6)); | ||||
| 	if (!xdg_grab) { | ||||
| 		return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_grab->pointer_grab.data = xdg_grab; | ||||
| 	xdg_grab->pointer_grab.interface = &xdg_pointer_grab_impl; | ||||
| 	xdg_grab->keyboard_grab.data = xdg_grab; | ||||
| 	xdg_grab->keyboard_grab.interface = &xdg_keyboard_grab_impl; | ||||
| 	xdg_grab->touch_grab.data = xdg_grab; | ||||
| 	xdg_grab->touch_grab.interface = &xdg_touch_grab_impl; | ||||
| 
 | ||||
| 	wl_list_init(&xdg_grab->popups); | ||||
| 
 | ||||
| 	wl_list_insert(&shell->popup_grabs, &xdg_grab->link); | ||||
| 	xdg_grab->seat = seat; | ||||
| 
 | ||||
| 	xdg_grab->seat_destroy.notify = xdg_popup_grab_handle_seat_destroy; | ||||
| 	wl_signal_add(&seat->events.destroy, &xdg_grab->seat_destroy); | ||||
| 
 | ||||
| 	return xdg_grab; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation; | ||||
| 
 | ||||
| static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_popup_resource( | ||||
| 		struct wl_resource *resource) { | ||||
| 	assert(wl_resource_instance_of(resource, &zxdg_popup_v6_interface, | ||||
| 		&zxdg_popup_v6_implementation)); | ||||
| 	return wl_resource_get_user_data(resource); | ||||
| } | ||||
| 
 | ||||
| void destroy_xdg_popup_v6(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); | ||||
| 	unmap_xdg_surface_v6(surface); | ||||
| 
 | ||||
| 	wl_resource_set_user_data(surface->popup->resource, NULL); | ||||
| 	wl_list_remove(&surface->popup->link); | ||||
| 	free(surface->popup); | ||||
| 	surface->popup = NULL; | ||||
| 
 | ||||
| 	surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; | ||||
| } | ||||
| 
 | ||||
| static void xdg_popup_handle_grab(struct wl_client *client, | ||||
| 		struct wl_resource *resource, struct wl_resource *seat_resource, | ||||
| 		uint32_t serial) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_popup_resource(resource); | ||||
| 	struct wlr_seat_client *seat_client = | ||||
| 		wlr_seat_client_from_resource(seat_resource); | ||||
| 	if (!surface) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (surface->popup->committed) { | ||||
| 		wl_resource_post_error(surface->popup->resource, | ||||
| 			ZXDG_POPUP_V6_ERROR_INVALID_GRAB, | ||||
| 			"xdg_popup is already mapped"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_popup_grab_v6 *popup_grab = | ||||
| 		get_xdg_shell_v6_popup_grab_from_seat(surface->client->shell, | ||||
| 			seat_client->seat); | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(popup_grab); | ||||
| 	bool parent_is_toplevel = | ||||
| 		surface->popup->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; | ||||
| 
 | ||||
| 	if ((topmost == NULL && !parent_is_toplevel) || | ||||
| 			(topmost != NULL && topmost != surface->popup->parent)) { | ||||
| 		wl_resource_post_error(surface->client->resource, | ||||
| 			ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, | ||||
| 			"xdg_popup was not created on the topmost popup"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	popup_grab->client = surface->client->client; | ||||
| 	surface->popup->seat = seat_client->seat; | ||||
| 
 | ||||
| 	wl_list_insert(&popup_grab->popups, &surface->popup->grab_link); | ||||
| 
 | ||||
| 	wlr_seat_pointer_start_grab(seat_client->seat, | ||||
| 		&popup_grab->pointer_grab); | ||||
| 	wlr_seat_keyboard_start_grab(seat_client->seat, | ||||
| 		&popup_grab->keyboard_grab); | ||||
| 	wlr_seat_touch_start_grab(seat_client->seat, | ||||
| 		&popup_grab->touch_grab); | ||||
| } | ||||
| 
 | ||||
| static void xdg_popup_handle_destroy(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_popup_resource(resource); | ||||
| 
 | ||||
| 	if (surface && !wl_list_empty(&surface->popups)) { | ||||
| 		wl_resource_post_error(surface->client->resource, | ||||
| 			ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, | ||||
| 			"xdg_popup was destroyed while it was not the topmost popup"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_resource_destroy(resource); | ||||
| } | ||||
| 
 | ||||
| static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = { | ||||
| 	.destroy = xdg_popup_handle_destroy, | ||||
| 	.grab = xdg_popup_handle_grab, | ||||
| }; | ||||
| 
 | ||||
| static void xdg_popup_handle_resource_destroy(struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_popup_resource(resource); | ||||
| 	if (surface != NULL) { | ||||
| 		destroy_xdg_popup_v6(surface); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void handle_xdg_surface_v6_popup_committed(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); | ||||
| 
 | ||||
| 	if (!surface->popup->committed) { | ||||
| 		schedule_xdg_surface_v6_configure(surface); | ||||
| 		surface->popup->committed = true; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| const struct wlr_surface_role xdg_popup_v6_surface_role = { | ||||
| 	.name = "xdg_popup_v6", | ||||
| 	.commit = handle_xdg_surface_v6_commit, | ||||
| 	.precommit = handle_xdg_surface_v6_precommit, | ||||
| }; | ||||
| 
 | ||||
| void create_xdg_popup_v6(struct wlr_xdg_surface_v6 *xdg_surface, | ||||
| 		struct wlr_xdg_surface_v6 *parent, | ||||
| 		struct wlr_xdg_positioner_v6_resource *positioner, int32_t id) { | ||||
| 	if (positioner->attrs.size.width == 0 || | ||||
| 			positioner->attrs.anchor_rect.width == 0) { | ||||
| 		wl_resource_post_error(xdg_surface->resource, | ||||
| 			ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER, | ||||
| 			"positioner object is not complete"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (!wlr_surface_set_role(xdg_surface->surface, &xdg_popup_v6_surface_role, | ||||
| 			xdg_surface, xdg_surface->resource, ZXDG_SHELL_V6_ERROR_ROLE)) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_surface->popup = calloc(1, sizeof(struct wlr_xdg_popup_v6)); | ||||
| 	if (!xdg_surface->popup) { | ||||
| 		wl_resource_post_no_memory(xdg_surface->resource); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_surface->popup->resource = | ||||
| 		wl_resource_create(xdg_surface->client->client, &zxdg_popup_v6_interface, | ||||
| 			wl_resource_get_version(xdg_surface->resource), id); | ||||
| 	if (xdg_surface->popup->resource == NULL) { | ||||
| 		free(xdg_surface->popup); | ||||
| 		wl_resource_post_no_memory(xdg_surface->resource); | ||||
| 		return; | ||||
| 	} | ||||
| 	wl_resource_set_implementation(xdg_surface->popup->resource, | ||||
| 		&zxdg_popup_v6_implementation, xdg_surface, | ||||
| 		xdg_popup_handle_resource_destroy); | ||||
| 
 | ||||
| 	xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_POPUP; | ||||
| 	xdg_surface->popup->base = xdg_surface; | ||||
| 	xdg_surface->popup->parent = parent; | ||||
| 	xdg_surface->popup->geometry = | ||||
| 		wlr_xdg_positioner_v6_get_geometry(&positioner->attrs); | ||||
| 
 | ||||
| 	// positioner properties
 | ||||
| 	memcpy(&xdg_surface->popup->positioner, &positioner->attrs, | ||||
| 		sizeof(struct wlr_xdg_positioner_v6)); | ||||
| 
 | ||||
| 	wl_list_insert(&parent->popups, &xdg_surface->popup->link); | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&parent->events.new_popup, xdg_surface->popup); | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, | ||||
| 		int *root_sx, int *root_sy) { | ||||
| 	struct wlr_box rect = popup->positioner.anchor_rect; | ||||
| 	enum zxdg_positioner_v6_anchor anchor = popup->positioner.anchor; | ||||
| 	int sx = 0, sy = 0; | ||||
| 
 | ||||
| 	if (anchor == ZXDG_POSITIONER_V6_ANCHOR_NONE) { | ||||
| 		sx = (rect.x + rect.width) / 2; | ||||
| 		sy = (rect.y + rect.height) / 2; | ||||
| 	} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_TOP) { | ||||
| 		sx = (rect.x + rect.width) / 2; | ||||
| 		sy = rect.y; | ||||
| 	} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) { | ||||
| 		sx = (rect.x + rect.width) / 2; | ||||
| 		sy = rect.y + rect.height; | ||||
| 	} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_LEFT) { | ||||
| 		sx = rect.x; | ||||
| 		sy = (rect.y + rect.height) / 2; | ||||
| 	} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_RIGHT) { | ||||
| 		sx = rect.x + rect.width; | ||||
| 		sy = (rect.y + rect.height) / 2; | ||||
| 	} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_TOP | | ||||
| 				ZXDG_POSITIONER_V6_ANCHOR_LEFT)) { | ||||
| 		sx = rect.x; | ||||
| 		sy = rect.y; | ||||
| 	} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_TOP | | ||||
| 				ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) { | ||||
| 		sx = rect.x + rect.width; | ||||
| 		sy = rect.y; | ||||
| 	} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM | | ||||
| 				ZXDG_POSITIONER_V6_ANCHOR_LEFT)) { | ||||
| 		sx = rect.x; | ||||
| 		sy = rect.y + rect.height; | ||||
| 	} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM | | ||||
| 				ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) { | ||||
| 		sx = rect.x + rect.width; | ||||
| 		sy = rect.y + rect.height; | ||||
| 	} | ||||
| 
 | ||||
| 	*root_sx = sx; | ||||
| 	*root_sy = sy; | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, | ||||
| 		int popup_sx, int popup_sy, int *toplevel_sx, int *toplevel_sy) { | ||||
| 	struct wlr_xdg_surface_v6 *parent = popup->parent; | ||||
| 	while (parent != NULL && parent->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { | ||||
| 		popup_sx += parent->popup->geometry.x; | ||||
| 		popup_sy += parent->popup->geometry.y; | ||||
| 		parent = parent->popup->parent; | ||||
| 	} | ||||
| 	assert(parent); | ||||
| 
 | ||||
| 	*toplevel_sx = popup_sx + parent->geometry.x; | ||||
| 	*toplevel_sy = popup_sy + parent->geometry.y; | ||||
| } | ||||
| 
 | ||||
| static void xdg_popup_v6_box_constraints(struct wlr_xdg_popup_v6 *popup, | ||||
| 		struct wlr_box *toplevel_sx_box, int *offset_x, int *offset_y) { | ||||
| 	int popup_width = popup->geometry.width; | ||||
| 	int popup_height = popup->geometry.height; | ||||
| 	int anchor_sx = 0, anchor_sy = 0; | ||||
| 	wlr_xdg_popup_v6_get_anchor_point(popup, &anchor_sx, &anchor_sy); | ||||
| 	int popup_sx = 0, popup_sy = 0; | ||||
| 	wlr_xdg_popup_v6_get_toplevel_coords(popup, popup->geometry.x, | ||||
| 		popup->geometry.y, &popup_sx, &popup_sy); | ||||
| 	*offset_x = 0, *offset_y = 0; | ||||
| 
 | ||||
| 	if (popup_sx < toplevel_sx_box->x) { | ||||
| 		*offset_x = toplevel_sx_box->x - popup_sx; | ||||
| 	} else if (popup_sx + popup_width > | ||||
| 			toplevel_sx_box->x + toplevel_sx_box->width) { | ||||
| 		*offset_x = toplevel_sx_box->x + toplevel_sx_box->width - | ||||
| 			(popup_sx + popup_width); | ||||
| 	} | ||||
| 
 | ||||
| 	if (popup_sy < toplevel_sx_box->y) { | ||||
| 		*offset_y = toplevel_sx_box->y - popup_sy; | ||||
| 	} else if (popup_sy + popup_height > | ||||
| 			toplevel_sx_box->y + toplevel_sx_box->height) { | ||||
| 		*offset_y = toplevel_sx_box->y + toplevel_sx_box->height - | ||||
| 			(popup_sy + popup_height); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static bool xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, | ||||
| 		struct wlr_box *toplevel_sx_box) { | ||||
| 	int offset_x = 0, offset_y = 0; | ||||
| 	xdg_popup_v6_box_constraints(popup, toplevel_sx_box, | ||||
| 		&offset_x, &offset_y); | ||||
| 
 | ||||
| 	if (!offset_x && !offset_y) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	bool flip_x = offset_x && | ||||
| 		(popup->positioner.constraint_adjustment & | ||||
| 		 ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X); | ||||
| 
 | ||||
| 	bool flip_y = offset_y && | ||||
| 		(popup->positioner.constraint_adjustment & | ||||
| 		 ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y); | ||||
| 
 | ||||
| 	if (flip_x) { | ||||
| 		wlr_positioner_v6_invert_x(&popup->positioner); | ||||
| 	} | ||||
| 	if (flip_y) { | ||||
| 		wlr_positioner_v6_invert_y(&popup->positioner); | ||||
| 	} | ||||
| 
 | ||||
| 	popup->geometry = | ||||
| 		wlr_xdg_positioner_v6_get_geometry(&popup->positioner); | ||||
| 
 | ||||
| 	xdg_popup_v6_box_constraints(popup, toplevel_sx_box, | ||||
| 		&offset_x, &offset_y); | ||||
| 
 | ||||
| 	if (!offset_x && !offset_y) { | ||||
| 		// no longer constrained
 | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	// revert the positioner back if it didn't fix it and go to the next part
 | ||||
| 	if (offset_x && flip_x) { | ||||
| 		wlr_positioner_v6_invert_x(&popup->positioner); | ||||
| 	} | ||||
| 	if (offset_y && flip_y) { | ||||
| 		wlr_positioner_v6_invert_y(&popup->positioner); | ||||
| 	} | ||||
| 
 | ||||
| 	popup->geometry = | ||||
| 		wlr_xdg_positioner_v6_get_geometry(&popup->positioner); | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| static bool xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, | ||||
| 		struct wlr_box *toplevel_sx_box) { | ||||
| 	int offset_x = 0, offset_y = 0; | ||||
| 	xdg_popup_v6_box_constraints(popup, toplevel_sx_box, | ||||
| 		&offset_x, &offset_y); | ||||
| 
 | ||||
| 	if (!offset_x && !offset_y) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	bool slide_x = offset_x && | ||||
| 		(popup->positioner.constraint_adjustment & | ||||
| 		 ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X); | ||||
| 
 | ||||
| 	bool slide_y = offset_y && | ||||
| 		(popup->positioner.constraint_adjustment & | ||||
| 		 ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y); | ||||
| 
 | ||||
| 	if (slide_x) { | ||||
| 		popup->geometry.x += offset_x; | ||||
| 	} | ||||
| 
 | ||||
| 	if (slide_y) { | ||||
| 		popup->geometry.y += offset_y; | ||||
| 	} | ||||
| 
 | ||||
| 	int toplevel_x = 0, toplevel_y = 0; | ||||
| 	wlr_xdg_popup_v6_get_toplevel_coords(popup, popup->geometry.x, | ||||
| 		popup->geometry.y, &toplevel_x, &toplevel_y); | ||||
| 
 | ||||
| 	if (slide_x && toplevel_x < toplevel_sx_box->x) { | ||||
| 		popup->geometry.x += toplevel_sx_box->x - toplevel_x; | ||||
| 	} | ||||
| 	if (slide_y && toplevel_y < toplevel_sx_box->y) { | ||||
| 		popup->geometry.y += toplevel_sx_box->y - toplevel_y; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_popup_v6_box_constraints(popup, toplevel_sx_box, | ||||
| 		&offset_x, &offset_y); | ||||
| 
 | ||||
| 	return !offset_x && !offset_y; | ||||
| } | ||||
| 
 | ||||
| static bool xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, | ||||
| 		struct wlr_box *toplevel_sx_box) { | ||||
| 	int offset_x, offset_y; | ||||
| 	xdg_popup_v6_box_constraints(popup, toplevel_sx_box, | ||||
| 		&offset_x, &offset_y); | ||||
| 
 | ||||
| 	if (!offset_x && !offset_y) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	bool resize_x = offset_x && | ||||
| 		(popup->positioner.constraint_adjustment & | ||||
| 		 ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X); | ||||
| 
 | ||||
| 	bool resize_y = offset_y && | ||||
| 		(popup->positioner.constraint_adjustment & | ||||
| 		 ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y); | ||||
| 
 | ||||
| 	if (resize_x) { | ||||
| 		popup->geometry.width -= offset_x; | ||||
| 	} | ||||
| 	if (resize_y) { | ||||
| 		popup->geometry.height -= offset_y; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_popup_v6_box_constraints(popup, toplevel_sx_box, | ||||
| 		&offset_x, &offset_y); | ||||
| 
 | ||||
| 	return !offset_x && !offset_y; | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, | ||||
| 		struct wlr_box *toplevel_sx_box) { | ||||
| 	if (xdg_popup_v6_unconstrain_flip(popup, toplevel_sx_box)) { | ||||
| 		return; | ||||
| 	} | ||||
| 	if (xdg_popup_v6_unconstrain_slide(popup, toplevel_sx_box)) { | ||||
| 		return; | ||||
| 	} | ||||
| 	if (xdg_popup_v6_unconstrain_resize(popup, toplevel_sx_box)) { | ||||
| 		return; | ||||
| 	} | ||||
| } | ||||
| @ -1,230 +0,0 @@ | ||||
| #include <assert.h> | ||||
| #include <stdlib.h> | ||||
| #include "types/wlr_xdg_shell_v6.h" | ||||
| 
 | ||||
| static const struct zxdg_positioner_v6_interface | ||||
| 	zxdg_positioner_v6_implementation; | ||||
| 
 | ||||
| struct wlr_xdg_positioner_v6_resource *get_xdg_positioner_v6_from_resource( | ||||
| 		struct wl_resource *resource) { | ||||
| 	assert(wl_resource_instance_of(resource, &zxdg_positioner_v6_interface, | ||||
| 		&zxdg_positioner_v6_implementation)); | ||||
| 	return wl_resource_get_user_data(resource); | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_destroy(struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 	free(positioner); | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_destroy(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	wl_resource_destroy(resource); | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_set_size(struct wl_client *client, | ||||
| 		struct wl_resource *resource, int32_t width, int32_t height) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 
 | ||||
| 	if (width < 1 || height < 1) { | ||||
| 		wl_resource_post_error(resource, | ||||
| 			ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, | ||||
| 			"width and height must be positive and non-zero"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	positioner->attrs.size.width = width; | ||||
| 	positioner->attrs.size.height = height; | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, | ||||
| 		struct wl_resource *resource, int32_t x, int32_t y, int32_t width, | ||||
| 		int32_t height) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 
 | ||||
| 	if (width < 1 || height < 1) { | ||||
| 		wl_resource_post_error(resource, | ||||
| 			ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, | ||||
| 			"width and height must be positive and non-zero"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	positioner->attrs.anchor_rect.x = x; | ||||
| 	positioner->attrs.anchor_rect.y = y; | ||||
| 	positioner->attrs.anchor_rect.width = width; | ||||
| 	positioner->attrs.anchor_rect.height = height; | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_set_anchor(struct wl_client *client, | ||||
| 		struct wl_resource *resource, uint32_t anchor) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 
 | ||||
| 	if (((anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP ) && | ||||
| 				(anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM)) || | ||||
| 			((anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) && | ||||
| 				(anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT))) { | ||||
| 		wl_resource_post_error(resource, | ||||
| 			ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, | ||||
| 			"same-axis values are not allowed"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	positioner->attrs.anchor = anchor; | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_set_gravity(struct wl_client *client, | ||||
| 		struct wl_resource *resource, uint32_t gravity) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 
 | ||||
| 	if (((gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) && | ||||
| 				(gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) || | ||||
| 			((gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) && | ||||
| 				(gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT))) { | ||||
| 		wl_resource_post_error(resource, | ||||
| 			ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, | ||||
| 			"same-axis values are not allowed"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	positioner->attrs.gravity = gravity; | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_set_constraint_adjustment( | ||||
| 		struct wl_client *client, struct wl_resource *resource, | ||||
| 		uint32_t constraint_adjustment) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 
 | ||||
| 	positioner->attrs.constraint_adjustment = constraint_adjustment; | ||||
| } | ||||
| 
 | ||||
| static void xdg_positioner_handle_set_offset(struct wl_client *client, | ||||
| 		struct wl_resource *resource, int32_t x, int32_t y) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(resource); | ||||
| 
 | ||||
| 	positioner->attrs.offset.x = x; | ||||
| 	positioner->attrs.offset.y = y; | ||||
| } | ||||
| 
 | ||||
| static const struct zxdg_positioner_v6_interface | ||||
| 		zxdg_positioner_v6_implementation = { | ||||
| 	.destroy = xdg_positioner_handle_destroy, | ||||
| 	.set_size = xdg_positioner_handle_set_size, | ||||
| 	.set_anchor_rect = xdg_positioner_handle_set_anchor_rect, | ||||
| 	.set_anchor = xdg_positioner_handle_set_anchor, | ||||
| 	.set_gravity = xdg_positioner_handle_set_gravity, | ||||
| 	.set_constraint_adjustment = | ||||
| 		xdg_positioner_handle_set_constraint_adjustment, | ||||
| 	.set_offset = xdg_positioner_handle_set_offset, | ||||
| }; | ||||
| 
 | ||||
| struct wlr_box wlr_xdg_positioner_v6_get_geometry( | ||||
| 		struct wlr_xdg_positioner_v6 *positioner) { | ||||
| 	struct wlr_box geometry = { | ||||
| 		.x = positioner->offset.x, | ||||
| 		.y = positioner->offset.y, | ||||
| 		.width = positioner->size.width, | ||||
| 		.height = positioner->size.height, | ||||
| 	}; | ||||
| 
 | ||||
| 	if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) { | ||||
| 		geometry.y += positioner->anchor_rect.y; | ||||
| 	} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) { | ||||
| 		geometry.y += | ||||
| 			positioner->anchor_rect.y + positioner->anchor_rect.height; | ||||
| 	} else { | ||||
| 		geometry.y += | ||||
| 			positioner->anchor_rect.y + positioner->anchor_rect.height / 2; | ||||
| 	} | ||||
| 
 | ||||
| 	if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) { | ||||
| 		geometry.x += positioner->anchor_rect.x; | ||||
| 	} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) { | ||||
| 		geometry.x += positioner->anchor_rect.x + positioner->anchor_rect.width; | ||||
| 	} else { | ||||
| 		geometry.x += | ||||
| 			positioner->anchor_rect.x + positioner->anchor_rect.width / 2; | ||||
| 	} | ||||
| 
 | ||||
| 	if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) { | ||||
| 		geometry.y -= geometry.height; | ||||
| 	} else if (!(positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) { | ||||
| 		geometry.y -= geometry.height / 2; | ||||
| 	} | ||||
| 
 | ||||
| 	if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) { | ||||
| 		geometry.x -= geometry.width; | ||||
| 	} else if (!(positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT)) { | ||||
| 		geometry.x -= geometry.width / 2; | ||||
| 	} | ||||
| 
 | ||||
| 	if (positioner->constraint_adjustment == | ||||
| 			ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) { | ||||
| 		return geometry; | ||||
| 	} | ||||
| 
 | ||||
| 	return geometry; | ||||
| } | ||||
| 
 | ||||
| void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6 *positioner) { | ||||
| 	if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) { | ||||
| 		positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_LEFT; | ||||
| 		positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_RIGHT; | ||||
| 	} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) { | ||||
| 		positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_RIGHT; | ||||
| 		positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_LEFT; | ||||
| 	} | ||||
| 
 | ||||
| 	if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) { | ||||
| 		positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_RIGHT; | ||||
| 		positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_LEFT; | ||||
| 	} else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) { | ||||
| 		positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_LEFT; | ||||
| 		positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_RIGHT; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void wlr_positioner_v6_invert_y( | ||||
| 		struct wlr_xdg_positioner_v6 *positioner) { | ||||
| 	if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) { | ||||
| 		positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_TOP; | ||||
| 		positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_BOTTOM; | ||||
| 	} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) { | ||||
| 		positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_BOTTOM; | ||||
| 		positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_TOP; | ||||
| 	} | ||||
| 
 | ||||
| 	if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) { | ||||
| 		positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_TOP; | ||||
| 		positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_BOTTOM; | ||||
| 	} else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) { | ||||
| 		positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_BOTTOM; | ||||
| 		positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_TOP; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void create_xdg_positioner_v6(struct wlr_xdg_client_v6 *client, uint32_t id) { | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		calloc(1, sizeof(struct wlr_xdg_positioner_v6_resource)); | ||||
| 	if (positioner == NULL) { | ||||
| 		wl_client_post_no_memory(client->client); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	positioner->resource = wl_resource_create(client->client, | ||||
| 		&zxdg_positioner_v6_interface, | ||||
| 		wl_resource_get_version(client->resource), id); | ||||
| 	if (positioner->resource == NULL) { | ||||
| 		free(positioner); | ||||
| 		wl_client_post_no_memory(client->client); | ||||
| 		return; | ||||
| 	} | ||||
| 	wl_resource_set_implementation(positioner->resource, | ||||
| 		&zxdg_positioner_v6_implementation, positioner, xdg_positioner_destroy); | ||||
| } | ||||
| @ -1,168 +0,0 @@ | ||||
| #include <assert.h> | ||||
| #include <stdlib.h> | ||||
| #include "types/wlr_xdg_shell_v6.h" | ||||
| #include "util/signal.h" | ||||
| 
 | ||||
| #define SHELL_VERSION 1 | ||||
| 
 | ||||
| static const struct zxdg_shell_v6_interface xdg_shell_impl; | ||||
| 
 | ||||
| static struct wlr_xdg_client_v6 *xdg_client_from_resource( | ||||
| 		struct wl_resource *resource) { | ||||
| 	assert(wl_resource_instance_of(resource, &zxdg_shell_v6_interface, | ||||
| 		&xdg_shell_impl)); | ||||
| 	return wl_resource_get_user_data(resource); | ||||
| } | ||||
| 
 | ||||
| static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, | ||||
| 		struct wl_resource *resource, uint32_t id) { | ||||
| 	struct wlr_xdg_client_v6 *client = | ||||
| 		xdg_client_from_resource(resource); | ||||
| 	create_xdg_positioner_v6(client, id); | ||||
| } | ||||
| 
 | ||||
| static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, | ||||
| 		struct wl_resource *client_resource, uint32_t id, | ||||
| 		struct wl_resource *surface_resource) { | ||||
| 	struct wlr_xdg_client_v6 *client = | ||||
| 		xdg_client_from_resource(client_resource); | ||||
| 	struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); | ||||
| 	create_xdg_surface_v6(client, surface, id); | ||||
| } | ||||
| 
 | ||||
| static void xdg_shell_handle_pong(struct wl_client *wl_client, | ||||
| 		struct wl_resource *resource, uint32_t serial) { | ||||
| 	struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource); | ||||
| 
 | ||||
| 	if (client->ping_serial != serial) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_event_source_timer_update(client->ping_timer, 0); | ||||
| 	client->ping_serial = 0; | ||||
| } | ||||
| 
 | ||||
| static void xdg_shell_handle_destroy(struct wl_client *wl_client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource); | ||||
| 
 | ||||
| 	if (!wl_list_empty(&client->surfaces)) { | ||||
| 		wl_resource_post_error(client->resource, | ||||
| 			ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES, | ||||
| 			"xdg_wm_base was destroyed before children"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_resource_destroy(resource); | ||||
| } | ||||
| 
 | ||||
| static const struct zxdg_shell_v6_interface xdg_shell_impl = { | ||||
| 	.destroy = xdg_shell_handle_destroy, | ||||
| 	.create_positioner = xdg_shell_handle_create_positioner, | ||||
| 	.get_xdg_surface = xdg_shell_handle_get_xdg_surface, | ||||
| 	.pong = xdg_shell_handle_pong, | ||||
| }; | ||||
| 
 | ||||
| static void xdg_client_v6_handle_resource_destroy( | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource); | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6 *surface, *tmp = NULL; | ||||
| 	wl_list_for_each_safe(surface, tmp, &client->surfaces, link) { | ||||
| 		wl_resource_destroy(surface->resource); | ||||
| 	} | ||||
| 
 | ||||
| 	if (client->ping_timer != NULL) { | ||||
| 		wl_event_source_remove(client->ping_timer); | ||||
| 	} | ||||
| 
 | ||||
| 	wl_list_remove(&client->link); | ||||
| 	free(client); | ||||
| } | ||||
| 
 | ||||
| static int xdg_client_v6_ping_timeout(void *user_data) { | ||||
| 	struct wlr_xdg_client_v6 *client = user_data; | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6 *surface; | ||||
| 	wl_list_for_each(surface, &client->surfaces, link) { | ||||
| 		wlr_signal_emit_safe(&surface->events.ping_timeout, surface); | ||||
| 	} | ||||
| 
 | ||||
| 	client->ping_serial = 0; | ||||
| 	return 1; | ||||
| } | ||||
| 
 | ||||
| static void xdg_shell_bind(struct wl_client *wl_client, void *data, | ||||
| 		uint32_t version, uint32_t id) { | ||||
| 	struct wlr_xdg_shell_v6 *xdg_shell = data; | ||||
| 	assert(wl_client && xdg_shell); | ||||
| 
 | ||||
| 	struct wlr_xdg_client_v6 *client = | ||||
| 		calloc(1, sizeof(struct wlr_xdg_client_v6)); | ||||
| 	if (client == NULL) { | ||||
| 		wl_client_post_no_memory(wl_client); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_list_init(&client->surfaces); | ||||
| 
 | ||||
| 	client->resource = | ||||
| 		wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id); | ||||
| 	if (client->resource == NULL) { | ||||
| 		free(client); | ||||
| 		wl_client_post_no_memory(wl_client); | ||||
| 		return; | ||||
| 	} | ||||
| 	client->client = wl_client; | ||||
| 	client->shell = xdg_shell; | ||||
| 
 | ||||
| 	wl_resource_set_implementation(client->resource, &xdg_shell_impl, client, | ||||
| 		xdg_client_v6_handle_resource_destroy); | ||||
| 	wl_list_insert(&xdg_shell->clients, &client->link); | ||||
| 
 | ||||
| 	struct wl_display *display = wl_client_get_display(client->client); | ||||
| 	struct wl_event_loop *loop = wl_display_get_event_loop(display); | ||||
| 	client->ping_timer = wl_event_loop_add_timer(loop, | ||||
| 		xdg_client_v6_ping_timeout, client); | ||||
| 	if (client->ping_timer == NULL) { | ||||
| 		wl_client_post_no_memory(client->client); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void handle_display_destroy(struct wl_listener *listener, void *data) { | ||||
| 	struct wlr_xdg_shell_v6 *xdg_shell = | ||||
| 		wl_container_of(listener, xdg_shell, display_destroy); | ||||
| 	wlr_signal_emit_safe(&xdg_shell->events.destroy, xdg_shell); | ||||
| 	wl_list_remove(&xdg_shell->display_destroy.link); | ||||
| 	wl_global_destroy(xdg_shell->global); | ||||
| 	free(xdg_shell); | ||||
| } | ||||
| 
 | ||||
| struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display) { | ||||
| 	struct wlr_xdg_shell_v6 *xdg_shell = | ||||
| 		calloc(1, sizeof(struct wlr_xdg_shell_v6)); | ||||
| 	if (!xdg_shell) { | ||||
| 		return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_shell->ping_timeout = 10000; | ||||
| 
 | ||||
| 	wl_list_init(&xdg_shell->clients); | ||||
| 	wl_list_init(&xdg_shell->popup_grabs); | ||||
| 
 | ||||
| 	struct wl_global *global = wl_global_create(display, | ||||
| 		&zxdg_shell_v6_interface, SHELL_VERSION, xdg_shell, xdg_shell_bind); | ||||
| 	if (!global) { | ||||
| 		free(xdg_shell); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 	xdg_shell->global = global; | ||||
| 
 | ||||
| 	wl_signal_init(&xdg_shell->events.new_surface); | ||||
| 	wl_signal_init(&xdg_shell->events.destroy); | ||||
| 
 | ||||
| 	xdg_shell->display_destroy.notify = handle_display_destroy; | ||||
| 	wl_display_add_destroy_listener(display, &xdg_shell->display_destroy); | ||||
| 
 | ||||
| 	return xdg_shell; | ||||
| } | ||||
| @ -1,606 +0,0 @@ | ||||
| #include <assert.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <wlr/util/log.h> | ||||
| #include "types/wlr_xdg_shell_v6.h" | ||||
| #include "util/signal.h" | ||||
| 
 | ||||
| bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface) { | ||||
| 	return surface->role == &xdg_toplevel_v6_surface_role || | ||||
| 		surface->role == &xdg_popup_v6_surface_role; | ||||
| } | ||||
| 
 | ||||
| struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface( | ||||
| 		struct wlr_surface *surface) { | ||||
| 	assert(wlr_surface_is_xdg_surface_v6(surface)); | ||||
| 	return (struct wlr_xdg_surface_v6 *)surface->role_data; | ||||
| } | ||||
| 
 | ||||
| static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation; | ||||
| 
 | ||||
| static struct wlr_xdg_surface_v6 *xdg_surface_from_resource( | ||||
| 		struct wl_resource *resource) { | ||||
| 	assert(wl_resource_instance_of(resource, &zxdg_surface_v6_interface, | ||||
| 		&zxdg_surface_v6_implementation)); | ||||
| 	return wl_resource_get_user_data(resource); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_configure_destroy( | ||||
| 		struct wlr_xdg_surface_v6_configure *configure) { | ||||
| 	if (configure == NULL) { | ||||
| 		return; | ||||
| 	} | ||||
| 	wl_list_remove(&configure->link); | ||||
| 	free(configure->toplevel_state); | ||||
| 	free(configure); | ||||
| } | ||||
| 
 | ||||
| void unmap_xdg_surface_v6(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	assert(surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE); | ||||
| 
 | ||||
| 	// TODO: probably need to ungrab before this event
 | ||||
| 	if (surface->mapped) { | ||||
| 		wlr_signal_emit_safe(&surface->events.unmap, surface); | ||||
| 	} | ||||
| 
 | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		free(surface->toplevel->title); | ||||
| 		surface->toplevel->title = NULL; | ||||
| 		free(surface->toplevel->app_id); | ||||
| 		surface->toplevel->app_id = NULL; | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		if (surface->popup->seat != NULL) { | ||||
| 			struct wlr_xdg_popup_grab_v6 *grab = | ||||
| 				get_xdg_shell_v6_popup_grab_from_seat(surface->client->shell, | ||||
| 					surface->popup->seat); | ||||
| 
 | ||||
| 			wl_list_remove(&surface->popup->grab_link); | ||||
| 
 | ||||
| 			if (wl_list_empty(&grab->popups)) { | ||||
| 				if (grab->seat->pointer_state.grab == &grab->pointer_grab) { | ||||
| 					wlr_seat_pointer_end_grab(grab->seat); | ||||
| 				} | ||||
| 				if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { | ||||
| 					wlr_seat_keyboard_end_grab(grab->seat); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			surface->popup->seat = NULL; | ||||
| 		} | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		assert(false && "not reached"); | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6_configure *configure, *tmp; | ||||
| 	wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { | ||||
| 		xdg_surface_configure_destroy(configure); | ||||
| 	} | ||||
| 
 | ||||
| 	surface->configured = surface->mapped = false; | ||||
| 	surface->configure_serial = 0; | ||||
| 	if (surface->configure_idle) { | ||||
| 		wl_event_source_remove(surface->configure_idle); | ||||
| 		surface->configure_idle = NULL; | ||||
| 	} | ||||
| 	surface->configure_next_serial = 0; | ||||
| 
 | ||||
| 	surface->has_next_geometry = false; | ||||
| 	memset(&surface->geometry, 0, sizeof(struct wlr_box)); | ||||
| 	memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); | ||||
| } | ||||
| 
 | ||||
| void destroy_xdg_surface_v6(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) { | ||||
| 		unmap_xdg_surface_v6(surface); | ||||
| 	} | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&surface->events.destroy, surface); | ||||
| 
 | ||||
| 	struct wlr_xdg_popup_v6 *popup_state, *next; | ||||
| 	wl_list_for_each_safe(popup_state, next, &surface->popups, link) { | ||||
| 		zxdg_popup_v6_send_popup_done(popup_state->resource); | ||||
| 		destroy_xdg_popup_v6(popup_state->base); | ||||
| 	} | ||||
| 
 | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		destroy_xdg_toplevel_v6(surface); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		destroy_xdg_popup_v6(surface); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		// This space is intentionally left blank
 | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_resource_set_user_data(surface->resource, NULL); | ||||
| 	surface->surface->role_data = NULL; | ||||
| 	wl_list_remove(&surface->link); | ||||
| 	wl_list_remove(&surface->surface_destroy.link); | ||||
| 	wl_list_remove(&surface->surface_commit.link); | ||||
| 	free(surface); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_get_toplevel(struct wl_client *client, | ||||
| 		struct wl_resource *resource, uint32_t id) { | ||||
| 	struct wlr_xdg_surface_v6 *xdg_surface = xdg_surface_from_resource(resource); | ||||
| 	create_xdg_toplevel_v6(xdg_surface, id); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_get_popup(struct wl_client *wl_client, | ||||
| 		struct wl_resource *resource, uint32_t id, | ||||
| 		struct wl_resource *parent_resource, | ||||
| 		struct wl_resource *positioner_resource) { | ||||
| 	struct wlr_xdg_surface_v6 *xdg_surface = | ||||
| 		xdg_surface_from_resource(resource); | ||||
| 	struct wlr_xdg_surface_v6 *parent = | ||||
| 		xdg_surface_from_resource(parent_resource); | ||||
| 	struct wlr_xdg_positioner_v6_resource *positioner = | ||||
| 		get_xdg_positioner_v6_from_resource(positioner_resource); | ||||
| 
 | ||||
| 	create_xdg_popup_v6(xdg_surface, parent, positioner, id); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_ack_configure(struct wl_client *client, | ||||
| 		struct wl_resource *resource, uint32_t serial) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); | ||||
| 
 | ||||
| 	if (surface->role == WLR_XDG_SURFACE_V6_ROLE_NONE) { | ||||
| 		wl_resource_post_error(surface->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, | ||||
| 			"xdg_surface must have a role"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	// First find the ack'ed configure
 | ||||
| 	bool found = false; | ||||
| 	struct wlr_xdg_surface_v6_configure *configure, *tmp; | ||||
| 	wl_list_for_each(configure, &surface->configure_list, link) { | ||||
| 		if (configure->serial == serial) { | ||||
| 			found = true; | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| 	if (!found) { | ||||
| 		wl_resource_post_error(surface->client->resource, | ||||
| 			ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE, | ||||
| 			"wrong configure serial: %u", serial); | ||||
| 		return; | ||||
| 	} | ||||
| 	// Then remove old configures from the list
 | ||||
| 	wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { | ||||
| 		if (configure->serial == serial) { | ||||
| 			break; | ||||
| 		} | ||||
| 		xdg_surface_configure_destroy(configure); | ||||
| 	} | ||||
| 
 | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		assert(0 && "not reached"); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		handle_xdg_toplevel_v6_ack_configure(surface, configure); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	surface->configured = true; | ||||
| 	surface->configure_serial = serial; | ||||
| 
 | ||||
| 	xdg_surface_configure_destroy(configure); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_set_window_geometry(struct wl_client *client, | ||||
| 		struct wl_resource *resource, int32_t x, int32_t y, int32_t width, | ||||
| 		int32_t height) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); | ||||
| 
 | ||||
| 	if (surface->role == WLR_XDG_SURFACE_V6_ROLE_NONE) { | ||||
| 		wl_resource_post_error(surface->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, | ||||
| 			"xdg_surface must have a role"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (width <= 0 || height <= 0) { | ||||
| 		wlr_log(WLR_ERROR, "Client tried to set invalid geometry"); | ||||
| 		wl_resource_post_error(resource, -1, "Tried to set invalid xdg-surface geometry"); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	surface->has_next_geometry = true; | ||||
| 	surface->next_geometry.height = height; | ||||
| 	surface->next_geometry.width = width; | ||||
| 	surface->next_geometry.x = x; | ||||
| 	surface->next_geometry.y = y; | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_destroy(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); | ||||
| 
 | ||||
| 	if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) { | ||||
| 		wlr_log(WLR_ERROR, "Tried to destroy an xdg_surface before its role " | ||||
| 			"object"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_resource_destroy(resource); | ||||
| } | ||||
| 
 | ||||
| static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = { | ||||
| 	.destroy = xdg_surface_handle_destroy, | ||||
| 	.get_toplevel = xdg_surface_handle_get_toplevel, | ||||
| 	.get_popup = xdg_surface_handle_get_popup, | ||||
| 	.ack_configure = xdg_surface_handle_ack_configure, | ||||
| 	.set_window_geometry = xdg_surface_handle_set_window_geometry, | ||||
| }; | ||||
| 
 | ||||
| static void xdg_surface_send_configure(void *user_data) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = user_data; | ||||
| 
 | ||||
| 	surface->configure_idle = NULL; | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6_configure *configure = | ||||
| 		calloc(1, sizeof(struct wlr_xdg_surface_v6_configure)); | ||||
| 	if (configure == NULL) { | ||||
| 		wl_client_post_no_memory(surface->client->client); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wl_list_insert(surface->configure_list.prev, &configure->link); | ||||
| 	configure->serial = surface->configure_next_serial; | ||||
| 
 | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		assert(0 && "not reached"); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		send_xdg_toplevel_v6_configure(surface, configure); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		zxdg_popup_v6_send_configure(surface->popup->resource, | ||||
| 			surface->popup->geometry.x, | ||||
| 			surface->popup->geometry.y, | ||||
| 			surface->popup->geometry.width, | ||||
| 			surface->popup->geometry.height); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	zxdg_surface_v6_send_configure(surface->resource, configure->serial); | ||||
| } | ||||
| 
 | ||||
| uint32_t schedule_xdg_surface_v6_configure(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	struct wl_display *display = wl_client_get_display(surface->client->client); | ||||
| 	struct wl_event_loop *loop = wl_display_get_event_loop(display); | ||||
| 	bool pending_same = false; | ||||
| 
 | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		assert(0 && "not reached"); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		pending_same = | ||||
| 			compare_xdg_surface_v6_toplevel_state(surface->toplevel); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	if (surface->configure_idle != NULL) { | ||||
| 		if (!pending_same) { | ||||
| 			// configure request already scheduled
 | ||||
| 			return surface->configure_next_serial; | ||||
| 		} | ||||
| 
 | ||||
| 		// configure request not necessary anymore
 | ||||
| 		wl_event_source_remove(surface->configure_idle); | ||||
| 		surface->configure_idle = NULL; | ||||
| 		return 0; | ||||
| 	} else { | ||||
| 		if (pending_same) { | ||||
| 			// configure request not necessary
 | ||||
| 			return 0; | ||||
| 		} | ||||
| 
 | ||||
| 		surface->configure_next_serial = wl_display_next_serial(display); | ||||
| 		surface->configure_idle = wl_event_loop_add_idle(loop, | ||||
| 			xdg_surface_send_configure, surface); | ||||
| 		return surface->configure_next_serial; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	if (surface->client->ping_serial != 0) { | ||||
| 		// already pinged
 | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	surface->client->ping_serial = | ||||
| 		wl_display_next_serial(wl_client_get_display(surface->client->client)); | ||||
| 	wl_event_source_timer_update(surface->client->ping_timer, | ||||
| 		surface->client->shell->ping_timeout); | ||||
| 	zxdg_shell_v6_send_ping(surface->client->resource, | ||||
| 		surface->client->ping_serial); | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_surface_v6_send_close(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		assert(0 && "not reached"); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		if (surface->toplevel) { | ||||
| 			zxdg_toplevel_v6_send_close(surface->toplevel->resource); | ||||
| 		} | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		if (surface->popup) { | ||||
| 			zxdg_popup_v6_send_popup_done(surface->popup->resource); | ||||
| 		} | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_surface_destroy(struct wl_listener *listener, | ||||
| 		void *data) { | ||||
| 	struct wlr_xdg_surface_v6 *xdg_surface = | ||||
| 		wl_container_of(listener, xdg_surface, surface_destroy); | ||||
| 	destroy_xdg_surface_v6(xdg_surface); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_surface_commit(struct wl_listener *listener, | ||||
| 		void *data) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		wl_container_of(listener, surface, surface_commit); | ||||
| 
 | ||||
| 	if (wlr_surface_has_buffer(surface->surface) && !surface->configured) { | ||||
| 		wl_resource_post_error(surface->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, | ||||
| 			"xdg_surface has never been configured"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (surface->role == WLR_XDG_SURFACE_V6_ROLE_NONE) { | ||||
| 		wl_resource_post_error(surface->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, | ||||
| 			"xdg_surface must have a role"); | ||||
| 		return; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void handle_xdg_surface_v6_commit(struct wlr_surface *wlr_surface) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		wlr_xdg_surface_v6_from_wlr_surface(wlr_surface); | ||||
| 	if (surface == NULL) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (surface->has_next_geometry) { | ||||
| 		surface->has_next_geometry = false; | ||||
| 		surface->geometry.x = surface->next_geometry.x; | ||||
| 		surface->geometry.y = surface->next_geometry.y; | ||||
| 		surface->geometry.width = surface->next_geometry.width; | ||||
| 		surface->geometry.height = surface->next_geometry.height; | ||||
| 	} | ||||
| 
 | ||||
| 	switch (surface->role) { | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_NONE: | ||||
| 		assert(false); | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: | ||||
| 		handle_xdg_surface_v6_toplevel_committed(surface); | ||||
| 		break; | ||||
| 	case WLR_XDG_SURFACE_V6_ROLE_POPUP: | ||||
| 		handle_xdg_surface_v6_popup_committed(surface); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	if (!surface->added) { | ||||
| 		surface->added = true; | ||||
| 		wlr_signal_emit_safe(&surface->client->shell->events.new_surface, | ||||
| 			surface); | ||||
| 	} | ||||
| 	if (surface->configured && wlr_surface_has_buffer(surface->surface) && | ||||
| 			!surface->mapped) { | ||||
| 		surface->mapped = true; | ||||
| 		wlr_signal_emit_safe(&surface->events.map, surface); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void handle_xdg_surface_v6_precommit(struct wlr_surface *wlr_surface) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		wlr_xdg_surface_v6_from_wlr_surface(wlr_surface); | ||||
| 	if (surface == NULL) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER && | ||||
| 			wlr_surface->pending.buffer_resource == NULL) { | ||||
| 		// This is a NULL commit
 | ||||
| 		if (surface->configured && surface->mapped) { | ||||
| 			unmap_xdg_surface_v6(surface); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_handle_resource_destroy(struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource); | ||||
| 	if (surface != NULL) { | ||||
| 		destroy_xdg_surface_v6(surface); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| struct wlr_xdg_surface_v6 *create_xdg_surface_v6( | ||||
| 		struct wlr_xdg_client_v6 *client, struct wlr_surface *surface, | ||||
| 		uint32_t id) { | ||||
| 	if (wlr_surface_has_buffer(surface)) { | ||||
| 		wl_resource_post_error(client->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, | ||||
| 			"xdg_surface must not have a buffer at creation"); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6 *xdg_surface = | ||||
| 		calloc(1, sizeof(struct wlr_xdg_surface_v6)); | ||||
| 	if (xdg_surface == NULL) { | ||||
| 		wl_client_post_no_memory(client->client); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_surface->client = client; | ||||
| 	xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; | ||||
| 	xdg_surface->surface = surface; | ||||
| 	xdg_surface->resource = wl_resource_create(client->client, | ||||
| 		&zxdg_surface_v6_interface, wl_resource_get_version(client->resource), | ||||
| 		id); | ||||
| 	if (xdg_surface->resource == NULL) { | ||||
| 		free(xdg_surface); | ||||
| 		wl_client_post_no_memory(client->client); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 	wl_resource_set_implementation(xdg_surface->resource, | ||||
| 		&zxdg_surface_v6_implementation, xdg_surface, | ||||
| 		xdg_surface_handle_resource_destroy); | ||||
| 
 | ||||
| 	wl_list_init(&xdg_surface->configure_list); | ||||
| 	wl_list_init(&xdg_surface->popups); | ||||
| 
 | ||||
| 	wl_signal_init(&xdg_surface->events.destroy); | ||||
| 	wl_signal_init(&xdg_surface->events.ping_timeout); | ||||
| 	wl_signal_init(&xdg_surface->events.new_popup); | ||||
| 	wl_signal_init(&xdg_surface->events.map); | ||||
| 	wl_signal_init(&xdg_surface->events.unmap); | ||||
| 
 | ||||
| 	wl_signal_add(&xdg_surface->surface->events.destroy, | ||||
| 		&xdg_surface->surface_destroy); | ||||
| 	xdg_surface->surface_destroy.notify = xdg_surface_handle_surface_destroy; | ||||
| 
 | ||||
| 	wl_signal_add(&xdg_surface->surface->events.commit, | ||||
| 		&xdg_surface->surface_commit); | ||||
| 	xdg_surface->surface_commit.notify = xdg_surface_handle_surface_commit; | ||||
| 
 | ||||
| 	wlr_log(WLR_DEBUG, "new xdg_surface %p (res %p)", xdg_surface, | ||||
| 		xdg_surface->resource); | ||||
| 	wl_list_insert(&client->surfaces, &xdg_surface->link); | ||||
| 
 | ||||
| 	return xdg_surface; | ||||
| } | ||||
| 
 | ||||
| static void xdg_popup_v6_get_position(struct wlr_xdg_popup_v6 *popup, | ||||
| 		double *popup_sx, double *popup_sy) { | ||||
| 	struct wlr_xdg_surface_v6 *parent = popup->parent; | ||||
| 	struct wlr_box parent_geo; | ||||
| 	wlr_xdg_surface_v6_get_geometry(parent, &parent_geo); | ||||
| 	*popup_sx = parent_geo.x + popup->geometry.x - | ||||
| 		popup->base->geometry.x; | ||||
| 	*popup_sy = parent_geo.y + popup->geometry.y - | ||||
| 		popup->base->geometry.y; | ||||
| } | ||||
| 
 | ||||
| struct wlr_surface *wlr_xdg_surface_v6_surface_at( | ||||
| 		struct wlr_xdg_surface_v6 *surface, double sx, double sy, | ||||
| 		double *sub_x, double *sub_y) { | ||||
| 	struct wlr_xdg_popup_v6 *popup_state; | ||||
| 	wl_list_for_each(popup_state, &surface->popups, link) { | ||||
| 		struct wlr_xdg_surface_v6 *popup = popup_state->base; | ||||
| 
 | ||||
| 		double popup_sx, popup_sy; | ||||
| 		xdg_popup_v6_get_position(popup_state, &popup_sx, &popup_sy); | ||||
| 
 | ||||
| 		struct wlr_surface *sub = wlr_xdg_surface_v6_surface_at(popup, | ||||
| 			sx - popup_sx, | ||||
| 			sy - popup_sy, | ||||
| 			sub_x, sub_y); | ||||
| 		if (sub != NULL) { | ||||
| 			return sub; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y); | ||||
| } | ||||
| 
 | ||||
| struct xdg_surface_v6_iterator_data { | ||||
| 	wlr_surface_iterator_func_t user_iterator; | ||||
| 	void *user_data; | ||||
| 	int x, y; | ||||
| }; | ||||
| 
 | ||||
| static void xdg_surface_v6_iterator(struct wlr_surface *surface, | ||||
| 		int sx, int sy, void *data) { | ||||
| 	struct xdg_surface_v6_iterator_data *iter_data = data; | ||||
| 	iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy, | ||||
| 		iter_data->user_data); | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface, | ||||
| 		int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) { | ||||
| 	struct xdg_surface_v6_iterator_data data = { | ||||
| 		.user_iterator = iterator, | ||||
| 		.user_data = user_data, | ||||
| 		.x = x, .y = y, | ||||
| 	}; | ||||
| 	wlr_surface_for_each_surface(surface->surface, xdg_surface_v6_iterator, | ||||
| 		&data); | ||||
| 
 | ||||
| 	struct wlr_xdg_popup_v6 *popup_state; | ||||
| 	wl_list_for_each(popup_state, &surface->popups, link) { | ||||
| 		struct wlr_xdg_surface_v6 *popup = popup_state->base; | ||||
| 		if (!popup->configured) { | ||||
| 			continue; | ||||
| 		} | ||||
| 
 | ||||
| 		double popup_sx, popup_sy; | ||||
| 		xdg_popup_v6_get_position(popup_state, &popup_sx, &popup_sy); | ||||
| 
 | ||||
| 		xdg_surface_v6_for_each_surface(popup, | ||||
| 			x + popup_sx, | ||||
| 			y + popup_sy, | ||||
| 			iterator, user_data); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void xdg_surface_v6_for_each_popup(struct wlr_xdg_surface_v6 *surface, | ||||
| 		int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) { | ||||
| 	struct wlr_xdg_popup_v6 *popup_state; | ||||
| 	wl_list_for_each(popup_state, &surface->popups, link) { | ||||
| 		struct wlr_xdg_surface_v6 *popup = popup_state->base; | ||||
| 		if (!popup->configured) { | ||||
| 			continue; | ||||
| 		} | ||||
| 
 | ||||
| 		double popup_sx, popup_sy; | ||||
| 		xdg_popup_v6_get_position(popup_state, &popup_sx, &popup_sy); | ||||
| 		iterator(popup->surface, x + popup_sx, y + popup_sy, user_data); | ||||
| 
 | ||||
| 		xdg_surface_v6_for_each_popup(popup, | ||||
| 			x + popup_sx, | ||||
| 			y + popup_sy, | ||||
| 			iterator, user_data); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface, | ||||
| 		wlr_surface_iterator_func_t iterator, void *user_data) { | ||||
| 	xdg_surface_v6_for_each_surface(surface, 0, 0, iterator, user_data); | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_surface_v6_for_each_popup(struct wlr_xdg_surface_v6 *surface, | ||||
| 		wlr_surface_iterator_func_t iterator, void *user_data) { | ||||
| 	xdg_surface_v6_for_each_popup(surface, 0, 0, iterator, user_data); | ||||
| } | ||||
| 
 | ||||
| void wlr_xdg_surface_v6_get_geometry(struct wlr_xdg_surface_v6 *surface, struct wlr_box *box) { | ||||
| 	wlr_surface_get_extends(surface->surface, box); | ||||
| 	/* The client never set the geometry */ | ||||
| 	if (!surface->geometry.width) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	wlr_box_intersection(box, &surface->geometry, box); | ||||
| } | ||||
| @ -1,525 +0,0 @@ | ||||
| #define _POSIX_C_SOURCE 200809L | ||||
| #include <assert.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <wlr/util/log.h> | ||||
| #include "types/wlr_xdg_shell_v6.h" | ||||
| #include "util/signal.h" | ||||
| 
 | ||||
| static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation; | ||||
| 
 | ||||
| static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_toplevel_resource( | ||||
| 		struct wl_resource *resource) { | ||||
| 	assert(wl_resource_instance_of(resource, &zxdg_toplevel_v6_interface, | ||||
| 		&zxdg_toplevel_v6_implementation)); | ||||
| 	return wl_resource_get_user_data(resource); | ||||
| } | ||||
| 
 | ||||
| void destroy_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	unmap_xdg_surface_v6(surface); | ||||
| 
 | ||||
| 	if (surface->toplevel->client_pending.fullscreen_output) { | ||||
| 		struct wlr_xdg_toplevel_v6_state *client_pending = | ||||
| 			&surface->toplevel->client_pending; | ||||
| 		wl_list_remove(&client_pending->fullscreen_output_destroy.link); | ||||
| 	} | ||||
| 	wl_resource_set_user_data(surface->toplevel->resource, NULL); | ||||
| 	free(surface->toplevel); | ||||
| 	surface->toplevel = NULL; | ||||
| 
 | ||||
| 	surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_destroy(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	wl_resource_destroy(resource); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_parent(struct wl_client *client, | ||||
| 		struct wl_resource *resource, struct wl_resource *parent_resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 
 | ||||
| 	struct wlr_xdg_surface_v6 *parent = NULL; | ||||
| 	if (parent_resource != NULL) { | ||||
| 		parent = xdg_surface_from_xdg_toplevel_resource(parent_resource); | ||||
| 	} | ||||
| 
 | ||||
| 	surface->toplevel->parent = parent; | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.set_parent, surface); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_title(struct wl_client *client, | ||||
| 		struct wl_resource *resource, const char *title) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 
 | ||||
| 	char *tmp = strdup(title); | ||||
| 	if (tmp == NULL) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	free(surface->toplevel->title); | ||||
| 	surface->toplevel->title = tmp; | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.set_title, surface); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_app_id(struct wl_client *client, | ||||
| 		struct wl_resource *resource, const char *app_id) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 
 | ||||
| 	char *tmp = strdup(app_id); | ||||
| 	if (tmp == NULL) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	free(surface->toplevel->app_id); | ||||
| 	surface->toplevel->app_id = tmp; | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.set_app_id, surface); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, | ||||
| 		struct wl_resource *resource, struct wl_resource *seat_resource, | ||||
| 		uint32_t serial, int32_t x, int32_t y) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	struct wlr_seat_client *seat = | ||||
| 		wlr_seat_client_from_resource(seat_resource); | ||||
| 
 | ||||
| 	if (!surface->configured) { | ||||
| 		wl_resource_post_error(surface->toplevel->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, | ||||
| 			"surface has not been configured yet"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (!wlr_seat_validate_grab_serial(seat->seat, serial)) { | ||||
| 		wlr_log(WLR_DEBUG, "invalid serial for grab"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_show_window_menu_event event = { | ||||
| 		.surface = surface, | ||||
| 		.seat = seat, | ||||
| 		.serial = serial, | ||||
| 		.x = x, | ||||
| 		.y = y, | ||||
| 	}; | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_show_window_menu, | ||||
| 		&event); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_move(struct wl_client *client, | ||||
| 		struct wl_resource *resource, struct wl_resource *seat_resource, | ||||
| 		uint32_t serial) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	struct wlr_seat_client *seat = | ||||
| 		wlr_seat_client_from_resource(seat_resource); | ||||
| 
 | ||||
| 	if (!surface->configured) { | ||||
| 		wl_resource_post_error(surface->toplevel->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, | ||||
| 			"surface has not been configured yet"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (!wlr_seat_validate_grab_serial(seat->seat, serial)) { | ||||
| 		wlr_log(WLR_DEBUG, "invalid serial for grab"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_move_event event = { | ||||
| 		.surface = surface, | ||||
| 		.seat = seat, | ||||
| 		.serial = serial, | ||||
| 	}; | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_move, &event); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_resize(struct wl_client *client, | ||||
| 		struct wl_resource *resource, struct wl_resource *seat_resource, | ||||
| 		uint32_t serial, uint32_t edges) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	struct wlr_seat_client *seat = | ||||
| 		wlr_seat_client_from_resource(seat_resource); | ||||
| 
 | ||||
| 	if (!surface->configured) { | ||||
| 		wl_resource_post_error(surface->toplevel->resource, | ||||
| 			ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, | ||||
| 			"surface has not been configured yet"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	if (!wlr_seat_validate_grab_serial(seat->seat, serial)) { | ||||
| 		wlr_log(WLR_DEBUG, "invalid serial for grab"); | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_resize_event event = { | ||||
| 		.surface = surface, | ||||
| 		.seat = seat, | ||||
| 		.serial = serial, | ||||
| 		.edges = edges, | ||||
| 	}; | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_resize, &event); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_max_size(struct wl_client *client, | ||||
| 		struct wl_resource *resource, int32_t width, int32_t height) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	surface->toplevel->client_pending.max_width = width; | ||||
| 	surface->toplevel->client_pending.max_height = height; | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_min_size(struct wl_client *client, | ||||
| 		struct wl_resource *resource, int32_t width, int32_t height) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	surface->toplevel->client_pending.min_width = width; | ||||
| 	surface->toplevel->client_pending.min_height = height; | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_maximized(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	surface->toplevel->client_pending.maximized = true; | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	surface->toplevel->client_pending.maximized = false; | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); | ||||
| } | ||||
| 
 | ||||
| static void handle_fullscreen_output_destroy(struct wl_listener *listener, | ||||
| 		void *data) { | ||||
| 	struct wlr_xdg_toplevel_v6_state *state = | ||||
| 		wl_container_of(listener, state, fullscreen_output_destroy); | ||||
| 	state->fullscreen_output = NULL; | ||||
| 	wl_list_remove(&state->fullscreen_output_destroy.link); | ||||
| } | ||||
| 
 | ||||
| static void store_fullscreen_pending(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool fullscreen, struct wlr_output *output) { | ||||
| 	struct wlr_xdg_toplevel_v6_state *state = | ||||
| 		&surface->toplevel->client_pending; | ||||
| 	state->fullscreen = fullscreen; | ||||
| 	if (state->fullscreen_output) { | ||||
| 		wl_list_remove(&state->fullscreen_output_destroy.link); | ||||
| 	} | ||||
| 	state->fullscreen_output = output; | ||||
| 	if (state->fullscreen_output) { | ||||
| 		state->fullscreen_output_destroy.notify = | ||||
| 			handle_fullscreen_output_destroy; | ||||
| 		wl_signal_add(&state->fullscreen_output->events.destroy, | ||||
| 				&state->fullscreen_output_destroy); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, | ||||
| 		struct wl_resource *resource, struct wl_resource *output_resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 
 | ||||
| 	struct wlr_output *output = NULL; | ||||
| 	if (output_resource != NULL) { | ||||
| 		output = wlr_output_from_resource(output_resource); | ||||
| 	} | ||||
| 
 | ||||
| 	store_fullscreen_pending(surface, true, output); | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { | ||||
| 		.surface = surface, | ||||
| 		.fullscreen = true, | ||||
| 		.output = output, | ||||
| 	}; | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 
 | ||||
| 	store_fullscreen_pending(surface, false, NULL); | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { | ||||
| 		.surface = surface, | ||||
| 		.fullscreen = false, | ||||
| 		.output = NULL, | ||||
| 	}; | ||||
| 
 | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_set_minimized(struct wl_client *client, | ||||
| 		struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface); | ||||
| } | ||||
| 
 | ||||
| static const struct zxdg_toplevel_v6_interface | ||||
| 		zxdg_toplevel_v6_implementation = { | ||||
| 	.destroy = xdg_toplevel_handle_destroy, | ||||
| 	.set_parent = xdg_toplevel_handle_set_parent, | ||||
| 	.set_title = xdg_toplevel_handle_set_title, | ||||
| 	.set_app_id = xdg_toplevel_handle_set_app_id, | ||||
| 	.show_window_menu = xdg_toplevel_handle_show_window_menu, | ||||
| 	.move = xdg_toplevel_handle_move, | ||||
| 	.resize = xdg_toplevel_handle_resize, | ||||
| 	.set_max_size = xdg_toplevel_handle_set_max_size, | ||||
| 	.set_min_size = xdg_toplevel_handle_set_min_size, | ||||
| 	.set_maximized = xdg_toplevel_handle_set_maximized, | ||||
| 	.unset_maximized = xdg_toplevel_handle_unset_maximized, | ||||
| 	.set_fullscreen = xdg_toplevel_handle_set_fullscreen, | ||||
| 	.unset_fullscreen = xdg_toplevel_handle_unset_fullscreen, | ||||
| 	.set_minimized = xdg_toplevel_handle_set_minimized, | ||||
| }; | ||||
| 
 | ||||
| void handle_xdg_toplevel_v6_ack_configure(struct wlr_xdg_surface_v6 *surface, | ||||
| 		struct wlr_xdg_surface_v6_configure *configure) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	assert(configure->toplevel_state != NULL); | ||||
| 
 | ||||
| 	surface->toplevel->last_acked = *configure->toplevel_state; | ||||
| } | ||||
| 
 | ||||
| bool compare_xdg_surface_v6_toplevel_state(struct wlr_xdg_toplevel_v6 *state) { | ||||
| 	// is pending state different from current state?
 | ||||
| 	if (!state->base->configured) { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	struct wlr_xdg_toplevel_v6_state *configured = NULL; | ||||
| 	if (wl_list_empty(&state->base->configure_list)) { | ||||
| 		// There are currently no pending configures, so check against the last
 | ||||
| 		// state acked by the client.
 | ||||
| 		configured = &state->last_acked; | ||||
| 	} else { | ||||
| 		struct wlr_xdg_surface_v6_configure *configure = | ||||
| 			wl_container_of(state->base->configure_list.prev, configure, link); | ||||
| 		configured = configure->toplevel_state; | ||||
| 	} | ||||
| 
 | ||||
| 	if (state->server_pending.activated != configured->activated) { | ||||
| 		return false; | ||||
| 	} | ||||
| 	if (state->server_pending.fullscreen != configured->fullscreen) { | ||||
| 		return false; | ||||
| 	} | ||||
| 	if (state->server_pending.maximized != configured->maximized) { | ||||
| 		return false; | ||||
| 	} | ||||
| 	if (state->server_pending.resizing != configured->resizing) { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	if (state->server_pending.width == configured->width && | ||||
| 			state->server_pending.height == configured->height) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (state->server_pending.width == 0 && state->server_pending.height == 0) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| void send_xdg_toplevel_v6_configure(struct wlr_xdg_surface_v6 *surface, | ||||
| 		struct wlr_xdg_surface_v6_configure *configure) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 
 | ||||
| 	configure->toplevel_state = malloc(sizeof(*configure->toplevel_state)); | ||||
| 	if (configure->toplevel_state == NULL) { | ||||
| 		wlr_log(WLR_ERROR, "Allocation failed"); | ||||
| 		wl_resource_post_no_memory(surface->toplevel->resource); | ||||
| 		return; | ||||
| 	} | ||||
| 	*configure->toplevel_state = surface->toplevel->server_pending; | ||||
| 
 | ||||
| 	uint32_t *s; | ||||
| 	struct wl_array states; | ||||
| 	wl_array_init(&states); | ||||
| 	if (surface->toplevel->server_pending.maximized) { | ||||
| 		s = wl_array_add(&states, sizeof(uint32_t)); | ||||
| 		if (!s) { | ||||
| 			wlr_log(WLR_ERROR, | ||||
| 				"Could not allocate state for maximized xdg_toplevel"); | ||||
| 			goto error_out; | ||||
| 		} | ||||
| 		*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; | ||||
| 	} | ||||
| 	if (surface->toplevel->server_pending.fullscreen) { | ||||
| 		s = wl_array_add(&states, sizeof(uint32_t)); | ||||
| 		if (!s) { | ||||
| 			wlr_log(WLR_ERROR, | ||||
| 				"Could not allocate state for fullscreen xdg_toplevel"); | ||||
| 			goto error_out; | ||||
| 		} | ||||
| 		*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; | ||||
| 	} | ||||
| 	if (surface->toplevel->server_pending.resizing) { | ||||
| 		s = wl_array_add(&states, sizeof(uint32_t)); | ||||
| 		if (!s) { | ||||
| 			wlr_log(WLR_ERROR, | ||||
| 				"Could not allocate state for resizing xdg_toplevel"); | ||||
| 			goto error_out; | ||||
| 		} | ||||
| 		*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; | ||||
| 	} | ||||
| 	if (surface->toplevel->server_pending.activated) { | ||||
| 		s = wl_array_add(&states, sizeof(uint32_t)); | ||||
| 		if (!s) { | ||||
| 			wlr_log(WLR_ERROR, | ||||
| 				"Could not allocate state for activated xdg_toplevel"); | ||||
| 			goto error_out; | ||||
| 		} | ||||
| 		*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; | ||||
| 	} | ||||
| 
 | ||||
| 	uint32_t width = surface->toplevel->server_pending.width; | ||||
| 	uint32_t height = surface->toplevel->server_pending.height; | ||||
| 	zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, | ||||
| 		height, &states); | ||||
| 
 | ||||
| 	wl_array_release(&states); | ||||
| 	return; | ||||
| 
 | ||||
| error_out: | ||||
| 	wl_array_release(&states); | ||||
| 	wl_resource_post_no_memory(surface->toplevel->resource); | ||||
| } | ||||
| 
 | ||||
| void handle_xdg_surface_v6_toplevel_committed(struct wlr_xdg_surface_v6 *surface) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 
 | ||||
| 	if (!surface->toplevel->added) { | ||||
| 		// on the first commit, send a configure request to tell the client it
 | ||||
| 		// is added
 | ||||
| 		schedule_xdg_surface_v6_configure(surface); | ||||
| 		surface->toplevel->added = true; | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	// apply state from the last acked configure now that the client committed
 | ||||
| 	surface->toplevel->current = surface->toplevel->last_acked; | ||||
| 
 | ||||
| 	// update state from the client that doesn't need compositor approval
 | ||||
| 	surface->toplevel->current.max_width = | ||||
| 		surface->toplevel->client_pending.max_width; | ||||
| 	surface->toplevel->current.min_width = | ||||
| 		surface->toplevel->client_pending.min_width; | ||||
| 	surface->toplevel->current.max_height = | ||||
| 		surface->toplevel->client_pending.max_height; | ||||
| 	surface->toplevel->current.min_height = | ||||
| 		surface->toplevel->client_pending.min_height; | ||||
| } | ||||
| 
 | ||||
| static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) { | ||||
| 	struct wlr_xdg_surface_v6 *surface = | ||||
| 		xdg_surface_from_xdg_toplevel_resource(resource); | ||||
| 	if (surface != NULL) { | ||||
| 		destroy_xdg_toplevel_v6(surface); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| const struct wlr_surface_role xdg_toplevel_v6_surface_role = { | ||||
| 	.name = "xdg_toplevel_v6", | ||||
| 	.commit = handle_xdg_surface_v6_commit, | ||||
| 	.precommit = handle_xdg_surface_v6_precommit, | ||||
| }; | ||||
| 
 | ||||
| void create_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *xdg_surface, | ||||
| 		uint32_t id) { | ||||
| 	if (!wlr_surface_set_role(xdg_surface->surface, &xdg_toplevel_v6_surface_role, | ||||
| 			xdg_surface, xdg_surface->resource, ZXDG_SHELL_V6_ERROR_ROLE)) { | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	xdg_surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); | ||||
| 	if (xdg_surface->toplevel == NULL) { | ||||
| 		wl_resource_post_no_memory(xdg_surface->resource); | ||||
| 		return; | ||||
| 	} | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.request_maximize); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.request_fullscreen); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.request_minimize); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.request_move); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.request_resize); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.request_show_window_menu); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.set_parent); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.set_title); | ||||
| 	wl_signal_init(&xdg_surface->toplevel->events.set_app_id); | ||||
| 
 | ||||
| 	xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; | ||||
| 	xdg_surface->toplevel->base = xdg_surface; | ||||
| 
 | ||||
| 	struct wl_resource *toplevel_resource = wl_resource_create( | ||||
| 		xdg_surface->client->client, &zxdg_toplevel_v6_interface, | ||||
| 		wl_resource_get_version(xdg_surface->resource), id); | ||||
| 	if (toplevel_resource == NULL) { | ||||
| 		free(xdg_surface->toplevel); | ||||
| 		wl_resource_post_no_memory(xdg_surface->resource); | ||||
| 		return; | ||||
| 	} | ||||
| 	xdg_surface->toplevel->resource = toplevel_resource; | ||||
| 	wl_resource_set_implementation(toplevel_resource, | ||||
| 		&zxdg_toplevel_v6_implementation, xdg_surface, | ||||
| 		xdg_toplevel_handle_resource_destroy); | ||||
| } | ||||
| 
 | ||||
| uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, | ||||
| 		uint32_t width, uint32_t height) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	surface->toplevel->server_pending.width = width; | ||||
| 	surface->toplevel->server_pending.height = height; | ||||
| 
 | ||||
| 	return schedule_xdg_surface_v6_configure(surface); | ||||
| } | ||||
| 
 | ||||
| uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool activated) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	surface->toplevel->server_pending.activated = activated; | ||||
| 
 | ||||
| 	return schedule_xdg_surface_v6_configure(surface); | ||||
| } | ||||
| 
 | ||||
| uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool maximized) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	surface->toplevel->server_pending.maximized = maximized; | ||||
| 
 | ||||
| 	return schedule_xdg_surface_v6_configure(surface); | ||||
| } | ||||
| 
 | ||||
| uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool fullscreen) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	surface->toplevel->server_pending.fullscreen = fullscreen; | ||||
| 
 | ||||
| 	return schedule_xdg_surface_v6_configure(surface); | ||||
| } | ||||
| 
 | ||||
| uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, | ||||
| 		bool resizing) { | ||||
| 	assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); | ||||
| 	surface->toplevel->server_pending.resizing = resizing; | ||||
| 
 | ||||
| 	return schedule_xdg_surface_v6_configure(surface); | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue