Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions layershellev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub enum LayerShellEvent<'a, T, Message> {
pub enum OutputOption {
LastOutput,

OutputName(String),

/// NOTE: The output should be in the same connection with the layershellev, that means if you
/// want to pass a [wl_output::WlOutput] to create a new layershell, you need to pass your
/// connection to layershellev first
Expand Down
62 changes: 39 additions & 23 deletions layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,14 @@ impl<T: 'static> Dispatch<wl_registry::WlRegistry, ()> for WindowState<T> {
{
state.last_wloutput.take();
}
state.outputs.retain(|x| x.0 != name);

let outputs_removed = state.outputs.extract_if(.., |o| o.0 == name);
for output_removed in outputs_removed {
state
.xdg_info_cache
.retain(|info| info.0.id() != output_removed.1.id());
}

let removed_states = state
.units
.extract_if(.., |unit| !unit.wl_surface.is_alive());
Expand Down Expand Up @@ -2178,31 +2185,28 @@ impl<T> Dispatch<zxdg_output_v1::ZxdgOutputV1, ()> for WindowState<T> {
_conn: &Connection,
_qhandle: &QueueHandle<Self>,
) {
if state.is_with_target() && !state.init_finished {
let Some((_, xdg_info)) = state
.xdg_info_cache
.iter_mut()
.find(|(_, info)| info.zxdgoutput == *proxy)
else {
return;
};
if let Some((_, xdg_info)) = state
.xdg_info_cache
.iter_mut()
.find(|(_, info)| info.zxdgoutput == *proxy)
{
match event {
zxdg_output_v1::Event::LogicalSize { width, height } => {
xdg_info.logical_size = (width, height);
}
zxdg_output_v1::Event::LogicalPosition { x, y } => {
xdg_info.position = (x, y);
}
zxdg_output_v1::Event::Name { name } => {
xdg_info.name = name;
zxdg_output_v1::Event::Name { ref name } => {
xdg_info.name = name.clone();
}
zxdg_output_v1::Event::Description { description } => {
xdg_info.description = description;
zxdg_output_v1::Event::Description { ref description } => {
xdg_info.description = description.clone();
}
_ => {}
};
return;
}

let Some(index) = state.units.iter().position(|info| {
info.zxdgoutput
.as_ref()
Expand Down Expand Up @@ -2503,6 +2507,12 @@ impl<T: 'static> WindowState<T> {

// do the step before, you get empty list

for (_, output_display) in &self.outputs {
let zxdgoutput = xdg_output_manager.get_xdg_output(output_display, &qh, ());
self.xdg_info_cache
.push((output_display.clone(), ZxdgOutputInfo::new(zxdgoutput)));
}
event_queue.blocking_dispatch(&mut self)?; // then make a dispatch
// so it is the same way, to get surface detach to protocol, first get the shell, like wmbase
// or layer_shell or session-shell, then get `surface` from the wl_surface you get before, and
// set it
Expand All @@ -2522,12 +2532,6 @@ impl<T: 'static> WindowState<T> {

let (binded_output, binded_xdginfo) = match self.start_mode.clone() {
StartMode::TargetScreen(name) => {
for (_, output_display) in &self.outputs {
let zxdgoutput = xdg_output_manager.get_xdg_output(output_display, &qh, ());
self.xdg_info_cache
.push((output_display.clone(), ZxdgOutputInfo::new(zxdgoutput)));
}
event_queue.blocking_dispatch(&mut self)?; // then make a dispatch
if let Some(cache) = self
.xdg_info_cache
.iter()
Expand All @@ -2536,7 +2540,7 @@ impl<T: 'static> WindowState<T> {
{
output = Some(cache.clone());
}
self.xdg_info_cache.clear();
// self.xdg_info_cache.clear();
let binded_output = output.as_ref().map(|(output, _)| output).cloned();
let binded_xdginfo = output.as_ref().map(|(_, xdginfo)| xdginfo).cloned();
(binded_output, binded_xdginfo)
Expand Down Expand Up @@ -2840,6 +2844,13 @@ impl<T: 'static> WindowState<T> {
);
}
(_, DispatchMessageInner::NewDisplay(output_display)) => {
let zxdgoutput =
xdg_output_manager.get_xdg_output(output_display, &qh, ());

window_state.xdg_info_cache.push((
output_display.clone(),
ZxdgOutputInfo::new(zxdgoutput.clone()),
));
if !window_state.is_allscreens() {
continue;
}
Expand Down Expand Up @@ -2877,8 +2888,6 @@ impl<T: 'static> WindowState<T> {
}
wl_surface.commit();

let zxdgoutput =
xdg_output_manager.get_xdg_output(output_display, &qh, ());
let mut fractional_scale = None;
if let Some(ref fractional_scale_manager) = fractional_scale_manager
{
Expand Down Expand Up @@ -2977,6 +2986,13 @@ impl<T: 'static> WindowState<T> {
)) => {
let output = match output_type {
OutputOption::Output(output) => Some(output),
OutputOption::OutputName(name) => {
window_state
.xdg_info_cache
.iter()
.find(|(_, info)| info.name == *name)
.map(|(output, _)| output.clone())
}
_ => {
let pos = window_state.surface_pos();

Expand Down
Loading