mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Add support for basic idle and idle inhibitor protocols
This commit is contained in:
		
							parent
							
								
									3e5458fa24
								
							
						
					
					
						commit
						aa9720f627
					
				
					 4 changed files with 56 additions and 0 deletions
				
			
		| 
						 | 
					@ -15,6 +15,8 @@
 | 
				
			||||||
#include <wlr/types/wlr_cursor.h>
 | 
					#include <wlr/types/wlr_cursor.h>
 | 
				
			||||||
#include <wlr/types/wlr_data_device.h>
 | 
					#include <wlr/types/wlr_data_device.h>
 | 
				
			||||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
 | 
					#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
 | 
				
			||||||
 | 
					#include <wlr/types/wlr_idle.h>
 | 
				
			||||||
 | 
					#include <wlr/types/wlr_idle_inhibit_v1.h>
 | 
				
			||||||
#include <wlr/types/wlr_input_device.h>
 | 
					#include <wlr/types/wlr_input_device.h>
 | 
				
			||||||
#include <wlr/types/wlr_keyboard.h>
 | 
					#include <wlr/types/wlr_keyboard.h>
 | 
				
			||||||
#include <wlr/types/wlr_keyboard_group.h>
 | 
					#include <wlr/types/wlr_keyboard_group.h>
 | 
				
			||||||
| 
						 | 
					@ -76,6 +78,8 @@ struct seat {
 | 
				
			||||||
	struct wlr_xcursor_manager *xcursor_manager;
 | 
						struct wlr_xcursor_manager *xcursor_manager;
 | 
				
			||||||
	struct wlr_drag_icon *drag_icon;
 | 
						struct wlr_drag_icon *drag_icon;
 | 
				
			||||||
	struct wlr_pointer_constraint_v1 *current_constraint;
 | 
						struct wlr_pointer_constraint_v1 *current_constraint;
 | 
				
			||||||
 | 
						struct wlr_idle *wlr_idle;
 | 
				
			||||||
 | 
						struct wlr_idle_inhibit_manager_v1 *wlr_idle_inhibit_manager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* if set, views cannot receive focus */
 | 
						/* if set, views cannot receive focus */
 | 
				
			||||||
	struct wlr_layer_surface_v1 *focused_layer;
 | 
						struct wlr_layer_surface_v1 *focused_layer;
 | 
				
			||||||
| 
						 | 
					@ -101,6 +105,7 @@ struct seat {
 | 
				
			||||||
	struct wl_listener start_drag;
 | 
						struct wl_listener start_drag;
 | 
				
			||||||
	struct wl_listener destroy_drag;
 | 
						struct wl_listener destroy_drag;
 | 
				
			||||||
	struct wl_listener constraint_commit;
 | 
						struct wl_listener constraint_commit;
 | 
				
			||||||
 | 
						struct wl_listener idle_inhibitor_create;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct server {
 | 
					struct server {
 | 
				
			||||||
| 
						 | 
					@ -329,6 +334,12 @@ struct constraint {
 | 
				
			||||||
	struct wl_listener destroy;
 | 
						struct wl_listener destroy;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct idle_inhibitor {
 | 
				
			||||||
 | 
						struct seat *seat;
 | 
				
			||||||
 | 
						struct wlr_idle_inhibitor_v1 *wlr_inhibitor;
 | 
				
			||||||
 | 
						struct wl_listener destroy;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup);
 | 
					void xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void xdg_toplevel_decoration(struct wl_listener *listener, void *data);
 | 
					void xdg_toplevel_decoration(struct wl_listener *listener, void *data);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -326,6 +326,7 @@ cursor_motion(struct wl_listener *listener, void *data)
 | 
				
			||||||
	struct seat *seat = wl_container_of(listener, seat, cursor_motion);
 | 
						struct seat *seat = wl_container_of(listener, seat, cursor_motion);
 | 
				
			||||||
	struct server *server = seat->server;
 | 
						struct server *server = seat->server;
 | 
				
			||||||
	struct wlr_event_pointer_motion *event = data;
 | 
						struct wlr_event_pointer_motion *event = data;
 | 
				
			||||||
 | 
						wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_relative_pointer_manager_v1_send_relative_motion(
 | 
						wlr_relative_pointer_manager_v1_send_relative_motion(
 | 
				
			||||||
		server->relative_pointer_manager,
 | 
							server->relative_pointer_manager,
 | 
				
			||||||
| 
						 | 
					@ -372,6 +373,7 @@ cursor_motion_absolute(struct wl_listener *listener, void *data)
 | 
				
			||||||
	struct seat *seat = wl_container_of(
 | 
						struct seat *seat = wl_container_of(
 | 
				
			||||||
		listener, seat, cursor_motion_absolute);
 | 
							listener, seat, cursor_motion_absolute);
 | 
				
			||||||
	struct wlr_event_pointer_motion_absolute *event = data;
 | 
						struct wlr_event_pointer_motion_absolute *event = data;
 | 
				
			||||||
 | 
						wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	double lx, ly;
 | 
						double lx, ly;
 | 
				
			||||||
	wlr_cursor_absolute_to_layout_coords(seat->cursor, event->device,
 | 
						wlr_cursor_absolute_to_layout_coords(seat->cursor, event->device,
 | 
				
			||||||
| 
						 | 
					@ -495,6 +497,7 @@ cursor_button(struct wl_listener *listener, void *data)
 | 
				
			||||||
	struct seat *seat = wl_container_of(listener, seat, cursor_button);
 | 
						struct seat *seat = wl_container_of(listener, seat, cursor_button);
 | 
				
			||||||
	struct server *server = seat->server;
 | 
						struct server *server = seat->server;
 | 
				
			||||||
	struct wlr_event_pointer_button *event = data;
 | 
						struct wlr_event_pointer_button *event = data;
 | 
				
			||||||
 | 
						wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	double sx, sy;
 | 
						double sx, sy;
 | 
				
			||||||
	struct wlr_surface *surface;
 | 
						struct wlr_surface *surface;
 | 
				
			||||||
| 
						 | 
					@ -592,6 +595,7 @@ cursor_axis(struct wl_listener *listener, void *data)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	struct seat *seat = wl_container_of(listener, seat, cursor_axis);
 | 
						struct seat *seat = wl_container_of(listener, seat, cursor_axis);
 | 
				
			||||||
	struct wlr_event_pointer_axis *event = data;
 | 
						struct wlr_event_pointer_axis *event = data;
 | 
				
			||||||
 | 
						wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Notify the client with pointer focus of the axis event. */
 | 
						/* Notify the client with pointer focus of the axis event. */
 | 
				
			||||||
	wlr_seat_pointer_notify_axis(seat->seat, event->time_msec,
 | 
						wlr_seat_pointer_notify_axis(seat->seat, event->time_msec,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -157,6 +157,7 @@ keyboard_key_notify(struct wl_listener *listener, void *data)
 | 
				
			||||||
	struct wlr_event_keyboard_key *event = data;
 | 
						struct wlr_event_keyboard_key *event = data;
 | 
				
			||||||
	struct wlr_seat *wlr_seat = server->seat.seat;
 | 
						struct wlr_seat *wlr_seat = server->seat.seat;
 | 
				
			||||||
	struct wlr_input_device *device = seat->keyboard_group->input_device;
 | 
						struct wlr_input_device *device = seat->keyboard_group->input_device;
 | 
				
			||||||
 | 
						wlr_idle_notify_activity(seat->wlr_idle, seat->seat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool handled = false;
 | 
						bool handled = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										40
									
								
								src/seat.c
									
										
									
									
									
								
							
							
						
						
									
										40
									
								
								src/seat.c
									
										
									
									
									
								
							| 
						 | 
					@ -169,6 +169,38 @@ new_input_notify(struct wl_listener *listener, void *data)
 | 
				
			||||||
	wlr_seat_set_capabilities(seat->seat, caps);
 | 
						wlr_seat_set_capabilities(seat->seat, caps);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					destroy_idle_inhibitor(struct wl_listener *listener, void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct idle_inhibitor *idle_inhibitor = wl_container_of(listener,
 | 
				
			||||||
 | 
							idle_inhibitor, destroy);
 | 
				
			||||||
 | 
						struct seat *seat = idle_inhibitor->seat;
 | 
				
			||||||
 | 
						wl_list_remove(&idle_inhibitor->destroy.link);
 | 
				
			||||||
 | 
						wlr_idle_set_enabled(seat->wlr_idle, seat->seat, wl_list_length(
 | 
				
			||||||
 | 
								&seat->wlr_idle_inhibit_manager->inhibitors) <= 1);
 | 
				
			||||||
 | 
						free(idle_inhibitor);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					new_idle_inhibitor(struct wl_listener *listener, void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
 | 
				
			||||||
 | 
						struct seat *seat = wl_container_of(listener, seat,
 | 
				
			||||||
 | 
							idle_inhibitor_create);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct idle_inhibitor *inhibitor = calloc(1,
 | 
				
			||||||
 | 
							sizeof(struct idle_inhibitor));
 | 
				
			||||||
 | 
						if (!inhibitor) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						inhibitor->seat = seat;
 | 
				
			||||||
 | 
						inhibitor->wlr_inhibitor = wlr_inhibitor;
 | 
				
			||||||
 | 
						inhibitor->destroy.notify = destroy_idle_inhibitor;
 | 
				
			||||||
 | 
						wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy);
 | 
				
			||||||
 | 
						wlr_idle_set_enabled(seat->wlr_idle, seat->seat, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
seat_init(struct server *server)
 | 
					seat_init(struct server *server)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -186,6 +218,14 @@ seat_init(struct server *server)
 | 
				
			||||||
	seat->new_input.notify = new_input_notify;
 | 
						seat->new_input.notify = new_input_notify;
 | 
				
			||||||
	wl_signal_add(&server->backend->events.new_input, &seat->new_input);
 | 
						wl_signal_add(&server->backend->events.new_input, &seat->new_input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						seat->wlr_idle = wlr_idle_create(server->wl_display);
 | 
				
			||||||
 | 
						seat->wlr_idle_inhibit_manager = wlr_idle_inhibit_v1_create(
 | 
				
			||||||
 | 
							server->wl_display);
 | 
				
			||||||
 | 
						wl_signal_add(&seat->wlr_idle_inhibit_manager->events.new_inhibitor,
 | 
				
			||||||
 | 
							&seat->idle_inhibitor_create);
 | 
				
			||||||
 | 
						seat->idle_inhibitor_create.notify = new_idle_inhibitor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	seat->cursor = wlr_cursor_create();
 | 
						seat->cursor = wlr_cursor_create();
 | 
				
			||||||
	if (!seat->cursor) {
 | 
						if (!seat->cursor) {
 | 
				
			||||||
		wlr_log(WLR_ERROR, "unable to create cursor");
 | 
							wlr_log(WLR_ERROR, "unable to create cursor");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue