mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-30 06:02:06 +02:00
This commit adds the ability to set container and workspace padding per monitor. To do so (and to simplify any future need of changing some value per monitor), and have it pass through to each workspace a new field was added to `Workspace` called `globals` which has a new struct called `WorkspaceGlobals`. `WorkspaceGlobals` includes any global values that might be needed by the workspace. This field is updated by the monitor for all its workspaces whenever the config is loaded or reloaded. It is also updated on `RetileAll` and on the function `update_focused_workspace`. This should make sure that every time a workspace needs to use it's `update` function, it has all the `globals` up to date! This also means that now the `update` function from workspaces doesn't take any argument at all, reducing all the need to get all the `work_area`, `work_area_offset`, `window_based_work_area_offset` or `window_based_work_area_offset_limit` simplifying the callers of this function quite a bit. Lastly this commit has also (sort of accidentaly) fixed an existing bug with the `move_workspace_to_monitor` function. This was previous removing the workspace from a monitor, but wasn't changing it's `focused_workspace_idx`, meaning that komorebi would get all messed up after that command. For example, the `border_manager` would get stuck and the komorebi-bar would crash. Now, the `remove_focused_workspace` function also focuses the previous workspace (which in turn will create a new workspace in case the removed workspace was the last workspace).
167 lines
5.3 KiB
Rust
167 lines
5.3 KiB
Rust
#![warn(clippy::all)]
|
|
#![allow(clippy::missing_errors_doc)]
|
|
|
|
pub use komorebi::animation::prefix::AnimationPrefix;
|
|
pub use komorebi::animation::PerAnimationPrefixConfig;
|
|
pub use komorebi::asc::ApplicationSpecificConfiguration;
|
|
pub use komorebi::colour::Colour;
|
|
pub use komorebi::colour::Rgb;
|
|
pub use komorebi::config_generation::ApplicationConfiguration;
|
|
pub use komorebi::config_generation::IdWithIdentifier;
|
|
pub use komorebi::config_generation::IdWithIdentifierAndComment;
|
|
pub use komorebi::config_generation::MatchingRule;
|
|
pub use komorebi::config_generation::MatchingStrategy;
|
|
pub use komorebi::container::Container;
|
|
pub use komorebi::core::config_generation::ApplicationConfigurationGenerator;
|
|
pub use komorebi::core::resolve_home_path;
|
|
pub use komorebi::core::AnimationStyle;
|
|
pub use komorebi::core::ApplicationIdentifier;
|
|
pub use komorebi::core::Arrangement;
|
|
pub use komorebi::core::Axis;
|
|
pub use komorebi::core::BorderImplementation;
|
|
pub use komorebi::core::BorderStyle;
|
|
pub use komorebi::core::Column;
|
|
pub use komorebi::core::ColumnSplit;
|
|
pub use komorebi::core::ColumnSplitWithCapacity;
|
|
pub use komorebi::core::ColumnWidth;
|
|
pub use komorebi::core::CustomLayout;
|
|
pub use komorebi::core::CycleDirection;
|
|
pub use komorebi::core::DefaultLayout;
|
|
pub use komorebi::core::Direction;
|
|
pub use komorebi::core::FocusFollowsMouseImplementation;
|
|
pub use komorebi::core::HidingBehaviour;
|
|
pub use komorebi::core::Layout;
|
|
pub use komorebi::core::MoveBehaviour;
|
|
pub use komorebi::core::OperationBehaviour;
|
|
pub use komorebi::core::OperationDirection;
|
|
pub use komorebi::core::PathExt;
|
|
pub use komorebi::core::Rect;
|
|
pub use komorebi::core::Sizing;
|
|
pub use komorebi::core::SocketMessage;
|
|
pub use komorebi::core::StackbarLabel;
|
|
pub use komorebi::core::StackbarMode;
|
|
pub use komorebi::core::StateQuery;
|
|
pub use komorebi::core::WindowKind;
|
|
pub use komorebi::monitor::Monitor;
|
|
pub use komorebi::monitor_reconciliator::MonitorNotification;
|
|
pub use komorebi::ring::Ring;
|
|
pub use komorebi::window::Window;
|
|
pub use komorebi::window_manager_event::WindowManagerEvent;
|
|
pub use komorebi::workspace::Workspace;
|
|
pub use komorebi::workspace::WorkspaceGlobals;
|
|
pub use komorebi::workspace::WorkspaceLayer;
|
|
pub use komorebi::AnimationsConfig;
|
|
pub use komorebi::AspectRatio;
|
|
pub use komorebi::BorderColours;
|
|
pub use komorebi::CrossBoundaryBehaviour;
|
|
pub use komorebi::GlobalState;
|
|
pub use komorebi::KomorebiTheme;
|
|
pub use komorebi::MonitorConfig;
|
|
pub use komorebi::Notification;
|
|
pub use komorebi::NotificationEvent;
|
|
pub use komorebi::PredefinedAspectRatio;
|
|
pub use komorebi::RuleDebug;
|
|
pub use komorebi::StackbarConfig;
|
|
pub use komorebi::State;
|
|
pub use komorebi::StaticConfig;
|
|
pub use komorebi::SubscribeOptions;
|
|
pub use komorebi::TabsConfig;
|
|
pub use komorebi::WindowContainerBehaviour;
|
|
pub use komorebi::WindowsApi;
|
|
pub use komorebi::WorkspaceConfig;
|
|
|
|
use komorebi::DATA_DIR;
|
|
|
|
use std::io::BufReader;
|
|
use std::io::Read;
|
|
use std::io::Write;
|
|
use std::net::Shutdown;
|
|
use std::time::Duration;
|
|
pub use uds_windows::UnixListener;
|
|
use uds_windows::UnixStream;
|
|
|
|
const KOMOREBI: &str = "komorebi.sock";
|
|
|
|
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
|
let socket = DATA_DIR.join(KOMOREBI);
|
|
let mut stream = UnixStream::connect(socket)?;
|
|
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
|
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
|
}
|
|
|
|
pub fn send_batch(messages: impl IntoIterator<Item = SocketMessage>) -> std::io::Result<()> {
|
|
let socket = DATA_DIR.join(KOMOREBI);
|
|
let mut stream = UnixStream::connect(socket)?;
|
|
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
|
let msgs = messages.into_iter().fold(String::new(), |mut s, m| {
|
|
if let Ok(m_str) = serde_json::to_string(&m) {
|
|
s.push_str(&m_str);
|
|
s.push('\n');
|
|
}
|
|
s
|
|
});
|
|
stream.write_all(msgs.as_bytes())
|
|
}
|
|
|
|
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
|
let socket = DATA_DIR.join(KOMOREBI);
|
|
|
|
let mut stream = UnixStream::connect(socket)?;
|
|
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
|
|
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
|
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
|
stream.shutdown(Shutdown::Write)?;
|
|
|
|
let mut reader = BufReader::new(stream);
|
|
let mut response = String::new();
|
|
reader.read_to_string(&mut response)?;
|
|
|
|
Ok(response)
|
|
}
|
|
|
|
pub fn subscribe(name: &str) -> std::io::Result<UnixListener> {
|
|
let socket = DATA_DIR.join(name);
|
|
|
|
match std::fs::remove_file(&socket) {
|
|
Ok(()) => {}
|
|
Err(error) => match error.kind() {
|
|
std::io::ErrorKind::NotFound => {}
|
|
_ => {
|
|
return Err(error);
|
|
}
|
|
},
|
|
};
|
|
|
|
let listener = UnixListener::bind(&socket)?;
|
|
|
|
send_message(&SocketMessage::AddSubscriberSocket(name.to_string()))?;
|
|
|
|
Ok(listener)
|
|
}
|
|
|
|
pub fn subscribe_with_options(
|
|
name: &str,
|
|
options: SubscribeOptions,
|
|
) -> std::io::Result<UnixListener> {
|
|
let socket = DATA_DIR.join(name);
|
|
|
|
match std::fs::remove_file(&socket) {
|
|
Ok(()) => {}
|
|
Err(error) => match error.kind() {
|
|
std::io::ErrorKind::NotFound => {}
|
|
_ => {
|
|
return Err(error);
|
|
}
|
|
},
|
|
};
|
|
|
|
let listener = UnixListener::bind(&socket)?;
|
|
|
|
send_message(&SocketMessage::AddSubscriberSocketWithOptions(
|
|
name.to_string(),
|
|
options,
|
|
))?;
|
|
|
|
Ok(listener)
|
|
}
|