Skip to content

Conversation

@d3adb5
Copy link
Contributor

@d3adb5 d3adb5 commented Aug 3, 2023

Reposition other popups when popups are dismissed / closed.

Fixes #237.

Reposition other popups when popups are dismissed / closed.

Fixes phuhl#237.
(screenWidth, screenHeight, _) <- getScreenPos (_dMainWindow newpopup) monitorId
let x = screenWidth - (notificationWidth + distanceRight)
y <- calculateY preceding distanceBetween distanceTop
windowMove (_dMainWindow newpopup) x y
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this has to be wrapped in an addSource call to make it thread safe

-- | Adjusts the position of all displayed notifications so they follow standardized placement rules.
readjustNotificationPositions :: Config -> TVar NotifyState -> IO ()
readjustNotificationPositions config tState = do
sortedDisplayedPopups <- sortOn _dNotiTop . filter (not . _dHasCustomPosition) . notiDisplayingList <$> readTVarIO tState
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readTVarIO state reads a shared memory location. I think for performance reasons (and readability) it makes sense to get the state once, before

Suggested change
sortedDisplayedPopups <- sortOn _dNotiTop . filter (not . _dHasCustomPosition) . notiDisplayingList <$> readTVarIO tState
state <- readTVarIO tState
sortedDisplayedPopups <- sortOn _dNotiTop . filter (not . _dHasCustomPosition) . notiDisplayingList state

readjustNotificationPositions config tState = do
sortedDisplayedPopups <- sortOn _dNotiTop . filter (not . _dHasCustomPosition) . notiDisplayingList <$> readTVarIO tState
newDisplayedPopups <- pushNotificationsUp config sortedDisplayedPopups
atomically $ modifyTVar' tState $ \state ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong, but this could loose notifications. Consider this scenario:

  • You read display notis out in line 451
  • then another process might kick in and adds a notification
  • You overwrite displayNoti List w/o new noti (as it was not present before)

It probably has all to be atomic

atomically $ modifyTVar' tState $ \state ->
state { notiDisplayingList = newDisplayedPopups ++ filter _dHasCustomPosition (notiDisplayingList state) }

pushNotificationsUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pushNotificationsUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup]
pushFirstNotificationUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup]

newFirst <- autoplaceNotification config Nothing f
pushNotificationsUp' config (newFirst:r)

pushNotificationsUp' :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pushNotificationsUp' :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup]
pushNextNotificationUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restack windows when a notification closes

2 participants