diff --git a/pupil_src/launchables/eye.py b/pupil_src/launchables/eye.py index 36916cead..4e3ee8e1c 100644 --- a/pupil_src/launchables/eye.py +++ b/pupil_src/launchables/eye.py @@ -12,6 +12,7 @@ import platform import signal import time +from functools import partial from types import SimpleNamespace @@ -281,16 +282,7 @@ def consume_events_and_render_buffer(): cpu_graph.draw() # render GUI - try: - clipboard = glfw.get_clipboard_string(main_window).decode() - except (AttributeError, glfw.GLFWError): - # clipboard is None, might happen on startup - clipboard = "" - g_pool.gui.update_clipboard(clipboard) user_input = g_pool.gui.update() - if user_input.clipboard != clipboard: - # only write to clipboard if content changed - glfw.set_clipboard_string(main_window, user_input.clipboard) for button, action, mods in user_input.buttons: x, y = glfw.get_cursor_pos(main_window) @@ -564,6 +556,8 @@ def set_window_size(): g_pool.writer = None g_pool.rec_path = None + on_focus = partial(gl_utils.window_focus_clipboard_callback, g_pool) + # Register callbacks main_window glfw.set_framebuffer_size_callback(main_window, on_resize) glfw.set_window_iconify_callback(main_window, on_iconify) @@ -573,6 +567,7 @@ def set_window_size(): glfw.set_cursor_pos_callback(main_window, on_pos) glfw.set_scroll_callback(main_window, on_scroll) glfw.set_drop_callback(main_window, on_drop) + glfw.set_window_focus_callback(main_window, on_focus) # load last gui configuration g_pool.gui.configuration = session_settings.get("ui_config", {}) diff --git a/pupil_src/launchables/player.py b/pupil_src/launchables/player.py index 681c6b890..4eaf79b27 100644 --- a/pupil_src/launchables/player.py +++ b/pupil_src/launchables/player.py @@ -654,6 +654,8 @@ def set_window_size(): ), ) + on_focus = partial(gl_utils.window_focus_clipboard_callback, g_pool) + # Register callbacks main_window glfw.set_framebuffer_size_callback(main_window, on_resize) glfw.set_key_callback(main_window, on_window_key) @@ -662,6 +664,7 @@ def set_window_size(): glfw.set_cursor_pos_callback(main_window, on_pos) glfw.set_scroll_callback(main_window, on_scroll) glfw.set_drop_callback(main_window, on_drop) + glfw.set_window_focus_callback(main_window, on_focus) toggle_general_settings(True) @@ -741,16 +744,7 @@ def handle_notifications(n): gl_utils.glViewport(0, 0, *window_size) - try: - clipboard = glfw.get_clipboard_string(main_window).decode() - except (AttributeError, glfw.GLFWError): - # clipbaord is None, might happen on startup - clipboard = "" - g_pool.gui.update_clipboard(clipboard) user_input = g_pool.gui.update() - if user_input.clipboard and user_input.clipboard != clipboard: - # only write to clipboard if content changed - glfw.set_clipboard_string(main_window, user_input.clipboard) for b in user_input.buttons: button, action, mods = b diff --git a/pupil_src/launchables/world.py b/pupil_src/launchables/world.py index b1fe04adc..88942da54 100644 --- a/pupil_src/launchables/world.py +++ b/pupil_src/launchables/world.py @@ -11,6 +11,7 @@ import os import platform import signal +from functools import partial from types import SimpleNamespace @@ -344,16 +345,7 @@ def consume_events_and_render_buffer(): p.gl_display() gl_utils.glViewport(0, 0, *window_size) - try: - clipboard = glfw.get_clipboard_string(main_window).decode() - except (AttributeError, glfw.GLFWError): - # clipboard is None, might happen on startup - clipboard = "" - g_pool.gui.update_clipboard(clipboard) user_input = g_pool.gui.update() - if user_input.clipboard != clipboard: - # only write to clipboard if content changed - glfw.set_clipboard_string(main_window, user_input.clipboard) for button, action, mods in user_input.buttons: x, y = glfw.get_cursor_pos(main_window) @@ -674,6 +666,8 @@ def set_window_size(): g_pool.plugin_by_name[default_capture_name], default_capture_settings ) + on_focus = partial(gl_utils.window_focus_clipboard_callback, g_pool) + # Register callbacks main_window glfw.set_framebuffer_size_callback(main_window, on_resize) glfw.set_key_callback(main_window, on_window_key) @@ -682,6 +676,7 @@ def set_window_size(): glfw.set_cursor_pos_callback(main_window, on_pos) glfw.set_scroll_callback(main_window, on_scroll) glfw.set_drop_callback(main_window, on_drop) + glfw.set_window_focus_callback(main_window, on_focus) # gl_state settings gl_utils.basic_gl_setup() @@ -781,16 +776,8 @@ def window_should_update(): p.gl_display() gl_utils.glViewport(0, 0, *window_size) - try: - clipboard = glfw.get_clipboard_string(main_window).decode() - except (AttributeError, glfw.GLFWError): - # clipboard is None, might happen on startup - clipboard = "" - g_pool.gui.update_clipboard(clipboard) + user_input = g_pool.gui.update() - if user_input.clipboard != clipboard: - # only write to clipboard if content changed - glfw.set_clipboard_string(main_window, user_input.clipboard) for button, action, mods in user_input.buttons: x, y = glfw.get_cursor_pos(main_window) diff --git a/pupil_src/shared_modules/gl_utils/__init__.py b/pupil_src/shared_modules/gl_utils/__init__.py index 0e3bdbd7a..32d612489 100644 --- a/pupil_src/shared_modules/gl_utils/__init__.py +++ b/pupil_src/shared_modules/gl_utils/__init__.py @@ -31,5 +31,6 @@ make_coord_system_norm_based, make_coord_system_pixel_based, window_coordinate_to_framebuffer_coordinate, + window_focus_clipboard_callback, ) from .window_position_manager import WindowPositionManager diff --git a/pupil_src/shared_modules/gl_utils/utils.py b/pupil_src/shared_modules/gl_utils/utils.py index ac952f185..356484650 100644 --- a/pupil_src/shared_modules/gl_utils/utils.py +++ b/pupil_src/shared_modules/gl_utils/utils.py @@ -129,6 +129,20 @@ def is_window_visible(window): return visible and not iconified +def window_focus_clipboard_callback(g_pool, window, focused): + if focused: + try: + clipboard = glfw.get_clipboard_string(window).decode() + except (AttributeError, glfw.GLFWError): + # clipboard is None, might happen on startup + clipboard = "" + g_pool.gui.update_clipboard(clipboard) + user_input = g_pool.gui.update() + if user_input.clipboard != clipboard: + # only write to clipboard if content changed + glfw.set_clipboard_string(main_window, user_input.clipboard) + + def cvmat_to_glmat(m): mat = np.eye(4, dtype=np.float32) mat = mat.flatten() diff --git a/pupil_src/shared_modules/service_ui.py b/pupil_src/shared_modules/service_ui.py index 767f6a799..f58132999 100644 --- a/pupil_src/shared_modules/service_ui.py +++ b/pupil_src/shared_modules/service_ui.py @@ -21,6 +21,8 @@ GLFWErrorReporting.set_default() +from functools import partial + from plugin import System_Plugin_Base from pyglui import cygl, ui from video_capture.neon_backend.plugin import Neon_Manager @@ -193,6 +195,8 @@ def reset_restart(): g_pool.menubar.append(ui.Button("Restart with default settings", reset_restart)) + on_focus = partial(gl_utils.window_focus_clipboard_callback, g_pool) + # Register callbacks main_window glfw.set_framebuffer_size_callback(main_window, on_resize) glfw.set_key_callback(main_window, on_window_key) @@ -200,6 +204,7 @@ def reset_restart(): glfw.set_mouse_button_callback(main_window, on_window_mouse_button) glfw.set_cursor_pos_callback(main_window, on_pos) glfw.set_scroll_callback(main_window, on_scroll) + glfw.set_window_focus_callback(main_window, on_focus) g_pool.gui.configuration = ui_config gl_utils.basic_gl_setup() @@ -217,16 +222,6 @@ def update_ui(self): gl_utils.glViewport(0, 0, *self.window_size) glfw.poll_events() self.gl_display() - try: - clipboard = glfw.get_clipboard_string(self.g_pool.main_window).decode() - except (AttributeError, glfw.GLFWError): - # clipbaord is None, might happen on startup - clipboard = "" - self.g_pool.gui.update_clipboard(clipboard) - user_input = self.g_pool.gui.update() - if user_input.clipboard and user_input.clipboard != clipboard: - # only write to clipboard if content changed - glfw.set_clipboard_string(self.g_pool.main_window, user_input.clipboard) glfw.swap_buffers(self.g_pool.main_window) else: