Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
PRJ-99 Allow to specify IDE window ID to show
Browse files Browse the repository at this point in the history
  • Loading branch information
SerVB committed Aug 17, 2020
1 parent 93def03 commit 5d591c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ actual object ParamsProvider {
val ENABLE_WSS: Boolean
val HANDSHAKE_TOKEN: String?
val MOBILE_SETTING: MobileSetting
val IDE_WINDOW_ID: Int?
val SCALING_RATIO: Double
get() = SYSTEM_SCALING_RATIO * USER_SCALING_RATIO

Expand Down Expand Up @@ -113,6 +114,7 @@ actual object ParamsProvider {
}
false -> MobileSetting.DISABLED
}
IDE_WINDOW_ID = searchParams.get("ideWindow")?.toIntOrNull()
}
}

Expand Down
3 changes: 2 additions & 1 deletion projector-client-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Name | Type | Default value | Description
`port` | String | `8887` | Set the port of `projector-server` to connect.
`wss` | Presence | Protocol of the web page | Enable security of WebSocket connection.
`token` | String? | Not present | Set a password which will be checked by the server on the connection.
`mobile` | String? | Not present | Enable overlay controls handy for mobile devices. Presented param activates all controls. Provide `onlyButtons` value if you don't use virtual keyboard.
`mobile` | String? | Not present | Enable overlay controls handy for mobile devices. Presented param activates all controls. Provide `onlyButtons` value if you don't use virtual keyboard.
`ideWindow` | Int? | Not present | Specify the IDE window ID to show. The first ID is `0`. If not presented, all IDE windows are shown.

### Debug/test parameters
Name | Type | Default value | Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
*/
package org.jetbrains.projector.client.web.window

import org.jetbrains.projector.client.common.misc.Logger
import org.jetbrains.projector.client.common.SingleRenderingSurfaceProcessor.Companion.shrinkByPaintEvents
import org.jetbrains.projector.client.common.misc.ImageCacher
import org.jetbrains.projector.client.common.misc.Logger
import org.jetbrains.projector.client.common.misc.ParamsProvider
import org.jetbrains.projector.common.misc.firstNotNullOrNull
import org.jetbrains.projector.common.protocol.data.ImageId
import org.jetbrains.projector.common.protocol.toClient.ServerWindowEvent
import org.jetbrains.projector.common.protocol.toClient.ServerWindowSetChangedEvent
import org.jetbrains.projector.common.protocol.toClient.WindowData
import org.jetbrains.projector.common.protocol.toClient.WindowType
import org.w3c.dom.HTMLCanvasElement
import org.w3c.dom.HTMLImageElement
import org.w3c.dom.HTMLLinkElement
Expand All @@ -39,6 +41,8 @@ import kotlin.collections.isNotEmpty

class WindowDataEventsProcessor(private val windowManager: WindowManager) {

private var excludedWindowIds = emptyList<Int>()

@OptIn(ExperimentalStdlibApi::class)
fun redrawWindows() {
synchronized(windowManager) {
Expand All @@ -51,37 +55,46 @@ class WindowDataEventsProcessor(private val windowManager: WindowManager) {
}

fun process(windowDataEvents: ServerWindowSetChangedEvent) {
removeAbsentWindows(windowDataEvents)
val excludedWindows = when (val selectedId = ParamsProvider.IDE_WINDOW_ID) {
null -> emptyList()

else -> windowDataEvents.windowDataList
.filter { it.windowType == WindowType.IDEA_WINDOW }
.sortedBy(WindowData::id)
.filterIndexed { index, _ -> index != selectedId }
}
excludedWindowIds = excludedWindows.map(WindowData::id)
val presentedWindows = windowDataEvents.windowDataList.subtract(excludedWindows)

removeAbsentWindows(presentedWindows)

synchronized(windowManager) {
windowDataEvents.windowDataList.forEach { event ->
presentedWindows.forEach { event ->
val window = windowManager.getOrCreate(event)

event.cursorType?.let { window.cursorType = it }
window.title = event.title
window.isShowing = event.isShowing
window.bounds = event.bounds
window.zIndex = (event.zOrder - windowDataEvents.windowDataList.size) * WindowManager.zIndexStride
window.zIndex = (event.zOrder - presentedWindows.size) * WindowManager.zIndexStride
}
}

setTitle(windowDataEvents)
setFavIcon(windowDataEvents)
setTitle(presentedWindows)
setFavIcon(presentedWindows)
}

private fun setTitle(windowDataEvents: ServerWindowSetChangedEvent) {
val topmostWindowTitle = windowDataEvents
.windowDataList
private fun setTitle(presentedWindows: Iterable<WindowData>) {
val topmostWindowTitle = presentedWindows
.filter(WindowData::isShowing)
.sortedByDescending(WindowData::zOrder)
.firstNotNullOrNull(WindowData::title)

document.title = topmostWindowTitle ?: DEFAULT_TITLE
}

private fun setFavIcon(windowDataEvents: ServerWindowSetChangedEvent) {
val topmostWindowIconIds = windowDataEvents
.windowDataList
private fun setFavIcon(presentedWindows: Iterable<WindowData>) {
val topmostWindowIconIds = presentedWindows
.filter(WindowData::isShowing)
.sortedByDescending(WindowData::zOrder)
.mapNotNull(WindowData::icons)
Expand Down Expand Up @@ -109,6 +122,10 @@ class WindowDataEventsProcessor(private val windowManager: WindowManager) {

@OptIn(ExperimentalStdlibApi::class)
fun draw(windowId: Int, commands: List<ServerWindowEvent>) {
if (windowId in excludedWindowIds) {
return
}

synchronized(windowManager) {
val window = windowManager[windowId]

Expand All @@ -126,8 +143,8 @@ class WindowDataEventsProcessor(private val windowManager: WindowManager) {
}
}

private fun removeAbsentWindows(windowDataEvents: ServerWindowSetChangedEvent) {
val presentedWindowIds = windowDataEvents.windowDataList.map(WindowData::id).toSet()
private fun removeAbsentWindows(presentedWindows: Iterable<WindowData>) {
val presentedWindowIds = presentedWindows.map(WindowData::id).toSet()

synchronized(windowManager) {
windowManager.cleanup(presentedWindowIds)
Expand Down

0 comments on commit 5d591c5

Please sign in to comment.