Introduce mode "locked"
This mode is automatically entered when the screen is locked.
This commit is contained in:
		
				
					committed by
					
						 Isaac Freund
						Isaac Freund
					
				
			
			
				
	
			
			
			
						parent
						
							744e6b3052
						
					
				
				
					commit
					03a2da9690
				
			| @ -135,8 +135,8 @@ that tag 1 through 9 are visible. | |||||||
| 	When set to _strict_ this is not the case. The focus will be updated on every cursor movement. | 	When set to _strict_ this is not the case. The focus will be updated on every cursor movement. | ||||||
|  |  | ||||||
| *map* [-release] _mode_ _modifiers_ _key_ _command_ | *map* [-release] _mode_ _modifiers_ _key_ _command_ | ||||||
| 	_mode_ is either “normal” (the default mode) or a mode created with | 	_mode_ is either "normal" (the default mode), "locked" (the mode entered when | ||||||
| 	*declare-mode*. | 	an input inhibitor such as a lock screen is active) or a mode created with *declare-mode*. | ||||||
| 	If _-release_ is specified the mapping is executed on key release rather than key press. | 	If _-release_ is specified the mapping is executed on key release rather than key press. | ||||||
| 	_modifiers_ is a list of one or more of the following | 	_modifiers_ is a list of one or more of the following | ||||||
| 	modifiers separated with a plus sign: | 	modifiers separated with a plus sign: | ||||||
|  | |||||||
| @ -89,11 +89,22 @@ pub fn init() !Self { | |||||||
|         .csd_filter = std.ArrayList([]const u8).init(util.gpa), |         .csd_filter = std.ArrayList([]const u8).init(util.gpa), | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     // Start with a single, empty mode called normal |  | ||||||
|     errdefer self.deinit(); |     errdefer self.deinit(); | ||||||
|     const owned_slice = try std.mem.dupe(util.gpa, u8, "normal"); |  | ||||||
|     try self.mode_to_id.putNoClobber(owned_slice, 0); |     // Start with two empty modes, "normal" and "locked" | ||||||
|     try self.modes.append(Mode.init()); |     try self.modes.ensureCapacity(2); | ||||||
|  |     { | ||||||
|  |         // Normal mode, id 0 | ||||||
|  |         const owned_slice = try std.mem.dupe(util.gpa, u8, "normal"); | ||||||
|  |         try self.mode_to_id.putNoClobber(owned_slice, 0); | ||||||
|  |         self.modes.appendAssumeCapacity(Mode.init()); | ||||||
|  |     } | ||||||
|  |     { | ||||||
|  |         // Locked mode, id 1 | ||||||
|  |         const owned_slice = try std.mem.dupe(util.gpa, u8, "locked"); | ||||||
|  |         try self.mode_to_id.putNoClobber(owned_slice, 1); | ||||||
|  |         self.modes.appendAssumeCapacity(Mode.init()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return self; |     return self; | ||||||
| } | } | ||||||
|  | |||||||
| @ -110,10 +110,14 @@ fn handleInhibitActivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) | |||||||
|  |  | ||||||
|     log.debug(.input_manager, "input inhibitor activated", .{}); |     log.debug(.input_manager, "input inhibitor activated", .{}); | ||||||
|  |  | ||||||
|     // Clear focus of all seats |  | ||||||
|     var seat_it = self.seats.first; |     var seat_it = self.seats.first; | ||||||
|     while (seat_it) |seat_node| : (seat_it = seat_node.next) { |     while (seat_it) |seat_node| : (seat_it = seat_node.next) { | ||||||
|  |         // Clear focus of all seats | ||||||
|         seat_node.data.setFocusRaw(.{ .none = {} }); |         seat_node.data.setFocusRaw(.{ .none = {} }); | ||||||
|  |  | ||||||
|  |         // Enter locked mode | ||||||
|  |         seat_node.data.prev_mode_id = seat_node.data.mode_id; | ||||||
|  |         seat_node.data.mode_id = 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     self.exclusive_client = self.wlr_input_inhibit_manager.active_client; |     self.exclusive_client = self.wlr_input_inhibit_manager.active_client; | ||||||
| @ -134,10 +138,11 @@ fn handleInhibitDeactivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(. | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     // After ensuring that any possible layer surface focus grab has occured, |     // After ensuring that any possible layer surface focus grab has occured, | ||||||
|     // have each Seat handle focus. |     // have each Seat handle focus and enter their previous mode. | ||||||
|     var seat_it = self.seats.first; |     var seat_it = self.seats.first; | ||||||
|     while (seat_it) |seat_node| : (seat_it = seat_node.next) { |     while (seat_it) |seat_node| : (seat_it = seat_node.next) { | ||||||
|         seat_node.data.focus(null); |         seat_node.data.focus(null); | ||||||
|  |         seat_node.data.mode_id = seat_node.data.prev_mode_id; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     self.server.root.startTransaction(); |     self.server.root.startTransaction(); | ||||||
|  | |||||||
| @ -53,6 +53,9 @@ keyboards: std.TailQueue(Keyboard) = .{}, | |||||||
| /// ID of the current keymap mode | /// ID of the current keymap mode | ||||||
| mode_id: usize = 0, | mode_id: usize = 0, | ||||||
|  |  | ||||||
|  | /// ID of previous keymap mode, used when returning from "locked" mode | ||||||
|  | prev_mode_id: usize = 0, | ||||||
|  |  | ||||||
| /// Currently focused output, may be the noop output if no | /// Currently focused output, may be the noop output if no | ||||||
| focused_output: *Output, | focused_output: *Output, | ||||||
|  |  | ||||||
|  | |||||||
| @ -30,9 +30,18 @@ pub fn enterMode( | |||||||
|     if (args.len < 2) return Error.NotEnoughArguments; |     if (args.len < 2) return Error.NotEnoughArguments; | ||||||
|     if (args.len > 2) return Error.TooManyArguments; |     if (args.len > 2) return Error.TooManyArguments; | ||||||
|  |  | ||||||
|  |     if (seat.mode_id == 1) { | ||||||
|  |         out.* = try std.fmt.allocPrint( | ||||||
|  |             allocator, | ||||||
|  |             "manually exiting mode 'locked' is not allowed", | ||||||
|  |             .{}, | ||||||
|  |         ); | ||||||
|  |         return Error.Other; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const config = seat.input_manager.server.config; |     const config = seat.input_manager.server.config; | ||||||
|     const target_mode = args[1]; |     const target_mode = args[1]; | ||||||
|     seat.mode_id = config.mode_to_id.get(target_mode) orelse { |     const mode_id = config.mode_to_id.get(target_mode) orelse { | ||||||
|         out.* = try std.fmt.allocPrint( |         out.* = try std.fmt.allocPrint( | ||||||
|             allocator, |             allocator, | ||||||
|             "cannot enter non-existant mode '{}'", |             "cannot enter non-existant mode '{}'", | ||||||
| @ -40,4 +49,15 @@ pub fn enterMode( | |||||||
|         ); |         ); | ||||||
|         return Error.Other; |         return Error.Other; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     if (mode_id == 1) { | ||||||
|  |         out.* = try std.fmt.allocPrint( | ||||||
|  |             allocator, | ||||||
|  |             "manually entering mode 'locked' is not allowed", | ||||||
|  |             .{}, | ||||||
|  |         ); | ||||||
|  |         return Error.Other; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     seat.mode_id = mode_id; | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user