Compare commits

...

1 Commits

Author SHA1 Message Date
Thorsten Ball
be5dc75ac2 WIP 2024-07-04 12:47:23 +02:00
5 changed files with 77 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
use std::ops::Range;
use std::{ops::Range, time::Duration};
use gpui::*;
use unicode_segmentation::*;
@@ -479,10 +479,31 @@ fn main() {
},
)
.unwrap();
window
.update(cx, |view, cx| {
view.focus_handle.focus(cx);
cx.activate(true)
cx.activate(true);
cx.spawn(|this, mut cx| async move {
cx.background_executor().timer(Duration::from_secs(5)).await;
this.update(&mut cx, |_, cx| {
println!("calling cx.activate()");
cx.activate(true);
println!("cx.activate() called.");
})
.unwrap();
println!("----------");
cx.update(|cx| {
println!("calling cx.activate_window()");
cx.activate_window();
println!("cx.activate_window() called");
})
.unwrap();
})
.detach();
})
.unwrap();
});

View File

@@ -221,6 +221,10 @@ impl<P: LinuxClient + 'static> Platform for P {
}
fn activate(&self, ignoring_other_apps: bool) {
println!(
"Platform.activate(ignoring_other_apps: {}) called",
ignoring_other_apps
);
log::info!("activate is not implemented on Linux, ignoring the call")
}

View File

@@ -21,6 +21,7 @@ use wayland_client::protocol::wl_callback::{self, WlCallback};
use wayland_client::protocol::wl_data_device_manager::DndAction;
use wayland_client::protocol::wl_data_offer::WlDataOffer;
use wayland_client::protocol::wl_pointer::AxisSource;
use wayland_client::protocol::wl_surface::WlSurface;
use wayland_client::protocol::{
wl_data_device, wl_data_device_manager, wl_data_offer, wl_data_source, wl_output, wl_region,
};
@@ -221,6 +222,7 @@ pub(crate) struct WaylandClientState {
primary_data_offer: Option<DataOffer<ZwpPrimarySelectionOfferV1>>,
cursor: Cursor,
pending_open_uri: Option<String>,
pub pending_window_activation: Option<WlSurface>,
event_loop: Option<EventLoop<'static, WaylandClientStatePtr>>,
common: LinuxCommon,
}
@@ -532,6 +534,7 @@ impl WaylandClient {
cursor,
pending_open_uri: None,
event_loop: Some(event_loop),
pending_window_activation: None,
}));
WaylandSource::new(conn, event_queue)
@@ -957,8 +960,17 @@ impl Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, ()> for WaylandClie
if let xdg_activation_token_v1::Event::Done { token } = event {
if let Some(uri) = state.pending_open_uri.take() {
open_uri_internal(&uri, Some(&token));
} else {
log::error!("called while pending_open_uri is None");
} else if let Some(surface) = state.pending_window_activation.take() {
println!("we got a surface");
if let Some(ref manager) = state.globals.activation {
println!("we're calling activate. token: {:?}", token);
manager.activate(token, &surface);
}
// if let Some(surface) = state.pending_activations.remove(&token) {
// if let Some(ref manager) = state.globals.activation {
// manager.activate(token, &surface);
// }
// }
}
}
token.destroy();

View File

@@ -74,6 +74,7 @@ struct InProgressConfigure {
pub struct WaylandWindowState {
xdg_surface: xdg_surface::XdgSurface,
acknowledged_first_configure: bool,
app_id: Option<String>,
pub surface: wl_surface::WlSurface,
decoration: Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>,
appearance: WindowAppearance,
@@ -156,6 +157,7 @@ impl WaylandWindowState {
Ok(Self {
xdg_surface,
app_id: None,
acknowledged_first_configure: false,
surface,
decoration,
@@ -808,7 +810,36 @@ impl PlatformWindow for WaylandWindow {
}
fn activate(&self) {
log::info!("Wayland does not support this API");
println!("WaylandWindow.activate called");
let state = self.borrow();
let activation = state.globals.activation.as_ref().cloned();
if let Some(manager) = activation {
let token = manager.get_activation_token(&state.globals.qh, ());
let serial = state.client.get_serial(SerialKind::MousePress);
println!("Creating activation token...");
token.set_serial(serial, &state.globals.seat);
println!("Token serial set: {:?}", serial);
token.set_surface(&state.surface);
println!("Surface set for activation: {:?}", &state.surface);
if let Some(app_id) = state.app_id.as_ref() {
token.set_app_id(app_id.clone());
println!("App ID set for activation: {}", app_id);
}
state
.client
.get_client()
.borrow_mut()
.pending_window_activation = Some(state.surface.clone());
token.commit();
println!("Activation token committed, waiting for done event.");
} else {
log::warn!("Wayland compositor does not support xdg_activation_v1");
}
}
fn is_active(&self) -> bool {
@@ -820,7 +851,9 @@ impl PlatformWindow for WaylandWindow {
}
fn set_app_id(&mut self, app_id: &str) {
self.borrow().toplevel.set_app_id(app_id.to_owned());
let mut state = self.borrow_mut();
state.app_id = Some(app_id.to_owned());
state.toplevel.set_app_id(app_id.to_owned());
}
fn set_background_appearance(&self, background_appearance: WindowBackgroundAppearance) {

View File

@@ -3578,6 +3578,7 @@ impl<'a> WindowContext<'a> {
/// Focus the current window and bring it to the foreground at the platform level.
pub fn activate_window(&self) {
println!("WindowContext.activate_window called");
self.window.platform_window.activate();
}