media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
916 stars 132 forks source link

auto hide mouse #618

Closed abdelaziz-mahdy closed 2 days ago

abdelaziz-mahdy commented 6 months ago

Add Feature to Hide Mouse on Controls Removal

Overview

This pull request introduces a new feature to the MaterialDesktopVideoControlsThemeData in the material_desktop.dart file of the media_kit_video_controls library. The primary addition is the hideMouseOnControlsRemoval property.

Changes

Usage

Users can now opt to hide the mouse cursor when the video controls are removed by setting the hideMouseOnControlsRemoval flag in the MaterialDesktopVideoControlsThemeData constructor.

Example:


MaterialDesktopVideoControlsThemeData(
  // ... other properties ...
  hideMouseOnControlsRemoval: true,
)
abdelaziz-mahdy commented 6 months ago

Currently, I'm unable to test this functionality on Windows. The only workaround I can propose, particularly if the hiding of the mouse cursor requires movement, involves setting a threshold of ignored pixel movement. Specifically, this would mean:

  1. Ignoring a certain number of pixels: The mouse cursor would be hidden unless the movement exceeds a predefined number of pixels. This is to ensure that minor, unintentional cursor movements don't disrupt the viewing experience.

  2. Showing controls upon exceeding the threshold: If the user's cursor movement exceeds this set threshold, the video controls would reappear, allowing for user interaction.

This approach aims to balance between providing a clean, uninterrupted view and ensuring that the controls are accessible when genuinely needed by the user.

let me know if that is good, and if the functionally works on windows and linux

Prince-of-death commented 1 month ago
import 'package:win32/win32.dart';
import 'package:win32/win32.dart' as win32;
import 'dart:ffi';
import 'package:ffi/ffi.dart';

Timer(const Duration(milliseconds: 100), () {
    Pointer<POINT> point = malloc();
    win32.GetCursorPos(point);
    win32.SetCursorPos(point.ref.x, point.ref.y);
    free(point);
});

something i found online https://stackoverflow.com/questions/74963577/how-to-hide-mouse-cursor-in-flutter

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:win32/win32.dart';
import 'package:win32/win32.dart' as win32;
import 'dart:ffi';
import 'package:ffi/ffi.dart';

class EnhancedMouseRegion extends StatefulWidget {
  final Function(PointerEnterEvent)? onEnter;
  final Function(PointerExitEvent)? onExit;
  final Function(PointerHoverEvent)? onHover;
  final MouseCursor cursor;
  final bool opaque;
  final HitTestBehavior? hitTestBehavior;
  final Widget? child;

  const EnhancedMouseRegion({
    super.key,
    this.onEnter,
    this.onExit,
    this.onHover,
    this.cursor = MouseCursor.defer,
    this.opaque = true,
    this.hitTestBehavior,
    this.child,
  });

  @override
  State<EnhancedMouseRegion> createState() => _EnhancedMouseRegionState();
}

class _EnhancedMouseRegionState extends State<EnhancedMouseRegion> {
  MouseCursor? lastCursor;

  @override
  Widget build(BuildContext context) {
    if (lastCursor != widget.cursor) {
      Timer(const Duration(milliseconds: 100), () {
        Pointer<POINT> point = malloc();
        win32.GetCursorPos(point);
        win32.SetCursorPos(point.ref.x, point.ref.y);
        free(point);
      });
    }
    lastCursor = widget.cursor;

    return MouseRegion(
      onEnter: widget.onEnter,
      onExit: widget.onExit,
      onHover: widget.onHover,
      cursor: widget.cursor,
      opaque: widget.opaque,
      hitTestBehavior: widget.hitTestBehavior,
      child: widget.child,
    );
  }
}

it may work. @abdelaziz-mahdy

abdelaziz-mahdy commented 1 month ago

Thank you for work around, but letting you know https://github.com/flutter/engine/commit/a759e94cee04d5878b164c8f91d4ef22bdaa552d Pushed a fix for the windows problem which should be in the next release of flutter

user1121114685 commented 4 weeks ago

感谢您的解决方案,但让您知道 flutter/engine@ a759e94 推送了 Windows 问题的修复程序,该修复程序应该在下一版本的 flutter 中

This is really good news, no more having to monitor the mouse all the time. Causing unnecessary waste of performance.

Prince-of-death commented 3 weeks ago

nice👌👍