Skip to content

Commit

Permalink
Merge pull request #93 from JetBrains/fix_focus_on_window_start
Browse files Browse the repository at this point in the history
Compose. Hot keys didn't work until we clicked on the window.
  • Loading branch information
igordmn authored Apr 15, 2021
2 parents 55c1cad + f829e23 commit bed10c5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import org.jetbrains.skiko.context.ContextHandler
import org.jetbrains.skiko.context.createContextHandler
import org.jetbrains.skiko.redrawer.Redrawer
import java.awt.Graphics
import java.awt.event.FocusEvent
import java.awt.event.HierarchyEvent
import java.awt.event.InputMethodListener
import java.awt.event.KeyListener
import java.awt.event.MouseListener
import java.awt.event.MouseMotionListener
import java.awt.event.MouseWheelListener
import java.awt.im.InputMethodRequests
import javax.swing.JPanel
import javax.swing.SwingUtilities.isEventDispatchThread

Expand Down Expand Up @@ -44,6 +46,10 @@ open class SkiaLayer(
// 3. to avoid double paint in one single frame, use needRedraw instead of redrawImmediately
redrawer?.needRedraw()
}

override fun getInputMethodRequests(): InputMethodRequests? {
return this@SkiaLayer.inputMethodRequests
}
}
add(backedLayer)
@Suppress("LeakingThis")
Expand Down Expand Up @@ -146,6 +152,25 @@ open class SkiaLayer(
}
}

// We need to delegate all event listeners to the Canvas (so and focus/input)
// Canvas is heavyweight AWT component, JPanel is lightweight Swing component
// Event handling doesn't properly work when we mix heavyweight and lightweight components.
// For example, Canvas will eat all mouse events
// (see "mouse events on a heavyweight component do not fall through to its parent",
// https://www.comp.nus.edu.sg/~cs3283/ftp/Java/swingConnect/archive/tech_topics_arch/mixing/mixing.html)

override fun enableInputMethods(enable: Boolean) {
backedLayer.enableInputMethods(enable)
}

override fun requestFocus() {
backedLayer.requestFocus()
}

override fun requestFocus(cause: FocusEvent.Cause?) {
backedLayer.requestFocus(cause)
}

override fun addInputMethodListener(l: InputMethodListener) {
backedLayer.addInputMethodListener(l)
}
Expand Down Expand Up @@ -186,8 +211,6 @@ open class SkiaLayer(
backedLayer.removeKeyListener(l)
}

private var redrawScheduled = false

/**
* Redraw on the next animation Frame (on vsync signal if vsync is enabled).
*/
Expand Down

0 comments on commit bed10c5

Please sign in to comment.