Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdg-activation: Initial implementation #207

Merged
merged 3 commits into from
Nov 9, 2023
Merged
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: 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 @@ -88,4 +88,4 @@ debug = true
lto = "fat"

[patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "a8f3c46" }
smithay = { git = "https://github.com/smithay//smithay", rev = "d5b352b" }
49 changes: 33 additions & 16 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use crate::{
},
state::{Common, SessionLock},
utils::prelude::*,
wayland::{handlers::screencopy::ScreencopySessions, protocols::screencopy::Session},
wayland::{
handlers::{screencopy::ScreencopySessions, xdg_activation::ActivationContext},
protocols::screencopy::Session,
},
};
use calloop::{timer::Timer, RegistrationToken};
use cosmic_comp_config::workspace::WorkspaceLayout;
Expand Down Expand Up @@ -1688,31 +1691,45 @@ impl State {
workspace.toggle_floating_window(seat);
}
Action::Spawn(command) => {
let wayland_display = self.common.socket.clone();
let (token, data) = self
.common
.shell
.xdg_activation_state
.create_external_token(None);
let (token, data) = (token.clone(), data.clone());

let seat = self.common.last_active_seat();
let output = seat.active_output();
let workspace = self.common.shell.active_space_mut(&output);
workspace.pending_tokens.insert(token.clone());
let handle = workspace.handle;
data.user_data
.insert_if_missing(move || ActivationContext::Workspace(handle));

let wayland_display = self.common.socket.clone();
let display = self
.common
.xwayland_state
.as_ref()
.map(|s| format!(":{}", s.display))
.unwrap_or_default();

std::thread::spawn(move || {
let mut cmd = std::process::Command::new("/bin/sh");
let mut cmd = std::process::Command::new("/bin/sh");

cmd.arg("-c")
.arg(command.clone())
.env("WAYLAND_DISPLAY", &wayland_display)
.env("DISPLAY", &display)
.env_remove("COSMIC_SESSION_SOCK");
cmd.arg("-c")
.arg(command.clone())
.env("WAYLAND_DISPLAY", &wayland_display)
.env("DISPLAY", &display)
.env("XDG_ACTIVATION_TOKEN", &*token)
.env("DESKTOP_STARTUP_ID", &*token)
.env_remove("COSMIC_SESSION_SOCK");

match cmd.spawn() {
Ok(mut child) => {
let _res = child.wait();
}
Err(err) => {
tracing::warn!(?err, "Failed to spawn \"{}\"", command);
}
std::thread::spawn(move || match cmd.spawn() {
Ok(mut child) => {
let _res = child.wait();
}
Err(err) => {
tracing::warn!(?err, "Failed to spawn \"{}\"", command);
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ impl ActiveFocus {
}

impl Shell {
pub fn set_focus<'a>(
pub fn append_focus_stack(
state: &mut State,
target: Option<&KeyboardFocusTarget>,
active_seat: &Seat<State>,
serial: Option<Serial>,
) {
// update FocusStack and notify layouts about new focus (if any window)
let element = match target {
Expand Down Expand Up @@ -128,6 +127,15 @@ impl Shell {
}
}
}
}

pub fn set_focus(
state: &mut State,
target: Option<&KeyboardFocusTarget>,
active_seat: &Seat<State>,
serial: Option<Serial>,
) {
Self::append_focus_stack(state, target, active_seat);

// update keyboard focus
if let Some(keyboard) = active_seat.get_keyboard() {
Expand Down
2 changes: 1 addition & 1 deletion src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub use self::grabs::*;

#[derive(Debug, Default)]
pub struct FloatingLayout {
pub(in crate::shell) space: Space<CosmicMapped>,
pub(crate) space: Space<CosmicMapped>,
}

impl FloatingLayout {
Expand Down
Loading