Skip to content

Commit

Permalink
add pin event
Browse files Browse the repository at this point in the history
  • Loading branch information
yavko committed Jun 4, 2024
1 parent 8423d77 commit e204ad9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 52 deletions.
66 changes: 31 additions & 35 deletions src/event_listener/async_im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,44 @@ impl Default for AsyncEventListener {

impl HasAsyncExecutor for AsyncEventListener {
async fn event_executor_async(&mut self, event: Event) -> crate::Result<()> {
use Event::*;
match event {
Event::WorkspaceChanged(id) => arm_async!(id, workspace_changed_events, self),
Event::WorkspaceAdded(id) => arm_async!(id, workspace_added_events, self),
Event::WorkspaceDeleted(data) => {
arm_async!(data, workspace_destroyed_events, self)
}
Event::WorkspaceMoved(evend) => arm_async!(evend, workspace_moved_events, self),
Event::WorkspaceRename(even) => arm_async!(even, workspace_rename_events, self),
Event::ActiveMonitorChanged(evend) => {
arm_async!(evend, active_monitor_changed_events, self)
}
Event::ActiveWindowChangedMerged(event) => {
WorkspaceChanged(id) => arm_async!(id, workspace_changed_events, self),
WorkspaceAdded(id) => arm_async!(id, workspace_added_events, self),
WorkspaceDeleted(data) => arm_async!(data, workspace_destroyed_events, self),
WorkspaceMoved(evend) => arm_async!(evend, workspace_moved_events, self),
WorkspaceRename(even) => arm_async!(even, workspace_rename_events, self),
ActiveMonitorChanged(evend) => arm_async!(evend, active_monitor_changed_events, self),
ActiveWindowChangedMerged(event) => {
arm_async!(event, active_window_changed_events, self)
}
Event::ActiveWindowChangedV1(_) => (),
Event::ActiveWindowChangedV2(_) => (),
Event::FullscreenStateChanged(bool) => {
arm_async!(bool, fullscreen_state_changed_events, self)
}
Event::MonitorAdded(monitor) => arm_async!(monitor, monitor_added_events, self),
Event::MonitorRemoved(monitor) => arm_async!(monitor, monitor_removed_events, self),
Event::WindowClosed(addr) => arm_async!(addr, window_close_events, self),
Event::WindowMoved(even) => arm_async!(even, window_moved_events, self),
Event::WindowOpened(even) => arm_async!(even, window_open_events, self),
Event::SpecialRemoved(monitor) => arm_async!(monitor, special_removed_events, self),
Event::ChangedSpecial(data) => arm_async!(data, special_changed_events, self),
Event::LayoutChanged(even) => arm_async!(even, keyboard_layout_change_events, self),
Event::SubMapChanged(map) => arm_async!(map, sub_map_changed_events, self),
Event::LayerOpened(namespace) => arm_async!(namespace, layer_open_events, self),
Event::LayerClosed(namespace) => arm_async!(namespace, layer_closed_events, self),
Event::FloatStateChanged(even) => arm_async!(even, float_state_events, self),
Event::UrgentStateChanged(even) => arm_async!(even, urgent_state_events, self),
Event::Minimize(data) => arm_async!(data, minimize_events, self),
Event::WindowTitleChanged(addr) => arm_async!(addr, window_title_changed_events, self),
Event::Screencast(data) => arm_async!(data, screencast_events, self),
Event::ConfigReloaded => arm_async!(config_reloaded_events, self),
Event::IgnoreGroupLockStateChanged(bool) => {
ActiveWindowChangedV1(_) => (),
ActiveWindowChangedV2(_) => (),
FullscreenStateChanged(bool) => arm_async!(bool, fullscreen_state_changed_events, self),
MonitorAdded(monitor) => arm_async!(monitor, monitor_added_events, self),
MonitorRemoved(monitor) => arm_async!(monitor, monitor_removed_events, self),
WindowClosed(addr) => arm_async!(addr, window_close_events, self),
WindowMoved(even) => arm_async!(even, window_moved_events, self),
WindowOpened(even) => arm_async!(even, window_open_events, self),
SpecialRemoved(monitor) => arm_async!(monitor, special_removed_events, self),
ChangedSpecial(data) => arm_async!(data, special_changed_events, self),
LayoutChanged(even) => arm_async!(even, keyboard_layout_change_events, self),
SubMapChanged(map) => arm_async!(map, sub_map_changed_events, self),
LayerOpened(namespace) => arm_async!(namespace, layer_open_events, self),
LayerClosed(namespace) => arm_async!(namespace, layer_closed_events, self),
FloatStateChanged(even) => arm_async!(even, float_state_events, self),
UrgentStateChanged(even) => arm_async!(even, urgent_state_events, self),
Minimize(data) => arm_async!(data, minimize_events, self),
WindowTitleChanged(addr) => arm_async!(addr, window_title_changed_events, self),
Screencast(data) => arm_async!(data, screencast_events, self),
ConfigReloaded => arm_async!(config_reloaded_events, self),
IgnoreGroupLockStateChanged(bool) => {
arm_async!(bool, ignore_group_lock_state_changed_events, self)
}
Event::LockGroupsStateChanged(bool) => {
LockGroupsStateChanged(bool) => {
arm_async!(bool, lock_groups_state_changed_events, self)
}
WindowPinned(data) => arm_async!(data, window_pin_state_toggled_events, self),
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/event_listener/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl HasExecutor for EventListener {
arm!(bool, ignore_group_lock_state_changed_events, self)
}
LockGroupsStateChanged(bool) => arm!(bool, lock_groups_state_changed_events, self),
WindowPinned(data) => arm!(data, window_pin_state_toggled_events, self),
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/event_listener/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ macro_rules! init_events {
config_reloaded_events: vec![],
ignore_group_lock_state_changed_events: vec![],
lock_groups_state_changed_events: vec![],
window_pin_state_toggled_events: vec![],
}
};
}
3 changes: 2 additions & 1 deletion src/event_listener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ add_listener!(window_title_change d, Address, "a window title is changed", "A wi
add_listener!(screencast, ScreencastEventData, "the screencast state of a window is changed", "screencast state changed" => data);
add_listener!(config_reload ed, "the configuration of Hyprland is reloaded", "config reloaded" => _empty);
add_listener!(ignore_group_lock_state_change d, bool, "the state of ignore group lock is toggled", "ignore group lock toggled to" => data);
add_listener!(lock_groups_state_change d, bool, "the state of lock groups is toggled ", "lock group state toggled to" => data);
add_listener!(lock_groups_state_change d, bool, "the state of lock groups is toggled", "lock group state toggled to" => data);
add_listener!(window_pin_state_toggle d, WindowPinEventData, "the pinned state of a window is changed", "window pin was set to" => state);
38 changes: 22 additions & 16 deletions src/event_listener/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ use once_cell::sync::Lazy;
use regex::{Error as RegexError, Regex};
use std::{fmt::Debug, pin::Pin};

/// This trait provides shared behaviour for listener types
pub(crate) trait Listener: HasExecutor {
/// This method starts the event listener
fn start_listener() -> crate::Result<()>;
}

/// This trait provides shared behaviour for listener types
pub(crate) trait AsyncListener: HasAsyncExecutor {
/// This method starts the event listener (async)
async fn start_listener_async() -> crate::Result<()>;
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ActiveWindowValue<T> {
Queued(T), // aka Some(T)
Expand Down Expand Up @@ -253,7 +241,8 @@ pub(crate) struct Events {
pub(crate) screencast_events: Closures<ScreencastEventData>,
pub(crate) config_reloaded_events: Vec<EmptyClosure>,
pub(crate) ignore_group_lock_state_changed_events: Closures<bool>,
pub(crate) lock_groups_state_changed_events: Closures<bool>
pub(crate) lock_groups_state_changed_events: Closures<bool>,
pub(crate) window_pin_state_toggled_events: Closures<WindowPinEventData>,
}

#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -284,7 +273,8 @@ pub(crate) struct AsyncEvents {
pub(crate) screencast_events: AsyncClosures<ScreencastEventData>,
pub(crate) config_reloaded_events: Vec<EmptyAsyncClosure>,
pub(crate) ignore_group_lock_state_changed_events: AsyncClosures<bool>,
pub(crate) lock_groups_state_changed_events: AsyncClosures<bool>
pub(crate) lock_groups_state_changed_events: AsyncClosures<bool>,
pub(crate) window_pin_state_toggled_events: AsyncClosures<WindowPinEventData>,
}

/// Event data for destroyworkspacev2 event
Expand Down Expand Up @@ -466,7 +456,7 @@ pub struct MonitorEventData {
pub workspace: WorkspaceType,
}

/// This struct holds monitor event data
/// This struct holds window float event data
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WindowFloatEventData {
/// The window address
Expand All @@ -475,6 +465,15 @@ pub struct WindowFloatEventData {
pub is_floating: bool,
}

/// This struct holds window pin event data
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WindowPinEventData {
/// The window address
pub window_address: Address,
/// The pin state
pub is_pinned: bool,
}

/// This enum holds every event type
#[derive(Debug, Clone)]
pub(crate) enum Event {
Expand Down Expand Up @@ -506,7 +505,8 @@ pub(crate) enum Event {
Screencast(ScreencastEventData),
ConfigReloaded,
IgnoreGroupLockStateChanged(bool),
LockGroupsStateChanged(bool)
LockGroupsStateChanged(bool),
WindowPinned(WindowPinEventData)
}

fn parse_string_as_work(str: String) -> WorkspaceType {
Expand Down Expand Up @@ -579,6 +579,7 @@ enum ParsedEventType {
ConfigReloaded,
IgnoreGroupLock,
LockGroups,
Pin,
Unknown,
}

Expand Down Expand Up @@ -681,6 +682,7 @@ static EVENT_SET: Lazy<Box<[(ParsedEventType, Regex)]>> = Lazy::new(|| {
(ParsedEventType::ConfigReloaded, r"configreloaded>>"),
(ParsedEventType::IgnoreGroupLock, r"ignoregrouplock>>(?P<state>[0-1])"),
(ParsedEventType::LockGroups, r"lockgroups>>(?P<state>[0-1])"),
(ParsedEventType::Pin, r"pin>>(?P<address>.*),(?P<state>[0-1])"),
(ParsedEventType::Unknown, r"(?P<Event>^[^>]*)"),
].into_iter()
.map(|(e, r)| (
Expand Down Expand Up @@ -873,6 +875,10 @@ pub(crate) fn event_parser(event: String) -> crate::Result<Vec<Event>> {
ParsedEventType::ConfigReloaded => Ok(Event::ConfigReloaded),
ParsedEventType::IgnoreGroupLock => Ok(Event::IgnoreGroupLockStateChanged(&captures["state"] == "1")),
ParsedEventType::LockGroups => Ok(Event::LockGroupsStateChanged(&captures["state"] == "1")),
ParsedEventType::Pin => Ok(Event::WindowPinned(WindowPinEventData {
window_address: Address::fmt_new(&captures["address"]),
is_pinned: &captures["state"] == "1"
})),
ParsedEventType::Unknown => {
#[cfg(not(feature = "silent"))]
{
Expand Down

0 comments on commit e204ad9

Please sign in to comment.