mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-30 20:34:49 +01:00
Merge pull request #5 from Ottatop/dev
Start work on tags, uncomment stuff
This commit is contained in:
commit
2113a26bcb
7 changed files with 87 additions and 27 deletions
|
@ -7,6 +7,8 @@
|
||||||
// The MessagePack format for these is a one-element map where the element's key is the enum name and its
|
// The MessagePack format for these is a one-element map where the element's key is the enum name and its
|
||||||
// value is a map of the enum's values
|
// value is a map of the enum's values
|
||||||
|
|
||||||
|
use crate::window::tag::Tag;
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy)]
|
||||||
pub struct CallbackId(pub u32);
|
pub struct CallbackId(pub u32);
|
||||||
|
|
||||||
|
@ -31,6 +33,12 @@ pub enum Msg {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
client_id: Option<u32>,
|
client_id: Option<u32>,
|
||||||
},
|
},
|
||||||
|
MoveToTag {
|
||||||
|
tag: Tag,
|
||||||
|
},
|
||||||
|
ToggleTag {
|
||||||
|
tag: Tag,
|
||||||
|
},
|
||||||
|
|
||||||
// Process management
|
// Process management
|
||||||
/// Spawn a program with an optional callback.
|
/// Spawn a program with an optional callback.
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
//! While Pinnacle is not a library, this documentation serves to guide those who want to
|
//! While Pinnacle is not a library, this documentation serves to guide those who want to
|
||||||
//! contribute or learn how building something like this works.
|
//! contribute or learn how building something like this works.
|
||||||
|
|
||||||
// test
|
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod backend;
|
mod backend;
|
||||||
mod cursor;
|
mod cursor;
|
||||||
|
@ -22,6 +20,7 @@ mod grab;
|
||||||
mod handlers;
|
mod handlers;
|
||||||
mod input;
|
mod input;
|
||||||
mod layout;
|
mod layout;
|
||||||
|
mod output;
|
||||||
mod pointer;
|
mod pointer;
|
||||||
mod render;
|
mod render;
|
||||||
mod state;
|
mod state;
|
||||||
|
|
31
src/output.rs
Normal file
31
src/output.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
use smithay::output::Output;
|
||||||
|
|
||||||
|
use crate::window::tag::Tag;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct OutputState {
|
||||||
|
focused_tags: Vec<Tag>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OutputState {
|
||||||
|
pub fn with<F, T>(output: &Output, mut func: F) -> T
|
||||||
|
where
|
||||||
|
F: FnMut(&mut Self) -> T,
|
||||||
|
{
|
||||||
|
output
|
||||||
|
.user_data()
|
||||||
|
.insert_if_missing(|| RefCell::<Self>::default);
|
||||||
|
|
||||||
|
let state = output.user_data().get::<RefCell<Self>>().unwrap();
|
||||||
|
|
||||||
|
func(&mut state.borrow_mut())
|
||||||
|
}
|
||||||
|
}
|
43
src/state.rs
43
src/state.rs
|
@ -92,8 +92,6 @@ pub struct State<B: Backend> {
|
||||||
pub pointer_location: Point<f64, Logical>,
|
pub pointer_location: Point<f64, Logical>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static NUM: AtomicU32 = AtomicU32::new(0);
|
|
||||||
|
|
||||||
impl<B: Backend> State<B> {
|
impl<B: Backend> State<B> {
|
||||||
/// Create the main [State].
|
/// Create the main [State].
|
||||||
///
|
///
|
||||||
|
@ -133,6 +131,7 @@ impl<B: Backend> State<B> {
|
||||||
loop_handle.insert_source(rx_channel, |msg, _, data| match msg {
|
loop_handle.insert_source(rx_channel, |msg, _, data| match msg {
|
||||||
Event::Msg(msg) => {
|
Event::Msg(msg) => {
|
||||||
// TODO: move this into its own function
|
// TODO: move this into its own function
|
||||||
|
// TODO: no like seriously this is getting a bit unwieldy
|
||||||
match msg {
|
match msg {
|
||||||
Msg::SetKeybind {
|
Msg::SetKeybind {
|
||||||
key,
|
key,
|
||||||
|
@ -177,28 +176,26 @@ impl<B: Backend> State<B> {
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
// .stdin(if callback_id.is_some() {
|
.stdin(if callback_id.is_some() {
|
||||||
// Stdio::piped()
|
Stdio::piped()
|
||||||
// } else {
|
} else {
|
||||||
// // piping to null because foot won't open without a callback_id
|
// piping to null because foot won't open without a callback_id
|
||||||
// // otherwise
|
// otherwise
|
||||||
// Stdio::null()
|
Stdio::null()
|
||||||
// })
|
})
|
||||||
// .stdout(if callback_id.is_some() {
|
.stdout(if callback_id.is_some() {
|
||||||
// Stdio::piped()
|
Stdio::piped()
|
||||||
// } else {
|
} else {
|
||||||
// Stdio::null()
|
Stdio::null()
|
||||||
// })
|
})
|
||||||
// .stderr(if callback_id.is_some() {
|
.stderr(if callback_id.is_some() {
|
||||||
// Stdio::piped()
|
Stdio::piped()
|
||||||
// } else {
|
} else {
|
||||||
// Stdio::null()
|
Stdio::null()
|
||||||
// })
|
})
|
||||||
.args(command)
|
.args(command)
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap(); // TODO: handle unwrap
|
.unwrap(); // TODO: handle unwrap
|
||||||
NUM.store(NUM.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
|
|
||||||
tracing::info!("{} processes", NUM.load(Ordering::SeqCst));
|
|
||||||
|
|
||||||
// TODO: find a way to make this hellish code look better, deal with unwraps
|
// TODO: find a way to make this hellish code look better, deal with unwraps
|
||||||
if let Some(callback_id) = callback_id {
|
if let Some(callback_id) = callback_id {
|
||||||
|
@ -208,9 +205,9 @@ impl<B: Backend> State<B> {
|
||||||
let stream_err = stream_out.clone();
|
let stream_err = stream_out.clone();
|
||||||
let stream_exit = stream_out.clone();
|
let stream_exit = stream_out.clone();
|
||||||
|
|
||||||
|
// TODO: make this not use 3 whole threads per process
|
||||||
if let Some(stdout) = stdout {
|
if let Some(stdout) = stdout {
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
// TODO: maybe find a way to make this async?
|
|
||||||
let mut reader = BufReader::new(stdout);
|
let mut reader = BufReader::new(stdout);
|
||||||
loop {
|
loop {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
@ -305,6 +302,8 @@ impl<B: Backend> State<B> {
|
||||||
command,
|
command,
|
||||||
callback_id,
|
callback_id,
|
||||||
} => todo!(),
|
} => todo!(),
|
||||||
|
Msg::MoveToTag { tag } => todo!(),
|
||||||
|
Msg::ToggleTag { tag } => todo!(),
|
||||||
Msg::Quit => {
|
Msg::Quit => {
|
||||||
data.state.loop_signal.stop();
|
data.state.loop_signal.stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,13 @@ use self::window_state::{Float, WindowState};
|
||||||
pub mod tag;
|
pub mod tag;
|
||||||
pub mod window_state;
|
pub mod window_state;
|
||||||
|
|
||||||
|
// TODO: maybe get rid of this and move the fn into resize_surface state because it's the only user
|
||||||
pub trait SurfaceState: Default + 'static {
|
pub trait SurfaceState: Default + 'static {
|
||||||
/// Access the [SurfaceState] associated with a [WlSurface].
|
/// Access the [`SurfaceState`] associated with a [`WlSurface`].
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// This function will panic if you use it within itself due to the use of a [RefCell].
|
/// This function will panic if you use it within itself due to the use of a [`RefCell`].
|
||||||
fn with_state<F, T>(wl_surface: &WlSurface, function: F) -> T
|
fn with_state<F, T>(wl_surface: &WlSurface, function: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> T,
|
F: FnOnce(&mut Self) -> T,
|
||||||
|
|
|
@ -4,4 +4,25 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
pub struct Tag(u32);
|
use smithay::desktop::Window;
|
||||||
|
|
||||||
|
use crate::{backend::Backend, state::State};
|
||||||
|
|
||||||
|
use super::window_state::WindowState;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct Tag(String);
|
||||||
|
|
||||||
|
impl Tag {
|
||||||
|
/// Returns all windows that have this tag.
|
||||||
|
pub fn windows<B: Backend>(&self, state: &State<B>) -> Vec<Window> {
|
||||||
|
state
|
||||||
|
.space
|
||||||
|
.elements()
|
||||||
|
.filter(|&window| {
|
||||||
|
WindowState::with_state(window, |win_state| win_state.tags.contains(self))
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub struct WindowState {
|
||||||
pub floating: Float,
|
pub floating: Float,
|
||||||
/// The window's resize state. See [WindowResizeState] for more.
|
/// The window's resize state. See [WindowResizeState] for more.
|
||||||
pub resize_state: WindowResizeState,
|
pub resize_state: WindowResizeState,
|
||||||
|
/// What tags the window is currently on.
|
||||||
pub tags: Vec<Tag>,
|
pub tags: Vec<Tag>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue