-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2007 from pupil-labs/cu-72t9b7
Ensure windows are visible when recovering a session
- Loading branch information
Showing
7 changed files
with
207 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ | |
|
||
from .utils import * | ||
from .trackball import * | ||
from .window_position_manager import WindowPositionManager |
85 changes: 85 additions & 0 deletions
85
pupil_src/shared_modules/gl_utils/window_position_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
""" | ||
(*)~--------------------------------------------------------------------------- | ||
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( | ||
window, | ||
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": | ||
# The OS handle re-positioning windows with invalid positions | ||
return previous_position | ||
|
||
elif os_name == "Linux": | ||
# The OS handle re-positioning windows with invalid positions | ||
return previous_position | ||
|
||
elif os_name == "Windows": | ||
|
||
def validate_previous_position(monitor) -> bool: | ||
return _will_window_be_visible_in_monitor( | ||
window=window, | ||
monitor=monitor, | ||
window_position=previous_position, | ||
) | ||
|
||
if any(validate_previous_position(m) for m in glfw.glfwGetMonitors()): | ||
return previous_position | ||
else: | ||
return default_position | ||
|
||
else: | ||
raise NotImplementedError(f"Unsupported system: {os_name}") | ||
|
||
|
||
def _will_window_be_visible_in_monitor( | ||
window, monitor, window_position, min_visible_width=30, min_visible_height=20 | ||
) -> bool: | ||
# Get the current window size and edges, and monitor rect | ||
window_size = glfw.glfwGetWindowSize(window) | ||
window_edges = glfw.glfwGetWindowFrameSize(window) | ||
monitor_rect = glfw.glfwGetMonitorWorkarea(monitor) | ||
|
||
# Calculate what the title bar rect would be | ||
# if the proposed `window_position` would be the actual window position | ||
title_bar_rect = glfw._Rectangle( | ||
x=window_position[0] - window_edges.left, | ||
y=window_position[1] - window_edges.top, | ||
width=window_size[0] + window_edges.left + window_edges.right, | ||
height=window_edges.top, | ||
) | ||
|
||
# Calculate the part of the title bar that is visible in the monitor, if any | ||
visible_rect = title_bar_rect.intersection(monitor_rect) | ||
|
||
# Return true if the visible title bar rect is big enough | ||
return ( | ||
visible_rect is not None | ||
and min_visible_width <= visible_rect.width | ||
and min_visible_height <= visible_rect.height | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters