in sample/src/main/kotlin/org/jetbrains/desktop/sample/linux/SkikoSampleLinux.kt [1328:1509]
fun handleEvent(event: Event): EventHandlerResult {
if (event !is Event.MouseMoved && event !is Event.WindowDraw) {
Logger.info { "$event" }
}
return when (event) {
Event.ApplicationStarted -> {
createWindow(useCustomTitlebar = true, renderingMode = RenderingMode.Auto)
EventHandlerResult.Stop
}
Event.ApplicationWantsToTerminate -> EventHandlerResult.Continue
Event.ApplicationWillTerminate -> EventHandlerResult.Continue
is Event.DisplayConfigurationChange -> EventHandlerResult.Continue
is Event.XdgDesktopSettingChange -> {
settingChanged(event.setting)
EventHandlerResult.Stop
}
is Event.WindowCloseRequest -> {
val windowId = event.windowId
val window = windows[windowId] ?: return EventHandlerResult.Continue
window.close()
windows.remove(windowId)
windowClipboardHandlers.remove(windowId)
requestSources.entries.removeIf { it.value == windowId }
notificationSources.entries.removeIf { entry ->
(entry.value == windowId).also { shouldRemove ->
if (shouldRemove) {
app.closeNotification(entry.key)
}
}
}
if (windows.isEmpty()) {
app.stopEventLoop()
}
EventHandlerResult.Stop
}
is Event.WindowDraw -> {
if (windows[event.windowId]?.performDrawing(event) == true) {
EventHandlerResult.Stop
} else {
EventHandlerResult.Continue
}
}
is Event.WindowConfigure -> {
windows[event.windowId]?.configure(event) ?: EventHandlerResult.Continue
}
is Event.MouseMoved -> {
windows[event.windowId]?.onMouseMoved(event.locationInWindow) ?: EventHandlerResult.Continue
}
is Event.DataTransfer -> {
clipboardPasteSerialToWindow.remove(event.serial)?.let { windowId ->
windows[windowId]?.onDataTransfer(event.content, app)
} ?: EventHandlerResult.Continue
}
is Event.DropPerformed -> {
windows[event.windowId]?.onDataTransfer(event.content, app) ?: EventHandlerResult.Continue
}
is Event.DragAndDropLeave -> EventHandlerResult.Stop
is Event.DragIconDraw -> {
currentDragIconDraw?.let { draw ->
val drawImpl = { surface: Surface ->
draw(surface.canvas, event.scale)
surface.flushAndSubmit()
true
}
event.softwareDrawData?.let { softwareDrawData ->
performSoftwareDrawing(event.size, softwareDrawData, drawImpl)
} ?: run {
dragIconDirectContext?.let {
performOpenGlDrawing(event.size, it, drawImpl)
} ?: run {
val eglFunc = app.getEglProcFunc()!!
val openGlInterface = GLAssembledInterface.createFromNativePointers(
ctxPtr = eglFunc.ctxPtr,
fPtr = eglFunc.fPtr,
)
val directContext = DirectContext.makeGLWithInterface(openGlInterface)
dragIconDirectContext = directContext
performOpenGlDrawing(event.size, directContext, drawImpl)
}
}
EventHandlerResult.Stop
} ?: EventHandlerResult.Continue
}
is Event.DragAndDropFinished -> {
windows[event.windowId]?.onDragAndDropFinished(event.action) ?: EventHandlerResult.Continue
currentDragIconDraw = null
dragIconDirectContext = null
EventHandlerResult.Stop
}
is Event.DataTransferCancelled -> {
onDataTransferCancelled(event.dataSource)
EventHandlerResult.Stop
}
is Event.DataTransferAvailable -> EventHandlerResult.Continue
is Event.FileChooserResponse -> {
Logger.info { "File chooser response: $event" }
EventHandlerResult.Stop
}
is Event.ActivationTokenResponse -> {
windows.keys.firstOrNull { it != keyWindowId }?.let { windowIdToActivate ->
val w = windows[windowIdToActivate]!!
w.window.activate(event.token)
}
EventHandlerResult.Stop
}
is Event.KeyDown -> {
if (modifiers.shortcutModifiers() == setOf(KeyModifiers.Control) && event.keyCode.value == KeyCode.N) {
createWindow(useCustomTitlebar = true, renderingMode = RenderingMode.Auto)
EventHandlerResult.Stop
} else if (modifiers.shortcutModifiers() == setOf(KeyModifiers.Control) && event.keyCode.value == KeyCode.P) {
val windowId = keyWindowId!!
val params = ShowNotificationParams(
title = "Notification from window $windowId",
body = "Clicking this notification will activate window $windowId",
soundFilePath = null,
)
app.requestShowNotification(params)?.let { requestId ->
requestSources[requestId] = windowId
}
EventHandlerResult.Stop
} else {
windows[keyWindowId]?.onKeyDown(event, app, modifiers, windowClipboardHandlers[keyWindowId]!!)
?: EventHandlerResult.Continue
}
}
is Event.KeyUp -> EventHandlerResult.Continue
is Event.ModifiersChanged -> {
modifiers = event.modifiers
EventHandlerResult.Stop
}
is Event.MouseDown -> windows[event.windowId]?.onMouseDown(
event,
modifiers,
windowClipboardHandlers[event.windowId]!!,
xdgDesktopSettings,
)
?: EventHandlerResult.Continue
is Event.MouseEntered -> windows[event.windowId]?.onMouseEntered(event.locationInWindow) ?: EventHandlerResult.Continue
is Event.MouseExited -> windows[event.windowId]?.onMouseExited() ?: EventHandlerResult.Continue
is Event.MouseUp -> {
if (event.button == MouseButton.LEFT) {
currentDragContent = null
}
windows[event.windowId]?.onMouseUp(event, xdgDesktopSettings) ?: EventHandlerResult.Continue
}
is Event.ScrollWheel -> EventHandlerResult.Continue
is Event.TextInput -> windows[keyWindowId]?.onTextInput(event, app) ?: EventHandlerResult.Continue
is Event.TextInputAvailability -> windows[event.windowId]?.onTextInputAvailability(event, app) ?: EventHandlerResult.Continue
is Event.WindowKeyboardEnter -> {
keyWindowId = event.windowId
EventHandlerResult.Continue
}
is Event.WindowKeyboardLeave -> {
check(keyWindowId == event.windowId)
keyWindowId = null
EventHandlerResult.Continue
}
is Event.WindowScaleChanged, is Event.WindowScreenChange -> EventHandlerResult.Continue
is Event.NotificationShown -> {
event.notificationId?.let { notificationId ->
requestSources.remove(event.requestId)?.let { requester ->
notificationSources[notificationId] = requester
} ?: run {
app.closeNotification(notificationId)
}
}
EventHandlerResult.Stop
}
is Event.NotificationClosed -> {
notificationSources.remove(event.notificationId)?.let { windowIdToActivate ->
event.activationToken?.let { activationToken ->
val w = windows[windowIdToActivate]!!
w.window.activate(activationToken)
}
}
EventHandlerResult.Stop
}
}
}