GithubHelp home page GithubHelp logo

leanflutter / screen_retriever Goto Github PK

View Code? Open in Web Editor NEW
45.0 2.0 18.0 421 KB

This plugin allows Flutter desktop apps to Retrieve information about screen size, displays, cursor position, etc.

License: MIT License

Dart 16.37% CMake 21.45% C++ 50.60% C 3.23% Swift 5.82% Ruby 2.54%
flutter flutter-desktop flutter-desktop-app

screen_retriever's Introduction

screen_retriever

pub version

This plugin allows Flutter desktop apps to Retrieve information about screen size, displays, cursor position, etc.


English | 简体中文


Platform Support

Linux macOS Windows
✔️ ✔️ ✔️

Quick Start

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  screen_retriever: ^0.1.9

Or

dependencies:
  screen_retriever:
    git:
      url: https://github.com/leanflutter/screen_retriever.git
      ref: main

Usage

Display? _primaryDisplay;
List<Display> _displayList = [];

void _init() async {
  _primaryDisplay = await screenRetriever.getPrimaryDisplay();
  _displayList = await screenRetriever.getAllDisplays();
  setState(() {});
}

Please see the example app of this plugin for a full example.

Who's using it?

API

ScreenRetriever

Method Description Linux macOS Windows
getCursorScreenPoint Returns Offset - The current absolute position of the mouse pointer. ✔️ ✔️ ✔️
getPrimaryDisplay Returns Display - The primary display. ✔️ ✔️ ✔️
getAllDisplays Returns List<Display> - An array of displays that are currently available. ✔️ ✔️ ✔️

License

MIT

screen_retriever's People

Contributors

christianedwardpadilla avatar fufesou avatar jpnurmi avatar kingtous avatar lijy91 avatar lukasz-lukasz-lukasz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

screen_retriever's Issues

Windows compilation fails, type errors

The following code fails to compile for me:

BOOL CALLBACK MonitorRepresentationEnumProc(HMONITOR monitor,
                                            HDC hdc,
                                            LPRECT clip,
                                            LPARAM list_ref) {
  flutter::EncodableValue* monitors =
      reinterpret_cast<flutter::EncodableValue*>(list_ref);
  flutter::EncodableMap display = MonitorToEncodableMap(monitor);
  std::get<flutter::EncodableList>(*monitors).push_back(display);
  return TRUE;
}

With the following error:

error: no matching member function for call to 'push_back'
std::get(*monitors).push_back(display);
third_party/lexan/libcxx/include/vector:586:62: note: candidate function not viable: no known conversion from 'EncodableMap' (aka 'map<EncodableValue, EncodableValue>') to 'const value_type' (aka 'const flutter::EncodableValue') for 1st argument
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);

Similarly, the plugin return block for GetAllDisplays:

void ScreenRetrieverPlugin::GetAllDisplays(
    const flutter::MethodCall<flutter::EncodableValue>& method_call,
    std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
  flutter::EncodableValue displays(std::in_place_type<flutter::EncodableList>);

  ::EnumDisplayMonitors(nullptr, nullptr, MonitorRepresentationEnumProc,
                        reinterpret_cast<LPARAM>(&displays));

  flutter::EncodableMap result_data = flutter::EncodableMap();
  result_data[flutter::EncodableValue("displays")] = displays;

  result->Success(result_data);
}

Causes this compilation error:

error: no matching member function for call to 'Success'
result->Success(result_data);
third_party/flutter_engine/shell/platform/common/client_wrapper/include/flutter/method_result.h:29:8: note: candidate function not viable: no known conversion from 'EncodableMap' (aka 'map<EncodableValue, EncodableValue>') to 'const flutter::EncodableValue' for 1st argument

Does the Windows package successfully compile for anyone else? I'm using the latest plugin version and the latest stable Flutter engine version.

Question - Does screen_retriever provide keyboard cursor position on Linux?

Does screen_retriever provide keyboard cursor position on Linux?

I am working on a floating emoji keyword in flutter. I would like to show the emoji keyboard when the user presses win + .. I was wondering if I can use screen_retriever to get the (x, y) coordinates of the keyboard cursor on the screen.

Wrong screen ID

In windows, when retrieving the list of screens, you cannot identify correctly the screen 1,2,3 ecc.. as they are set on windows.

how to resolved Permission denied in linux

❯ flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
CMake Error at cmake_install.cmake:66 (file):
  file INSTALL cannot copy file
  "/home/naveen/Desktop/dev/faltu/test_screen_retriever/build/linux/x64/debug/intermediates_do_not_run/test_screen_retriever"
  to "/usr/local/test_screen_retriever": Permission denied.


Building Linux application...                                           
Exception: Build process failed

App fails to build after adding this plugin

Windows app fails fo build and run right after adding this plugin as a dependency (on its own or with another plugin, e.g. windows_manager).

Steps:

  1. Create a new Flutter application project
  2. Run flutter pub add screen_retriever
  3. See the debug console in VS Code
    4 (optional). Try to run the app in debug mode

The error immediately appearing in the console is:

Creating symlink from source to dest failed with ERROR_INVALID_FUNCTION. Try moving your Flutter project to the same drive as your Flutter SDK.

For me, the project and Flutter SDK are in the same parent folder. Most likely reason is that all this files are stored on exFAT volume.

FYI:
Flutter (Channel stable, 3.16.2, on Microsoft Windows [Version 10.0.19045.3570], locale en-US)
• Flutter version 3.16.2
• Framework revision 9e1c857886 (5 days ago), 2023-11-30 11:51:18 -0600
• Engine revision cf7a9d0800
• Dart version 3.2.2
• DevTools version 2.28.3

no such module 'screen_retriever'

Dear leanflutter Org,

I want to use your window_manger plugin, but I get the following error when running the application.

/Users/USER/Documents/Development/privat/REPO/macos/Flutter/GeneratedPluginRegistrant.swift:8:8: error: no such module 'screen_retriever'
import screen_retriever

I have followed the installation instruction with adding window_manager 0.3.7 to the pubspec.yaml. In the main.dart i also added ensureInitialized. Attatched is my main.dart file. I have looked into the GeneratedPluginRegistrant file, there is the import screen_retriever added as well as the import window_manager. Also tried pod install --repo-update in the ./macOS path. flutter clean does also not help.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();

  try {
    if (Platform.isWindows || Platform.isMacOS) {
      var windowOptions = const WindowOptions(size: Size(800, 600));

      await windowManager.waitUntilReadyToShow(windowOptions, () async {
        await windowManager.show();
        await windowManager.focus();
      });
    }

    setupServices();

    logger(message: 'Waiting for services');

    await services.allReady();

    runApp(const MainApp());
  } catch (error) {
    logger(message: '$error');
  }
}

Same value for display height and display visible height

Since version 0.1.9

getPrimaryDisplay().size.height and getPrimaryDisplay().visibleSize.height returns the same value.

On 0.1.8 visibleSize.height returns the display height without the taskbar height.

Is the 0.1.9 behaviour intended?

Incorrect displays size

Hello! There are 2 displays. Each has resolution = 1920x1080.
Display 1 is primary.
изображение

I have next code, which shows info about displays in different positions:

  List<Display> displaysList = await screenRetriever.getAllDisplays();
  displaysList.forEach((display) {
    print(display.toJson());
  });

I will show only necessary info.

name: \.\DISPLAY1, size: {width: 1920.0, height: 1080.0}, visiblePosition: {x: 0.0, y: 0.0}, visibleSize: {width: 1920.0, height: 1040.0}
name: \.\DISPLAY4, size: {width: 3840.0, height: 1081.0}, visiblePosition: {x: 1920.0, y: 1.0}, visibleSize: {width: 1920.0, height: 1040.0}

At first, why second display has width 3840 px? It has 1920 px.

Let's change displays' position
изображение
Not code prints:

name: \.\DISPLAY1, size: {width: 1920.0, height: 1080.0}, visiblePosition: {x: 0.0, y: 0.0}, visibleSize: {width: 1920.0, height: 1040.0}
name: \.\DISPLAY4, size: {width: 0.0, height: 1080.0}, visiblePosition: {x: -1920.0, y: 0.0}, visibleSize: {width: 1920.0, height: 1040.0}

Second display now has width = 0 px. What??? How???

Next position:
изображение

name: \.\DISPLAY1, size: {width: 1920.0, height: 1080.0}, visiblePosition: {x: 0.0, y: 0.0}, visibleSize: {width: 1920.0, height: 1040.0}
name: \.\DISPLAY4, size: {width: 1920.0, height: 2160.0}, visiblePosition: {x: 0.0, y: 1080.0}, visibleSize: {width: 1920.0, height: 1040.0}

Not second display has normal width, but height = 2160. :-(

Last position:
изображение

name: \.\DISPLAY1, size: {width: 1920.0, height: 1080.0}, visiblePosition: {x: 0.0, y: 0.0}, visibleSize: {width: 1920.0, height: 1040.0},
name: \.\DISPLAY4, size: {width: 1920.0, height: 0.0}, visiblePosition: {x: 0.0, y: -1080.0}, visibleSize: {width: 1920.0, height: 1040.0},

At this time second display has height = 0. How it works???

N.b. Visible positiion all display in different positions: work good!
Visible size: height lost 40 pixels

In conclusion: size of displays (if I have 2 and more displays) determines incorrect

ScreenListener support for macos and windows

Are ScreenListener events supported on macos and windows? Looking at the code, it seems that the only version that emits events is Linux when displays are added/removed in the following lines:

g_signal_connect_object(display, "monitor-added",

g_signal_connect_object(display, "monitor-removed",

I would like to have that ability on the other systems, but don't have the knowledge enough to know how to modify your code to do so.

As a side note, there's also no documentation on the README going over the event and whether it is supported on different systems.

Retrieved display name is not correct on Windows.

I use a Huawei Windows11 laptop connected to two external displays. On that machine, retrieving all displays yields incorrect display names with unexpected prefix characters. However, running the same code on my M1 MacBook Pro with the same external displays retrieves the correct display names.

final displays = await screenRetriever.getAllDisplays();
debugPrint('displays : ${displays.map((e) => e.name)}');

on Windows :
flutter: displays : (\\.\DISPLAY1, \\.\DISPLAY2, \\.\DISPLAY3)

on Mac :
flutter: displays : (Built-in Retina Display, 27UF10, U32N3G6R3B)

FYI:

Doctor summary (to see all details, run flutter doctor -v):
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)
[√] Android Studio (version 2023.1)
[√] Connected device (3 available)
[√] Network resources

ScreenRetrieverPlugin.swift:97:34: error: type 'NSScreen' has no member 'views'

Launching lib/main.dart on macOS in debug mode... 2023-05-23 15:33:53.370 xcodebuild[98841:1088419] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled) /Users/aapeli/.pub-cache/hosted/pub.flutter-io.cn/screen_retriever-0.1.6/macos/Classes/ScreenRetrieverPlugin.swift:97:34: error: type 'NSScreen' has no member 'views' "displays": NSScreen.views.map({ screen in ~~~~~~~~ ^~~~~ ** BUILD FAILED **

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.