Skip to content

Commit

Permalink
Add ext-foreign-toplevel-list-v1 protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 authored and Drakulix committed Aug 29, 2024
1 parent 59b0e0e commit 1342c00
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ inherits = "release"
lto = "fat"

[patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "5dc0153" }
smithay = { git = "https://github.com/smithay//smithay", rev = "298bef3" }
12 changes: 11 additions & 1 deletion src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use smithay::{
utils::{IsAlive, Logical, Point, Rectangle, Serial, Size},
wayland::{
compositor::with_states,
foreign_toplevel_list::ForeignToplevelListState,
seat::WaylandFocus,
session_lock::LockSurface,
shell::wlr_layer::{KeyboardInteractivity, Layer, LayerSurfaceCachedState},
Expand All @@ -55,7 +56,11 @@ use crate::{
utils::{prelude::*, quirks::WORKSPACE_OVERVIEW_NAMESPACE},
wayland::{
handlers::{
toplevel_management::minimize_rectangle, xdg_activation::ActivationContext,
foreign_toplevel_list::{
new_foreign_toplevel, refresh_foreign_toplevels, remove_foreign_toplevel,
},
toplevel_management::minimize_rectangle,
xdg_activation::ActivationContext,
xdg_shell::popup::get_popup_toplevel,
},
protocols::{
Expand Down Expand Up @@ -1184,6 +1189,7 @@ impl Common {
);
self.popups.cleanup();
self.toplevel_info_state.refresh(&self.workspace_state);
refresh_foreign_toplevels(&self.shell.read().unwrap());
self.refresh_idle_inhibit();
}

Expand Down Expand Up @@ -1851,6 +1857,7 @@ impl Shell {
&mut self,
window: &CosmicSurface,
toplevel_info: &mut ToplevelInfoState<State, CosmicSurface>,
foreign_toplevel_list: &mut ForeignToplevelListState,
workspace_state: &mut WorkspaceState<State>,
evlh: &LoopHandle<'static, State>,
) -> Option<KeyboardFocusTarget> {
Expand Down Expand Up @@ -1933,6 +1940,7 @@ impl Shell {
toplevel_info.new_toplevel(&window, workspace_state);
toplevel_enter_output(&window, &output);
toplevel_enter_workspace(&window, &workspace.handle);
new_foreign_toplevel(&window, foreign_toplevel_list);

let mut workspace_state = workspace_state.update();

Expand Down Expand Up @@ -2064,6 +2072,7 @@ impl Shell {
surface: &S,
seat: &Seat<State>,
toplevel_info: &mut ToplevelInfoState<State, CosmicSurface>,
foreign_toplevel_list: &mut ForeignToplevelListState,
) where
CosmicSurface: PartialEq<S>,
{
Expand Down Expand Up @@ -2113,6 +2122,7 @@ impl Shell {

if let Some(surface) = surface {
toplevel_info.remove_toplevel(&surface);
remove_foreign_toplevel(&surface, foreign_toplevel_list);
self.pending_windows.push((surface, seat.clone(), None));
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ use smithay::{
alpha_modifier::AlphaModifierState,
compositor::{CompositorClientState, CompositorState, SurfaceData},
dmabuf::{DmabufFeedback, DmabufGlobal, DmabufState},
foreign_toplevel_list::ForeignToplevelListState,
fractional_scale::{with_fractional_scale, FractionalScaleManagerState},
idle_inhibit::IdleInhibitManagerState,
idle_notify::IdleNotifierState,
Expand Down Expand Up @@ -192,6 +193,7 @@ pub struct Common {
pub compositor_state: CompositorState,
pub data_device_state: DataDeviceState,
pub dmabuf_state: DmabufState,
pub foreign_toplevel_list: ForeignToplevelListState,
pub fractional_scale_state: FractionalScaleManagerState,
pub keyboard_shortcuts_inhibit_state: KeyboardShortcutsInhibitState,
pub output_state: OutputManagerState,
Expand Down Expand Up @@ -486,6 +488,8 @@ impl State {
let compositor_state = CompositorState::new::<Self>(dh);
let data_device_state = DataDeviceState::new::<Self>(dh);
let dmabuf_state = DmabufState::new();
let foreign_toplevel_list =
ForeignToplevelListState::new_with_filter::<State>(dh, client_is_privileged);
let fractional_scale_state = FractionalScaleManagerState::new::<State>(dh);
let keyboard_shortcuts_inhibit_state = KeyboardShortcutsInhibitState::new::<Self>(dh);
let output_state = OutputManagerState::new_with_xdg_output::<Self>(dh);
Expand Down Expand Up @@ -581,6 +585,7 @@ impl State {
compositor_state,
data_device_state,
dmabuf_state,
foreign_toplevel_list,
fractional_scale_state,
idle_notifier_state,
idle_inhibit_manager_state,
Expand Down
1 change: 1 addition & 0 deletions src/wayland/handlers/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl State {
let res = shell.map_window(
&window,
&mut self.common.toplevel_info_state,
&mut self.common.foreign_toplevel_list,
&mut self.common.workspace_state,
&self.common.event_loop_handle,
);
Expand Down
68 changes: 68 additions & 0 deletions src/wayland/handlers/foreign_toplevel_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: GPL-3.0-only

use crate::{
shell::{CosmicSurface, Shell},
state::State,
};
use smithay::wayland::foreign_toplevel_list::{
ForeignToplevelHandle, ForeignToplevelListHandler, ForeignToplevelListState,
};
use std::sync::Mutex;

impl ForeignToplevelListHandler for State {
fn foreign_toplevel_list_state(&mut self) -> &mut ForeignToplevelListState {
&mut self.common.foreign_toplevel_list
}
}

pub fn new_foreign_toplevel(
window: &CosmicSurface,
foreign_toplevel_list: &mut ForeignToplevelListState,
) {
let toplevel_handle =
foreign_toplevel_list.new_toplevel::<State>(window.title(), window.app_id());
*window
.user_data()
.get_or_insert::<Mutex<Option<ForeignToplevelHandle>>, _>(Default::default)
.lock()
.unwrap() = Some(toplevel_handle);
}

pub fn remove_foreign_toplevel(
window: &CosmicSurface,
foreign_toplevel_list: &mut ForeignToplevelListState,
) {
if let Some(handle) = window
.user_data()
.get::<Mutex<Option<ForeignToplevelHandle>>>()
{
if let Some(handle) = handle.lock().unwrap().take() {
foreign_toplevel_list.remove_toplevel(&handle);
}
}
}

pub fn refresh_foreign_toplevels(shell: &Shell) {
for (window, _) in shell
.workspaces
.spaces()
.flat_map(|workspace| workspace.mapped())
.flat_map(|mapped| mapped.windows())
{
let foreign_toplevel_handle = window
.user_data()
.get::<Mutex<Option<ForeignToplevelHandle>>>()
.and_then(|handle| handle.lock().unwrap().clone());
if let Some(handle) = foreign_toplevel_handle {
let app_id = window.app_id();
let title = window.title();
if handle.app_id() != app_id || handle.title() != title {
handle.send_app_id(&app_id);
handle.send_title(&title);
handle.send_done();
}
}
}
}

smithay::delegate_foreign_toplevel_list!(State);
1 change: 1 addition & 0 deletions src/wayland/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod decoration;
pub mod dmabuf;
pub mod drm;
pub mod drm_lease;
pub mod foreign_toplevel_list;
pub mod fractional_scale;
pub mod idle_inhibit;
pub mod idle_notify;
Expand Down
1 change: 1 addition & 0 deletions src/wayland/handlers/xdg_shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ impl XdgShellHandler for State {
surface.wl_surface(),
&seat,
&mut self.common.toplevel_info_state,
&mut self.common.foreign_toplevel_list,
);

let output = shell
Expand Down
8 changes: 7 additions & 1 deletion src/xwayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl XwmHandler for State {
let res = shell.map_window(
&window,
&mut self.common.toplevel_info_state,
&mut self.common.foreign_toplevel_list,
&mut self.common.workspace_state,
&self.common.event_loop_handle,
);
Expand Down Expand Up @@ -342,7 +343,12 @@ impl XwmHandler for State {
shell.override_redirect_windows.retain(|or| or != &window);
} else {
let seat = shell.seats.last_active().clone();
shell.unmap_surface(&window, &seat, &mut self.common.toplevel_info_state);
shell.unmap_surface(
&window,
&seat,
&mut self.common.toplevel_info_state,
&mut self.common.foreign_toplevel_list,
);
}

let outputs = if let Some(wl_surface) = window.wl_surface() {
Expand Down

0 comments on commit 1342c00

Please sign in to comment.