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

Ensure windows are visible when recovering a session #2007

Merged
merged 14 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pupil_src/launchables/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ def toggle_general_settings(collapsed):
width, height = session_settings.get("window_size", default_window_size)

main_window = glfw.glfwCreateWindow(width, height, title, None, None)
window_pos = session_settings.get("window_position", window_position_default)
window_position_manager = gl_utils.WindowPositionManager()
window_pos = window_position_manager.new_window_position(
default_position=window_position_default,
previous_position=session_settings.get("window_position", None),
)
glfw.glfwSetWindowPos(main_window, window_pos[0], window_pos[1])
glfw.glfwMakeContextCurrent(main_window)
cygl.utils.init()
Expand Down
14 changes: 12 additions & 2 deletions pupil_src/launchables/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ def get_dt():
width += icon_bar_width
width, height = session_settings.get("window_size", (width, height))

window_pos = session_settings.get("window_position", window_position_default)
window_position_manager = gl_utils.WindowPositionManager()
window_pos = window_position_manager.new_window_position(
default_position=window_position_default,
previous_position=session_settings.get("window_position", None),
)

window_name = f"Pupil Player: {meta_info.recording_name} - {rec_dir}"

glfw.glfwInit()
Expand Down Expand Up @@ -836,7 +841,12 @@ def on_drop(window, count, paths):
)
session_settings.clear()
w, h = session_settings.get("window_size", (1280, 720))
window_pos = session_settings.get("window_position", window_position_default)

window_position_manager = gl_utils.WindowPositionManager()
window_pos = window_position_manager.new_window_position(
default_position=window_position_default,
previous_position=session_settings.get("window_position", None),
)

glfw.glfwInit()
glfw.glfwWindowHint(glfw.GLFW_SCALE_TO_MONITOR, glfw.GLFW_TRUE)
Expand Down
6 changes: 5 additions & 1 deletion pupil_src/launchables/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,11 @@ def handle_notifications(noti):
if hide_ui:
glfw.glfwWindowHint(glfw.GLFW_VISIBLE, 0) # hide window
main_window = glfw.glfwCreateWindow(width, height, "Pupil Capture - World")
window_pos = session_settings.get("window_position", window_position_default)
window_position_manager = gl_utils.WindowPositionManager()
window_pos = window_position_manager.new_window_position(
default_position=window_position_default,
previous_position=session_settings.get("window_position", None),
)
glfw.glfwSetWindowPos(main_window, window_pos[0], window_pos[1])
glfw.glfwMakeContextCurrent(main_window)
cygl.utils.init()
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 @@ -11,3 +11,4 @@

from .utils import *
from .trackball import *
from .window_position_manager import WindowPositionManager
40 changes: 40 additions & 0 deletions pupil_src/shared_modules/gl_utils/window_position_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
(*)~---------------------------------------------------------------------------
Pupil - eye tracking platform
Copyright (C) 2012-2020 Pupil Labs

Distributed under the terms of the GNU
Lesser General Public License (LGPL v3.0).
See COPYING and COPYING.LESSER for license details.
---------------------------------------------------------------------------~(*)
"""
import logging
import platform
import typing as T

import glfw


class WindowPositionManager:
def __init__(self):
pass

@staticmethod
def new_window_position(
default_position: T.Tuple[int, int],
previous_position: T.Optional[T.Tuple[int, int]],
) -> T.Tuple[int, int]:

if previous_position is None:
return default_position

os_name = platform.system()

if os_name == "Darwin":
return previous_position
elif os_name == "Linux":
return previous_position
elif os_name == "Windows":
return previous_position
else:
raise NotImplementedError(f"Unsupported system: {os_name}")
9 changes: 9 additions & 0 deletions pupil_src/shared_modules/glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class GLFWmonitor(Structure):
glfwGetPrimaryMonitor = _glfw.glfwGetPrimaryMonitor
glfwGetPrimaryMonitor.restype = POINTER(GLFWmonitor)
# glfwGetMonitorPos = _glfw.glfwGetMonitorPos
# glfwGetMonitorWorkarea = _glfw.glfwGetMonitorWorkarea
papr marked this conversation as resolved.
Show resolved Hide resolved
# glfwGetMonitorPhysicalSize = _glfw.glfwGetMonitorPhysicalSize
glfwGetMonitorName = _glfw.glfwGetMonitorName
glfwGetMonitorName.restype = c_char_p
Expand Down Expand Up @@ -656,6 +657,14 @@ def glfwGetMonitorPos(monitor):
return xpos.value, ypos.value


def glfwGetMonitorWorkarea(monitor):
xpos, ypos, width, height = c_int(0), c_int(0), c_int(0), c_int(0)
_glfw.glfwGetMonitorWorkarea(
monitor, byref(xpos), byref(ypos), byref(width), byref(height)
)
return xpos.value, ypos.value, width.value, height.value
romanroibu marked this conversation as resolved.
Show resolved Hide resolved


def glfwGetMonitorPhysicalSize(monitor):
width, height = c_int(0), c_int(0)
_glfw.glfwGetMonitorPhysicalSize(monitor, byref(width), byref(height))
Expand Down
8 changes: 7 additions & 1 deletion pupil_src/shared_modules/service_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ def __init__(
self,
g_pool,
window_size=window_size_default,
window_position=window_position_default,
window_position=None,
gui_scale=1.0,
ui_config={},
):
super().__init__(g_pool)

self.texture = np.zeros((1, 1, 3), dtype=np.uint8) + 128

window_position_manager = gl_utils.WindowPositionManager()
window_position = window_position_manager.new_window_position(
default_position=window_position_default,
previous_position=window_position,
)

glfw.glfwInit()
glfw.glfwWindowHint(glfw.GLFW_SCALE_TO_MONITOR, glfw.GLFW_TRUE)
if g_pool.hide_ui:
Expand Down