mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-29 20:34:46 +01:00
Float all windows for tests and improve window positioning
This commit is contained in:
parent
0b353c45f2
commit
194da9e557
4 changed files with 79 additions and 41 deletions
|
@ -90,11 +90,7 @@ pub fn setup_wlcs_dummy() -> anyhow::Result<(State, EventLoop<'static, State>)>
|
|||
}
|
||||
|
||||
impl State {
|
||||
pub fn start_wlcs_config<F>(
|
||||
&mut self,
|
||||
socket_dir: &Path,
|
||||
run_config: F,
|
||||
) -> anyhow::Result<()>
|
||||
pub fn start_wlcs_config<F>(&mut self, socket_dir: &Path, run_config: F) -> anyhow::Result<()>
|
||||
where
|
||||
F: FnOnce() -> () + Send + 'static,
|
||||
{
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
use pinnacle::state::State;
|
||||
|
||||
mod inner {
|
||||
use pinnacle_api::layout::{CyclingLayoutManager, MasterStackLayout};
|
||||
use pinnacle_api::window::rules::{WindowRule, WindowRuleCondition};
|
||||
use pinnacle_api::ApiModules;
|
||||
|
||||
#[pinnacle_api::config(modules)]
|
||||
async fn main() {
|
||||
#[allow(unused_variables)]
|
||||
let ApiModules { layout, .. } = modules;
|
||||
let ApiModules { layout, window, .. } = modules;
|
||||
|
||||
let _layout_requester = layout.set_manager(CyclingLayoutManager::new([
|
||||
Box::<MasterStackLayout>::default() as _,
|
||||
]));
|
||||
window.add_window_rule(
|
||||
WindowRuleCondition::default().all(vec![]),
|
||||
WindowRule::new().floating(true),
|
||||
);
|
||||
|
||||
let _layout_requester =
|
||||
layout.set_manager(CyclingLayoutManager::new([
|
||||
Box::new(MasterStackLayout::default()) as _,
|
||||
]));
|
||||
}
|
||||
|
||||
pub(crate) fn start_config() {
|
||||
|
@ -23,12 +29,9 @@ pub fn run_config(state: &mut State) {
|
|||
let temp_dir = tempfile::tempdir().expect("failed to setup temp dir for socket");
|
||||
let socket_dir = temp_dir.path().to_owned();
|
||||
state
|
||||
.start_wlcs_config(
|
||||
&socket_dir,
|
||||
move || {
|
||||
inner::start_config();
|
||||
drop(temp_dir);
|
||||
},
|
||||
)
|
||||
.start_wlcs_config(&socket_dir, move || {
|
||||
inner::start_config();
|
||||
drop(temp_dir);
|
||||
})
|
||||
.expect("failed to start wlcs config");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
pub(crate) mod config;
|
||||
mod input_backend;
|
||||
mod main_loop;
|
||||
pub(crate) mod config;
|
||||
|
||||
use std::{
|
||||
io,
|
||||
|
@ -111,6 +111,19 @@ static SUPPORTED_EXTENSIONS: &[WlcsExtensionDescriptor] = extension_list!(
|
|||
// 12 Missing extension: zwp_text_input_manager_v2>= 1
|
||||
// 11 Missing extension: zwp_text_input_manager_v3>= 1
|
||||
// 180 Missing extension: zxdg_shell_v6>= 1
|
||||
|
||||
// mostly from https://github.com/Smithay/smithay/issues/781
|
||||
("wl_compositor", 6),
|
||||
("wl_subcompositor", 1),
|
||||
("wl_shm", 1),
|
||||
("wl_data_device_manager", 3),
|
||||
("wl_seat", 9),
|
||||
("wl_output", 4),
|
||||
("wp_presentation", 1),
|
||||
("wp_viewporter", 1),
|
||||
("xdg_shell", 6),
|
||||
("linux-dmabuf-v1", 5),
|
||||
("xdg_shell", 6),
|
||||
);
|
||||
|
||||
static DESCRIPTOR: WlcsIntegrationDescriptor = WlcsIntegrationDescriptor {
|
||||
|
@ -194,11 +207,13 @@ impl Wlcs for PinnacleHandle {
|
|||
unsafe { ffi_dispatch!(wayland_client_handle(), wl_display_get_fd, display) };
|
||||
let surface_id =
|
||||
unsafe { ffi_dispatch!(wayland_client_handle(), wl_proxy_get_id, surface) };
|
||||
let _ = conn.sender.send(WlcsEvent::PositionWindow {
|
||||
client_id,
|
||||
surface_id,
|
||||
location: (x, y).into(),
|
||||
});
|
||||
conn.sender
|
||||
.send(WlcsEvent::PositionWindow {
|
||||
client_id,
|
||||
surface_id,
|
||||
location: (x, y).into(),
|
||||
})
|
||||
.expect("failed to send position_window_absolute");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ use std::{sync::Arc, time::Duration};
|
|||
|
||||
use pinnacle::{
|
||||
backend::wlcs::setup_wlcs_dummy,
|
||||
state::{ClientState, State},
|
||||
state::{ClientState, State, WithState},
|
||||
window::window_state::FloatingOrTiled,
|
||||
};
|
||||
use smithay::{
|
||||
backend::input::{ButtonState, DeviceCapability, InputEvent},
|
||||
|
@ -10,19 +11,21 @@ use smithay::{
|
|||
calloop::channel::{Channel, Event},
|
||||
wayland_server::{Client, Resource},
|
||||
},
|
||||
utils::Rectangle,
|
||||
wayland::seat::WaylandFocus,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::run_config, input_backend::{
|
||||
config::run_config,
|
||||
input_backend::{
|
||||
WlcsDevice, WlcsInputBackend, WlcsPointerButtonEvent, WlcsPointerMotionAbsoluteEvent,
|
||||
WlcsPointerMotionEvent, WlcsTouchDownEvent, WlcsTouchUpEvent,
|
||||
}, WlcsEvent
|
||||
},
|
||||
WlcsEvent,
|
||||
};
|
||||
|
||||
pub(crate) fn run(channel: Channel<WlcsEvent>) {
|
||||
let (mut state, mut event_loop) =
|
||||
setup_wlcs_dummy().expect("failed to setup dummy backend");
|
||||
let (mut state, mut event_loop) = setup_wlcs_dummy().expect("failed to setup dummy backend");
|
||||
|
||||
event_loop
|
||||
.handle()
|
||||
|
@ -46,8 +49,6 @@ pub(crate) fn run(channel: Channel<WlcsEvent>) {
|
|||
state.xdisplay = Some(u32::MAX);
|
||||
run_config(&mut state);
|
||||
|
||||
// FIXME: use a custom socker_dir to avoid having to number sockets
|
||||
|
||||
// wait for the config to connect to the layout service
|
||||
while state.layout_state.layout_request_sender.is_none() {
|
||||
event_loop
|
||||
|
@ -71,6 +72,7 @@ pub(crate) fn run(channel: Channel<WlcsEvent>) {
|
|||
}
|
||||
|
||||
fn handle_event(event: WlcsEvent, state: &mut State) {
|
||||
tracing::debug!("handle_event {:?}", event);
|
||||
match event {
|
||||
WlcsEvent::Stop => state.shutdown(),
|
||||
WlcsEvent::NewClient { stream, client_id } => {
|
||||
|
@ -85,19 +87,41 @@ fn handle_event(event: WlcsEvent, state: &mut State) {
|
|||
surface_id,
|
||||
location,
|
||||
} => {
|
||||
// TODO: handle this in a Pinnacle-applicable way (LayoutManager?)
|
||||
let client = state.backend.wlcs_mut().clients.get(&client_id);
|
||||
let toplevel = state.space.elements().find(|w| {
|
||||
if let Some(surface) = w.wl_surface() {
|
||||
state.display_handle.get_client(surface.id()).ok().as_ref() == client
|
||||
&& surface.id().protocol_id() == surface_id
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
let window = state
|
||||
.space
|
||||
.elements()
|
||||
.find(|w| {
|
||||
if let Some(surface) = w.wl_surface() {
|
||||
state.display_handle.get_client(surface.id()).ok().as_ref() == client
|
||||
&& surface.id().protocol_id() == surface_id
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.cloned();
|
||||
|
||||
if let Some(toplevel) = toplevel {
|
||||
state.space.map_element(toplevel.clone(), location, false);
|
||||
if let Some(window) = window {
|
||||
state.space.map_element(window.clone(), location, false);
|
||||
|
||||
let size = state
|
||||
.space
|
||||
.element_geometry(&window)
|
||||
.expect("window to be positioned was not mapped")
|
||||
.size;
|
||||
|
||||
if window.with_state(|state| state.floating_or_tiled.is_tiled()) {
|
||||
window.toggle_floating();
|
||||
}
|
||||
|
||||
window.with_state_mut(|state| {
|
||||
state.floating_or_tiled =
|
||||
FloatingOrTiled::Floating(Rectangle::from_loc_and_size(location, size));
|
||||
});
|
||||
|
||||
for output in state.space.outputs_for_element(&window) {
|
||||
state.schedule_render(&output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue