Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make address parsing consistent between events and data commands #88

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum WindowIdentifier<'a> {
impl std::fmt::Display for WindowIdentifier<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let out = match self {
WindowIdentifier::Address(addr) => format!("address:0x{addr}"),
WindowIdentifier::Address(addr) => format!("address:{addr}"),
WindowIdentifier::ProcessId(id) => format!("pid:{id}"),
WindowIdentifier::ClassRegularExpression(regex) => regex.to_string(),
WindowIdentifier::Title(title) => format!("title:{title}"),
Expand Down
20 changes: 12 additions & 8 deletions src/event_listener/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
}
}
ParsedEventType::ActiveWindowChangedV2 => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
if addr != "," {
events.push(Event::ActiveWindowChangedV2(Some(Address::new(addr))));
} else {
Expand All @@ -848,7 +848,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
events.push(Event::MonitorAdded(monitor.to_string()));
}
ParsedEventType::WindowOpened => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
let workspace = &captures["workspace"];
let class = &captures["class"];
let title = &captures["title"];
Expand All @@ -860,11 +860,11 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
}));
}
ParsedEventType::WindowClosed => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
events.push(Event::WindowClosed(Address::new(addr)));
}
ParsedEventType::WindowMoved => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
let work = &captures["workspace"];
events.push(Event::WindowMoved(WindowMoveEvent {
window_address: Address::new(addr),
Expand Down Expand Up @@ -892,15 +892,15 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
events.push(Event::LayerClosed(namespace.to_string()));
}
ParsedEventType::FloatStateChanged => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
let state = &captures["floatstate"] == "0"; // FIXME: does 0 mean it's floating?
events.push(Event::FloatStateChanged(WindowFloatEventData {
window_address: Address::new(addr),
is_floating: state,
}));
}
ParsedEventType::Minimize => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
let state = &captures["state"] == "1";
events.push(Event::Minimize(MinimizeEventData {
window_address: Address::new(addr),
Expand All @@ -916,11 +916,11 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
}));
}
ParsedEventType::UrgentStateChanged => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
events.push(Event::UrgentStateChanged(Address::new(addr)));
}
ParsedEventType::WindowTitleChanged => {
let addr = &captures["address"];
let addr = format_event_addr(&captures["address"]);
events.push(Event::WindowTitleChanged(Address::new(addr)));
}
ParsedEventType::Unknown => {
Expand Down Expand Up @@ -958,3 +958,7 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {

Ok(events)
}

fn format_event_addr(addr: &str) -> String {
format!("0x{addr}")
}
Loading