shell: Unify element_for_(x11_|wl_)surface

This commit is contained in:
Victoria Brekenfeld 2024-03-21 12:44:40 +01:00 committed by Victoria Brekenfeld
parent dbe2a073ef
commit 6858238bd6
13 changed files with 56 additions and 105 deletions

View file

@ -118,21 +118,13 @@ impl State {
impl XdgDecorationHandler for State {
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(toplevel.wl_surface())
{
if let Some(mapped) = self.common.shell.element_for_surface(toplevel.wl_surface()) {
State::new_decoration(mapped, toplevel.wl_surface());
}
}
fn request_mode(&mut self, toplevel: ToplevelSurface, mode: XdgMode) {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(toplevel.wl_surface())
{
if let Some(mapped) = self.common.shell.element_for_surface(toplevel.wl_surface()) {
State::request_mode(mapped, toplevel.wl_surface(), mode);
} else {
toplevel.with_pending_state(|state| state.decoration_mode = Some(mode));
@ -140,11 +132,7 @@ impl XdgDecorationHandler for State {
}
fn unset_mode(&mut self, toplevel: ToplevelSurface) {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(toplevel.wl_surface())
{
if let Some(mapped) = self.common.shell.element_for_surface(toplevel.wl_surface()) {
State::unset_mode(mapped, toplevel.wl_surface())
}
}
@ -156,7 +144,7 @@ impl KdeDecorationHandler for State {
}
fn new_decoration(&mut self, surface: &WlSurface, decoration: &OrgKdeKwinServerDecoration) {
if let Some(mapped) = self.common.shell.element_for_wl_surface(surface) {
if let Some(mapped) = self.common.shell.element_for_surface(surface) {
let mode = State::new_decoration(mapped, surface);
decoration.mode(mode);
}
@ -170,7 +158,7 @@ impl KdeDecorationHandler for State {
) {
if let WEnum::Value(mode) = mode {
// TODO: We need to store this value until it gets mapped and apply it then, if it is not mapped yet.
if let Some(mapped) = self.common.shell.element_for_wl_surface(surface) {
if let Some(mapped) = self.common.shell.element_for_surface(surface) {
State::request_mode(
mapped,
surface,
@ -185,7 +173,7 @@ impl KdeDecorationHandler for State {
}
fn release(&mut self, _decoration: &OrgKdeKwinServerDecoration, surface: &WlSurface) {
if let Some(mapped) = self.common.shell.element_for_wl_surface(surface) {
if let Some(mapped) = self.common.shell.element_for_surface(surface) {
State::unset_mode(mapped, surface)
}
}

View file

@ -31,7 +31,7 @@ impl InputMethodHandler for State {
fn parent_geometry(&self, parent: &WlSurface) -> Rectangle<i32, smithay::utils::Logical> {
self.common
.shell
.element_for_wl_surface(parent)
.element_for_surface(parent)
.map(|e| e.geometry())
.unwrap_or_default()
}

View file

@ -965,7 +965,7 @@ pub fn render_window_to_buffer(
for seat in common.seats() {
if let Some(location) = {
// we need to find the mapped element in that case
if let Some(mapped) = common.shell.element_for_surface(&window) {
if let Some(mapped) = common.shell.element_for_surface(window) {
mapped.cursor_position(seat).and_then(|mut p| {
p -= mapped.active_window_offset().to_f64();
if p.x < 0. || p.y < 0. {
@ -1174,7 +1174,7 @@ impl State {
pub fn schedule_window_session(&mut self, surface: &WlSurface) {
if let Some(element) = surface
.wl_surface()
.and_then(|surface| self.common.shell.element_for_wl_surface(&surface).cloned())
.and_then(|surface| self.common.shell.element_for_surface(&surface).cloned())
{
let active = element.active_window();
if active.wl_surface().as_ref() == Some(surface) {

View file

@ -105,7 +105,7 @@ impl XdgActivationHandler for State {
surface: WlSurface,
) {
if let Some(context) = token_data.user_data.get::<ActivationContext>() {
if let Some(element) = self.common.shell.element_for_wl_surface(&surface).cloned() {
if let Some(element) = self.common.shell.element_for_surface(&surface).cloned() {
match context {
ActivationContext::UrgentOnly => {
if let Some((workspace, _output)) =

View file

@ -76,7 +76,7 @@ impl XdgShellHandler for State {
let kind = PopupKind::Xdg(surface);
if let Some(root) = find_popup_root_surface(&kind)
.ok()
.and_then(|root| self.common.shell.element_for_wl_surface(&root))
.and_then(|root| self.common.shell.element_for_surface(&root))
{
let target = root.clone().into();
let ret = self
@ -169,7 +169,7 @@ impl XdgShellHandler for State {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(surface.wl_surface())
.element_for_surface(surface.wl_surface())
.cloned()
{
if !mapped.is_stack()
@ -184,7 +184,7 @@ impl XdgShellHandler for State {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(surface.wl_surface())
.element_for_surface(surface.wl_surface())
.cloned()
{
let seat = self.common.last_active_seat().clone();
@ -196,7 +196,7 @@ impl XdgShellHandler for State {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(surface.wl_surface())
.element_for_surface(surface.wl_surface())
.cloned()
{
self.common.shell.unmaximize_request(&mapped);
@ -214,7 +214,7 @@ impl XdgShellHandler for State {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(surface.wl_surface())
.element_for_surface(surface.wl_surface())
.cloned()
{
let from = self
@ -351,7 +351,7 @@ impl XdgShellHandler for State {
if let Some(mapped) = self
.common
.shell
.element_for_wl_surface(surface.wl_surface())
.element_for_surface(surface.wl_surface())
.cloned()
{
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {

View file

@ -29,7 +29,7 @@ use tracing::{trace, warn};
impl Shell {
pub fn unconstrain_popup(&self, surface: &PopupSurface) {
if let Some(parent) = get_popup_toplevel(&surface) {
if let Some(elem) = self.element_for_wl_surface(&parent) {
if let Some(elem) = self.element_for_surface(&parent) {
let (mut element_geo, output, is_tiled) =
if let Some(workspace) = self.space_for(elem) {
let Some(elem_geo) = workspace.element_geometry(elem) else {

View file

@ -13,7 +13,7 @@ impl XWaylandKeyboardGrabHandler for State {
.shell
.workspaces
.spaces()
.find_map(|x| x.element_for_wl_surface(surface))?;
.find_map(|x| x.element_for_surface(surface))?;
Some(KeyboardFocusTarget::Element(element.clone()))
}
}