mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
feat(wm): impl window debugging socket message
I think this was only used in komorebi-gui before. I should see how difficult it'll be to migrate that for macOS as well.
This commit is contained in:
1 parent
563c3b8446
commit
61369df025
4 files changed
+80
-19
No files matched your search
@@ -407,7 +407,7 @@ pub enum SocketMessage {
|
||||
SocketSchema,
|
||||
StaticConfigSchema,
|
||||
GenerateStaticConfig,
|
||||
// DebugWindow(isize),
|
||||
DebugWindow(u32),
|
||||
}
|
||||
|
||||
impl SocketMessage {
|
||||
|
||||
@@ -8,7 +8,10 @@ use crate::SESSION_FLOATING_APPLICATIONS;
|
||||
use crate::SUBSCRIPTION_SOCKET_OPTIONS;
|
||||
use crate::SUBSCRIPTION_SOCKETS;
|
||||
use crate::WORKSPACE_MATCHING_RULES;
|
||||
use crate::accessibility::AccessibilityApi;
|
||||
use crate::application::Application;
|
||||
use crate::build;
|
||||
use crate::cf_array_as;
|
||||
use crate::core::ApplicationIdentifier;
|
||||
use crate::core::MoveBehaviour;
|
||||
use crate::core::SocketMessage;
|
||||
@@ -24,6 +27,7 @@ use crate::core::default_layout::ScrollingLayoutOptions;
|
||||
use crate::core::layout::Layout;
|
||||
use crate::core::operation_direction::OperationDirection;
|
||||
use crate::core::rect::Rect;
|
||||
use crate::core_graphics::CoreGraphicsApi;
|
||||
use crate::macos_api::MacosApi;
|
||||
use crate::monitor::MonitorInformation;
|
||||
use crate::notify_subscribers;
|
||||
@@ -31,12 +35,16 @@ use crate::state::GlobalState;
|
||||
use crate::state::State;
|
||||
use crate::static_config::StaticConfig;
|
||||
use crate::window::AdhocWindow;
|
||||
use crate::window::RuleDebug;
|
||||
use crate::window::Window;
|
||||
use crate::window::WindowInfo;
|
||||
use crate::window_manager::WindowManager;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use crate::workspace::WorkspaceWindowLocation;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use objc2_core_foundation::CFDictionary;
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
@@ -1594,6 +1602,28 @@ impl WindowManager {
|
||||
workspace.resize_dimensions = resize;
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::DebugWindow(window_id) => {
|
||||
if let Some(window_list_info) = CoreGraphicsApi::window_list_info() {
|
||||
for raw_window_info in cf_array_as::<CFDictionary>(&window_list_info) {
|
||||
let raw_info = WindowInfo::new(raw_window_info);
|
||||
let application = Application::new(raw_info.owner_pid)?;
|
||||
if let Some(elements) = application.window_elements() {
|
||||
for element in elements {
|
||||
if let Ok(wid) = AccessibilityApi::window_id(&element)
|
||||
&& wid == window_id
|
||||
&& let Ok(window) = Window::new(element, application.clone())
|
||||
{
|
||||
let mut rule_debug = RuleDebug::default();
|
||||
let _ = window.should_manage(None, &mut rule_debug);
|
||||
let schema = serde_json::to_string_pretty(&rule_debug)?;
|
||||
|
||||
reply.write_all(schema.as_bytes())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notify_subscribers(
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::macos_api::MacosApi;
|
||||
use crate::notify_subscribers;
|
||||
use crate::state::State;
|
||||
use crate::window::AdhocWindow;
|
||||
use crate::window::RuleDebug;
|
||||
use crate::window::Window;
|
||||
use crate::window::should_act;
|
||||
use crate::window_manager::WindowManager;
|
||||
@@ -64,6 +65,8 @@ impl WindowManager {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut rule_debug = RuleDebug::default();
|
||||
|
||||
let mut should_manage = true;
|
||||
{
|
||||
let application = self.application(event.process_id())?;
|
||||
@@ -72,7 +75,7 @@ impl WindowManager {
|
||||
{
|
||||
let window_id = window.id;
|
||||
let print_window = window.clone();
|
||||
should_manage = window.should_manage(Some(event))?;
|
||||
should_manage = window.should_manage(Some(event), &mut rule_debug)?;
|
||||
|
||||
if UNMANAGED_WINDOW_IDS.lock().contains(&window_id) {
|
||||
should_manage = false;
|
||||
@@ -389,7 +392,7 @@ impl WindowManager {
|
||||
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))?
|
||||
&& !window.should_manage(Some(event), &mut rule_debug)?
|
||||
{
|
||||
create = false;
|
||||
}
|
||||
|
||||
+44
-16
@@ -132,7 +132,7 @@ unsafe extern "C-unwind" fn window_observer_callback(
|
||||
#[derive(Debug, Default)]
|
||||
pub struct WindowInfo {
|
||||
name: Option<String>,
|
||||
owner_pid: i32,
|
||||
pub owner_pid: i32,
|
||||
owner_name: String,
|
||||
alpha: f32,
|
||||
bounds: WindowBounds,
|
||||
@@ -642,13 +642,13 @@ impl Window {
|
||||
pub fn should_manage(
|
||||
self,
|
||||
event: Option<WindowManagerEvent>,
|
||||
// debug: &mut RuleDebug,
|
||||
debug: &mut RuleDebug,
|
||||
) -> eyre::Result<bool> {
|
||||
if !self.is_valid() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
// debug.is_window = true;
|
||||
debug.is_window = true;
|
||||
|
||||
// let rect = Rect::from(MacosApi::window_rect(&self.element).unwrap_or_default());
|
||||
//
|
||||
@@ -668,7 +668,7 @@ impl Window {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
// debug.has_title = true;
|
||||
debug.has_title = true;
|
||||
|
||||
// let is_cloaked = self.is_cloaked().unwrap_or_default();
|
||||
//
|
||||
@@ -699,10 +699,11 @@ impl Window {
|
||||
self.subrole(),
|
||||
self.path(),
|
||||
) {
|
||||
// debug.title = Some(title.clone());
|
||||
// debug.exe_name = Some(exe_name.clone());
|
||||
// debug.class = Some(class.clone());
|
||||
// debug.path = Some(path.clone());
|
||||
debug.title = Some(title.clone());
|
||||
debug.exe_name = Some(exe_name.clone());
|
||||
debug.role = Some(role.clone());
|
||||
debug.subrole = Some(subrole.clone());
|
||||
debug.path = Some(path.to_string_lossy().to_string());
|
||||
// calls for styles can fail quite often for events with windows that aren't really "windows"
|
||||
// since we have moved up calls of should_manage to the beginning of the process_event handler,
|
||||
// we should handle failures here gracefully to be able to continue the execution of process_event
|
||||
@@ -716,6 +717,7 @@ impl Window {
|
||||
&[&role, &subrole],
|
||||
&path.to_string_lossy(),
|
||||
event,
|
||||
debug,
|
||||
);
|
||||
// debug.should_manage = eligible;
|
||||
return Ok(eligible);
|
||||
@@ -962,6 +964,32 @@ impl AspectRatio {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct RuleDebug {
|
||||
pub should_manage: bool,
|
||||
pub is_window: bool,
|
||||
// pub has_minimum_width: bool,
|
||||
// pub has_minimum_height: bool,
|
||||
pub has_title: bool,
|
||||
// pub is_cloaked: bool,
|
||||
// pub allow_cloaked: bool,
|
||||
// pub allow_layered_transparency: bool,
|
||||
// pub window_style: Option<WindowStyle>,
|
||||
// pub extended_window_style: Option<ExtendedWindowStyle>,
|
||||
pub title: Option<String>,
|
||||
pub exe_name: Option<String>,
|
||||
pub role: Option<String>,
|
||||
pub subrole: Option<String>,
|
||||
pub path: Option<String>,
|
||||
pub matches_permaignore_class: Option<String>,
|
||||
pub matches_ignore_identifier: Option<MatchingRule>,
|
||||
pub matches_managed_override: Option<MatchingRule>,
|
||||
// pub matches_layered_whitelist: Option<MatchingRule>,
|
||||
pub matches_floating_applications: Option<MatchingRule>,
|
||||
// pub matches_wsl2_gui: Option<String>,
|
||||
// pub matches_no_titlebar: Option<MatchingRule>,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn window_is_eligible(
|
||||
_window_id: u32,
|
||||
@@ -972,13 +1000,13 @@ fn window_is_eligible(
|
||||
// style: &WindowStyle,
|
||||
// ex_style: &ExtendedWindowStyle,
|
||||
_event: Option<WindowManagerEvent>,
|
||||
// debug: &mut RuleDebug,
|
||||
debug: &mut RuleDebug,
|
||||
) -> bool {
|
||||
{
|
||||
let permaignore_classes = PERMAIGNORE_CLASSES.lock();
|
||||
for class in classes {
|
||||
if permaignore_classes.contains(&class.to_string()) {
|
||||
// debug.matches_permaignore_class = Some(class.clone());
|
||||
debug.matches_permaignore_class = Some(class.to_string());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -987,7 +1015,7 @@ fn window_is_eligible(
|
||||
let regex_identifiers = REGEX_IDENTIFIERS.lock();
|
||||
|
||||
let ignore_identifiers = IGNORE_IDENTIFIERS.lock();
|
||||
let should_ignore = if let Some(_rule) = should_act(
|
||||
let should_ignore = if let Some(rule) = should_act(
|
||||
title,
|
||||
exe_name,
|
||||
classes,
|
||||
@@ -995,14 +1023,14 @@ fn window_is_eligible(
|
||||
&ignore_identifiers,
|
||||
®ex_identifiers,
|
||||
) {
|
||||
// debug.matches_ignore_identifier = Some(rule);
|
||||
debug.matches_ignore_identifier = Some(rule);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let manage_identifiers = MANAGE_IDENTIFIERS.lock();
|
||||
let managed_override = if let Some(_rule) = should_act(
|
||||
let managed_override = if let Some(rule) = should_act(
|
||||
title,
|
||||
exe_name,
|
||||
classes,
|
||||
@@ -1010,14 +1038,14 @@ fn window_is_eligible(
|
||||
&manage_identifiers,
|
||||
®ex_identifiers,
|
||||
) {
|
||||
// debug.matches_managed_override = Some(rule);
|
||||
debug.matches_managed_override = Some(rule);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let floating_identifiers = FLOATING_APPLICATIONS.lock();
|
||||
if let Some(_rule) = should_act(
|
||||
if let Some(rule) = should_act(
|
||||
title,
|
||||
exe_name,
|
||||
classes,
|
||||
@@ -1025,7 +1053,7 @@ fn window_is_eligible(
|
||||
&floating_identifiers,
|
||||
®ex_identifiers,
|
||||
) {
|
||||
// debug.matches_floating_applications = Some(rule);
|
||||
debug.matches_floating_applications = Some(rule);
|
||||
}
|
||||
|
||||
if should_ignore && !managed_override {
|
||||
|
||||
Reference in new issue
Block a user