export const useWindowManager = () => {
const context = useContext(WindowManagerContext);
if (!context) {
throw new Error('useWindowManager must be used within a WindowManagerProvider');
}
return context;
};
export const metadata = {
title: 'My Next.js App',
description: 'A Next.js App with draggable windows',
};
import './globals.css';
import { WindowManagerProvider } from '../contexts/WindowManagerContext';
import AnimatedBackground from '../components/AnimatedBackground';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
{/* Include the AnimatedBackground as a client component */}
{children}
);
}
TASK: Currently when windows are maximised they do underneaeth the taskbar. I do not want this to happen. How can I make it so that windows do not go underneath teh taksbar whne maximised?
To ensure that maximized windows do not go underneath the taskbar, you need to adjust the calculation of the window's maximum height in the maximizeWindow function within your WindowManagerContext.tsx. Specifically, you should subtract the taskbar's height from the window's maximum height when maximizing.
Here's how you can modify your maximizeWindow function:
Define the Taskbar Height
Since your taskbar has a fixed height of h-10 in Tailwind CSS, which corresponds to 2.5rem (or 40px), you can define a constant for the taskbar height:
const TASKBAR_HEIGHT_PX = 40; // Adjust this value if your taskbar height changes
Adjust the Maximum Height Calculation
In your maximizeWindow function, subtract the TASKBAR_HEIGHT_PX from the window.innerHeight when calculating maxHeight. This ensures that the maximized window's height does not extend into the taskbar's area.
const maximizeWindow = (name: string) => {
setWindowStates((prev) => {
const state = prev[name];
const isMaximized = !state.maximized;
if (isMaximized) {
// Store previous size and position
const prevSizePosition = {
prevWidth: state.width,
prevHeight: state.height,
prevX: state.x,
prevY: state.y,
};
// Define taskbar height
const TASKBAR_HEIGHT_PX = 40; // Adjust this value based on your taskbar's actual height
const maxWidth = window.innerWidth - 20; // Adjusted width for spacing
const maxHeight = window.innerHeight - TASKBAR_HEIGHT_PX - 20; // Subtract taskbar height
// Adjust to align with grid
const adjustedWidth = Math.floor(maxWidth / GRID_SIZE) * GRID_SIZE;
const adjustedHeight = Math.floor(maxHeight / GRID_SIZE) * GRID_SIZE;
return {
...prev,
[name]: {
...state,
maximized: true,
...prevSizePosition,
x: 10, // Adjusted for spacing when maximized
y: 10, // Adjusted for spacing when maximized
width: adjustedWidth,
height: adjustedHeight,
},
};
} else {
// Restore previous size and position
return {
...prev,
[name]: {
...state,
maximized: false,
width: state.prevWidth || state.width,
height: state.prevHeight || state.height,
x: state.prevX || state.x,
y: state.prevY || state.y,
},
};
}
});
bringToFront(name);
};
Verify the Taskbar Height
Ensure that the TASKBAR_HEIGHT_PX matches the actual height of your taskbar. If you ever change the taskbar's height in your CSS, remember to update this value accordingly.
Optional: Make Taskbar Height Dynamic
If your taskbar height can change (e.g., due to responsive design), you might want to calculate the taskbar's height dynamically. Here's how you can do it:
However, since document is not available during server-side rendering in Next.js, you'll need to ensure this code runs on the client side. You can adjust your code as follows:
const maximizeWindow = (name: string) => {
setWindowStates((prev) => {
const state = prev[name];
const isMaximized = !state.maximized;
if (isMaximized) {
// Client-side check for taskbar height
let TASKBAR_HEIGHT_PX = 40; // Default value
if (typeof window !== 'undefined') {
const taskbar = document.querySelector('.taskbar');
if (taskbar) {
TASKBAR_HEIGHT_PX = taskbar.clientHeight;
}
}
// Rest of your code...
}
});
bringToFront(name);
};
Remember to add the className="taskbar" to your taskbar component:
By adjusting the maxHeight calculation to account for the taskbar's height, you ensure that maximized windows remain fully visible without overlapping the taskbar.
Summary:
Adjust the maxHeight in your maximizeWindow function to subtract the taskbar's height. This prevents maximized windows from going underneath the taskbar.