Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rednering on hidpi device #199

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChewingTextService/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ add_library(ChewingTextService SHARED
# resources
${PROJECT_SOURCE_DIR}/ChewingTextService.rc
${PROJECT_SOURCE_DIR}/mainicon.ico
# manifest
${PROJECT_SOURCE_DIR}/ChewingTextService.manifest
)

target_link_libraries(ChewingTextService
Expand Down
7 changes: 7 additions & 0 deletions ChewingTextService/ChewingTextService.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
27 changes: 18 additions & 9 deletions libIME/src/window/candidate_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ const COL_SPACING: u32 = 8;

impl CandidateWindow {
fn recalculate_size(&self) -> Result<()> {
let margin = self.nine_patch_bitmap.margin().ceil() as u32;
let margin = self.nine_patch_bitmap.margin().ceil();
if self.items.borrow().is_empty() {
unsafe { self.window.resize(margin as i32 * 2, margin as i32 * 2) };
self.resize_swap_chain(margin * 2, margin * 2)?;
// Convert to HW pixels
let width = 2.0 * margin * self.dpi / USER_DEFAULT_SCREEN_DPI as f32;
let height = 2.0 * margin * self.dpi / USER_DEFAULT_SCREEN_DPI as f32;

unsafe { self.window.resize(width as i32, height as i32) };
self.resize_swap_chain(width as u32, height as u32)?;
}

let mut selkey_width = 0.0_f32;
Expand Down Expand Up @@ -119,8 +123,12 @@ impl CandidateWindow {
let rows = items_len.div_ceil(cand_per_row).clamp(1, u32::MAX);
let width = cand_per_row * (selkey_width + text_width).ceil() as u32
+ (cand_per_row - 1) * COL_SPACING
+ 2 * margin;
let height = rows * item_height as u32 + (rows - 1) * ROW_SPACING + 2 * margin;
+ 2 * margin as u32;
let height = rows * item_height as u32 + (rows - 1) * ROW_SPACING + 2 * margin as u32;

// Convert to HW pixels
let width = width * self.dpi as u32 / USER_DEFAULT_SCREEN_DPI;
let height = height * self.dpi as u32 / USER_DEFAULT_SCREEN_DPI;

unsafe { self.window.resize(width as i32, height as i32) };
self.resize_swap_chain(width, height)?;
Expand Down Expand Up @@ -200,10 +208,11 @@ impl CandidateWindow {

target.BeginDraw();
let rect = D2D_RECT_F {
top: rc.top as f32,
left: rc.left as f32,
right: rc.right as f32,
bottom: rc.bottom as f32,
top: 0.0,
left: 0.0,
// Convert to DIPs
right: rc.right as f32 * USER_DEFAULT_SCREEN_DPI as f32 / self.dpi,
bottom: rc.bottom as f32 * USER_DEFAULT_SCREEN_DPI as f32 / self.dpi,
};
self.nine_patch_bitmap.draw_bitmap(target, rect)?;

Expand Down
14 changes: 10 additions & 4 deletions libIME/src/window/message_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ impl MessageWindow {
let margin = self.nine_patch_bitmap.margin();
let width = metrics.width + margin * 2.0;
let height = metrics.height + margin * 2.0;

// Convert to HW pixels
let width = width * self.dpi / USER_DEFAULT_SCREEN_DPI as f32;
let height = height * self.dpi / USER_DEFAULT_SCREEN_DPI as f32;

unsafe {
SetWindowPos(
self.window.hwnd.get(),
Expand Down Expand Up @@ -148,10 +153,11 @@ impl MessageWindow {

target.BeginDraw();
let rect = D2D_RECT_F {
top: rc.top as f32,
left: rc.left as f32,
right: rc.right as f32,
bottom: rc.bottom as f32,
top: 0.0,
left: 0.0,
// Convert to DIPs
right: rc.right as f32 * USER_DEFAULT_SCREEN_DPI as f32 / self.dpi,
bottom: rc.bottom as f32 * USER_DEFAULT_SCREEN_DPI as f32 / self.dpi,
};
self.nine_patch_bitmap.draw_bitmap(target, rect)?;
let margin = self.nine_patch_bitmap.margin();
Expand Down