From 9f3d6fe0e9a07e1991716c8aa80e385a5bf9c38d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 24 Jan 2017 07:30:57 +0530 Subject: [PATCH] Fix mouse co-ordinates incorrect on OS X retina Fixes #43 --- kitty/boss.py | 2 +- kitty/constants.py | 5 +++-- kitty/main.py | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 897864f35..dbe9c59a8 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -339,7 +339,7 @@ class Boss(Thread): @callback def on_mouse_move(self, window, xpos, ypos): - mouse_cursor_pos[:2] = xpos, ypos + mouse_cursor_pos[:2] = int(xpos * viewport_size.x_ratio), int(ypos * viewport_size.y_ratio) self.show_mouse_cursor() w = self.window_for_pos(xpos, ypos) if w is not None: diff --git a/kitty/constants.py b/kitty/constants.py index 82e8852d4..b8acdc0df 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -45,13 +45,14 @@ del _get_config_dir class ViewportSize: - __slots__ = ('width', 'height') + __slots__ = ('width', 'height', 'x_ratio', 'y_ratio') def __init__(self): self.width = self.height = 1024 + self.x_ratio = self.y_ratio = 1.0 def __repr__(self): - return '(width={}, height={})'.format(self.width, self.height) + return '(width={}, height={}, x_ratio={}, y_ratio={})'.format(self.width, self.height, self.x_ratio, self.y_ratio) def get_boss(): diff --git a/kitty/main.py b/kitty/main.py index bde12d0e6..058cd6d07 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -108,6 +108,9 @@ def run_app(opts, args): with open(logo_data_file, 'rb') as f: window.set_icon(f.read(), 256, 256) viewport_size.width, viewport_size.height = window.get_framebuffer_size() + w, h = window.get_window_size() + viewport_size.x_ratio = viewport_size.width / float(w) + viewport_size.y_ratio = viewport_size.height / float(h) glewInit() boss = Boss(window, opts, args) boss.start()