호스트 GUI 골격과 프로토콜 메시지 코덱 추가
- winit + wgpu(Vulkan) + egui 기반 호스트 창: 얇은 제목 표시줄, 왼쪽 토글과 사이드 메뉴, 미연결 화면의 IP 입력과 최근 접속 목록, 승인 대기 화면 - 모든 제어 메시지 페이로드와 영상 패킷 헤더의 인코딩/디코딩 및 테스트 - 개발 환경 설치 문서(docs/dev-setup.md)
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
76097ade1e18ad4dfdb3bb5d2fe1f86c35ca5b56- 부모
- f1702c2
변경된 파일 12개
+943-7Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기| @@ -11,3 +11,9 @@ path = "src/main.rs" | ||
| 11 | 11 | |
| 12 | 12 | [dependencies] |
| 13 | 13 | bytes = "1.12.2" |
| 14 | 추가: egui = "0.37.0" | |
| 15 | 추가: egui-wgpu = { version = "0.37.0", features = ["winit", "wayland", "x11"] } | |
| 16 | 추가: egui-winit = "0.37.0" | |
| 17 | 추가: env_logger = "0.11.12" | |
| 18 | 추가: log = "0.4.35" | |
| 19 | 추가: pollster = "1.0.3" |
| @@ -8,8 +8,10 @@ Ubuntu(Wayland/X11)에서 Android 기기 화면을 실시간으로 미러링하 | ||
| 8 | 8 | |
| 9 | 9 | | 경로 | 내용 | |
| 10 | 10 | |---|---| |
| 11 | 삭제: | `src/`, `tests/` | 호스트 클라이언트 (Rust). 현재는 제어 채널 프레이밍(`src/protocol`)만 구현되어 있습니다. | | |
| 11 | 추가: | `src/protocol/` | 제어 채널 프레이밍과 메시지 페이로드 인코딩/디코딩 (Rust 라이브러리) | | |
| 12 | 추가: | `src/ui/` | 호스트 GUI. winit 창에 wgpu(Vulkan)로 직접 그리고, 설정·입력 UI는 egui로 같은 렌더 패스에 그립니다. | | |
| 12 | 13 | | `android/` | Android 동반 앱과 shell 권한 데몬 (Kotlin, Gradle). 데몬은 동반 앱 APK 안에 함께 들어가며 `app_process`로 실행됩니다. | |
| 14 | 추가: | `docs/dev-setup.md` | 개발 환경 설치 방법 | | |
| 13 | 15 | |
| 14 | 16 | ## 연결 구조 요약 |
| 15 | 17 |
| @@ -0,0 +1,80 @@ | ||
| 1 | 추가: # 개발 환경 설치 (Ubuntu 26.04) | |
| 2 | 추가: | |
| 3 | 추가: 기준 PC: NVIDIA RTX 5080 / RTX 5060 Ti (드라이버 595), Intel UHD 630, Wayland 세션. | |
| 4 | 추가: | |
| 5 | 추가: ## 1. 시스템 패키지 | |
| 6 | 추가: | |
| 7 | 추가: ```bash | |
| 8 | 추가: sudo apt update | |
| 9 | 추가: ``` | |
| 10 | 추가: | |
| 11 | 추가: ```bash | |
| 12 | 추가: sudo apt install -y openjdk-25-jdk-headless android-sdk-platform-tools-common clang libclang-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavfilter-dev libavdevice-dev libva-dev vainfo nvidia-vaapi-driver vulkan-tools | |
| 13 | 추가: ``` | |
| 14 | 추가: | |
| 15 | 추가: | 패키지 | 용도 | | |
| 16 | 추가: |---|---| | |
| 17 | 추가: | `openjdk-25-jdk-headless` | Android 빌드용 `javac` (이미 설치된 Java 25 런타임과 같은 버전) | | |
| 18 | 추가: | `android-sdk-platform-tools-common` | USB로 연결한 폰을 adb가 인식하도록 하는 udev 규칙 | | |
| 19 | 추가: | `clang`, `libclang-dev` | `ffmpeg-next` 바인딩 생성(bindgen) | | |
| 20 | 추가: | `libav*-dev` | 영상 디코딩 (FFmpeg 8) | | |
| 21 | 추가: | `libva-dev`, `vainfo`, `nvidia-vaapi-driver` | VA-API 하드웨어 디코딩과 확인 도구 | | |
| 22 | 추가: | `vulkan-tools` | `vulkaninfo`로 wgpu가 쓸 Vulkan 드라이버 확인 | | |
| 23 | 추가: | |
| 24 | 추가: ## 2. Android SDK | |
| 25 | 추가: | |
| 26 | 추가: ```bash | |
| 27 | 추가: mkdir -p ~/Android/Sdk/cmdline-tools | |
| 28 | 추가: ``` | |
| 29 | 추가: | |
| 30 | 추가: ```bash | |
| 31 | 추가: curl -fL -o /tmp/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-16111833_latest.zip | |
| 32 | 추가: ``` | |
| 33 | 추가: | |
| 34 | 추가: ```bash | |
| 35 | 추가: echo "e025545c62a8e64c7559119566a569fb1dec5f60 /tmp/cmdline-tools.zip" | sha1sum -c - | |
| 36 | 추가: ``` | |
| 37 | 추가: | |
| 38 | 추가: ```bash | |
| 39 | 추가: unzip -q /tmp/cmdline-tools.zip -d ~/Android/Sdk/cmdline-tools && mv ~/Android/Sdk/cmdline-tools/cmdline-tools ~/Android/Sdk/cmdline-tools/latest | |
| 40 | 추가: ``` | |
| 41 | 추가: | |
| 42 | 추가: 환경 변수를 `~/.profile`에 추가하고 현재 셸에 적용한다. | |
| 43 | 추가: | |
| 44 | 추가: ```bash | |
| 45 | 추가: cat >> ~/.profile <<'EOF' | |
| 46 | 추가: export ANDROID_HOME="$HOME/Android/Sdk" | |
| 47 | 추가: export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH" | |
| 48 | 추가: EOF | |
| 49 | 추가: ``` | |
| 50 | 추가: | |
| 51 | 추가: ```bash | |
| 52 | 추가: source ~/.profile | |
| 53 | 추가: ``` | |
| 54 | 추가: | |
| 55 | 추가: SDK 라이선스를 확인하고 동의한다(직접 읽고 `y` 입력). | |
| 56 | 추가: | |
| 57 | 추가: ```bash | |
| 58 | 추가: sdkmanager --licenses | |
| 59 | 추가: ``` | |
| 60 | 추가: | |
| 61 | 추가: ```bash | |
| 62 | 추가: sdkmanager "platform-tools" "platforms;android-36" "build-tools;36.1.0" | |
| 63 | 추가: ``` | |
| 64 | 추가: | |
| 65 | 추가: ## 3. 확인 | |
| 66 | 추가: | |
| 67 | 추가: ```bash | |
| 68 | 추가: javac -version && adb version && vainfo 2>&1 | grep -i 'driver version' && vulkaninfo --summary 2>/dev/null | grep -i devicename | |
| 69 | 추가: ``` | |
| 70 | 추가: | |
| 71 | 추가: ```bash | |
| 72 | 추가: cd android && ./gradlew assembleDebug | |
| 73 | 추가: ``` | |
| 74 | 추가: | |
| 75 | 추가: ## 테스트 기기 준비 (Galaxy S21+, Android 15) | |
| 76 | 추가: | |
| 77 | 추가: 1. 설정 > 휴대전화 정보 > 소프트웨어 정보 > 빌드번호를 7번 눌러 개발자 옵션을 켠다. | |
| 78 | 추가: 2. 개발자 옵션에서 USB 디버깅과 무선 디버깅을 켠다. | |
| 79 | 추가: 3. 설정 > 보안 및 개인정보 보호 > 자동 차단(Auto Blocker)이 켜져 있으면 끈다. | |
| 80 | 추가: 4. USB로 연결한 뒤 `adb devices`로 기기가 `device` 상태로 보이는지 확인한다. |
| @@ -1,7 +1,9 @@ | ||
| 1 | 추가: mod ui; | |
| 2 | 추가: | |
| 1 | 3 | fn main() { |
| 2 | 삭제: println!( | |
| 3 | 삭제: "android-remote {} (protocol v{}): 아직 구현 전입니다.", | |
| 4 | 삭제: env!("CARGO_PKG_VERSION"), | |
| 5 | 삭제: wayland_android_remote::protocol::VERSION | |
| 6 | 삭제: ); | |
| 4 | 추가: env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); | |
| 5 | 추가: if let Err(e) = ui::run() { | |
| 6 | 추가: log::error!("{e}"); | |
| 7 | 추가: std::process::exit(1); | |
| 8 | 추가: } | |
| 7 | 9 | } |
Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기| @@ -5,9 +5,17 @@ | ||
| 5 | 5 | //! 여러 프레임이 한 번에 도착하는 경우를 모두 처리한다. |
| 6 | 6 | |
| 7 | 7 | mod frame; |
| 8 | 추가: mod messages; | |
| 8 | 9 | mod msg_type; |
| 9 | 10 | |
| 10 | 11 | pub use frame::{Frame, FrameDecoder, FrameHeader, encode_frame}; |
| 12 | 추가: pub use messages::{ | |
| 13 | 추가: AuthChallenge, AuthGrant, AuthHello, AuthResponse, AuthResult, AuthResultCode, AuthStatus, | |
| 14 | 추가: ChannelAttach, ChannelKind, ClipboardMime, ClipboardOrigin, ClipboardSync, CodecMask, | |
| 15 | 추가: ErrorMessage, KeyAction, KeyEvent, MAX_HOSTNAME_LEN, MAX_VIDEO_DATA_LEN, Message, ScrollEvent, | |
| 16 | 추가: SystemAction, TextInput, TouchAction, TouchEvent, VIDEO_HEADER_LEN, VideoCodec, VideoConfig, | |
| 17 | 추가: VideoConfigRequest, VideoPacketHeader, auth_signing_message, check_empty, error_code, | |
| 18 | 추가: }; | |
| 11 | 19 | pub use msg_type::MsgType; |
| 12 | 20 | |
| 13 | 21 | /// 프로토콜 식별자 (ASCII 'A', 'R'). |
| @@ -27,13 +35,25 @@ pub mod flags { | ||
| 27 | 35 | pub const COMPRESSED: u16 = 0x0002; |
| 28 | 36 | } |
| 29 | 37 | |
| 30 | 삭제: /// 프레임 디코딩 중 발생하는 오류. 발생하면 스트림 동기가 깨진 것이므로 연결을 끊는다. | |
| 38 | 추가: /// 프레임·페이로드 디코딩 중 발생하는 오류. | |
| 39 | 추가: /// | |
| 40 | 추가: /// 헤더 오류는 스트림 동기가 깨진 것이므로 연결을 끊는다. 페이로드 오류는 프레임 경계는 | |
| 41 | 추가: /// 유지되므로 ERROR 응답 후 계속할지 호출 측이 정한다. | |
| 31 | 42 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 32 | 43 | pub enum ProtocolError { |
| 33 | 44 | BadMagic(u16), |
| 34 | 45 | UnsupportedVersion(u8), |
| 35 | 46 | UnknownMsgType(u8), |
| 36 | 47 | PayloadTooLarge(u32), |
| 48 | 추가: /// 페이로드 길이·코드 값·UTF-8 등이 메시지 규격에 맞지 않음. | |
| 49 | 추가: InvalidPayload { | |
| 50 | 추가: msg_type: MsgType, | |
| 51 | 추가: reason: &'static str, | |
| 52 | 추가: }, | |
| 53 | 추가: /// 비디오 채널 패킷 헤더가 규격에 맞지 않음. | |
| 54 | 추가: InvalidVideoHeader(&'static str), | |
| 55 | 추가: /// 비디오 패킷 `data_len`이 [`MAX_VIDEO_DATA_LEN`]을 넘음. | |
| 56 | 추가: VideoDataTooLarge(u32), | |
| 37 | 57 | } |
| 38 | 58 | |
| 39 | 59 | impl std::fmt::Display for ProtocolError { |
| @@ -45,6 +65,13 @@ impl std::fmt::Display for ProtocolError { | ||
| 45 | 65 | Self::PayloadTooLarge(n) => { |
| 46 | 66 | write!(f, "payload_len {n}이 상한 {MAX_PAYLOAD_LEN}을 넘음") |
| 47 | 67 | } |
| 68 | 추가: Self::InvalidPayload { msg_type, reason } => { | |
| 69 | 추가: write!(f, "잘못된 {msg_type:?} 페이로드: {reason}") | |
| 70 | 추가: } | |
| 71 | 추가: Self::InvalidVideoHeader(reason) => write!(f, "잘못된 비디오 패킷 헤더: {reason}"), | |
| 72 | 추가: Self::VideoDataTooLarge(n) => { | |
| 73 | 추가: write!(f, "비디오 data_len {n}이 상한 {MAX_VIDEO_DATA_LEN}을 넘음") | |
| 74 | 추가: } | |
| 48 | 75 | } |
| 49 | 76 | } |
| 50 | 77 | } |
| @@ -0,0 +1,46 @@ | ||
| 1 | 추가: //! 한글 표시용 시스템 폰트 등록. egui 기본 폰트에는 한글 글리프가 없다. | |
| 2 | 추가: | |
| 3 | 추가: use std::process::Command; | |
| 4 | 추가: use std::sync::Arc; | |
| 5 | 추가: | |
| 6 | 추가: use egui::{FontData, FontDefinitions, FontFamily}; | |
| 7 | 추가: | |
| 8 | 추가: const FALLBACK_PATH: &str = "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"; | |
| 9 | 추가: | |
| 10 | 추가: /// fontconfig에서 한국어 sans 폰트를 찾아 모든 글꼴 계열의 대체 폰트로 추가한다. | |
| 11 | 추가: pub fn install_korean_font(ctx: &egui::Context) { | |
| 12 | 추가: let (path, index) = fc_match_korean().unwrap_or_else(|| (FALLBACK_PATH.to_owned(), 0)); | |
| 13 | 추가: let bytes = match std::fs::read(&path) { | |
| 14 | 추가: Ok(b) => b, | |
| 15 | 추가: Err(e) => { | |
| 16 | 추가: log::warn!("한글 폰트를 읽지 못했습니다 ({path}): {e}"); | |
| 17 | 추가: return; | |
| 18 | 추가: } | |
| 19 | 추가: }; | |
| 20 | 추가: | |
| 21 | 추가: let mut data = FontData::from_owned(bytes); | |
| 22 | 추가: data.index = index; | |
| 23 | 추가: | |
| 24 | 추가: let mut fonts = FontDefinitions::default(); | |
| 25 | 추가: fonts.font_data.insert("korean".to_owned(), Arc::new(data)); | |
| 26 | 추가: for family in [FontFamily::Proportional, FontFamily::Monospace] { | |
| 27 | 추가: fonts | |
| 28 | 추가: .families | |
| 29 | 추가: .entry(family) | |
| 30 | 추가: .or_default() | |
| 31 | 추가: .push("korean".to_owned()); | |
| 32 | 추가: } | |
| 33 | 추가: ctx.set_fonts(fonts); | |
| 34 | 추가: } | |
| 35 | 추가: | |
| 36 | 추가: fn fc_match_korean() -> Option<(String, u32)> { | |
| 37 | 추가: let out = Command::new("fc-match") | |
| 38 | 추가: .args(["-f", "%{file}\n%{index}", "sans-serif:lang=ko"]) | |
| 39 | 추가: .output() | |
| 40 | 추가: .ok()?; | |
| 41 | 추가: let text = String::from_utf8(out.stdout).ok()?; | |
| 42 | 추가: let mut lines = text.lines(); | |
| 43 | 추가: let path = lines.next()?.trim().to_owned(); | |
| 44 | 추가: let index = lines.next()?.trim().parse().ok()?; | |
| 45 | 추가: (!path.is_empty()).then_some((path, index)) | |
| 46 | 추가: } |
| @@ -0,0 +1,79 @@ | ||
| 1 | 추가: //! 창 각 영역의 크기와 위치 (기획서 4.1 ~ 4.3). 단위는 논리 픽셀. | |
| 2 | 추가: | |
| 3 | 추가: use egui::{Rect, Vec2, pos2, vec2}; | |
| 4 | 추가: | |
| 5 | 추가: /// 왼쪽 풀-하이트 토글 버튼 너비. | |
| 6 | 추가: pub const TOGGLE_W: f32 = 14.0; | |
| 7 | 추가: /// 펼쳤을 때 사이드 메뉴 너비. | |
| 8 | 추가: pub const PANEL_W: f32 = 232.0; | |
| 9 | 추가: /// 얇은 상단 제목 표시줄 높이. | |
| 10 | 추가: pub const TITLE_H: f32 = 22.0; | |
| 11 | 추가: /// 뷰포트를 감싸는 검은 테두리 두께. | |
| 12 | 추가: pub const BORDER: f32 = 4.0; | |
| 13 | 추가: /// 연결 전 기본 뷰포트 크기. Galaxy S21+ 화면 비율(1080x2400, 9:20)에 맞춘다. | |
| 14 | 추가: pub const DEFAULT_VIEWPORT: Vec2 = vec2(360.0, 800.0); | |
| 15 | 추가: | |
| 16 | 추가: /// 한 프레임의 영역 배치. | |
| 17 | 추가: #[derive(Debug, Clone, Copy)] | |
| 18 | 추가: pub struct Layout { | |
| 19 | 추가: pub toggle: Rect, | |
| 20 | 추가: pub panel: Option<Rect>, | |
| 21 | 추가: pub title_bar: Rect, | |
| 22 | 추가: pub viewport: Rect, | |
| 23 | 추가: } | |
| 24 | 추가: | |
| 25 | 추가: /// 뷰포트 크기와 사이드 메뉴 상태로 창 안쪽 크기를 계산한다. | |
| 26 | 추가: pub fn window_size(viewport: Vec2, panel_open: bool) -> Vec2 { | |
| 27 | 추가: let panel = if panel_open { PANEL_W } else { 0.0 }; | |
| 28 | 추가: vec2( | |
| 29 | 추가: TOGGLE_W + panel + BORDER * 2.0 + viewport.x, | |
| 30 | 추가: TITLE_H + viewport.y + BORDER, | |
| 31 | 추가: ) | |
| 32 | 추가: } | |
| 33 | 추가: | |
| 34 | 추가: /// 창 전체 영역을 [토글][사이드 메뉴][제목 표시줄 + 뷰포트] 순서로 나눈다. | |
| 35 | 추가: pub fn compute(screen: Rect, panel_open: bool) -> Layout { | |
| 36 | 추가: let toggle = Rect::from_min_size(screen.min, vec2(TOGGLE_W, screen.height())); | |
| 37 | 추가: let mut x = toggle.max.x; | |
| 38 | 추가: | |
| 39 | 추가: let panel = panel_open.then(|| { | |
| 40 | 추가: let r = Rect::from_min_max(pos2(x, screen.min.y), pos2(x + PANEL_W, screen.max.y)); | |
| 41 | 추가: x = r.max.x; | |
| 42 | 추가: r | |
| 43 | 추가: }); | |
| 44 | 추가: | |
| 45 | 추가: let title_bar = Rect::from_min_max(pos2(x, screen.min.y), pos2(screen.max.x, TITLE_H)); | |
| 46 | 추가: let viewport = Rect::from_min_max( | |
| 47 | 추가: pos2(x + BORDER, title_bar.max.y), | |
| 48 | 추가: pos2(screen.max.x - BORDER, screen.max.y - BORDER), | |
| 49 | 추가: ); | |
| 50 | 추가: | |
| 51 | 추가: Layout { | |
| 52 | 추가: toggle, | |
| 53 | 추가: panel, | |
| 54 | 추가: title_bar, | |
| 55 | 추가: viewport, | |
| 56 | 추가: } | |
| 57 | 추가: } | |
| 58 | 추가: | |
| 59 | 추가: #[cfg(test)] | |
| 60 | 추가: mod tests { | |
| 61 | 추가: use super::*; | |
| 62 | 추가: | |
| 63 | 추가: #[test] | |
| 64 | 추가: fn viewport_keeps_requested_size() { | |
| 65 | 추가: for open in [false, true] { | |
| 66 | 추가: let size = window_size(DEFAULT_VIEWPORT, open); | |
| 67 | 추가: let layout = compute(Rect::from_min_size(pos2(0.0, 0.0), size), open); | |
| 68 | 추가: assert_eq!(layout.viewport.size(), DEFAULT_VIEWPORT); | |
| 69 | 추가: assert_eq!(layout.panel.is_some(), open); | |
| 70 | 추가: } | |
| 71 | 추가: } | |
| 72 | 추가: | |
| 73 | 추가: #[test] | |
| 74 | 추가: fn opening_panel_adds_only_panel_width() { | |
| 75 | 추가: let closed = window_size(DEFAULT_VIEWPORT, false); | |
| 76 | 추가: let open = window_size(DEFAULT_VIEWPORT, true); | |
| 77 | 추가: assert_eq!(open - closed, vec2(PANEL_W, 0.0)); | |
| 78 | 추가: } | |
| 79 | 추가: } |
| @@ -0,0 +1,230 @@ | ||
| 1 | 추가: //! 호스트 GUI. winit 창 위에 wgpu로 직접 그리고, 설정·입력 UI는 egui로 같은 렌더 패스에 얹는다. | |
| 2 | 추가: //! 영상은 이후 같은 wgpu 디바이스에 텍스처로 올려 그린다. | |
| 3 | 추가: | |
| 4 | 추가: mod fonts; | |
| 5 | 추가: mod layout; | |
| 6 | 추가: mod recent; | |
| 7 | 추가: mod view; | |
| 8 | 추가: | |
| 9 | 추가: use std::num::NonZeroU32; | |
| 10 | 추가: use std::sync::Arc; | |
| 11 | 추가: use std::time::{Duration, Instant}; | |
| 12 | 추가: | |
| 13 | 추가: use egui::ViewportId; | |
| 14 | 추가: use egui_wgpu::winit::Painter; | |
| 15 | 추가: use egui_wgpu::{RendererOptions, SurfaceConfig, WgpuConfiguration, WgpuSetup, WgpuSetupCreateNew}; | |
| 16 | 추가: use egui_winit::winit; | |
| 17 | 추가: use winit::application::ApplicationHandler; | |
| 18 | 추가: use winit::dpi::{LogicalSize, PhysicalPosition}; | |
| 19 | 추가: use winit::event::WindowEvent; | |
| 20 | 추가: use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; | |
| 21 | 추가: use winit::window::{Window, WindowId}; | |
| 22 | 추가: | |
| 23 | 추가: use view::{Actions, View}; | |
| 24 | 추가: | |
| 25 | 추가: /// 이벤트 루프를 만들고 창이 닫힐 때까지 실행한다. | |
| 26 | 추가: pub fn run() -> Result<(), Box<dyn std::error::Error>> { | |
| 27 | 추가: let event_loop = EventLoop::new()?; | |
| 28 | 추가: let mut app = App::new(); | |
| 29 | 추가: event_loop.run_app(&mut app)?; | |
| 30 | 추가: Ok(()) | |
| 31 | 추가: } | |
| 32 | 추가: | |
| 33 | 추가: struct Gfx { | |
| 34 | 추가: window: Arc<Window>, | |
| 35 | 추가: painter: Painter, | |
| 36 | 추가: egui_winit: egui_winit::State, | |
| 37 | 추가: } | |
| 38 | 추가: | |
| 39 | 추가: struct App { | |
| 40 | 추가: ctx: egui::Context, | |
| 41 | 추가: view: View, | |
| 42 | 추가: gfx: Option<Gfx>, | |
| 43 | 추가: next_repaint: Option<Instant>, | |
| 44 | 추가: } | |
| 45 | 추가: | |
| 46 | 추가: impl App { | |
| 47 | 추가: fn new() -> Self { | |
| 48 | 추가: let ctx = egui::Context::default(); | |
| 49 | 추가: ctx.set_visuals(egui::Visuals::dark()); | |
| 50 | 추가: fonts::install_korean_font(&ctx); | |
| 51 | 추가: Self { | |
| 52 | 추가: ctx, | |
| 53 | 추가: view: View::new(), | |
| 54 | 추가: gfx: None, | |
| 55 | 추가: next_repaint: None, | |
| 56 | 추가: } | |
| 57 | 추가: } | |
| 58 | 추가: | |
| 59 | 추가: fn init_gfx(&self, event_loop: &ActiveEventLoop) -> Result<Gfx, Box<dyn std::error::Error>> { | |
| 60 | 추가: let size = self.view.window_size(); | |
| 61 | 추가: let attrs = Window::default_attributes() | |
| 62 | 추가: .with_title("Android Remote") | |
| 63 | 추가: .with_decorations(false) | |
| 64 | 추가: .with_resizable(false) | |
| 65 | 추가: .with_inner_size(LogicalSize::new(size.x, size.y)); | |
| 66 | 추가: let window = Arc::new(event_loop.create_window(attrs)?); | |
| 67 | 추가: | |
| 68 | 추가: let mut setup = WgpuSetupCreateNew::from_display_handle(event_loop.owned_display_handle()); | |
| 69 | 추가: setup.power_preference = egui_wgpu::wgpu::PowerPreference::HighPerformance; | |
| 70 | 추가: let config = WgpuConfiguration { | |
| 71 | 추가: // 프레임 큐를 1장으로 제한해 입력에서 화면까지의 지연을 줄인다. | |
| 72 | 추가: surface: SurfaceConfig::LOW_LATENCY, | |
| 73 | 추가: wgpu_setup: WgpuSetup::CreateNew(setup), | |
| 74 | 추가: ..Default::default() | |
| 75 | 추가: }; | |
| 76 | 추가: let mut painter = pollster::block_on(Painter::new( | |
| 77 | 추가: self.ctx.clone(), | |
| 78 | 추가: config, | |
| 79 | 추가: false, | |
| 80 | 추가: RendererOptions::default(), | |
| 81 | 추가: )); | |
| 82 | 추가: pollster::block_on(painter.set_window(ViewportId::ROOT, Some(window.clone())))?; | |
| 83 | 추가: if let Some(rs) = painter.render_state() { | |
| 84 | 추가: let info = rs.adapter.get_info(); | |
| 85 | 추가: log::info!("GPU: {} ({:?})", info.name, info.backend); | |
| 86 | 추가: } | |
| 87 | 추가: | |
| 88 | 추가: let egui_winit = egui_winit::State::new( | |
| 89 | 추가: self.ctx.clone(), | |
| 90 | 추가: ViewportId::ROOT, | |
| 91 | 추가: event_loop, | |
| 92 | 추가: Some(window.scale_factor() as f32), | |
| 93 | 추가: window.theme(), | |
| 94 | 추가: painter.max_texture_side(), | |
| 95 | 추가: ); | |
| 96 | 추가: | |
| 97 | 추가: Ok(Gfx { | |
| 98 | 추가: window, | |
| 99 | 추가: painter, | |
| 100 | 추가: egui_winit, | |
| 101 | 추가: }) | |
| 102 | 추가: } | |
| 103 | 추가: | |
| 104 | 추가: fn redraw(&mut self, event_loop: &ActiveEventLoop) { | |
| 105 | 추가: let Some(gfx) = self.gfx.as_mut() else { | |
| 106 | 추가: return; | |
| 107 | 추가: }; | |
| 108 | 추가: let raw_input = gfx.egui_winit.take_egui_input(&gfx.window); | |
| 109 | 추가: let mut actions = Actions::default(); | |
| 110 | 추가: let view = &mut self.view; | |
| 111 | 추가: let output = self.ctx.run_ui(raw_input, |ui| view.ui(ui, &mut actions)); | |
| 112 | 추가: | |
| 113 | 추가: gfx.egui_winit | |
| 114 | 추가: .handle_platform_output(&gfx.window, output.platform_output); | |
| 115 | 추가: let primitives = self.ctx.tessellate(output.shapes, output.pixels_per_point); | |
| 116 | 추가: let mut textures = output.textures_delta; | |
| 117 | 추가: gfx.painter.paint_and_update_textures( | |
| 118 | 추가: ViewportId::ROOT, | |
| 119 | 추가: output.pixels_per_point, | |
| 120 | 추가: [0.0, 0.0, 0.0, 1.0], | |
| 121 | 추가: &primitives, | |
| 122 | 추가: &mut textures, | |
| 123 | 추가: Vec::new(), | |
| 124 | 추가: &gfx.window, | |
| 125 | 추가: ); | |
| 126 | 추가: | |
| 127 | 추가: let delay = output | |
| 128 | 추가: .viewport_output | |
| 129 | 추가: .get(&ViewportId::ROOT) | |
| 130 | 추가: .map_or(Duration::MAX, |v| v.repaint_delay); | |
| 131 | 추가: if delay.is_zero() { | |
| 132 | 추가: gfx.window.request_redraw(); | |
| 133 | 추가: } else { | |
| 134 | 추가: self.next_repaint = Instant::now().checked_add(delay); | |
| 135 | 추가: } | |
| 136 | 추가: | |
| 137 | 추가: self.apply(actions, event_loop); | |
| 138 | 추가: } | |
| 139 | 추가: | |
| 140 | 추가: fn apply(&mut self, actions: Actions, event_loop: &ActiveEventLoop) { | |
| 141 | 추가: let Some(gfx) = &self.gfx else { return }; | |
| 142 | 추가: let window = &gfx.window; | |
| 143 | 추가: if actions.close { | |
| 144 | 추가: event_loop.exit(); | |
| 145 | 추가: return; | |
| 146 | 추가: } | |
| 147 | 추가: if actions.start_drag | |
| 148 | 추가: && let Err(e) = window.drag_window() | |
| 149 | 추가: { | |
| 150 | 추가: log::debug!("창 이동 실패: {e}"); | |
| 151 | 추가: } | |
| 152 | 추가: if actions.minimize { | |
| 153 | 추가: window.set_minimized(true); | |
| 154 | 추가: } | |
| 155 | 추가: if let Some(open) = actions.panel_toggled { | |
| 156 | 추가: let size = self.view.window_size(); | |
| 157 | 추가: // X11에서는 창을 왼쪽으로 옮겨 뷰포트 위치를 유지한다. Wayland는 클라이언트가 | |
| 158 | 추가: // 창 위치를 정할 수 없어 오른쪽으로 넓어진다. | |
| 159 | 추가: if let Ok(pos) = window.outer_position() { | |
| 160 | 추가: let dx = (layout::PANEL_W as f64 * window.scale_factor()).round() as i32; | |
| 161 | 추가: let x = if open { pos.x - dx } else { pos.x + dx }; | |
| 162 | 추가: window.set_outer_position(PhysicalPosition::new(x, pos.y)); | |
| 163 | 추가: } | |
| 164 | 추가: let _ = window.request_inner_size(LogicalSize::new(size.x, size.y)); | |
| 165 | 추가: window.request_redraw(); | |
| 166 | 추가: } | |
| 167 | 추가: } | |
| 168 | 추가: } | |
| 169 | 추가: | |
| 170 | 추가: impl ApplicationHandler for App { | |
| 171 | 추가: fn resumed(&mut self, event_loop: &ActiveEventLoop) { | |
| 172 | 추가: if self.gfx.is_some() { | |
| 173 | 추가: return; | |
| 174 | 추가: } | |
| 175 | 추가: match self.init_gfx(event_loop) { | |
| 176 | 추가: Ok(gfx) => { | |
| 177 | 추가: gfx.window.request_redraw(); | |
| 178 | 추가: self.gfx = Some(gfx); | |
| 179 | 추가: } | |
| 180 | 추가: Err(e) => { | |
| 181 | 추가: log::error!("창 또는 GPU 초기화 실패: {e}"); | |
| 182 | 추가: event_loop.exit(); | |
| 183 | 추가: } | |
| 184 | 추가: } | |
| 185 | 추가: } | |
| 186 | 추가: | |
| 187 | 추가: fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) { | |
| 188 | 추가: let Some(gfx) = self.gfx.as_mut() else { | |
| 189 | 추가: return; | |
| 190 | 추가: }; | |
| 191 | 추가: let response = gfx.egui_winit.on_window_event(&gfx.window, &event); | |
| 192 | 추가: | |
| 193 | 추가: match event { | |
| 194 | 추가: WindowEvent::CloseRequested => { | |
| 195 | 추가: event_loop.exit(); | |
| 196 | 추가: return; | |
| 197 | 추가: } | |
| 198 | 추가: WindowEvent::Resized(size) => { | |
| 199 | 추가: if let (Some(w), Some(h)) = | |
| 200 | 추가: (NonZeroU32::new(size.width), NonZeroU32::new(size.height)) | |
| 201 | 추가: { | |
| 202 | 추가: gfx.painter.on_window_resized(ViewportId::ROOT, w, h); | |
| 203 | 추가: } | |
| 204 | 추가: } | |
| 205 | 추가: WindowEvent::RedrawRequested => { | |
| 206 | 추가: self.redraw(event_loop); | |
| 207 | 추가: return; | |
| 208 | 추가: } | |
| 209 | 추가: _ => {} | |
| 210 | 추가: } | |
| 211 | 추가: | |
| 212 | 추가: if response.repaint { | |
| 213 | 추가: gfx.window.request_redraw(); | |
| 214 | 추가: } | |
| 215 | 추가: } | |
| 216 | 추가: | |
| 217 | 추가: fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { | |
| 218 | 추가: match self.next_repaint { | |
| 219 | 추가: Some(at) if at <= Instant::now() => { | |
| 220 | 추가: self.next_repaint = None; | |
| 221 | 추가: if let Some(gfx) = &self.gfx { | |
| 222 | 추가: gfx.window.request_redraw(); | |
| 223 | 추가: } | |
| 224 | 추가: event_loop.set_control_flow(ControlFlow::Wait); | |
| 225 | 추가: } | |
| 226 | 추가: Some(at) => event_loop.set_control_flow(ControlFlow::WaitUntil(at)), | |
| 227 | 추가: None => event_loop.set_control_flow(ControlFlow::Wait), | |
| 228 | 추가: } | |
| 229 | 추가: } | |
| 230 | 추가: } |
| @@ -0,0 +1,147 @@ | ||
| 1 | 추가: //! 접속 주소 파싱과 최근 접속 IP 기록 (기획서 4.4). | |
| 2 | 추가: | |
| 3 | 추가: use std::fs; | |
| 4 | 추가: use std::io; | |
| 5 | 추가: use std::net::{IpAddr, SocketAddr}; | |
| 6 | 추가: use std::path::PathBuf; | |
| 7 | 추가: | |
| 8 | 추가: /// 데몬 기본 포트 (기획서 5.4). | |
| 9 | 추가: pub const DEFAULT_PORT: u16 = 27200; | |
| 10 | 추가: /// 최근 접속 기록 최대 개수. | |
| 11 | 추가: const MAX_RECENT: usize = 8; | |
| 12 | 추가: | |
| 13 | 추가: /// 'IP' 또는 'IP:포트' 입력을 소켓 주소로 바꾼다. IPv6는 '[::1]:27200' 형식도 받는다. | |
| 14 | 추가: pub fn parse_target(input: &str) -> Result<SocketAddr, &'static str> { | |
| 15 | 추가: let s = input.trim(); | |
| 16 | 추가: if s.is_empty() { | |
| 17 | 추가: return Err("IP 주소를 입력하세요"); | |
| 18 | 추가: } | |
| 19 | 추가: if let Ok(addr) = s.parse::<SocketAddr>() { | |
| 20 | 추가: if addr.port() == 0 { | |
| 21 | 추가: return Err("포트 번호가 올바르지 않습니다"); | |
| 22 | 추가: } | |
| 23 | 추가: return Ok(addr); | |
| 24 | 추가: } | |
| 25 | 추가: if let Ok(ip) = s.parse::<IpAddr>() { | |
| 26 | 추가: return Ok(SocketAddr::new(ip, DEFAULT_PORT)); | |
| 27 | 추가: } | |
| 28 | 추가: Err("IP 주소 형식이 올바르지 않습니다") | |
| 29 | 추가: } | |
| 30 | 추가: | |
| 31 | 추가: /// 기본 포트면 IP만, 아니면 'IP:포트'로 표시한다. | |
| 32 | 추가: pub fn display_target(addr: SocketAddr) -> String { | |
| 33 | 추가: if addr.port() == DEFAULT_PORT { | |
| 34 | 추가: addr.ip().to_string() | |
| 35 | 추가: } else { | |
| 36 | 추가: addr.to_string() | |
| 37 | 추가: } | |
| 38 | 추가: } | |
| 39 | 추가: | |
| 40 | 추가: /// 최근 접속에 성공한 주소 목록. 가장 최근 것이 맨 앞이다. | |
| 41 | 추가: #[derive(Debug, Default)] | |
| 42 | 추가: pub struct RecentTargets { | |
| 43 | 추가: items: Vec<String>, | |
| 44 | 추가: path: Option<PathBuf>, | |
| 45 | 추가: } | |
| 46 | 추가: | |
| 47 | 추가: impl RecentTargets { | |
| 48 | 추가: /// `~/.config/android-remote/recent_ips`에서 읽는다. 파일이 없으면 빈 목록이다. | |
| 49 | 추가: pub fn load() -> Self { | |
| 50 | 추가: let path = config_dir().map(|d| d.join("recent_ips")); | |
| 51 | 추가: let items = path | |
| 52 | 추가: .as_ref() | |
| 53 | 추가: .and_then(|p| fs::read_to_string(p).ok()) | |
| 54 | 추가: .map(|s| parse_lines(&s)) | |
| 55 | 추가: .unwrap_or_default(); | |
| 56 | 추가: Self { items, path } | |
| 57 | 추가: } | |
| 58 | 추가: | |
| 59 | 추가: pub fn items(&self) -> &[String] { | |
| 60 | 추가: &self.items | |
| 61 | 추가: } | |
| 62 | 추가: | |
| 63 | 추가: /// 접속 성공한 주소를 맨 앞에 넣고 파일에 저장한다. | |
| 64 | 추가: #[expect(dead_code, reason = "AUTH_RESULT(OK) 수신 처리를 구현할 때 호출한다")] | |
| 65 | 추가: pub fn record(&mut self, target: &str) -> io::Result<()> { | |
| 66 | 추가: push_front_dedup(&mut self.items, target); | |
| 67 | 추가: let Some(path) = &self.path else { | |
| 68 | 추가: return Ok(()); | |
| 69 | 추가: }; | |
| 70 | 추가: if let Some(dir) = path.parent() { | |
| 71 | 추가: fs::create_dir_all(dir)?; | |
| 72 | 추가: } | |
| 73 | 추가: fs::write(path, self.items.join("\n") + "\n") | |
| 74 | 추가: } | |
| 75 | 추가: } | |
| 76 | 추가: | |
| 77 | 추가: fn parse_lines(s: &str) -> Vec<String> { | |
| 78 | 추가: let mut items = Vec::new(); | |
| 79 | 추가: for line in s.lines().map(str::trim).filter(|l| !l.is_empty()) { | |
| 80 | 추가: if parse_target(line).is_ok() && !items.iter().any(|i| i == line) { | |
| 81 | 추가: items.push(line.to_owned()); | |
| 82 | 추가: } | |
| 83 | 추가: } | |
| 84 | 추가: items.truncate(MAX_RECENT); | |
| 85 | 추가: items | |
| 86 | 추가: } | |
| 87 | 추가: | |
| 88 | 추가: fn push_front_dedup(items: &mut Vec<String>, target: &str) { | |
| 89 | 추가: items.retain(|i| i != target); | |
| 90 | 추가: items.insert(0, target.to_owned()); | |
| 91 | 추가: items.truncate(MAX_RECENT); | |
| 92 | 추가: } | |
| 93 | 추가: | |
| 94 | 추가: /// `$XDG_CONFIG_HOME/android-remote` 또는 `~/.config/android-remote`. | |
| 95 | 추가: pub fn config_dir() -> Option<PathBuf> { | |
| 96 | 추가: let base = std::env::var_os("XDG_CONFIG_HOME") | |
| 97 | 추가: .filter(|v| !v.is_empty()) | |
| 98 | 추가: .map(PathBuf::from) | |
| 99 | 추가: .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".config")))?; | |
| 100 | 추가: Some(base.join("android-remote")) | |
| 101 | 추가: } | |
| 102 | 추가: | |
| 103 | 추가: #[cfg(test)] | |
| 104 | 추가: mod tests { | |
| 105 | 추가: use super::*; | |
| 106 | 추가: | |
| 107 | 추가: #[test] | |
| 108 | 추가: fn parses_ip_with_default_port() { | |
| 109 | 추가: let addr = parse_target(" 192.168.0.12 ").unwrap(); | |
| 110 | 추가: assert_eq!(addr, "192.168.0.12:27200".parse().unwrap()); | |
| 111 | 추가: assert_eq!(display_target(addr), "192.168.0.12"); | |
| 112 | 추가: } | |
| 113 | 추가: | |
| 114 | 추가: #[test] | |
| 115 | 추가: fn parses_ip_with_port() { | |
| 116 | 추가: let addr = parse_target("100.64.1.2:5000").unwrap(); | |
| 117 | 추가: assert_eq!(addr.port(), 5000); | |
| 118 | 추가: assert_eq!(display_target(addr), "100.64.1.2:5000"); | |
| 119 | 추가: assert_eq!(parse_target("[fd00::1]:27200").unwrap().port(), 27200); | |
| 120 | 추가: } | |
| 121 | 추가: | |
| 122 | 추가: #[test] | |
| 123 | 추가: fn rejects_bad_input() { | |
| 124 | 추가: assert!(parse_target("").is_err()); | |
| 125 | 추가: assert!(parse_target("phone.local").is_err()); | |
| 126 | 추가: assert!(parse_target("192.168.0.300").is_err()); | |
| 127 | 추가: assert!(parse_target("10.0.0.1:0").is_err()); | |
| 128 | 추가: } | |
| 129 | 추가: | |
| 130 | 추가: #[test] | |
| 131 | 추가: fn recent_list_dedups_and_caps() { | |
| 132 | 추가: let mut items = Vec::new(); | |
| 133 | 추가: for i in 0..10 { | |
| 134 | 추가: push_front_dedup(&mut items, &format!("10.0.0.{i}")); | |
| 135 | 추가: } | |
| 136 | 추가: push_front_dedup(&mut items, "10.0.0.5"); | |
| 137 | 추가: assert_eq!(items.len(), MAX_RECENT); | |
| 138 | 추가: assert_eq!(items[0], "10.0.0.5"); | |
| 139 | 추가: assert_eq!(items.iter().filter(|i| *i == "10.0.0.5").count(), 1); | |
| 140 | 추가: } | |
| 141 | 추가: | |
| 142 | 추가: #[test] | |
| 143 | 추가: fn load_skips_invalid_lines() { | |
| 144 | 추가: let items = parse_lines("10.0.0.1\n\nnot-an-ip\n10.0.0.1\n10.0.0.2:5000\n"); | |
| 145 | 추가: assert_eq!(items, vec!["10.0.0.1", "10.0.0.2:5000"]); | |
| 146 | 추가: } | |
| 147 | 추가: } |
| @@ -0,0 +1,317 @@ | ||
| 1 | 추가: //! 화면 그리기와 사용자 조작 처리 (기획서 4절). 창 조작은 [`Actions`]로 돌려주고 | |
| 2 | 추가: //! 실제 winit 호출은 상위 [`super::App`]에서 한다. | |
| 3 | 추가: | |
| 4 | 추가: use std::net::SocketAddr; | |
| 5 | 추가: | |
| 6 | 추가: use egui::{ | |
| 7 | 추가: Align2, Button, Color32, FontId, Key, Rect, RichText, Sense, TextEdit, Ui, UiBuilder, Vec2, | |
| 8 | 추가: pos2, vec2, | |
| 9 | 추가: }; | |
| 10 | 추가: | |
| 11 | 추가: use super::layout::{self, DEFAULT_VIEWPORT, Layout}; | |
| 12 | 추가: use super::recent::{RecentTargets, display_target, parse_target}; | |
| 13 | 추가: | |
| 14 | 추가: const FRAME_COLOR: Color32 = Color32::BLACK; | |
| 15 | 추가: const PANEL_BG: Color32 = Color32::from_rgb(0x14, 0x14, 0x14); | |
| 16 | 추가: const DIM_TEXT: Color32 = Color32::from_rgb(0x8a, 0x8a, 0x8a); | |
| 17 | 추가: const INPUT_BG: Color32 = Color32::from_rgb(0x1c, 0x1c, 0x1c); | |
| 18 | 추가: const ERROR_TEXT: Color32 = Color32::from_rgb(0xe0, 0x6c, 0x6c); | |
| 19 | 추가: | |
| 20 | 추가: /// 한 프레임 동안 UI가 요청한 창 동작. | |
| 21 | 추가: #[derive(Debug, Default)] | |
| 22 | 추가: pub struct Actions { | |
| 23 | 추가: pub start_drag: bool, | |
| 24 | 추가: pub minimize: bool, | |
| 25 | 추가: pub close: bool, | |
| 26 | 추가: /// 사이드 메뉴 열림 상태가 바뀌었다. 값은 새 상태다. | |
| 27 | 추가: pub panel_toggled: Option<bool>, | |
| 28 | 추가: } | |
| 29 | 추가: | |
| 30 | 추가: #[derive(Debug, Clone, PartialEq)] | |
| 31 | 추가: enum Connection { | |
| 32 | 추가: /// 검은 화면과 IP 입력창 (기획서 4.4). | |
| 33 | 추가: Disconnected, | |
| 34 | 추가: /// 휴대폰 승인 대기. 네트워크 연결은 아직 구현 전이다. | |
| 35 | 추가: Connecting { target: SocketAddr }, | |
| 36 | 추가: } | |
| 37 | 추가: | |
| 38 | 추가: /// 사이드 메뉴 설정값 (기획서 4.3). 아직 기기로 전송하지는 않는다. | |
| 39 | 추가: #[derive(Debug, Clone)] | |
| 40 | 추가: struct StreamSettings { | |
| 41 | 추가: max_size: u16, | |
| 42 | 추가: max_fps: u8, | |
| 43 | 추가: bitrate_mbps: u32, | |
| 44 | 추가: sync_clipboard_on_focus: bool, | |
| 45 | 추가: usb_adb_mode: bool, | |
| 46 | 추가: } | |
| 47 | 추가: | |
| 48 | 추가: impl Default for StreamSettings { | |
| 49 | 추가: fn default() -> Self { | |
| 50 | 추가: Self { | |
| 51 | 추가: max_size: 1920, | |
| 52 | 추가: max_fps: 60, | |
| 53 | 추가: bitrate_mbps: 8, | |
| 54 | 추가: sync_clipboard_on_focus: false, | |
| 55 | 추가: usb_adb_mode: false, | |
| 56 | 추가: } | |
| 57 | 추가: } | |
| 58 | 추가: } | |
| 59 | 추가: | |
| 60 | 추가: pub struct View { | |
| 61 | 추가: panel_open: bool, | |
| 62 | 추가: viewport_size: Vec2, | |
| 63 | 추가: connection: Connection, | |
| 64 | 추가: ip_input: String, | |
| 65 | 추가: input_error: Option<String>, | |
| 66 | 추가: focus_input: bool, | |
| 67 | 추가: recent: RecentTargets, | |
| 68 | 추가: settings: StreamSettings, | |
| 69 | 추가: } | |
| 70 | 추가: | |
| 71 | 추가: impl View { | |
| 72 | 추가: pub fn new() -> Self { | |
| 73 | 추가: Self { | |
| 74 | 추가: panel_open: false, | |
| 75 | 추가: viewport_size: DEFAULT_VIEWPORT, | |
| 76 | 추가: connection: Connection::Disconnected, | |
| 77 | 추가: ip_input: String::new(), | |
| 78 | 추가: input_error: None, | |
| 79 | 추가: focus_input: true, | |
| 80 | 추가: recent: RecentTargets::load(), | |
| 81 | 추가: settings: StreamSettings::default(), | |
| 82 | 추가: } | |
| 83 | 추가: } | |
| 84 | 추가: | |
| 85 | 추가: /// 현재 상태에 맞는 창 안쪽 크기 (논리 픽셀). | |
| 86 | 추가: pub fn window_size(&self) -> Vec2 { | |
| 87 | 추가: layout::window_size(self.viewport_size, self.panel_open) | |
| 88 | 추가: } | |
| 89 | 추가: | |
| 90 | 추가: pub fn ui(&mut self, ui: &mut Ui, actions: &mut Actions) { | |
| 91 | 추가: let screen = ui.max_rect(); | |
| 92 | 추가: let layout = layout::compute(screen, self.panel_open); | |
| 93 | 추가: | |
| 94 | 추가: ui.painter().rect_filled(screen, 0.0, FRAME_COLOR); | |
| 95 | 추가: | |
| 96 | 추가: self.toggle_button(ui, &layout, actions); | |
| 97 | 추가: if let Some(panel) = layout.panel { | |
| 98 | 추가: self.side_panel(ui, panel); | |
| 99 | 추가: } | |
| 100 | 추가: title_bar(ui, layout.title_bar, actions); | |
| 101 | 추가: ui.painter() | |
| 102 | 추가: .rect_filled(layout.viewport, 0.0, Color32::BLACK); | |
| 103 | 추가: | |
| 104 | 추가: match self.connection.clone() { | |
| 105 | 추가: Connection::Disconnected => self.disconnected_screen(ui, layout.viewport), | |
| 106 | 추가: Connection::Connecting { target } => { | |
| 107 | 추가: self.connecting_screen(ui, layout.viewport, target) | |
| 108 | 추가: } | |
| 109 | 추가: } | |
| 110 | 추가: } | |
| 111 | 추가: | |
| 112 | 추가: fn toggle_button(&mut self, ui: &mut Ui, layout: &Layout, actions: &mut Actions) { | |
| 113 | 추가: let resp = ui.interact(layout.toggle, egui::Id::unique("toggle"), Sense::click()); | |
| 114 | 추가: let color = if resp.hovered() { | |
| 115 | 추가: Color32::from_gray(0x2a) | |
| 116 | 추가: } else { | |
| 117 | 추가: FRAME_COLOR | |
| 118 | 추가: }; | |
| 119 | 추가: ui.painter().rect_filled(layout.toggle, 0.0, color); | |
| 120 | 추가: let symbol = if self.panel_open { ">" } else { "<" }; | |
| 121 | 추가: ui.painter().text( | |
| 122 | 추가: layout.toggle.center(), | |
| 123 | 추가: Align2::CENTER_CENTER, | |
| 124 | 추가: symbol, | |
| 125 | 추가: FontId::monospace(13.0), | |
| 126 | 추가: DIM_TEXT, | |
| 127 | 추가: ); | |
| 128 | 추가: if resp.clicked() { | |
| 129 | 추가: self.panel_open = !self.panel_open; | |
| 130 | 추가: actions.panel_toggled = Some(self.panel_open); | |
| 131 | 추가: } | |
| 132 | 추가: } | |
| 133 | 추가: | |
| 134 | 추가: fn side_panel(&mut self, ui: &mut Ui, rect: Rect) { | |
| 135 | 추가: ui.painter().rect_filled(rect, 0.0, PANEL_BG); | |
| 136 | 추가: let connected = false; | |
| 137 | 추가: let inner = rect.shrink2(vec2(14.0, 16.0)); | |
| 138 | 추가: ui.scope_builder(UiBuilder::new().max_rect(inner), |ui| { | |
| 139 | 추가: ui.spacing_mut().item_spacing.y = 10.0; | |
| 140 | 추가: let s = &mut self.settings; | |
| 141 | 추가: | |
| 142 | 추가: ui.label(RichText::new("해상도").color(DIM_TEXT)); | |
| 143 | 추가: egui::ComboBox::from_id_salt("max_size") | |
| 144 | 추가: .selected_text(size_label(s.max_size)) | |
| 145 | 추가: .width(inner.width()) | |
| 146 | 추가: .show_ui(ui, |ui| { | |
| 147 | 추가: for v in [0, 2400, 1920, 1600, 1280, 1024] { | |
| 148 | 추가: ui.selectable_value(&mut s.max_size, v, size_label(v)); | |
| 149 | 추가: } | |
| 150 | 추가: }); | |
| 151 | 추가: | |
| 152 | 추가: ui.label(RichText::new("FPS").color(DIM_TEXT)); | |
| 153 | 추가: ui.horizontal(|ui| { | |
| 154 | 추가: for v in [30, 60, 90, 120] { | |
| 155 | 추가: ui.selectable_value(&mut s.max_fps, v, v.to_string()); | |
| 156 | 추가: } | |
| 157 | 추가: }); | |
| 158 | 추가: | |
| 159 | 추가: ui.label(RichText::new("비트레이트").color(DIM_TEXT)); | |
| 160 | 추가: ui.add(egui::Slider::new(&mut s.bitrate_mbps, 2..=40).suffix(" Mbps")); | |
| 161 | 추가: | |
| 162 | 추가: ui.separator(); | |
| 163 | 추가: ui.checkbox( | |
| 164 | 추가: &mut s.sync_clipboard_on_focus, | |
| 165 | 추가: "창 포커스 시 클립보드 동기화", | |
| 166 | 추가: ); | |
| 167 | 추가: ui.checkbox(&mut s.usb_adb_mode, "USB ADB 모드"); | |
| 168 | 추가: | |
| 169 | 추가: ui.separator(); | |
| 170 | 추가: ui.add_enabled_ui(connected, |ui| { | |
| 171 | 추가: ui.horizontal(|ui| { | |
| 172 | 추가: for label in ["Back", "Home", "Recents"] { | |
| 173 | 추가: // 연결 후 SYSTEM_ACTION으로 전송한다. | |
| 174 | 추가: let _ = ui.button(label); | |
| 175 | 추가: } | |
| 176 | 추가: }); | |
| 177 | 추가: }); | |
| 178 | 추가: }); | |
| 179 | 추가: } | |
| 180 | 추가: | |
| 181 | 추가: fn disconnected_screen(&mut self, ui: &mut Ui, viewport: Rect) { | |
| 182 | 추가: let center = viewport.center(); | |
| 183 | 추가: let input_rect = Rect::from_center_size(center, vec2(220.0, 30.0)); | |
| 184 | 추가: | |
| 185 | 추가: let edit = TextEdit::singleline(&mut self.ip_input) | |
| 186 | 추가: .hint_text("IP 주소") | |
| 187 | 추가: .align(Align2::CENTER_CENTER) | |
| 188 | 추가: .background_color(INPUT_BG) | |
| 189 | 추가: .text_color(Color32::WHITE) | |
| 190 | 추가: .font(FontId::proportional(16.0)) | |
| 191 | 추가: .margin(vec2(8.0, 6.0)); | |
| 192 | 추가: let resp = ui.put(input_rect, edit); | |
| 193 | 추가: if std::mem::take(&mut self.focus_input) { | |
| 194 | 추가: resp.request_focus(); | |
| 195 | 추가: } | |
| 196 | 추가: if resp.changed() { | |
| 197 | 추가: self.input_error = None; | |
| 198 | 추가: } | |
| 199 | 추가: | |
| 200 | 추가: let enter = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)); | |
| 201 | 추가: if enter { | |
| 202 | 추가: let input = self.ip_input.clone(); | |
| 203 | 추가: self.try_connect(&input); | |
| 204 | 추가: } | |
| 205 | 추가: | |
| 206 | 추가: let mut y = input_rect.max.y + 8.0; | |
| 207 | 추가: if let Some(err) = &self.input_error { | |
| 208 | 추가: ui.painter().text( | |
| 209 | 추가: pos2(center.x, y), | |
| 210 | 추가: Align2::CENTER_TOP, | |
| 211 | 추가: err, | |
| 212 | 추가: FontId::proportional(13.0), | |
| 213 | 추가: ERROR_TEXT, | |
| 214 | 추가: ); | |
| 215 | 추가: y += 22.0; | |
| 216 | 추가: } | |
| 217 | 추가: | |
| 218 | 추가: if resp.has_focus() || self.ip_input.is_empty() { | |
| 219 | 추가: let mut picked = None; | |
| 220 | 추가: for item in self.recent.items() { | |
| 221 | 추가: let r = Rect::from_center_size(pos2(center.x, y + 12.0), vec2(220.0, 24.0)); | |
| 222 | 추가: let b = Button::new(RichText::new(item).color(DIM_TEXT)).frame(false); | |
| 223 | 추가: if ui.put(r, b).clicked() { | |
| 224 | 추가: picked = Some(item.clone()); | |
| 225 | 추가: } | |
| 226 | 추가: y += 26.0; | |
| 227 | 추가: } | |
| 228 | 추가: if let Some(item) = picked { | |
| 229 | 추가: self.ip_input = item.clone(); | |
| 230 | 추가: self.try_connect(&item); | |
| 231 | 추가: } | |
| 232 | 추가: } | |
| 233 | 추가: } | |
| 234 | 추가: | |
| 235 | 추가: fn try_connect(&mut self, input: &str) { | |
| 236 | 추가: match parse_target(input) { | |
| 237 | 추가: Ok(target) => { | |
| 238 | 추가: self.ip_input = display_target(target); | |
| 239 | 추가: self.input_error = None; | |
| 240 | 추가: self.connection = Connection::Connecting { target }; | |
| 241 | 추가: } | |
| 242 | 추가: Err(msg) => { | |
| 243 | 추가: self.input_error = Some(msg.to_owned()); | |
| 244 | 추가: self.focus_input = true; | |
| 245 | 추가: } | |
| 246 | 추가: } | |
| 247 | 추가: } | |
| 248 | 추가: | |
| 249 | 추가: fn connecting_screen(&mut self, ui: &mut Ui, viewport: Rect, target: SocketAddr) { | |
| 250 | 추가: let c = viewport.center(); | |
| 251 | 추가: let p = ui.painter(); | |
| 252 | 추가: p.text( | |
| 253 | 추가: c - vec2(0.0, 14.0), | |
| 254 | 추가: Align2::CENTER_CENTER, | |
| 255 | 추가: "휴대폰 승인 대기 중 (취소: Esc)", | |
| 256 | 추가: FontId::proportional(15.0), | |
| 257 | 추가: Color32::WHITE, | |
| 258 | 추가: ); | |
| 259 | 추가: p.text( | |
| 260 | 추가: c + vec2(0.0, 14.0), | |
| 261 | 추가: Align2::CENTER_CENTER, | |
| 262 | 추가: format!("{} · 확인 코드 ------", display_target(target)), | |
| 263 | 추가: FontId::proportional(13.0), | |
| 264 | 추가: DIM_TEXT, | |
| 265 | 추가: ); | |
| 266 | 추가: if ui.input(|i| i.key_pressed(Key::Escape)) { | |
| 267 | 추가: self.connection = Connection::Disconnected; | |
| 268 | 추가: self.focus_input = true; | |
| 269 | 추가: } | |
| 270 | 추가: } | |
| 271 | 추가: } | |
| 272 | 추가: | |
| 273 | 추가: fn title_bar(ui: &mut Ui, rect: Rect, actions: &mut Actions) { | |
| 274 | 추가: let btn = vec2(rect.height() + 6.0, rect.height()); | |
| 275 | 추가: let close_rect = Rect::from_min_size(pos2(rect.max.x - btn.x, rect.min.y), btn); | |
| 276 | 추가: let min_rect = close_rect.translate(vec2(-btn.x, 0.0)); | |
| 277 | 추가: let drag_rect = Rect::from_min_max(rect.min, pos2(min_rect.min.x, rect.max.y)); | |
| 278 | 추가: | |
| 279 | 추가: let drag = ui.interact(drag_rect, egui::Id::unique("title_drag"), Sense::drag()); | |
| 280 | 추가: if drag.drag_started() { | |
| 281 | 추가: actions.start_drag = true; | |
| 282 | 추가: } | |
| 283 | 추가: | |
| 284 | 추가: if title_button(ui, min_rect, "–", Color32::from_gray(0x33)).clicked() { | |
| 285 | 추가: actions.minimize = true; | |
| 286 | 추가: } | |
| 287 | 추가: if title_button(ui, close_rect, "×", Color32::from_rgb(0xc4, 0x2b, 0x1c)).clicked() { | |
| 288 | 추가: actions.close = true; | |
| 289 | 추가: } | |
| 290 | 추가: } | |
| 291 | 추가: | |
| 292 | 추가: fn title_button(ui: &mut Ui, rect: Rect, text: &str, hover_bg: Color32) -> egui::Response { | |
| 293 | 추가: let resp = ui.interact( | |
| 294 | 추가: rect, | |
| 295 | 추가: egui::Id::unique(("title_button", text)), | |
| 296 | 추가: Sense::click(), | |
| 297 | 추가: ); | |
| 298 | 추가: if resp.hovered() { | |
| 299 | 추가: ui.painter().rect_filled(rect, 0.0, hover_bg); | |
| 300 | 추가: } | |
| 301 | 추가: ui.painter().text( | |
| 302 | 추가: rect.center(), | |
| 303 | 추가: Align2::CENTER_CENTER, | |
| 304 | 추가: text, | |
| 305 | 추가: FontId::proportional(14.0), | |
| 306 | 추가: Color32::from_gray(0xc8), | |
| 307 | 추가: ); | |
| 308 | 추가: resp | |
| 309 | 추가: } | |
| 310 | 추가: | |
| 311 | 추가: fn size_label(v: u16) -> String { | |
| 312 | 추가: if v == 0 { | |
| 313 | 추가: "원본".to_owned() | |
| 314 | 추가: } else { | |
| 315 | 추가: format!("{v}p") | |
| 316 | 추가: } | |
| 317 | 추가: } |