mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 23:28:34 +01:00
refactor(wm): tidy up 3a24b51
Instead of doing an adhoc check just against PERMAIGNORE classes, we might as well construct a temporary Window to check the result of the full Window.should_manage call.
This commit is contained in:
1 parent
e478ab8d0a
commit
8c4c1963bc
1 file changed
+119
-126
+119
-126
@@ -1,7 +1,6 @@
|
||||
use crate::FLOATING_APPLICATIONS;
|
||||
use crate::Notification;
|
||||
use crate::NotificationEvent;
|
||||
use crate::PERMAIGNORE_CLASSES;
|
||||
use crate::REGEX_IDENTIFIERS;
|
||||
use crate::TABBED_APPLICATIONS;
|
||||
use crate::WORKSPACE_MATCHING_RULES;
|
||||
@@ -379,149 +378,143 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
// this happens sometimes because of the mouse event from input listener which emits a show
|
||||
if let Some(element) = &window_element {
|
||||
let subrole = AdhocWindow::subrole(element).unwrap_or_default();
|
||||
if PERMAIGNORE_CLASSES.lock().contains(&subrole) {
|
||||
tracing::debug!(
|
||||
"ignoring AXDialog window that got past the initial filter"
|
||||
);
|
||||
create = false
|
||||
}
|
||||
// before a window has updated things like its subrole, so we need to check again
|
||||
let application = self.application(process_id)?;
|
||||
if let Some(element) = &window_element
|
||||
&& let Ok(window) = Window::new(element.clone(), application.clone())
|
||||
&& !window.should_manage(Some(event))?
|
||||
{
|
||||
create = false;
|
||||
}
|
||||
|
||||
if create && !tabbed_window {
|
||||
let application = self.application(process_id)?;
|
||||
if let Some(element) = window_element
|
||||
&& let Ok(mut window) = Window::new(element, application.clone())
|
||||
{
|
||||
window.observe(&self.run_loop)?;
|
||||
if create
|
||||
&& !tabbed_window
|
||||
&& let Some(element) = window_element
|
||||
&& let Ok(mut window) = Window::new(element, application.clone())
|
||||
{
|
||||
window.observe(&self.run_loop)?;
|
||||
|
||||
let behaviour = self.window_management_behaviour(
|
||||
focused_monitor_idx,
|
||||
focused_workspace_idx,
|
||||
);
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let workspace_contains_window = workspace.contains_window(window.id);
|
||||
let monocle_container = workspace.monocle_container.clone();
|
||||
let behaviour = self
|
||||
.window_management_behaviour(focused_monitor_idx, focused_workspace_idx);
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let workspace_contains_window = workspace.contains_window(window.id);
|
||||
let monocle_container = workspace.monocle_container.clone();
|
||||
|
||||
let floating_applications = FLOATING_APPLICATIONS.lock();
|
||||
let mut should_float = false;
|
||||
let floating_applications = FLOATING_APPLICATIONS.lock();
|
||||
let mut should_float = false;
|
||||
|
||||
if !floating_applications.is_empty() {
|
||||
let regex_identifiers = REGEX_IDENTIFIERS.lock();
|
||||
if !floating_applications.is_empty() {
|
||||
let regex_identifiers = REGEX_IDENTIFIERS.lock();
|
||||
|
||||
if let (
|
||||
Some(title),
|
||||
Some(exe_name),
|
||||
Some(role),
|
||||
Some(subrole),
|
||||
Some(path),
|
||||
) = (
|
||||
window.title(),
|
||||
window.exe(),
|
||||
window.role(),
|
||||
window.subrole(),
|
||||
window.path(),
|
||||
) {
|
||||
should_float = should_act(
|
||||
&title,
|
||||
&exe_name,
|
||||
&[&role, &subrole],
|
||||
&path.to_string_lossy(),
|
||||
&floating_applications,
|
||||
®ex_identifiers,
|
||||
)
|
||||
.is_some();
|
||||
}
|
||||
if let (
|
||||
Some(title),
|
||||
Some(exe_name),
|
||||
Some(role),
|
||||
Some(subrole),
|
||||
Some(path),
|
||||
) = (
|
||||
window.title(),
|
||||
window.exe(),
|
||||
window.role(),
|
||||
window.subrole(),
|
||||
window.path(),
|
||||
) {
|
||||
should_float = should_act(
|
||||
&title,
|
||||
&exe_name,
|
||||
&[&role, &subrole],
|
||||
&path.to_string_lossy(),
|
||||
&floating_applications,
|
||||
®ex_identifiers,
|
||||
)
|
||||
.is_some();
|
||||
}
|
||||
}
|
||||
|
||||
if behaviour.float_override
|
||||
if behaviour.float_override
|
||||
|| behaviour.floating_layer_override
|
||||
// TODO: look into if we want to have a Manage command here too
|
||||
|| (should_float /*&& !matches!(event, WindowManagerEvent::Manage(_))*/ )
|
||||
{
|
||||
let placement = if behaviour.floating_layer_override {
|
||||
// Floating layer override placement
|
||||
behaviour.floating_layer_placement
|
||||
} else if behaviour.float_override {
|
||||
// Float override placement
|
||||
behaviour.float_override_placement
|
||||
} else {
|
||||
// Float rule placement
|
||||
behaviour.float_rule_placement
|
||||
};
|
||||
// Center floating windows according to the proper placement if not
|
||||
// on a floating workspace
|
||||
let center_spawned_floats = placement.should_center() && workspace.tile;
|
||||
workspace.floating_windows_mut().push_back(window.clone());
|
||||
workspace.layer = WorkspaceLayer::Floating;
|
||||
if center_spawned_floats {
|
||||
let mut floating_window = window.clone();
|
||||
floating_window.center(
|
||||
&workspace.globals.work_area,
|
||||
placement.should_resize(),
|
||||
)?;
|
||||
}
|
||||
|
||||
self.update_focused_workspace(false, false)?;
|
||||
{
|
||||
let placement = if behaviour.floating_layer_override {
|
||||
// Floating layer override placement
|
||||
behaviour.floating_layer_placement
|
||||
} else if behaviour.float_override {
|
||||
// Float override placement
|
||||
behaviour.float_override_placement
|
||||
} else {
|
||||
match behaviour.current_behaviour {
|
||||
WindowContainerBehaviour::Create => {
|
||||
workspace.new_container_for_window(&window)?;
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
WindowContainerBehaviour::Append => {
|
||||
workspace
|
||||
.focused_container_mut()
|
||||
.ok_or_eyre("there is no focused container")?
|
||||
.add_window(&window)?;
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
self.update_focused_workspace(true, false)?;
|
||||
}
|
||||
}
|
||||
// Float rule placement
|
||||
behaviour.float_rule_placement
|
||||
};
|
||||
// Center floating windows according to the proper placement if not
|
||||
// on a floating workspace
|
||||
let center_spawned_floats = placement.should_center() && workspace.tile;
|
||||
workspace.floating_windows_mut().push_back(window.clone());
|
||||
workspace.layer = WorkspaceLayer::Floating;
|
||||
if center_spawned_floats {
|
||||
let mut floating_window = window.clone();
|
||||
floating_window
|
||||
.center(&workspace.globals.work_area, placement.should_resize())?;
|
||||
}
|
||||
|
||||
// TODO: not sure if this is needed on macOS
|
||||
if (self.focused_workspace()?.containers().len() == 1
|
||||
&& self.focused_workspace()?.floating_windows().is_empty())
|
||||
|| (self.focused_workspace()?.containers().is_empty()
|
||||
&& self.focused_workspace()?.floating_windows().len() == 1)
|
||||
{
|
||||
// If after adding this window the workspace only contains 1 window, it
|
||||
// means it was previously empty and we focused the desktop to unfocus
|
||||
// any previous window from other workspace, so now we need to focus
|
||||
// this window again. This is needed because sometimes some windows
|
||||
// first send the `FocusChange` event and only the `Show` event after
|
||||
// and we will be focusing the desktop on the `FocusChange` event since
|
||||
// it is still empty.
|
||||
window.focus(self.mouse_follows_focus)?;
|
||||
self.update_focused_workspace(false, false)?;
|
||||
} else {
|
||||
match behaviour.current_behaviour {
|
||||
WindowContainerBehaviour::Create => {
|
||||
workspace.new_container_for_window(&window)?;
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
WindowContainerBehaviour::Append => {
|
||||
workspace
|
||||
.focused_container_mut()
|
||||
.ok_or_eyre("there is no focused container")?
|
||||
.add_window(&window)?;
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
self.update_focused_workspace(true, false)?;
|
||||
}
|
||||
}
|
||||
|
||||
if workspace_contains_window {
|
||||
let mut monocle_window_event = false;
|
||||
if let Some(ref monocle) = monocle_container
|
||||
&& let Some(monocle_window) = monocle.focused_window()
|
||||
{
|
||||
// we should have the window_id at this point
|
||||
if monocle_window.id == window_id.unwrap_or_default() {
|
||||
monocle_window_event = true;
|
||||
}
|
||||
}
|
||||
|
||||
let workspace = self.focused_workspace()?;
|
||||
if !(monocle_window_event || workspace.layer != WorkspaceLayer::Tiling)
|
||||
&& monocle_container.is_some()
|
||||
{
|
||||
window.hide()?;
|
||||
}
|
||||
// TODO: not sure if this is needed on macOS
|
||||
if (self.focused_workspace()?.containers().len() == 1
|
||||
&& self.focused_workspace()?.floating_windows().is_empty())
|
||||
|| (self.focused_workspace()?.containers().is_empty()
|
||||
&& self.focused_workspace()?.floating_windows().len() == 1)
|
||||
{
|
||||
// If after adding this window the workspace only contains 1 window, it
|
||||
// means it was previously empty and we focused the desktop to unfocus
|
||||
// any previous window from other workspace, so now we need to focus
|
||||
// this window again. This is needed because sometimes some windows
|
||||
// first send the `FocusChange` event and only the `Show` event after
|
||||
// and we will be focusing the desktop on the `FocusChange` event since
|
||||
// it is still empty.
|
||||
window.focus(self.mouse_follows_focus)?;
|
||||
}
|
||||
|
||||
// let workspace = self.focused_workspace_mut()?;
|
||||
// workspace.new_container_for_window(&window)?;
|
||||
//
|
||||
// self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
|
||||
if workspace_contains_window {
|
||||
let mut monocle_window_event = false;
|
||||
if let Some(ref monocle) = monocle_container
|
||||
&& let Some(monocle_window) = monocle.focused_window()
|
||||
{
|
||||
// we should have the window_id at this point
|
||||
if monocle_window.id == window_id.unwrap_or_default() {
|
||||
monocle_window_event = true;
|
||||
}
|
||||
}
|
||||
|
||||
let workspace = self.focused_workspace()?;
|
||||
if !(monocle_window_event || workspace.layer != WorkspaceLayer::Tiling)
|
||||
&& monocle_container.is_some()
|
||||
{
|
||||
window.hide()?;
|
||||
}
|
||||
}
|
||||
|
||||
// let workspace = self.focused_workspace_mut()?;
|
||||
// workspace.new_container_for_window(&window)?;
|
||||
//
|
||||
// self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
}
|
||||
WindowManagerEvent::Destroy(_, process_id) => {
|
||||
|
||||
Reference in new issue
Block a user