Skip to content

Commit

Permalink
Add ext-session-lock protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Oct 26, 2023
1 parent 1d799f4 commit 49cd558
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 23 deletions.
37 changes: 22 additions & 15 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "debug")]
use crate::backend::render::element::AsGlowRenderer;
use crate::{
backend::render::{workspace_elements, CLEAR_COLOR},
backend::render::{session_lock_elements, workspace_elements, CLEAR_COLOR},
config::OutputConfig,
shell::Shell,
state::{BackendData, ClientState, Common, Fps, SurfaceDmabufFeedback},
Expand Down Expand Up @@ -1223,20 +1223,27 @@ impl Surface {
.map(|((w, start), idx)| (w.handle, idx, start));
let workspace = (workspace.handle, idx);

let elements = workspace_elements(
Some(&render_node),
&mut renderer,
state,
&self.output,
previous_workspace,
workspace,
CursorMode::All,
&mut Some(&mut self.fps),
false,
)
.map_err(|err| {
anyhow::format_err!("Failed to accumulate elements for rendering: {:?}", err)
})?;
let elements = if let Some(session_lock) = &state.session_lock {
session_lock_elements(&mut renderer, &self.output, session_lock)
.into_iter()
.map(|x| crate::shell::WorkspaceRenderElement::from(x).into())
.collect()
} else {
workspace_elements(
Some(&render_node),
&mut renderer,
state,
&self.output,
previous_workspace,
workspace,
CursorMode::All,
&mut Some(&mut self.fps),
false,
)
.map_err(|err| {
anyhow::format_err!("Failed to accumulate elements for rendering: {:?}", err)
})?
};
self.fps.elements();

let res = compositor.render_frame::<_, _, GlesTexture>(
Expand Down
49 changes: 47 additions & 2 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
focus::target::WindowGroup, grabs::SeatMoveGrabState, layout::tiling::ANIMATION_DURATION,
CosmicMapped, CosmicMappedRenderElement, OverviewMode, Trigger, WorkspaceRenderElement,
},
state::{Common, Fps},
state::{Common, Fps, SessionLock},
utils::prelude::*,
wayland::{
handlers::{
Expand All @@ -42,7 +42,7 @@ use smithay::{
buffer_dimensions,
damage::{Error as RenderError, OutputDamageTracker, RenderOutputResult},
element::{
surface::render_elements_from_surface_tree,
surface::{render_elements_from_surface_tree, WaylandSurfaceRenderElement},
utils::{Relocate, RelocateRenderElement},
Element, Id, Kind, RenderElement,
},
Expand Down Expand Up @@ -812,6 +812,10 @@ where
WorkspaceRenderElement<R>: RenderElement<R>,
Source: Clone,
{
if let Some(session_lock) = &state.session_lock {
return render_session_lock(renderer, target, damage_tracker, age, output, session_lock);
}

let (previous_workspace, workspace) = state.shell.workspaces.active(output);
let (previous_idx, idx) = state.shell.workspaces.active_num(output);
let previous_workspace = previous_workspace
Expand All @@ -838,6 +842,47 @@ where
result
}

pub fn render_session_lock<R, Target>(
renderer: &mut R,
target: Target,
damage_tracker: &mut OutputDamageTracker,
age: usize,
output: &Output,
session_lock: &SessionLock,
) -> Result<RenderOutputResult, RenderError<R>>
where
R: Renderer + ImportAll + Bind<Target>,
<R as Renderer>::TextureId: Clone + 'static,
{
let elements = session_lock_elements(renderer, output, session_lock);
renderer.bind(target).map_err(RenderError::Rendering)?;
damage_tracker.render_output(renderer, age, &elements, CLEAR_COLOR)
}

pub fn session_lock_elements<R>(
renderer: &mut R,
output: &Output,
session_lock: &SessionLock,
) -> Vec<WaylandSurfaceRenderElement<R>>
where
R: Renderer + ImportAll,
<R as Renderer>::TextureId: Clone + 'static,
{
if let Some(surface) = session_lock.surfaces.get(output) {
let scale = Scale::from(output.current_scale().fractional_scale());
render_elements_from_surface_tree(
renderer,
surface.wl_surface(),
(0, 0),
scale,
1.0,
Kind::Unspecified,
)
} else {
Vec::new()
}
}

pub fn render_workspace<R, Target, OffTarget, Source>(
gpu: Option<&DrmNode>,
renderer: &mut R,
Expand Down
38 changes: 34 additions & 4 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::{
backend::render::cursor::CursorState,
config::{xkb_config_to_wl, Action, Config, KeyPattern, WorkspaceLayout},
shell::{
focus::{target::PointerFocusTarget, FocusDirection},
focus::{
target::{KeyboardFocusTarget, PointerFocusTarget},
FocusDirection,
},
grabs::{ResizeEdge, SeatMoveGrabState},
layout::{
floating::ResizeGrabMarker,
Expand All @@ -13,7 +16,7 @@ use crate::{
Direction, FocusResult, MoveResult, OverviewMode, ResizeDirection, ResizeMode, Trigger,
Workspace,
},
state::Common,
state::{Common, SessionLock},
utils::prelude::*,
wayland::{handlers::screencopy::ScreencopySessions, protocols::screencopy::Session},
};
Expand Down Expand Up @@ -281,7 +284,12 @@ impl State {
let serial = SERIAL_COUNTER.next_serial();
let time = Event::time_msec(&event);
let keyboard = seat.get_keyboard().unwrap();
let current_focus = keyboard.current_focus();
let mut current_focus = keyboard.current_focus();
if self.common.session_lock.is_some() {
if !matches!(current_focus, Some(KeyboardFocusTarget::LockSurface(_))) {
current_focus = None;
}
}
if let Some((action, pattern)) = keyboard
.input(
self,
Expand Down Expand Up @@ -565,6 +573,7 @@ impl State {
&self.common.shell.override_redirect_windows,
overview.0.clone(),
workspace,
self.common.session_lock.as_ref(),
)
.map(|(target, pos)| (target, pos.as_logical()));

Expand Down Expand Up @@ -646,6 +655,7 @@ impl State {
&self.common.shell.override_redirect_windows,
overview.0,
workspace,
self.common.session_lock.as_ref(),
)
.map(|(target, pos)| (target, pos.as_logical()));

Expand Down Expand Up @@ -776,6 +786,7 @@ impl State {
&self.common.shell.override_redirect_windows,
overview.0,
workspace,
self.common.session_lock.as_ref(),
)
.map(|(target, pos)| (target, pos.as_logical()));

Expand Down Expand Up @@ -852,7 +863,12 @@ impl State {
let workspace = self.common.shell.active_space_mut(&output);
let mut under = None;

if let Some(window) = workspace.get_fullscreen() {
if let Some(session_lock) = self.common.session_lock.as_ref() {
under = session_lock
.surfaces
.get(&output)
.map(|lock| lock.clone().into());
} else if let Some(window) = workspace.get_fullscreen() {
let layers = layer_map_for_output(&output);
if let Some(layer) =
layers.layer_under(WlrLayer::Overlay, relative_pos.as_logical())
Expand Down Expand Up @@ -1153,6 +1169,10 @@ impl State {
pattern: KeyPattern,
direction: Option<Direction>,
) {
if self.common.session_lock.is_some() {
return;
}

match action {
Action::Terminate => {
self.common.should_stop = true;
Expand Down Expand Up @@ -1718,10 +1738,20 @@ impl State {
override_redirect_windows: &[X11Surface],
overview: OverviewMode,
workspace: &mut Workspace,
session_lock: Option<&SessionLock>,
) -> Option<(PointerFocusTarget, Point<i32, Global>)> {
let relative_pos = global_pos.to_local(output);
let output_geo = output.geometry();

if let Some(session_lock) = session_lock {
return session_lock.surfaces.get(output).map(|surface| {
(
PointerFocusTarget::LockSurface(surface.clone()),
output_geo.loc,
)
});
}

if let Some(window) = workspace.get_fullscreen() {
let layers = layer_map_for_output(output);
if let Some(layer) = layers.layer_under(WlrLayer::Overlay, relative_pos.as_logical()) {
Expand Down
3 changes: 3 additions & 0 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ impl Common {
KeyboardFocusTarget::Popup(_) => {
continue; // Focus is valid
}
KeyboardFocusTarget::LockSurface(_) => {
continue; // Focus is valid
}
};
} else {
if let KeyboardFocusTarget::Popup(_) = target {
Expand Down
Loading

0 comments on commit 49cd558

Please sign in to comment.