Skip to content

Commit

Permalink
Focus loss with project context (#69)
Browse files Browse the repository at this point in the history
* Focus loss dismissal dependent on project clicked inside

* Updated changelog and bump version to v0.5.3

* Only loosing focus when key is inside project
  • Loading branch information
Unthrottled authored Feb 18, 2021
1 parent 5c57547 commit a86b902
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# AMII Changelog

## [0.5.1]

### Changed

- How the AFK gifs are dismissed. They only get dismissed when the project it is on gains focus again. Not when any project gains focus.

## [0.5.2]

### Fixed
Expand Down
5 changes: 2 additions & 3 deletions docs/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
- Not being able to set frustration probability
- Not being able to disable sound
- The idle meme display position and meme display being persisted incorrectly.
### Changed
- How the AFK gifs are dismissed. They only get dismissed when the project it is on gains focus again. Not when any project gains focus.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = io.unthrottled
pluginName_ = Anime Memes
pluginVersion = 0.5.2
pluginVersion = 0.5.3
pluginSinceBuild = 202.6397.94
pluginUntilBuild = 211.*
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
Expand Down
19 changes: 13 additions & 6 deletions src/main/kotlin/io/unthrottled/amii/memes/MemePanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ class MemePanel(
return AWTEventListener { e ->
if (invulnerable) return@AWTEventListener

val isFocusLoss = memePanelSettings.dismissal == FOCUS_LOSS
if (e is MouseEvent) {
val wasInside = isInsideMemePanel(e)
val wasInsideProject = UIUtil.isDescendingFrom(e.component, rootPane)
if (e.id == MouseEvent.MOUSE_PRESSED) {
if ((!wasInside && memePanelSettings.dismissal == FOCUS_LOSS) || clickedInside) {
val wasClickedOutsideProject = !wasInside && wasInsideProject && isFocusLoss
if (wasClickedOutsideProject || clickedInside) {
dismissMeme()
} else if (wasInside) {
fadeoutAlarm.cancelAllRequests()
Expand All @@ -170,7 +173,8 @@ class MemePanel(
e is KeyEvent && e.id == KeyEvent.KEY_PRESSED
) {
if (
memePanelSettings.dismissal == FOCUS_LOSS &&
isFocusLoss &&
UIUtil.isDescendingFrom(e.component, rootPane) &&
ALLOWED_KEYS.contains(e.keyCode).not()
) {
dismissMeme()
Expand Down Expand Up @@ -228,18 +232,21 @@ class MemePanel(
removeMeme()
}

private fun isInsideMemePanel(e: MouseEvent): Boolean {
private fun isInsideMemePanel(e: MouseEvent): Boolean =
isInsideComponent(e, this)

private fun isInsideComponent(e: MouseEvent, rootPane1: JComponent): Boolean {
val target = RelativePoint(e)
val ogComponent = target.originalComponent
return when {
ogComponent.isShowing.not() -> true
ogComponent is MenuElement -> false
UIUtil.isDescendingFrom(ogComponent, this) -> true
UIUtil.isDescendingFrom(ogComponent, rootPane1) -> true
this.isShowing.not() -> false
else -> {
val point = target.screenPoint
SwingUtilities.convertPointFromScreen(point, this)
this.contains(point)
SwingUtilities.convertPointFromScreen(point, rootPane1)
rootPane1.contains(point)
}
}
}
Expand Down

0 comments on commit a86b902

Please sign in to comment.