summaryrefslogtreecommitdiff
path: root/kvmd/apps/vnc/rfb/encodings.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-03-23 00:50:48 +0300
committerDevaev Maxim <[email protected]>2020-03-23 00:50:48 +0300
commit94b779c5868a20f46c1d78c56fd19e01285a4e25 (patch)
treede49298f962c0c376499b69c7e6db90757cc5cc1 /kvmd/apps/vnc/rfb/encodings.py
parent4e0f7e61a25f8e64a4ce73aff75b30f8ac771ff5 (diff)
refactoring
Diffstat (limited to 'kvmd/apps/vnc/rfb/encodings.py')
-rw-r--r--kvmd/apps/vnc/rfb/encodings.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/kvmd/apps/vnc/rfb/encodings.py b/kvmd/apps/vnc/rfb/encodings.py
new file mode 100644
index 00000000..cb1d4761
--- /dev/null
+++ b/kvmd/apps/vnc/rfb/encodings.py
@@ -0,0 +1,69 @@
+# ========================================================================== #
+# #
+# KVMD - The main Pi-KVM daemon. #
+# #
+# Copyright (C) 2020 Maxim Devaev <[email protected]> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <https://www.gnu.org/licenses/>. #
+# #
+# ========================================================================== #
+
+
+import dataclasses
+
+from typing import FrozenSet
+from typing import Any
+
+
+# =====
+class RfbEncodings:
+ RESIZE = -223 # DesktopSize Pseudo-encoding
+ RENAME = -307 # DesktopName Pseudo-encoding
+ LEDS_STATE = -261 # LED State Pseudo-encoding
+
+ TIGHT = 7
+ TIGHT_JPEG_QUALITIES = dict(zip( # JPEG Quality Level Pseudo-encoding
+ [-32, -31, -30, -29, -28, -27, -26, -25, -24, -23],
+ [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
+ ))
+
+
[email protected](frozen=True)
+class RfbClientEncodings:
+ encodings: FrozenSet[int]
+
+ has_resize: bool = dataclasses.field(default=False)
+ has_rename: bool = dataclasses.field(default=False)
+ has_leds_state: bool = dataclasses.field(default=False)
+
+ has_tight: bool = dataclasses.field(default=False)
+ tight_jpeg_quality: int = dataclasses.field(default=0)
+
+ def __post_init__(self) -> None:
+ self.__set("has_resize", (RfbEncodings.RESIZE in self.encodings))
+ self.__set("has_rename", (RfbEncodings.RENAME in self.encodings))
+ self.__set("has_leds_state", (RfbEncodings.LEDS_STATE in self.encodings))
+
+ self.__set("has_tight", (RfbEncodings.TIGHT in self.encodings))
+ self.__set("tight_jpeg_quality", self.__get_tight_jpeg_quality())
+
+ def __set(self, key: str, value: Any) -> None:
+ object.__setattr__(self, key, value)
+
+ def __get_tight_jpeg_quality(self) -> int:
+ if RfbEncodings.TIGHT in self.encodings:
+ qualities = self.encodings.intersection(RfbEncodings.TIGHT_JPEG_QUALITIES)
+ if qualities:
+ return RfbEncodings.TIGHT_JPEG_QUALITIES[max(qualities)]
+ return 0