Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
fix: few errors and dynamic mode switching
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 29, 2024
1 parent 76c6fda commit 0fd8148
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/views/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class _DesktopViewState extends State<DesktopView> {
output: output,
outputIndex: outputIndex,
decorHeight: SurfaceDecor.heightFor(context),
mode: Breakpoints.large.isActive(_key.currentContext!) ? WindowManagerMode.floating : WindowManagerMode.stacking,
),
),
) : null,
Expand Down
10 changes: 9 additions & 1 deletion lib/widgets/surface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ class SurfaceDecor extends StatelessWidget {
] : actions,
);

if (surface.size != null) {
if (surface.size!.width != null) {
value = Container(
width: surface.size!.width!.toDouble(),
child: value,
);
}
}

if (onDrag != null) {
value = GestureDetector(
onPanUpdate: onDrag!,
child: value,
);
}

return value;
}

Expand Down
31 changes: 23 additions & 8 deletions lib/widgets/wm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class WindowView extends StatelessWidget {
if (win.surface.maximized) win.restore();

// FIXME: a bug where multiple windows can drag at the same time after being raised.
if (!_win.isOnTop) _win.raiseToTop();
if (!win.isOnTop) win.raiseToTop();

_win.x += info.delta.dx;
_win.y += info.delta.dy;
win.x += info.delta.dx;
win.y += info.delta.dy;
},
),
ClipRRect(
Expand Down Expand Up @@ -105,13 +105,15 @@ class WindowManagerView extends StatefulWidget {
required this.windowManager,
required this.output,
required this.outputIndex,
this.mode,
this.decorHeight = kSurfaceDecorHeight,
});

final DisplayServer displayServer;
final WindowManager windowManager;
final Output output;
final int outputIndex;
final WindowManagerMode? mode;
final double decorHeight;

@override
Expand All @@ -130,6 +132,12 @@ class _WindowManagerViewState extends State<WindowManagerView> {
return list;
}

Size _getDesktopSize(BuildContext context) {
final renderObject = context.findRenderObject();
if (renderObject == null) return Size(1, 1);
return (renderObject as RenderBox).size;
}

Widget _buildTiling(BuildContext context) =>
GridView(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
Expand All @@ -138,7 +146,7 @@ class _WindowManagerViewState extends State<WindowManagerView> {
children: _getWindows(context).map(
(win) => WindowView(
win: win,
desktopSize: (context.findRenderObject() as RenderBox).size,
desktopSize: _getDesktopSize(context),
decorHeight: widget.decorHeight,
)
).toList(),
Expand All @@ -149,7 +157,7 @@ class _WindowManagerViewState extends State<WindowManagerView> {
children: _getWindows(context).map(
(win) => WindowView(
win: win,
desktopSize: (context.findRenderObject() as RenderBox).size,
desktopSize: _getDesktopSize(context),
decorHeight: widget.decorHeight,
),
).toList(),
Expand All @@ -161,15 +169,21 @@ class _WindowManagerViewState extends State<WindowManagerView> {
children: _getWindows(context).map(
(win) => WindowView(
win: win,
desktopSize: (context.findRenderObject() as RenderBox).size,
desktopSize: _getDesktopSize(context),
decorHeight: widget.decorHeight,
),
).toList(),
);

@override
Widget build(BuildContext context) =>
MultiProvider(
Widget build(BuildContext context) {
if (widget.mode != null) {
if (widget.mode! != widget.windowManager.mode) {
widget.windowManager.mode = widget.mode!;
}
}

return MultiProvider(
providers: [
ChangeNotifierProvider<DisplayServer>.value(value: widget.displayServer),
ChangeNotifierProvider<WindowManager>.value(value: widget.windowManager),
Expand All @@ -182,4 +196,5 @@ class _WindowManagerViewState extends State<WindowManagerView> {
})[widget.windowManager.mode]!,
),
);
}
}

0 comments on commit 0fd8148

Please sign in to comment.