mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-30 22:22:08 +02:00
refactor(logging): make use of tracing::instrument
This commit is contained in:
@@ -99,8 +99,9 @@ impl Container {
|
||||
self.windows.focused_mut()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_window(&mut self, idx: usize) {
|
||||
tracing::info!("focusing window at index: {}", idx);
|
||||
tracing::info!("focusing window");
|
||||
self.windows.focus(idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ fn setup() -> Result<WorkerGuard> {
|
||||
tracing::subscriber::set_global_default(
|
||||
tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.finish()
|
||||
.with(
|
||||
tracing_subscriber::fmt::Layer::default()
|
||||
@@ -80,6 +79,7 @@ fn setup() -> Result<WorkerGuard> {
|
||||
Ok(guard)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
fn main() -> Result<()> {
|
||||
match std::env::args().count() {
|
||||
1 => {
|
||||
|
||||
@@ -104,11 +104,13 @@ impl Monitor {
|
||||
self.workspaces.focused_mut()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_workspace(&mut self, idx: usize) -> Result<()> {
|
||||
tracing::info!("focusing workspace");
|
||||
|
||||
{
|
||||
let workspaces = self.workspaces_mut();
|
||||
|
||||
tracing::info!("focusing workspace at index: {}", idx);
|
||||
if workspaces.get(idx).is_none() {
|
||||
workspaces.resize(idx + 1, Workspace::default());
|
||||
}
|
||||
@@ -131,7 +133,6 @@ impl Monitor {
|
||||
}
|
||||
|
||||
pub fn update_focused_workspace(&mut self) -> Result<()> {
|
||||
tracing::info!("updating workspace: {}", self.focused_workspace_idx());
|
||||
let work_area = *self.work_area_size();
|
||||
|
||||
self.focused_workspace_mut()
|
||||
|
||||
@@ -17,6 +17,7 @@ use crate::FLOAT_CLASSES;
|
||||
use crate::FLOAT_EXES;
|
||||
use crate::FLOAT_TITLES;
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
|
||||
let listener = wm
|
||||
.lock()
|
||||
@@ -26,11 +27,11 @@ pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
|
||||
.expect("could not clone unix listener");
|
||||
|
||||
thread::spawn(move || {
|
||||
tracing::info!("listening for commands");
|
||||
tracing::info!("listening");
|
||||
for client in listener.incoming() {
|
||||
match client {
|
||||
Ok(stream) => match wm.lock().unwrap().process_command(stream) {
|
||||
Ok(()) => tracing::info!("command processed"),
|
||||
Ok(stream) => match wm.lock().unwrap().read_commands(stream) {
|
||||
Ok(()) => {}
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
},
|
||||
Err(error) => {
|
||||
@@ -43,118 +44,130 @@ pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
|
||||
}
|
||||
|
||||
impl WindowManager {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn process_command(&mut self, stream: UnixStream) -> Result<()> {
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn process_command(&mut self, message: SocketMessage) -> Result<()> {
|
||||
match message {
|
||||
SocketMessage::Promote => self.promote_container_to_front()?,
|
||||
SocketMessage::FocusWindow(direction) => {
|
||||
self.focus_container_in_direction(direction)?;
|
||||
}
|
||||
SocketMessage::MoveWindow(direction) => {
|
||||
self.move_container_in_direction(direction)?;
|
||||
}
|
||||
SocketMessage::StackWindow(direction) => self.add_window_to_container(direction)?,
|
||||
SocketMessage::UnstackWindow => self.remove_window_from_container()?,
|
||||
SocketMessage::CycleStack(direction) => {
|
||||
self.cycle_container_window_in_direction(direction)?;
|
||||
}
|
||||
SocketMessage::ToggleFloat => self.toggle_float()?,
|
||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||
SocketMessage::ContainerPadding(monitor_idx, workspace_idx, size) => {
|
||||
self.set_container_padding(monitor_idx, workspace_idx, size)?;
|
||||
}
|
||||
SocketMessage::WorkspacePadding(monitor_idx, workspace_idx, size) => {
|
||||
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
|
||||
}
|
||||
SocketMessage::FloatClass(target) => {
|
||||
let mut float_classes = FLOAT_CLASSES.lock().unwrap();
|
||||
if !float_classes.contains(&target) {
|
||||
float_classes.push(target);
|
||||
}
|
||||
}
|
||||
SocketMessage::FloatExe(target) => {
|
||||
let mut float_exes = FLOAT_EXES.lock().unwrap();
|
||||
if !float_exes.contains(&target) {
|
||||
float_exes.push(target);
|
||||
}
|
||||
}
|
||||
SocketMessage::FloatTitle(target) => {
|
||||
let mut float_titles = FLOAT_TITLES.lock().unwrap();
|
||||
if !float_titles.contains(&target) {
|
||||
float_titles.push(target);
|
||||
}
|
||||
}
|
||||
SocketMessage::AdjustContainerPadding(sizing, adjustment) => {
|
||||
self.adjust_container_padding(sizing, adjustment)?;
|
||||
}
|
||||
SocketMessage::AdjustWorkspacePadding(sizing, adjustment) => {
|
||||
self.adjust_workspace_padding(sizing, adjustment)?;
|
||||
}
|
||||
SocketMessage::MoveContainerToWorkspaceNumber(workspace_idx) => {
|
||||
self.move_container_to_workspace(workspace_idx, true)?;
|
||||
}
|
||||
SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => {
|
||||
self.move_container_to_monitor(monitor_idx, true)?;
|
||||
}
|
||||
SocketMessage::TogglePause => {
|
||||
tracing::info!("pausing");
|
||||
self.is_paused = !self.is_paused;
|
||||
}
|
||||
SocketMessage::FocusMonitorNumber(monitor_idx) => {
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
self.update_focused_workspace(true)?;
|
||||
}
|
||||
SocketMessage::Retile => {
|
||||
for monitor in self.monitors_mut() {
|
||||
let work_area = *monitor.work_area_size();
|
||||
monitor
|
||||
.focused_workspace_mut()
|
||||
.context("there is no workspace")?
|
||||
.update(&work_area)?;
|
||||
}
|
||||
}
|
||||
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
|
||||
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout(layout)?,
|
||||
SocketMessage::WorkspaceLayout(monitor_idx, workspace_idx, layout) => {
|
||||
self.set_workspace_layout(monitor_idx, workspace_idx, layout)?;
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
SocketMessage::Stop => {
|
||||
tracing::error!(
|
||||
"received stop command, restoring all hidden windows and terminating process"
|
||||
);
|
||||
self.restore_all_windows();
|
||||
std::process::exit(0)
|
||||
}
|
||||
SocketMessage::EnsureWorkspaces(monitor_idx, workspace_count) => {
|
||||
self.ensure_workspaces_for_monitor(monitor_idx, workspace_count)?;
|
||||
}
|
||||
SocketMessage::WorkspaceName(monitor_idx, workspace_idx, name) => {
|
||||
self.set_workspace_name(monitor_idx, workspace_idx, name)?;
|
||||
}
|
||||
SocketMessage::State => {
|
||||
let state = serde_json::to_string_pretty(self)?;
|
||||
let mut socket = dirs::home_dir().context("there is no home directory")?;
|
||||
socket.push("komorebic.sock");
|
||||
let socket = socket.as_path();
|
||||
|
||||
let mut stream = UnixStream::connect(&socket)?;
|
||||
stream.write_all(state.as_bytes())?;
|
||||
}
|
||||
}
|
||||
|
||||
tracing::info!("processed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, stream))]
|
||||
pub fn read_commands(&mut self, stream: UnixStream) -> Result<()> {
|
||||
let stream = BufReader::new(stream);
|
||||
for line in stream.lines() {
|
||||
let message = SocketMessage::from_str(&line?)?;
|
||||
|
||||
if self.is_paused {
|
||||
if let SocketMessage::TogglePause = message {
|
||||
tracing::info!("resuming window management");
|
||||
tracing::info!("resuming");
|
||||
self.is_paused = !self.is_paused;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("ignoring commands while paused");
|
||||
tracing::trace!("ignoring while paused");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("processing command: {}", &message);
|
||||
match message {
|
||||
SocketMessage::Promote => self.promote_container_to_front()?,
|
||||
SocketMessage::FocusWindow(direction) => {
|
||||
self.focus_container_in_direction(direction)?;
|
||||
}
|
||||
SocketMessage::MoveWindow(direction) => {
|
||||
self.move_container_in_direction(direction)?;
|
||||
}
|
||||
SocketMessage::StackWindow(direction) => self.add_window_to_container(direction)?,
|
||||
SocketMessage::UnstackWindow => self.remove_window_from_container()?,
|
||||
SocketMessage::CycleStack(direction) => {
|
||||
self.cycle_container_window_in_direction(direction)?;
|
||||
}
|
||||
SocketMessage::ToggleFloat => self.toggle_float()?,
|
||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||
SocketMessage::ContainerPadding(monitor_idx, workspace_idx, size) => {
|
||||
self.set_container_padding(monitor_idx, workspace_idx, size)?;
|
||||
}
|
||||
SocketMessage::WorkspacePadding(monitor_idx, workspace_idx, size) => {
|
||||
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
|
||||
}
|
||||
SocketMessage::FloatClass(target) => {
|
||||
let mut float_classes = FLOAT_CLASSES.lock().unwrap();
|
||||
if !float_classes.contains(&target) {
|
||||
float_classes.push(target);
|
||||
}
|
||||
}
|
||||
SocketMessage::FloatExe(target) => {
|
||||
let mut float_exes = FLOAT_EXES.lock().unwrap();
|
||||
if !float_exes.contains(&target) {
|
||||
float_exes.push(target);
|
||||
}
|
||||
}
|
||||
SocketMessage::FloatTitle(target) => {
|
||||
let mut float_titles = FLOAT_TITLES.lock().unwrap();
|
||||
if !float_titles.contains(&target) {
|
||||
float_titles.push(target);
|
||||
}
|
||||
}
|
||||
SocketMessage::AdjustContainerPadding(sizing, adjustment) => {
|
||||
self.adjust_container_padding(sizing, adjustment)?;
|
||||
}
|
||||
SocketMessage::AdjustWorkspacePadding(sizing, adjustment) => {
|
||||
self.adjust_workspace_padding(sizing, adjustment)?;
|
||||
}
|
||||
SocketMessage::MoveContainerToWorkspaceNumber(workspace_idx) => {
|
||||
self.move_container_to_workspace(workspace_idx, true)?;
|
||||
}
|
||||
SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => {
|
||||
self.move_container_to_monitor(monitor_idx, true)?;
|
||||
}
|
||||
SocketMessage::TogglePause => self.is_paused = !self.is_paused,
|
||||
SocketMessage::FocusMonitorNumber(monitor_idx) => {
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
self.update_focused_workspace(true)?;
|
||||
}
|
||||
SocketMessage::Retile => {
|
||||
for monitor in self.monitors_mut() {
|
||||
let work_area = *monitor.work_area_size();
|
||||
monitor
|
||||
.focused_workspace_mut()
|
||||
.context("there is no workspace")?
|
||||
.update(&work_area)?;
|
||||
}
|
||||
}
|
||||
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
|
||||
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout(layout)?,
|
||||
SocketMessage::WorkspaceLayout(monitor_idx, workspace_idx, layout) => {
|
||||
self.set_workspace_layout(monitor_idx, workspace_idx, layout)?;
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
SocketMessage::Stop => {
|
||||
tracing::error!("received stop command, restoring all hidden windows and terminating process");
|
||||
self.restore_all_windows();
|
||||
std::process::exit(0)
|
||||
}
|
||||
SocketMessage::EnsureWorkspaces(monitor_idx, workspace_count) => {
|
||||
self.ensure_workspaces_for_monitor(monitor_idx, workspace_count)?;
|
||||
}
|
||||
SocketMessage::WorkspaceName(monitor_idx, workspace_idx, name) => {
|
||||
self.set_workspace_name(monitor_idx, workspace_idx, name)?;
|
||||
}
|
||||
SocketMessage::State => {
|
||||
let state = serde_json::to_string_pretty(self)?;
|
||||
let mut socket = dirs::home_dir().context("there is no home directory")?;
|
||||
socket.push("komorebic.sock");
|
||||
let socket = socket.as_path();
|
||||
|
||||
let mut stream = UnixStream::connect(&socket)?;
|
||||
stream.write_all(state.as_bytes())?;
|
||||
}
|
||||
}
|
||||
self.process_command(message)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -11,11 +11,12 @@ use crate::window_manager::WindowManager;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::MULTI_WINDOW_EXES;
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn listen_for_events(wm: Arc<Mutex<WindowManager>>) {
|
||||
let receiver = wm.lock().unwrap().incoming_events.lock().unwrap().clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
tracing::info!("listening for events");
|
||||
tracing::info!("listening");
|
||||
loop {
|
||||
select! {
|
||||
recv(receiver) -> mut maybe_event => {
|
||||
@@ -33,9 +34,10 @@ pub fn listen_for_events(wm: Arc<Mutex<WindowManager>>) {
|
||||
|
||||
impl WindowManager {
|
||||
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn process_event(&mut self, event: &mut WindowManagerEvent) -> Result<()> {
|
||||
if self.is_paused {
|
||||
tracing::info!("ignoring events while paused");
|
||||
tracing::trace!("ignoring while paused");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -46,7 +48,7 @@ impl WindowManager {
|
||||
| WindowManagerEvent::MoveResizeStart(_, window)
|
||||
| WindowManagerEvent::MoveResizeEnd(_, window) => {
|
||||
let monitor_idx = self
|
||||
.monitor_idx_from_window(window)
|
||||
.monitor_idx_from_window(*window)
|
||||
.context("there is no monitor associated with this window, it may have already been destroyed")?;
|
||||
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
@@ -76,8 +78,6 @@ impl WindowManager {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("processing event: {}", event);
|
||||
|
||||
match event {
|
||||
WindowManagerEvent::Minimize(_, window) | WindowManagerEvent::Destroy(_, window) => {
|
||||
self.focused_workspace_mut()?.remove_window(window.hwnd)?;
|
||||
@@ -163,7 +163,7 @@ impl WindowManager {
|
||||
WindowManagerEvent::MouseCapture(..) => {}
|
||||
};
|
||||
|
||||
tracing::debug!("updating list of known hwnds");
|
||||
tracing::trace!("updating list of known hwnds");
|
||||
let mut known_hwnds = vec![];
|
||||
for monitor in self.monitors() {
|
||||
for workspace in monitor.workspaces() {
|
||||
@@ -184,8 +184,7 @@ impl WindowManager {
|
||||
.open(hwnd_json)?;
|
||||
|
||||
serde_json::to_writer_pretty(&file, &known_hwnds)?;
|
||||
|
||||
tracing::info!("finished processing event: {}", event);
|
||||
tracing::info!("processed: {}", event.window().to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ use crate::LAYERED_EXE_WHITELIST;
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Window {
|
||||
pub(crate) hwnd: isize,
|
||||
pub(crate) original_style: GwlStyle,
|
||||
}
|
||||
|
||||
impl Display for Window {
|
||||
@@ -67,7 +66,7 @@ impl Serialize for Window {
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub const fn hwnd(&self) -> HWND {
|
||||
pub const fn hwnd(self) -> HWND {
|
||||
HWND(self.hwnd)
|
||||
}
|
||||
|
||||
@@ -109,15 +108,15 @@ impl Window {
|
||||
WindowsApi::position_window(self.hwnd(), &rect, top)
|
||||
}
|
||||
|
||||
pub fn hide(&self) {
|
||||
pub fn hide(self) {
|
||||
WindowsApi::hide_window(self.hwnd());
|
||||
}
|
||||
|
||||
pub fn restore(&self) {
|
||||
pub fn restore(self) {
|
||||
WindowsApi::restore_window(self.hwnd());
|
||||
}
|
||||
|
||||
pub fn focus(&self) -> Result<()> {
|
||||
pub fn focus(self) -> Result<()> {
|
||||
// Attach komorebi thread to Window thread
|
||||
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
|
||||
let current_thread_id = WindowsApi::current_thread_id();
|
||||
@@ -141,64 +140,34 @@ impl Window {
|
||||
WindowsApi::set_focus(self.hwnd())
|
||||
}
|
||||
|
||||
pub fn update_style(&self, style: GwlStyle) -> Result<()> {
|
||||
pub fn update_style(self, style: GwlStyle) -> Result<()> {
|
||||
WindowsApi::update_style(self.hwnd(), isize::try_from(style.bits())?)
|
||||
}
|
||||
|
||||
pub fn restore_style(&self) -> Result<()> {
|
||||
self.update_style(self.original_style)
|
||||
}
|
||||
|
||||
pub fn remove_border(&self) -> Result<()> {
|
||||
let mut style = self.style()?;
|
||||
style.remove(GwlStyle::BORDER);
|
||||
self.update_style(style)
|
||||
}
|
||||
|
||||
pub fn add_border(&self) -> Result<()> {
|
||||
let mut style = self.style()?;
|
||||
style.insert(GwlStyle::BORDER);
|
||||
self.update_style(style)
|
||||
}
|
||||
|
||||
pub fn remove_padding_and_title_bar(&self) -> Result<()> {
|
||||
let mut style = self.style()?;
|
||||
style.remove(GwlStyle::THICKFRAME);
|
||||
style.remove(GwlStyle::CAPTION);
|
||||
self.update_style(style)
|
||||
}
|
||||
|
||||
pub fn add_padding_padding_and_title_bar(&self) -> Result<()> {
|
||||
let mut style = self.style()?;
|
||||
style.insert(GwlStyle::THICKFRAME);
|
||||
style.insert(GwlStyle::CAPTION);
|
||||
self.update_style(style)
|
||||
}
|
||||
|
||||
pub fn style(&self) -> Result<GwlStyle> {
|
||||
pub fn style(self) -> Result<GwlStyle> {
|
||||
let bits = u32::try_from(WindowsApi::gwl_style(self.hwnd())?)?;
|
||||
GwlStyle::from_bits(bits).context("there is no gwl style")
|
||||
}
|
||||
|
||||
pub fn ex_style(&self) -> Result<GwlExStyle> {
|
||||
pub fn ex_style(self) -> Result<GwlExStyle> {
|
||||
let bits = u32::try_from(WindowsApi::gwl_ex_style(self.hwnd())?)?;
|
||||
GwlExStyle::from_bits(bits).context("there is no gwl style")
|
||||
}
|
||||
|
||||
pub fn title(&self) -> Result<String> {
|
||||
pub fn title(self) -> Result<String> {
|
||||
WindowsApi::window_text_w(self.hwnd())
|
||||
}
|
||||
|
||||
pub fn exe(&self) -> Result<String> {
|
||||
pub fn exe(self) -> Result<String> {
|
||||
let (process_id, _) = WindowsApi::window_thread_process_id(self.hwnd());
|
||||
WindowsApi::exe(WindowsApi::process_handle(process_id)?)
|
||||
}
|
||||
|
||||
pub fn class(&self) -> Result<String> {
|
||||
pub fn class(self) -> Result<String> {
|
||||
WindowsApi::real_window_class_w(self.hwnd())
|
||||
}
|
||||
|
||||
pub fn is_cloaked(&self) -> Result<bool> {
|
||||
pub fn is_cloaked(self) -> Result<bool> {
|
||||
WindowsApi::is_window_cloaked(self.hwnd())
|
||||
}
|
||||
|
||||
@@ -206,7 +175,8 @@ impl Window {
|
||||
WindowsApi::is_window(self.hwnd())
|
||||
}
|
||||
|
||||
pub fn should_manage(&self, event: Option<WindowManagerEvent>) -> Result<bool> {
|
||||
#[tracing::instrument(fields(exe, title))]
|
||||
pub fn should_manage(self, event: Option<WindowManagerEvent>) -> Result<bool> {
|
||||
let classes = FLOAT_CLASSES.lock().unwrap();
|
||||
let exes = FLOAT_EXES.lock().unwrap();
|
||||
let titles = FLOAT_TITLES.lock().unwrap();
|
||||
@@ -258,8 +228,8 @@ impl Window {
|
||||
{
|
||||
Ok(true)
|
||||
} else {
|
||||
if let Some(event) = event {
|
||||
tracing::debug!("ignoring window: {} (event: {})", self, event);
|
||||
if event.is_some() {
|
||||
tracing::debug!("ignoring (exe: {}, title: {})", exe_name, title);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
|
||||
@@ -34,6 +34,7 @@ pub struct WindowManager {
|
||||
pub is_paused: bool,
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn new(incoming: Arc<Mutex<Receiver<WindowManagerEvent>>>) -> Result<WindowManager> {
|
||||
let home = dirs::home_dir().context("there is no home directory")?;
|
||||
let mut socket = home;
|
||||
@@ -62,6 +63,7 @@ pub fn new(incoming: Arc<Mutex<Receiver<WindowManagerEvent>>>) -> Result<WindowM
|
||||
}
|
||||
|
||||
impl WindowManager {
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn init(&mut self) -> Result<()> {
|
||||
tracing::info!("initialising");
|
||||
WindowsApi::load_monitor_information(&mut self.monitors)?;
|
||||
@@ -69,21 +71,33 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn update_focused_workspace(&mut self, mouse_follows_focus: bool) -> Result<()> {
|
||||
tracing::info!("updating monitor: {}", self.focused_monitor_idx());
|
||||
tracing::info!("updating");
|
||||
|
||||
self.focused_monitor_mut()
|
||||
.context("there is no monitor")?
|
||||
.update_focused_workspace()?;
|
||||
|
||||
if mouse_follows_focus {
|
||||
self.focused_window_mut()?.focus()?;
|
||||
if let Ok(window) = self.focused_window_mut() {
|
||||
window.focus()?;
|
||||
} else {
|
||||
let desktop_window = Window {
|
||||
hwnd: WindowsApi::desktop_window()?,
|
||||
};
|
||||
|
||||
desktop_window.focus()?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn restore_all_windows(&mut self) {
|
||||
tracing::info!("restoring all hidden windows");
|
||||
|
||||
for monitor in self.monitors_mut() {
|
||||
for workspace in monitor.workspaces_mut() {
|
||||
for containers in workspace.containers_mut() {
|
||||
@@ -95,7 +109,10 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_to_monitor(&mut self, idx: usize, follow: bool) -> Result<()> {
|
||||
tracing::info!("moving container");
|
||||
|
||||
let monitor = self.focused_monitor_mut().context("there is no monitor")?;
|
||||
let container = monitor
|
||||
.focused_workspace_mut()
|
||||
@@ -118,14 +135,19 @@ impl WindowManager {
|
||||
self.update_focused_workspace(true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_to_workspace(&mut self, idx: usize, follow: bool) -> Result<()> {
|
||||
tracing::info!("moving container");
|
||||
|
||||
let monitor = self.focused_monitor_mut().context("there is no monitor")?;
|
||||
monitor.move_container_to_workspace(idx, follow)?;
|
||||
monitor.load_focused_workspace()?;
|
||||
self.update_focused_workspace(true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
tracing::info!("focusing container");
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let new_idx = workspace
|
||||
@@ -138,7 +160,10 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
tracing::info!("moving container");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let current_idx = workspace.focused_container_idx();
|
||||
@@ -151,7 +176,10 @@ impl WindowManager {
|
||||
self.update_focused_workspace(true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn cycle_container_window_in_direction(&mut self, direction: CycleDirection) -> Result<()> {
|
||||
tracing::info!("cycling container windows");
|
||||
|
||||
let container = self.focused_container_mut()?;
|
||||
|
||||
if container.windows().len() == 1 {
|
||||
@@ -167,7 +195,10 @@ impl WindowManager {
|
||||
self.update_focused_workspace(true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn add_window_to_container(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
tracing::info!("adding window to container");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let current_container_idx = workspace.focused_container_idx();
|
||||
|
||||
@@ -195,13 +226,19 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_container_to_front(&mut self) -> Result<()> {
|
||||
tracing::info!("promoting container");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.promote_container()?;
|
||||
self.update_focused_workspace(true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn remove_window_from_container(&mut self) -> Result<()> {
|
||||
tracing::info!("removing window");
|
||||
|
||||
if self.focused_container()?.windows().len() == 1 {
|
||||
return Err(eyre::anyhow!("a container must have at least one window"));
|
||||
}
|
||||
@@ -212,6 +249,7 @@ impl WindowManager {
|
||||
self.update_focused_workspace(true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_float(&mut self) -> Result<()> {
|
||||
let hwnd = WindowsApi::top_visible_window()?;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -225,17 +263,18 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
if is_floating_window {
|
||||
tracing::info!("unfloating window");
|
||||
self.unfloat_window()?;
|
||||
self.update_focused_workspace(true)
|
||||
} else {
|
||||
tracing::info!("floating window");
|
||||
self.float_window()?;
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn float_window(&mut self) -> Result<()> {
|
||||
tracing::info!("floating window");
|
||||
|
||||
let work_area = self.focused_monitor_work_area()?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -262,11 +301,15 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn unfloat_window(&mut self) -> Result<()> {
|
||||
tracing::info!("unfloating window");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_container_for_floating_window()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_monocle(&mut self) -> Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
@@ -278,17 +321,26 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn monocle_on(&mut self) -> Result<()> {
|
||||
tracing::info!("enabling monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_monocle_container()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn monocle_off(&mut self) -> Result<()> {
|
||||
tracing::info!("disabling monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.reintegrate_monocle_container()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn flip_layout(&mut self, layout_flip: LayoutFlip) -> Result<()> {
|
||||
tracing::info!("flipping layout monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
#[allow(clippy::match_same_arms)]
|
||||
@@ -328,13 +380,19 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn change_workspace_layout(&mut self, layout: Layout) -> Result<()> {
|
||||
tracing::info!("changing layout");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.set_layout(layout);
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn adjust_workspace_padding(&mut self, sizing: Sizing, adjustment: i32) -> Result<()> {
|
||||
tracing::info!("adjusting workspace padding");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let padding = workspace
|
||||
@@ -346,7 +404,10 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn adjust_container_padding(&mut self, sizing: Sizing, adjustment: i32) -> Result<()> {
|
||||
tracing::info!("adjusting container padding");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let padding = workspace
|
||||
@@ -358,12 +419,15 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn set_workspace_layout(
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
layout: Layout,
|
||||
) -> Result<()> {
|
||||
tracing::info!("setting workspace layout");
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
|
||||
let monitor = self
|
||||
@@ -390,11 +454,14 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn ensure_workspaces_for_monitor(
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_count: usize,
|
||||
) -> Result<()> {
|
||||
tracing::info!("ensuring workspace count");
|
||||
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
@@ -405,12 +472,15 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn set_workspace_padding(
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
size: i32,
|
||||
) -> Result<()> {
|
||||
tracing::info!("setting workspace padding");
|
||||
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
@@ -426,12 +496,15 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn set_workspace_name(
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
name: String,
|
||||
) -> Result<()> {
|
||||
tracing::info!("setting workspace name");
|
||||
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
@@ -448,12 +521,15 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn set_container_padding(
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
size: i32,
|
||||
) -> Result<()> {
|
||||
tracing::info!("setting container padding");
|
||||
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
@@ -498,7 +574,10 @@ impl WindowManager {
|
||||
.work_area_size())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_monitor(&mut self, idx: usize) -> Result<()> {
|
||||
tracing::info!("focusing monitor");
|
||||
|
||||
if self.monitors().get(idx).is_some() {
|
||||
self.monitors.focus(idx);
|
||||
} else {
|
||||
@@ -508,7 +587,7 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn monitor_idx_from_window(&mut self, window: &Window) -> Option<usize> {
|
||||
pub fn monitor_idx_from_window(&mut self, window: Window) -> Option<usize> {
|
||||
let hmonitor = WindowsApi::monitor_from_window(window.hwnd());
|
||||
|
||||
for (i, monitor) in self.monitors().iter().enumerate() {
|
||||
@@ -534,7 +613,10 @@ impl WindowManager {
|
||||
.context("there is no workspace")
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_workspace(&mut self, idx: usize) -> Result<()> {
|
||||
tracing::info!("focusing workspace");
|
||||
|
||||
let monitor = self
|
||||
.focused_monitor_mut()
|
||||
.context("there is no workspace")?;
|
||||
|
||||
@@ -64,6 +64,19 @@ impl Display for WindowManagerEvent {
|
||||
}
|
||||
|
||||
impl WindowManagerEvent {
|
||||
pub const fn window(self) -> Window {
|
||||
match self {
|
||||
WindowManagerEvent::Destroy(_, window)
|
||||
| WindowManagerEvent::FocusChange(_, window)
|
||||
| WindowManagerEvent::Hide(_, window)
|
||||
| WindowManagerEvent::Minimize(_, window)
|
||||
| WindowManagerEvent::Show(_, window)
|
||||
| WindowManagerEvent::MoveResizeStart(_, window)
|
||||
| WindowManagerEvent::MoveResizeEnd(_, window)
|
||||
| WindowManagerEvent::MouseCapture(_, window) => window,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn from_win_event(winevent: WinEvent, window: Window) -> Option<Self> {
|
||||
match winevent {
|
||||
WinEvent::ObjectDestroy => Some(Self::Destroy(winevent, window)),
|
||||
|
||||
@@ -40,6 +40,7 @@ use bindings::Windows::Win32::UI::KeyboardAndMouseInput::SetFocus;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::AllowSetForegroundWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::EnumWindows;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetCursorPos;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetDesktopWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetTopWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetWindowLongPtrW;
|
||||
@@ -276,6 +277,10 @@ impl WindowsApi {
|
||||
Result::from(WindowsResult::from(unsafe { GetTopWindow(HWND::NULL).0 }))
|
||||
}
|
||||
|
||||
pub fn desktop_window() -> Result<isize> {
|
||||
Result::from(WindowsResult::from(unsafe { GetDesktopWindow() }))
|
||||
}
|
||||
|
||||
pub fn next_window(hwnd: HWND) -> Result<isize> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
GetWindow(hwnd, GW_HWNDNEXT).0
|
||||
|
||||
@@ -11,7 +11,6 @@ use bindings::Windows::Win32::UI::Accessibility::HWINEVENTHOOK;
|
||||
use crate::container::Container;
|
||||
use crate::monitor::Monitor;
|
||||
use crate::ring::Ring;
|
||||
use crate::styles::GwlStyle;
|
||||
use crate::window::Window;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::windows_api::WindowsApi;
|
||||
@@ -40,14 +39,7 @@ pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
let is_minimized = WindowsApi::is_iconic(hwnd);
|
||||
|
||||
if is_visible && is_window && !is_minimized {
|
||||
let mut window = Window {
|
||||
hwnd: hwnd.0,
|
||||
original_style: GwlStyle::empty(),
|
||||
};
|
||||
|
||||
if let Ok(style) = window.style() {
|
||||
window.original_style = style;
|
||||
}
|
||||
let window = Window { hwnd: hwnd.0 };
|
||||
|
||||
if let Ok(should_manage) = window.should_manage(None) {
|
||||
if should_manage {
|
||||
@@ -75,14 +67,7 @@ pub extern "system" fn win_event_hook(
|
||||
return;
|
||||
}
|
||||
|
||||
let mut window = Window {
|
||||
hwnd: hwnd.0,
|
||||
original_style: GwlStyle::empty(),
|
||||
};
|
||||
|
||||
if let Ok(style) = window.style() {
|
||||
window.original_style = style;
|
||||
}
|
||||
let window = Window { hwnd: hwnd.0 };
|
||||
|
||||
let winevent = unsafe { ::std::mem::transmute(event) };
|
||||
let event_type = if let Some(event) = WindowManagerEvent::from_win_event(winevent, window) {
|
||||
|
||||
@@ -448,8 +448,10 @@ impl Workspace {
|
||||
self.containers.focused_mut()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container(&mut self, idx: usize) {
|
||||
tracing::info!("focusing container at index: {}", idx);
|
||||
tracing::info!("focusing container");
|
||||
|
||||
self.containers.focus(idx);
|
||||
}
|
||||
|
||||
@@ -462,7 +464,6 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub fn swap_containers(&mut self, i: usize, j: usize) {
|
||||
tracing::info!("swapping containers: {}, {}", i, j);
|
||||
self.containers.swap(i, j);
|
||||
self.focus_container(j);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user