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

move clipboard updates to a focus callback, perfs enh + stability fix #2334

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
13 changes: 4 additions & 9 deletions pupil_src/launchables/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import platform
import signal
import time
from functools import partial
from types import SimpleNamespace


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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", {})
Expand Down
12 changes: 3 additions & 9 deletions pupil_src/launchables/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions pupil_src/launchables/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import platform
import signal
from functools import partial
from types import SimpleNamespace


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pupil_src/shared_modules/gl_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions pupil_src/shared_modules/gl_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 5 additions & 10 deletions pupil_src/shared_modules/service_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -193,13 +195,16 @@ 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)
glfw.set_char_callback(main_window, on_window_char)
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()

Expand All @@ -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:
Expand Down