-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: reposition popups upon dismissal #240
base: master
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
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 -> |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushNotificationsUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup] | |
pushFirstNotificationUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup] |
newFirst <- autoplaceNotification config Nothing f | ||
pushNotificationsUp' config (newFirst:r) | ||
|
||
pushNotificationsUp' :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushNotificationsUp' :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup] | |
pushNextNotificationUp :: Config -> [DisplayingNotificationPopup] -> IO [DisplayingNotificationPopup] |
Reposition other popups when popups are dismissed / closed.
Fixes #237.