Update smithay
This commit is contained in:
parent
a9740e5040
commit
73b12194c0
19 changed files with 202 additions and 137 deletions
53
Cargo.lock
generated
53
Cargo.lock
generated
|
|
@ -1260,7 +1260,20 @@ checksum = "a0f8a69e60d75ae7dab4ef26a59ca99f2a89d4c142089b537775ae0c198bdcde"
|
|||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"bytemuck",
|
||||
"drm-ffi",
|
||||
"drm-ffi 0.7.1",
|
||||
"drm-fourcc",
|
||||
"rustix 0.38.32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "drm"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98888c4bbd601524c11a7ed63f814b8825f420514f78e96f752c437ae9cbb5d1"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"bytemuck",
|
||||
"drm-ffi 0.8.0",
|
||||
"drm-fourcc",
|
||||
"rustix 0.38.32",
|
||||
]
|
||||
|
|
@ -1271,7 +1284,17 @@ version = "0.7.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41334f8405792483e32ad05fbb9c5680ff4e84491883d2947a4757dc54cb2ac6"
|
||||
dependencies = [
|
||||
"drm-sys",
|
||||
"drm-sys 0.6.1",
|
||||
"rustix 0.38.32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "drm-ffi"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97c98727e48b7ccb4f4aea8cfe881e5b07f702d17b7875991881b41af7278d53"
|
||||
dependencies = [
|
||||
"drm-sys 0.7.0",
|
||||
"rustix 0.38.32",
|
||||
]
|
||||
|
||||
|
|
@ -1291,6 +1314,16 @@ dependencies = [
|
|||
"linux-raw-sys 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "drm-sys"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd39dde40b6e196c2e8763f23d119ddb1a8714534bf7d77fa97a65b0feda3986"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"linux-raw-sys 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.23.0"
|
||||
|
|
@ -1926,12 +1959,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gbm"
|
||||
version = "0.14.2"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "313702b30cdeb83ddc72bc14dcee67803cd0ae2d12282ea06e368c25a900c844"
|
||||
checksum = "45bf55ba6dd53ad0ac115046ff999c5324c283444ee6e0be82454c4e8eb2f36a"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"drm",
|
||||
"bitflags 2.4.2",
|
||||
"drm 0.12.0",
|
||||
"drm-fourcc",
|
||||
"gbm-sys",
|
||||
"libc",
|
||||
|
|
@ -4525,7 +4558,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
|
|||
[[package]]
|
||||
name = "smithay"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/smithay//smithay?rev=eea0d9c#eea0d9c171f30eb50247632fcddbb84f1dd147f0"
|
||||
source = "git+https://github.com/smithay//smithay?rev=64356be#64356be949f2ad5f70f601cd10255eafed2ce2ce"
|
||||
dependencies = [
|
||||
"appendlist",
|
||||
"ash",
|
||||
|
|
@ -4535,8 +4568,8 @@ dependencies = [
|
|||
"cgmath",
|
||||
"cursor-icon",
|
||||
"downcast-rs",
|
||||
"drm",
|
||||
"drm-ffi",
|
||||
"drm 0.12.0",
|
||||
"drm-ffi 0.8.0",
|
||||
"drm-fourcc",
|
||||
"encoding_rs",
|
||||
"errno",
|
||||
|
|
@ -4660,7 +4693,7 @@ dependencies = [
|
|||
"cfg_aliases 0.2.0",
|
||||
"cocoa",
|
||||
"core-graphics",
|
||||
"drm",
|
||||
"drm 0.11.1",
|
||||
"fastrand 2.0.1",
|
||||
"foreign-types",
|
||||
"js-sys",
|
||||
|
|
|
|||
|
|
@ -119,4 +119,4 @@ inherits = "release"
|
|||
lto = "fat"
|
||||
|
||||
[patch."https://github.com/Smithay/smithay.git"]
|
||||
smithay = {git = "https://github.com/smithay//smithay", rev = "eea0d9c"}
|
||||
smithay = {git = "https://github.com/smithay//smithay", rev = "64356be"}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ pub fn draw_surface_cursor<R>(
|
|||
) -> Vec<(CursorRenderElement<R>, Point<i32, BufferCoords>)>
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
{
|
||||
let position = location.into();
|
||||
let scale = scale.into();
|
||||
|
|
@ -202,7 +202,7 @@ pub fn draw_dnd_icon<R>(
|
|||
) -> Vec<WaylandSurfaceRenderElement<R>>
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
{
|
||||
if get_role(&surface) != Some("dnd_icon") {
|
||||
warn!(
|
||||
|
|
|
|||
|
|
@ -458,8 +458,11 @@ pub fn init_backend(
|
|||
}
|
||||
}
|
||||
}
|
||||
X11Event::Input(event) => state.process_x11_event(event),
|
||||
X11Event::Focus(_) => {} // TODO: release all keys when losing focus and make sure to go through our keyboard filter code
|
||||
X11Event::Input {
|
||||
event,
|
||||
window_id: _,
|
||||
} => state.process_x11_event(event),
|
||||
X11Event::Focus { .. } => {} // TODO: release all keys when losing focus and make sure to go through our keyboard filter code
|
||||
})
|
||||
.map_err(|_| anyhow::anyhow!("Failed to insert X11 Backend into event loop"))?;
|
||||
|
||||
|
|
|
|||
71
src/main.rs
71
src/main.rs
|
|
@ -9,6 +9,7 @@ use smithay::{
|
|||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use state::State;
|
||||
use std::{env, ffi::OsString, os::unix::process::CommandExt, process, sync::Arc};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
|
|
@ -40,6 +41,51 @@ pub mod xwayland;
|
|||
static GLOBAL: profiling::tracy_client::ProfiledAllocator<std::alloc::System> =
|
||||
profiling::tracy_client::ProfiledAllocator::new(std::alloc::System, 10);
|
||||
|
||||
// called by the Xwayland source, either after starting or failing
|
||||
impl State {
|
||||
fn notify_ready(&mut self) {
|
||||
// TODO: Don't notify again, but potentially import updated env-variables
|
||||
// into systemd and the session?
|
||||
self.ready.call_once(|| {
|
||||
// potentially tell systemd we are setup now
|
||||
#[cfg(feature = "systemd")]
|
||||
if let state::BackendData::Kms(_) = &self.backend {
|
||||
systemd::ready(&self.common);
|
||||
}
|
||||
|
||||
// potentially tell the session we are setup now
|
||||
if let Err(err) =
|
||||
session::setup_socket(self.common.event_loop_handle.clone(), &self.common)
|
||||
{
|
||||
warn!(?err, "Failed to setup cosmic-session communication");
|
||||
}
|
||||
|
||||
let mut args = env::args().skip(1);
|
||||
self.common.kiosk_child = if let Some(exec) = args.next() {
|
||||
// Run command in kiosk mode
|
||||
let mut command = process::Command::new(&exec);
|
||||
command.args(args);
|
||||
command.envs(
|
||||
session::get_env(&self.common).expect("WAYLAND_DISPLAY should be valid UTF-8"),
|
||||
);
|
||||
unsafe { command.pre_exec(|| Ok(utils::rlimit::restore_nofile_limit())) };
|
||||
|
||||
info!("Running {:?}", exec);
|
||||
command
|
||||
.spawn()
|
||||
.map_err(|err| {
|
||||
// TODO: replace with `inspect_err` once stable
|
||||
error!(?err, "Error running kiosk child.");
|
||||
err
|
||||
})
|
||||
.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// setup logger
|
||||
logger::init_logger()?;
|
||||
|
|
@ -60,27 +106,6 @@ fn main() -> Result<()> {
|
|||
);
|
||||
// init backend
|
||||
backend::init_backend_auto(&display, &mut event_loop, &mut state)?;
|
||||
// potentially tell systemd we are setup now
|
||||
#[cfg(feature = "systemd")]
|
||||
if let state::BackendData::Kms(_) = &state.backend {
|
||||
systemd::ready(&state);
|
||||
}
|
||||
// potentially tell the session we are setup now
|
||||
session::setup_socket(event_loop.handle(), &state)?;
|
||||
|
||||
let mut args = env::args().skip(1);
|
||||
let mut child_opt = if let Some(exec) = args.next() {
|
||||
// Run command in kiosk mode
|
||||
let mut command = process::Command::new(&exec);
|
||||
command.args(args);
|
||||
command.envs(session::get_env(&state)?);
|
||||
unsafe { command.pre_exec(|| Ok(utils::rlimit::restore_nofile_limit())) };
|
||||
|
||||
info!("Running {:?}", exec);
|
||||
Some(command.spawn()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Err(err) = theme::watch_theme(event_loop.handle()) {
|
||||
warn!(?err, "Failed to watch theme");
|
||||
|
|
@ -137,7 +162,7 @@ fn main() -> Result<()> {
|
|||
let _ = state.common.display_handle.flush_clients();
|
||||
|
||||
// check if kiosk child is running
|
||||
if let Some(ref mut child) = child_opt {
|
||||
if let Some(child) = state.common.kiosk_child.as_mut() {
|
||||
match child.try_wait() {
|
||||
// Kiosk child exited with status
|
||||
Ok(Some(exit_status)) => {
|
||||
|
|
@ -161,7 +186,7 @@ fn main() -> Result<()> {
|
|||
})?;
|
||||
|
||||
// kill kiosk child if loop exited
|
||||
if let Some(mut child) = child_opt {
|
||||
if let Some(mut child) = state.common.kiosk_child.take() {
|
||||
let _ = child.kill();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use std::{
|
|||
};
|
||||
use tracing::{error, warn};
|
||||
|
||||
use crate::state::{ClientState, State};
|
||||
use crate::state::{ClientState, Common, State};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "message")]
|
||||
|
|
@ -59,24 +59,23 @@ unsafe fn set_cloexec(fd: RawFd) -> rustix::io::Result<()> {
|
|||
rustix::io::fcntl_setfd(fd, flags | rustix::io::FdFlags::CLOEXEC)
|
||||
}
|
||||
|
||||
pub fn get_env(state: &State) -> Result<HashMap<String, String>> {
|
||||
pub fn get_env(common: &Common) -> Result<HashMap<String, String>> {
|
||||
let mut env = HashMap::new();
|
||||
env.insert(
|
||||
String::from("WAYLAND_DISPLAY"),
|
||||
state
|
||||
.common
|
||||
common
|
||||
.socket
|
||||
.clone()
|
||||
.into_string()
|
||||
.map_err(|_| anyhow!("wayland socket is no valid utf-8 string?"))?,
|
||||
);
|
||||
if let Some(display) = state.common.xwayland_state.as_ref().map(|s| s.display) {
|
||||
if let Some(display) = common.xwayland_state.as_ref().map(|s| s.display) {
|
||||
env.insert(String::from("DISPLAY"), format!(":{}", display));
|
||||
}
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
pub fn setup_socket(handle: LoopHandle<State>, state: &State) -> Result<()> {
|
||||
pub fn setup_socket(handle: LoopHandle<State>, common: &Common) -> Result<()> {
|
||||
if let Ok(fd_num) = std::env::var("COSMIC_SESSION_SOCK") {
|
||||
if let Ok(fd) = fd_num.parse::<RawFd>() {
|
||||
let mut session_socket = match unsafe { set_cloexec(fd) } {
|
||||
|
|
@ -89,7 +88,7 @@ pub fn setup_socket(handle: LoopHandle<State>, state: &State) -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
let env = get_env(state)?;
|
||||
let env = get_env(common)?;
|
||||
let message = serde_json::to_string(&Message::SetEnv { variables: env })
|
||||
.with_context(|| "Failed to encode environment variables into json")?;
|
||||
let bytes = message.into_bytes();
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ impl CosmicMapped {
|
|||
) -> (Vec<C>, Vec<C>)
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
C: From<CosmicMappedRenderElement<R>>,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ impl CosmicStack {
|
|||
) -> (Vec<C>, Vec<C>)
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
C: From<CosmicStackRenderElement<R>>,
|
||||
{
|
||||
let offset = self
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ impl CosmicSurface {
|
|||
) -> (Vec<C>, Vec<C>)
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
C: From<WaylandSurfaceRenderElement<R>>,
|
||||
{
|
||||
match self.0.underlying_surface() {
|
||||
|
|
@ -734,7 +734,7 @@ impl X11Relatable for CosmicSurface {
|
|||
impl<R> AsRenderElements<R> for CosmicSurface
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
{
|
||||
type RenderElement = WaylandSurfaceRenderElement<R>;
|
||||
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ impl CosmicWindow {
|
|||
) -> (Vec<C>, Vec<C>)
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
C: From<CosmicWindowRenderElement<R>>,
|
||||
{
|
||||
let has_ssd = self.0.with_program(|p| p.has_ssd(false));
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ use smithay::{
|
|||
Seat,
|
||||
},
|
||||
output::Output,
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Scale, Serial, Size, SERIAL_COUNTER},
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Scale, Serial, SERIAL_COUNTER},
|
||||
};
|
||||
use std::{cell::RefCell, collections::HashSet, sync::atomic::Ordering, time::Instant};
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ impl MoveGrabState {
|
|||
pub fn render<I, R>(&self, renderer: &mut R, output: &Output, theme: &CosmicTheme) -> Vec<I>
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
I: From<CosmicMappedRenderElement<R>>,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1219,7 +1219,7 @@ impl FloatingLayout {
|
|||
)
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
CosmicWindowRenderElement<R>: RenderElement<R>,
|
||||
CosmicStackRenderElement<R>: RenderElement<R>,
|
||||
|
|
|
|||
|
|
@ -3833,7 +3833,7 @@ impl TilingLayout {
|
|||
>
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
CosmicWindowRenderElement<R>: RenderElement<R>,
|
||||
CosmicStackRenderElement<R>: RenderElement<R>,
|
||||
|
|
@ -4678,7 +4678,7 @@ fn render_old_tree<R>(
|
|||
)
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
CosmicWindowRenderElement<R>: RenderElement<R>,
|
||||
CosmicStackRenderElement<R>: RenderElement<R>,
|
||||
|
|
@ -4838,7 +4838,7 @@ fn render_new_tree<R>(
|
|||
)
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
CosmicWindowRenderElement<R>: RenderElement<R>,
|
||||
CosmicStackRenderElement<R>: RenderElement<R>,
|
||||
|
|
|
|||
|
|
@ -1036,7 +1036,7 @@ impl Workspace {
|
|||
>
|
||||
where
|
||||
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CosmicMappedRenderElement<R>: RenderElement<R>,
|
||||
CosmicWindowRenderElement<R>: RenderElement<R>,
|
||||
CosmicStackRenderElement<R>: RenderElement<R>,
|
||||
|
|
|
|||
14
src/state.rs
14
src/state.rs
|
|
@ -99,12 +99,14 @@ use smithay::{
|
|||
use time::UtcOffset;
|
||||
use tracing::error;
|
||||
|
||||
use std::{cell::RefCell, ffi::OsString, time::Duration};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
sync::{Arc, RwLock},
|
||||
cell::RefCell,
|
||||
collections::{HashSet, VecDeque},
|
||||
ffi::OsString,
|
||||
process::Child,
|
||||
sync::{Arc, Once, RwLock},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::{collections::VecDeque, time::Instant};
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "resources/i18n"]
|
||||
|
|
@ -155,6 +157,7 @@ pub fn advertised_node_for_surface(w: &WlSurface, dh: &DisplayHandle) -> Option<
|
|||
pub struct State {
|
||||
pub backend: BackendData,
|
||||
pub common: Common,
|
||||
pub ready: Once,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -174,6 +177,7 @@ pub struct Common {
|
|||
pub local_offset: time::UtcOffset,
|
||||
pub gesture_state: Option<GestureState>,
|
||||
|
||||
pub kiosk_child: Option<Child>,
|
||||
pub theme: cosmic::Theme,
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
|
|
@ -484,6 +488,7 @@ impl State {
|
|||
should_stop: false,
|
||||
gesture_state: None,
|
||||
|
||||
kiosk_child: None,
|
||||
theme: cosmic::theme::system_preference(),
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
|
|
@ -526,6 +531,7 @@ impl State {
|
|||
xwayland_state: None,
|
||||
},
|
||||
backend: BackendData::Unset,
|
||||
ready: Once::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::state::State;
|
||||
use crate::state::Common;
|
||||
use libsystemd::daemon::{booted, notify, NotifyState};
|
||||
use std::process::Command;
|
||||
use tracing::{error, warn};
|
||||
|
||||
pub fn ready(state: &State) {
|
||||
pub fn ready(common: &Common) {
|
||||
if booted() {
|
||||
match Command::new("systemctl")
|
||||
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
|
||||
.env("WAYLAND_DISPLAY", &state.common.socket)
|
||||
.env("WAYLAND_DISPLAY", &common.socket)
|
||||
.env(
|
||||
"DISPLAY",
|
||||
&state
|
||||
.common
|
||||
&common
|
||||
.xwayland_state
|
||||
.as_ref()
|
||||
.map(|s| format!(":{}", s.display))
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub fn screenshot_window(state: &mut State, surface: &CosmicSurface) {
|
|||
) -> anyhow::Result<()>
|
||||
where
|
||||
R: Renderer + ImportAll + Offscreen<GlesRenderbuffer> + ExportMem,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
<R as Renderer>::Error: Send + Sync + 'static,
|
||||
{
|
||||
let bbox = bbox_from_surface_tree(&window.wl_surface().unwrap(), (0, 0));
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ impl InputMethodHandler for State {
|
|||
.map(|e| e.geometry())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn popup_repositioned(&mut self, _: PopupSurface) {}
|
||||
}
|
||||
|
||||
delegate_input_method_manager!(State);
|
||||
|
|
|
|||
138
src/xwayland.rs
138
src/xwayland.rs
|
|
@ -1,4 +1,4 @@
|
|||
use std::{ffi::OsString, os::unix::io::OwnedFd};
|
||||
use std::{ffi::OsString, os::unix::io::OwnedFd, process::Stdio};
|
||||
|
||||
use crate::{
|
||||
backend::render::cursor::{load_cursor_theme, Cursor, CursorShape},
|
||||
|
|
@ -39,8 +39,6 @@ use tracing::{error, trace, warn};
|
|||
pub struct XWaylandState {
|
||||
pub xwm: Option<X11Wm>,
|
||||
pub display: u32,
|
||||
#[allow(unused)]
|
||||
xwayland: XWayland,
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
@ -49,84 +47,84 @@ impl State {
|
|||
return;
|
||||
}
|
||||
|
||||
let (xwayland, source) = XWayland::new(&self.common.display_handle);
|
||||
let token =
|
||||
match self
|
||||
.common
|
||||
.event_loop_handle
|
||||
.insert_source(source, move |event, _, data| match event {
|
||||
XWaylandEvent::Ready {
|
||||
connection,
|
||||
client,
|
||||
client_fd: _,
|
||||
display: _,
|
||||
} => {
|
||||
let mut wm = match X11Wm::start_wm(
|
||||
data.common.event_loop_handle.clone(),
|
||||
data.common.display_handle.clone(),
|
||||
connection,
|
||||
client,
|
||||
) {
|
||||
Ok(wm) => wm,
|
||||
Err(err) => {
|
||||
error!(?err, "Failed to start Xwayland WM");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let (theme, size) = load_cursor_theme();
|
||||
let cursor = Cursor::load(&theme, CursorShape::Default, size);
|
||||
let image = cursor.get_image(1, 0);
|
||||
if let Err(err) = wm.set_cursor(
|
||||
&image.pixels_rgba,
|
||||
Size::from((image.width as u16, image.height as u16)),
|
||||
Point::from((image.xhot as u16, image.yhot as u16)),
|
||||
) {
|
||||
warn!(
|
||||
id = ?wm.id(),
|
||||
?err,
|
||||
"Failed to set default cursor for Xwayland WM",
|
||||
);
|
||||
}
|
||||
|
||||
let xwayland_state = data.common.xwayland_state.as_mut().unwrap();
|
||||
xwayland_state.xwm = Some(wm);
|
||||
}
|
||||
XWaylandEvent::Exited => {
|
||||
if let Some(mut xwayland_state) = data.common.xwayland_state.take() {
|
||||
xwayland_state.xwm = None;
|
||||
}
|
||||
}
|
||||
}) {
|
||||
Ok(token) => token,
|
||||
Err(err) => {
|
||||
error!(?err, "Failed to listen for Xwayland");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match xwayland.start(
|
||||
self.common.event_loop_handle.clone(),
|
||||
let (xwayland, client) = match XWayland::spawn(
|
||||
&self.common.display_handle,
|
||||
None,
|
||||
//vec![("WAYLAND_DEBUG", "client")].into_iter(),
|
||||
std::iter::empty::<(OsString, OsString)>(),
|
||||
true,
|
||||
Stdio::null(),
|
||||
Stdio::null(),
|
||||
|user_data| {
|
||||
if let Some(node) = render_node {
|
||||
user_data.insert_if_missing(|| node);
|
||||
}
|
||||
},
|
||||
) {
|
||||
Ok(display) => {
|
||||
self.common.xwayland_state = Some(XWaylandState {
|
||||
xwayland,
|
||||
xwm: None,
|
||||
display,
|
||||
});
|
||||
}
|
||||
Ok((xwayland, client)) => (xwayland, client),
|
||||
Err(err) => {
|
||||
error!(?err, "Failed to start Xwayland.");
|
||||
self.common.event_loop_handle.remove(token);
|
||||
self.notify_ready();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match self
|
||||
.common
|
||||
.event_loop_handle
|
||||
.insert_source(xwayland, move |event, _, data| match event {
|
||||
XWaylandEvent::Ready {
|
||||
x11_socket,
|
||||
display_number,
|
||||
} => {
|
||||
data.common.xwayland_state = Some(XWaylandState {
|
||||
xwm: None,
|
||||
display: display_number,
|
||||
});
|
||||
|
||||
let mut wm = match X11Wm::start_wm(
|
||||
data.common.event_loop_handle.clone(),
|
||||
data.common.display_handle.clone(),
|
||||
x11_socket,
|
||||
client.clone(),
|
||||
) {
|
||||
Ok(wm) => wm,
|
||||
Err(err) => {
|
||||
error!(?err, "Failed to start Xwayland WM");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let (theme, size) = load_cursor_theme();
|
||||
let cursor = Cursor::load(&theme, CursorShape::Default, size);
|
||||
let image = cursor.get_image(1, 0);
|
||||
if let Err(err) = wm.set_cursor(
|
||||
&image.pixels_rgba,
|
||||
Size::from((image.width as u16, image.height as u16)),
|
||||
Point::from((image.xhot as u16, image.yhot as u16)),
|
||||
) {
|
||||
warn!(
|
||||
id = ?wm.id(),
|
||||
?err,
|
||||
"Failed to set default cursor for Xwayland WM",
|
||||
);
|
||||
}
|
||||
|
||||
let xwayland_state = data.common.xwayland_state.as_mut().unwrap();
|
||||
xwayland_state.xwm = Some(wm);
|
||||
data.notify_ready();
|
||||
}
|
||||
XWaylandEvent::Error => {
|
||||
if let Some(mut xwayland_state) = data.common.xwayland_state.take() {
|
||||
xwayland_state.xwm = None;
|
||||
}
|
||||
data.notify_ready();
|
||||
}
|
||||
}) {
|
||||
Ok(_token) => {}
|
||||
Err(err) => {
|
||||
error!(?err, "Failed to listen for Xwayland");
|
||||
self.notify_ready();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue