Skip to content

Commit

Permalink
fix: filter by active workspace in overlap notify
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Dec 5, 2024
1 parent fcd5378 commit e91c3e8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 27 deletions.
62 changes: 39 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,65 @@ name = "cosmic-comp"
version = "0.1.0"

[workspace]
members = [
"cosmic-comp-config",
]
members = ["cosmic-comp-config"]

[dependencies]
anyhow = {version = "1.0.51", features = ["backtrace"]}
anyhow = { version = "1.0.51", features = ["backtrace"] }
bitflags = "2.4"
bytemuck = "1.12"
calloop = {version = "0.14.1", features = ["executor"]}
cosmic-comp-config = {path = "cosmic-comp-config"}
cosmic-config = {git = "https://github.com/pop-os/libcosmic/", features = ["calloop", "macro"]}
cosmic-protocols = {git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = ["server"]}
calloop = { version = "0.14.1", features = ["executor"] }
cosmic-comp-config = { path = "cosmic-comp-config" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic/", features = [
"calloop",
"macro",
] }
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = [
"server",
] }
cosmic-settings-config = { git = "https://github.com/pop-os/cosmic-settings-daemon" }
edid-rs = {version = "0.1"}
egui = {version = "0.29.0", optional = true}
egui_plot = {version = "0.29.0", optional = true}
edid-rs = { version = "0.1" }
egui = { version = "0.29.0", optional = true }
egui_plot = { version = "0.29.0", optional = true }
glow = "0.12.0"
i18n-embed = {version = "0.14", features = ["fluent-system", "desktop-requester"]}
i18n-embed = { version = "0.14", features = [
"fluent-system",
"desktop-requester",
] }
i18n-embed-fl = "0.8"
iced_tiny_skia = {git = "https://github.com/pop-os/libcosmic/"}
iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/" }
indexmap = "2.0"
keyframe = "1.1.1"
lazy_static = "1.4.0"
libc = "0.2.149"
libcosmic = {git = "https://github.com/pop-os/libcosmic/", default-features = false}
libsystemd = {version = "0.7", optional = true}
log-panics = {version = "2", features = ["with-backtrace"]}
libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false }
libsystemd = { version = "0.7", optional = true }
log-panics = { version = "2", features = ["with-backtrace"] }
once_cell = "1.18.0"
ordered-float = "4.0"
png = "0.17.5"
regex = "1"
ron = "0.8"
rust-embed = {version = "8.0", features = ["debug-embed"]}
rust-embed = { version = "8.0", features = ["debug-embed"] }
sanitize-filename = "0.5.0"
sendfd = "0.4.1"
serde = {version = "1", features = ["derive"]}
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "1.0.26"
time = {version = "0.3.30", features = ["macros", "formatting", "local-offset"]}
time = { version = "0.3.30", features = [
"macros",
"formatting",
"local-offset",
] }
tiny-skia = "0.11"
tracing = { version = "0.1.37", features = ["max_level_debug", "release_max_level_info"] }
tracing = { version = "0.1.37", features = [
"max_level_debug",
"release_max_level_info",
] }
tracing-journald = "0.3.0"
tracing-subscriber = {version = "0.3.16", features = ["env-filter", "tracing-log"]}
tracing-subscriber = { version = "0.3.16", features = [
"env-filter",
"tracing-log",
] }
wayland-backend = "0.3.3"
wayland-scanner = "0.31.1"
xcursor = "0.3.3"
Expand Down Expand Up @@ -116,7 +132,7 @@ debug = true
inherits = "release"

[profile.release]
lto = "fat"

# lto = "fat"
opt-level = 1
[patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "bc1d732" }
13 changes: 13 additions & 0 deletions src/wayland/handlers/overlap_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ impl OverlapNotifyHandler for State {
let shell = self.common.shell.read().unwrap();
shell.outputs().cloned().collect::<Vec<_>>().into_iter()
}

fn active_workspaces(
&self,
) -> impl Iterator<Item = crate::wayland::protocols::workspace::WorkspaceHandle> {
let shell = self.common.shell.read().unwrap();
shell
.workspaces
.sets
.iter()
.map(|(_, set)| set.workspaces[set.active].handle)
.collect::<Vec<_>>()
.into_iter()
}
}

delegate_overlap_notify!(State);
32 changes: 28 additions & 4 deletions src/wayland/protocols/overlap_notify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only

use std::{collections::HashMap, sync::Mutex};
use std::{
collections::{HashMap, HashSet},
sync::Mutex,
};

use cosmic_protocols::{
overlap_notify::v1::server::{
Expand Down Expand Up @@ -32,8 +35,11 @@ use wayland_backend::server::{GlobalId, ObjectId};

use crate::utils::prelude::{RectExt, RectGlobalExt, RectLocalExt};

use super::toplevel_info::{
ToplevelHandleState, ToplevelInfoGlobalData, ToplevelInfoHandler, ToplevelState, Window,
use super::{
toplevel_info::{
ToplevelHandleState, ToplevelInfoGlobalData, ToplevelInfoHandler, ToplevelState, Window,
},
workspace::WorkspaceHandle,
};

#[derive(Debug)]
Expand Down Expand Up @@ -82,8 +88,10 @@ impl OverlapNotifyState {
+ 'static,
W: Window + 'static,
{
let active_workspaces: Vec<_> = state.active_workspaces().collect();
for output in state.outputs() {
let map = layer_map_for_output(&output);

for layer_surface in map.layers() {
if let Some(data) = layer_surface
.user_data()
Expand All @@ -100,7 +108,22 @@ impl OverlapNotifyState {
.as_local()
.to_global(&output);

for window in state.toplevel_info_state().registered_toplevels() {
for window in
state
.toplevel_info_state()
.registered_toplevels()
.filter(|w| {
let state = w
.user_data()
.get::<ToplevelState>()
.unwrap()
.lock()
.unwrap();
active_workspaces.iter().any(|active_workspace| {
state.in_workspace(&active_workspace)
})
})
{
if let Some(window_geo) = window.global_geometry() {
if let Some(intersection) = layer_geo.intersection(window_geo) {
// relative to layer location
Expand Down Expand Up @@ -146,6 +169,7 @@ pub trait OverlapNotifyHandler: ToplevelInfoHandler {
fn overlap_notify_state(&mut self) -> &mut OverlapNotifyState;
fn layer_surface_from_resource(&self, resource: ZwlrLayerSurfaceV1) -> Option<LayerSurface>;
fn outputs(&self) -> impl Iterator<Item = Output>;
fn active_workspaces(&self) -> impl Iterator<Item = (WorkspaceHandle)>;
}

pub struct OverlapNotifyGlobalData {
Expand Down
4 changes: 4 additions & 0 deletions src/wayland/protocols/toplevel_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ impl ToplevelStateInner {
pub fn foreign_handle(&self) -> Option<&ForeignToplevelHandle> {
self.foreign_handle.as_ref()
}

pub fn in_workspace(&self, handle: &WorkspaceHandle) -> bool {
self.workspaces.contains(handle)
}
}

pub struct ToplevelHandleStateInner<W: Window> {
Expand Down

0 comments on commit e91c3e8

Please sign in to comment.