diff --git a/src/components/Controls.jsx b/src/components/Controls.jsx index 605f7b6..e8cfd84 100644 --- a/src/components/Controls.jsx +++ b/src/components/Controls.jsx @@ -12,7 +12,7 @@ import { PresentToAllIcon, } from "../icons"; import IconButton from "./IconButton"; -import { selectScreen } from "./screen"; +import { selectScreens } from "./screen"; import { useGlobalPageContext, usePage } from "./PresentationContext"; import { A, useLocation, useNavigate, useParams } from "@solidjs/router"; import { SLIDE_COUNT } from "./Presentation"; @@ -71,7 +71,7 @@ export default function () { //TODO think of manual solution with creating two windows and the user having to manually move them to a different screen if (!isWindowManagementSupported) return; const screens = await window.getScreenDetails(); - const presentationScreen = selectScreen(screens); + const [presentationScreen, notesScreen] = selectScreens(screens); // The order of requesting fullscreen and then opening the window is important // The other way around does not work @@ -80,12 +80,15 @@ export default function () { screen: presentationScreen, }); + // Can't show notes if there is no screen for them + if (!notesScreen) return; + // Open control in new window on current screen - const newWindow = openWindow( - screens.currentScreen.left, - screens.currentScreen.top, - screens.currentScreen.width, - screens.currentScreen.height, + const notesWindow = openWindow( + notesScreen.left, + notesScreen.top, + notesScreen.width, + notesScreen.height, "/notes" ); } diff --git a/src/components/screen.js b/src/components/screen.js index 5fe234e..8a52b10 100644 --- a/src/components/screen.js +++ b/src/components/screen.js @@ -1,24 +1,43 @@ /** * "Algorithm" to select the presentation screen * @param {ScreenDetails} screens - * @returns {ScreenDetailed} + * @returns {[presenation: ScreenDetailed, notes?: ScreenDetailed]} */ -export function selectScreen(screens) { - const secondaryScreens = screens.screens.filter( - (screen) => !screen.isPrimary +export function selectScreens(screens) { + // Don't confuse current screen with the primary screen + const { primary, internals, externals } = screens.screens.reduce( + (accumulator, current) => { + if (current.isPrimary) { + accumulator.primary = current; + return accumulator; + } + + if (current.isInternal) { + accumulator.internals.push(current); + return accumulator; + } + + accumulator.externals.push(current); + return accumulator; + }, + /** @type {{ primary: ScreenDetailed | null, internals: ScreenDetailed[], externals: ScreenDetailed[] }} */ + ({ primary: null, internals: [], externals: [] }) ); - // If there are no secondary screens, use the primary screen - if (secondaryScreens.length === 0) return screens.currentScreen; + console.debug("Screens", { primary, internals, externals }); - // If there is only one secondary screen, use it - if (secondaryScreens.length === 1) return secondaryScreens[0]; + // Assume there is always primary screen + if (primary === null) + throw new Error( + "No primary screen found. Are you running in headless mode?" + ); // Use first not built in secondary screen - const externalScreen = secondaryScreens.find((screen) => !screen.isInternal); + if (externals.length > 0) return [externals[0], primary]; - // If there is no external screen, use the first secondary screen - if (!externalScreen) return secondaryScreens[0]; + // If there is no external screen, use the first secondary internal screen + if (internals.length > 0) return [internals[0], primary]; - return externalScreen; + // Fallback to the primary screen + return [primary]; }