Skip to content

Commit

Permalink
Implement resize-to-local-window
Browse files Browse the repository at this point in the history
Re: #142
  • Loading branch information
gujjwal00 committed May 17, 2023
1 parent 8d1eeba commit d04e4e1
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 6 deletions.
216 changes: 216 additions & 0 deletions app/roomSchema/com.gaurav.avnc.model.db.MainDb/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"formatVersion": 1,
"database": {
"version": 4,
"identityHash": "5ff9de8e52fb13b10ee86f9c75714cd5",
"entities": [
{
"tableName": "profiles",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`ID` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, `securityType` INTEGER NOT NULL, `channelType` INTEGER NOT NULL, `colorLevel` INTEGER NOT NULL, `imageQuality` INTEGER NOT NULL, `useRawEncoding` INTEGER NOT NULL DEFAULT 0, `zoom1` REAL NOT NULL DEFAULT 1.0, `zoom2` REAL NOT NULL DEFAULT 1.0, `viewOnly` INTEGER NOT NULL, `useLocalCursor` INTEGER NOT NULL, `serverTypeHint` TEXT NOT NULL DEFAULT '', `compatFlags` INTEGER NOT NULL, `gestureStyle` TEXT NOT NULL DEFAULT 'auto', `screenOrientation` TEXT NOT NULL DEFAULT 'auto', `shortcutRank` INTEGER NOT NULL DEFAULT 0, `useRepeater` INTEGER NOT NULL, `idOnRepeater` INTEGER NOT NULL, `resizeRemoteDesktop` INTEGER NOT NULL DEFAULT 0, `sshHost` TEXT NOT NULL, `sshPort` INTEGER NOT NULL, `sshUsername` TEXT NOT NULL, `sshAuthType` INTEGER NOT NULL, `sshPassword` TEXT NOT NULL, `sshPrivateKey` TEXT NOT NULL, `sshPrivateKeyPassword` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "ID",
"columnName": "ID",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "host",
"columnName": "host",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "port",
"columnName": "port",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "password",
"columnName": "password",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "securityType",
"columnName": "securityType",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "channelType",
"columnName": "channelType",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "colorLevel",
"columnName": "colorLevel",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "imageQuality",
"columnName": "imageQuality",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "useRawEncoding",
"columnName": "useRawEncoding",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "zoom1",
"columnName": "zoom1",
"affinity": "REAL",
"notNull": true,
"defaultValue": "1.0"
},
{
"fieldPath": "zoom2",
"columnName": "zoom2",
"affinity": "REAL",
"notNull": true,
"defaultValue": "1.0"
},
{
"fieldPath": "viewOnly",
"columnName": "viewOnly",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "useLocalCursor",
"columnName": "useLocalCursor",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "serverTypeHint",
"columnName": "serverTypeHint",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "compatFlags",
"columnName": "compatFlags",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "gestureStyle",
"columnName": "gestureStyle",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "'auto'"
},
{
"fieldPath": "screenOrientation",
"columnName": "screenOrientation",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "'auto'"
},
{
"fieldPath": "shortcutRank",
"columnName": "shortcutRank",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "useRepeater",
"columnName": "useRepeater",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "idOnRepeater",
"columnName": "idOnRepeater",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "resizeRemoteDesktop",
"columnName": "resizeRemoteDesktop",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "sshHost",
"columnName": "sshHost",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sshPort",
"columnName": "sshPort",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "sshUsername",
"columnName": "sshUsername",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sshAuthType",
"columnName": "sshAuthType",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "sshPassword",
"columnName": "sshPassword",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sshPrivateKey",
"columnName": "sshPrivateKey",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sshPrivateKeyPassword",
"columnName": "sshPrivateKeyPassword",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"ID"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5ff9de8e52fb13b10ee86f9c75714cd5')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.junit.Test
class DatabaseTest {
private val dbName = "Bond. James Bond."
private val minVersion = 1
private val maxVersion = 3
private val maxVersion = 4

@get:Rule
val helper = MigrationTestHelper(instrumentation, MainDb::class.java)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/cpp/native-vnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ Java_com_gaurav_avnc_vnc_VncClient_nativeSendCutText(JNIEnv *env, jobject thiz,
return (jboolean) result;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_gaurav_avnc_vnc_VncClient_nativeSetDesktopSize(JNIEnv *env, jobject thiz, jlong client_ptr, jint width,
jint height) {
return (jboolean) SendExtDesktopSize((rfbClient *) client_ptr, width, height);
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_gaurav_avnc_vnc_VncClient_nativeRefreshFrameBuffer(JNIEnv *env, jobject thiz, jlong clientPtr) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/gaurav/avnc/model/ServerProfile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ data class ServerProfile(
*/
var idOnRepeater: Int = 0,

/**
* Resize remote desktop to match with local window size.
*/
@ColumnInfo(defaultValue = "0")
var resizeRemoteDesktop: Boolean = false,

/**
* These values are used for SSH Tunnel
*/
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/gaurav/avnc/model/db/MainDb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import androidx.room.migration.AutoMigrationSpec
import androidx.sqlite.db.SupportSQLiteDatabase
import com.gaurav.avnc.model.ServerProfile

@Database(entities = [ServerProfile::class], version = 3, exportSchema = true, autoMigrations = [
AutoMigration(from = 1, to = 2, spec = MainDb.MigrationSpec1to2::class),
AutoMigration(from = 2, to = 3, spec = MainDb.MigrationSpec2to3::class)
@Database(entities = [ServerProfile::class], version = 4, exportSchema = true, autoMigrations = [
AutoMigration(from = 1, to = 2, spec = MainDb.MigrationSpec1to2::class), // in v2.0.0
AutoMigration(from = 2, to = 3, spec = MainDb.MigrationSpec2to3::class), // in v2.1.0
AutoMigration(from = 3, to = 4) // in v2.3.0
])
abstract class MainDb : RoomDatabase() {
abstract val serverProfileDao: ServerProfileDao
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/gaurav/avnc/ui/vnc/LayoutManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class LayoutManager(activity: VncActivity) {
manuallyGenerateWindowInsets()

applyInsets()
viewModel.resizeRemoteDesktop()
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/gaurav/avnc/viewmodel/VncViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ class VncViewModel(val profile: ServerProfile, app: Application) : BaseViewModel
return loginInfoRequest.requestResponse(type) // Blocking call
}

/**
* Resize remote desktop to match with local window size (if requested by user).
* In portrait mode, safe area is used instead of window to exclude the keyboard.
*/
fun resizeRemoteDesktop() {
if (profile.resizeRemoteDesktop) frameState.let {
if (it.windowWidth > it.windowHeight)
messenger.setDesktopSize(it.windowWidth.toInt(), it.windowHeight.toInt())
else
messenger.setDesktopSize(it.safeArea.width().toInt(), it.safeArea.height().toInt())
}
}

/**************************************************************************
* [VncClient.Observer] Implementation
**************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/gaurav/avnc/vnc/Messenger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ class Messenger(private val client: VncClient) {
fun sendClipboardText(text: String) {
execute { client.sendCutText(text) }
}

fun setDesktopSize(width: Int, height: Int) {
execute { client.setDesktopSize(width, height) }
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/gaurav/avnc/vnc/VncClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ class VncClient(private val observer: Observer) {
nativeSendCutText(nativePtr, text.toByteArray(StandardCharsets.ISO_8859_1), false)
}

/**
* Set remote desktop size to given dimensions.
* This needs server support to actually work.
* Non-positive [width] & [height] are ignored.
*/
fun setDesktopSize(width: Int, height: Int) = ifConnected {
if (width > 0 && height > 0)
nativeSetDesktopSize(nativePtr, width, height)
}

/**
* Sends a request for full frame buffer update to remote server.
*/
Expand Down Expand Up @@ -221,6 +231,11 @@ class VncClient(private val observer: Observer) {
block()
}

private inline fun ifConnected(block: () -> Unit) {
if (connected)
block()
}

private external fun nativeClientCreate(): Long
private external fun nativeConfigure(clientPtr: Long, securityType: Int, useLocalCursor: Boolean, imageQuality: Int, useRawEncoding: Boolean)
private external fun nativeInit(clientPtr: Long, host: String, port: Int): Boolean
Expand All @@ -229,6 +244,7 @@ class VncClient(private val observer: Observer) {
private external fun nativeSendKeyEvent(clientPtr: Long, keySym: Int, xtCode: Int, isDown: Boolean): Boolean
private external fun nativeSendPointerEvent(clientPtr: Long, x: Int, y: Int, mask: Int): Boolean
private external fun nativeSendCutText(clientPtr: Long, bytes: ByteArray, isUTF8: Boolean): Boolean
private external fun nativeSetDesktopSize(clientPtr: Long, width: Int, height: Int): Boolean
private external fun nativeRefreshFrameBuffer(clientPtr: Long): Boolean
private external fun nativeGetDesktopName(clientPtr: Long): String
private external fun nativeGetWidth(clientPtr: Long): Int
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/layout/fragment_profile_editor_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@
app:layout_constraintTop_toTopOf="@id/button_up_delay"
app:tint="?colorControlNormal" />

<!--Resize remote desktop-->
<CheckBox
android:id="@+id/resize_remote_desktop"
style="@style/FormField.CheckBox"
android:checked="@={profile.resizeRemoteDesktop}"
android:text="@string/title_resize_remote_desktop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_up_delay" />

<!--Image Quality-->
<TextView
android:id="@+id/image_quality_label"
Expand All @@ -209,7 +219,7 @@
android:progress="@={profile.imageQuality}"
app:layout_constraintEnd_toStartOf="@id/raw_encoding"
app:layout_constraintStart_toEndOf="@id/image_quality_label"
app:layout_constraintTop_toBottomOf="@id/button_up_delay" />
app:layout_constraintTop_toBottomOf="@id/resize_remote_desktop" />

<CheckBox
android:id="@+id/raw_encoding"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<string name="title_hide_remote_cursor">Hide remote pointer</string>
<string name="title_key_compat_mode">Send legacy key events</string>
<string name="title_button_up_delay">Send delayed click events</string>
<string name="title_resize_remote_desktop">Resize remote session to local window</string>
<string name="title_image_quality">Image quality</string>
<string name="title_orientation">Orientation</string>
<string name="title_image_quality_raw">Raw</string>
Expand Down
2 changes: 1 addition & 1 deletion extern/libvncserver

0 comments on commit d04e4e1

Please sign in to comment.