{"id":30969653,"url":"https://github.com/alihassan143/screenstate","last_synced_at":"2026-05-06T03:32:58.842Z","repository":{"id":65485578,"uuid":"593166720","full_name":"alihassan143/Screenstate","owner":"alihassan143","description":"Desktop Screen State","archived":false,"fork":false,"pushed_at":"2025-04-22T03:42:55.000Z","size":240,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T06:08:12.829Z","etag":null,"topics":["flutter","macos","screen","screenstate","windows"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/desktop_screenstate","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alihassan143.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-25T11:53:15.000Z","updated_at":"2025-04-22T03:42:59.000Z","dependencies_parsed_at":"2024-03-07T19:43:56.570Z","dependency_job_id":"0e52ff9f-21b7-4158-b970-023401515b36","html_url":"https://github.com/alihassan143/Screenstate","commit_stats":{"total_commits":2,"total_committers":2,"mean_commits":1.0,"dds":0.5,"last_synced_commit":"12da23e9228b5cd60ff955e4251a6b0c42d42927"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alihassan143/Screenstate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alihassan143%2FScreenstate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alihassan143%2FScreenstate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alihassan143%2FScreenstate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alihassan143%2FScreenstate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alihassan143","download_url":"https://codeload.github.com/alihassan143/Screenstate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alihassan143%2FScreenstate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274736595,"owners_count":25340168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flutter","macos","screen","screenstate","windows"],"created_at":"2025-09-12T01:12:58.131Z","updated_at":"2026-05-06T03:32:58.806Z","avatar_url":"https://github.com/alihassan143.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Desktop ScreenState\n\n**Desktop ScreenState** is a Flutter desktop plugin that provides functionality for your application to accurately determine whether the screen is on or off, as well as to detect if it's locked or unlocked.\n\n## Platform Support\n\n|   Linux   |   macOS   |  Windows  |\n| :-------: | :-------: | :-------: |\n|     ✅     |     ✅     |     ✅     |\n\n### macOS\n\nNo changes are required.\n\n### Windows\n\nMake the following changes to the respective files:\n\n#### `windows/runner/flutter_window.h`\n\n```diff\n#ifndef RUNNER_FLUTTER_WINDOW_H_\n#define RUNNER_FLUTTER_WINDOW_H_\n\n#include \u003cflutter/dart_project.h\u003e\n#include \u003cflutter/flutter_view_controller.h\u003e\n+ #include \u003cwinuser.h\u003e\n#include \u003cmemory\u003e\n\n#include \"win32_window.h\"\n\n// A window that does nothing but host a Flutter view.\nclass FlutterWindow : public Win32Window {\n public:\n  // Creates a new FlutterWindow hosting a Flutter view running |project|.\n  explicit FlutterWindow(const flutter::DartProject\u0026 project);\n  virtual ~FlutterWindow();\n\n protected:\n  // Win32Window:\n  bool OnCreate() override;\n  void OnDestroy() override;\n  LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,\n                         LPARAM const lparam) noexcept override;\n\n private:\n  // The project to run.\n  flutter::DartProject project_;\n+ HPOWERNOTIFY power_notification_handle_ = nullptr;\n  // The Flutter instance hosted by this window.\n  std::unique_ptr\u003cflutter::FlutterViewController\u003e flutter_controller_;\n};\n\n#endif  // RUNNER_FLUTTER_WINDOW_H_\n\n\n```\n#### `windows/runner/flutter_window.cpp`\n```diff\n#include \"flutter_window.h\"\n\n#include \u003coptional\u003e\n+ #include \u003cwtsapi32.h\u003e\n#include \"flutter/generated_plugin_registrant.h\"\n+ #pragma comment( lib, \"wtsapi32.lib\" )\n\nFlutterWindow::FlutterWindow(const flutter::DartProject\u0026 project)\n    : project_(project) {}\n\nFlutterWindow::~FlutterWindow() {\n+ if (power_notification_handle_) {\n+ UnregisterPowerSettingNotification(power_notification_handle_);\n+ }\n}\n\nbool FlutterWindow::OnCreate() {\n  if (!Win32Window::OnCreate()) {\n    return false;\n  }\n\n  RECT frame = GetClientArea();\n\n  // The size here must match the window dimensions to avoid unnecessary surface\n  // creation / destruction in the startup path.\n  flutter_controller_ = std::make_unique\u003cflutter::FlutterViewController\u003e(\n      frame.right - frame.left, frame.bottom - frame.top, project_);\n  // Ensure that basic setup of the controller was successful.\n  if (!flutter_controller_-\u003eengine() || !flutter_controller_-\u003eview()) {\n    return false;\n  }\n  RegisterPlugins(flutter_controller_-\u003eengine());\n  SetChildContent(flutter_controller_-\u003eview()-\u003eGetNativeWindow());\n+ power_notification_handle_ = RegisterPowerSettingNotification(GetHandle(), \u0026GUID_CONSOLE_DISPLAY_STATE, DEVICE_NOTIFY_WINDOW_HANDLE);\n+ WTSRegisterSessionNotification(GetHandle(),NOTIFY_FOR_THIS_SESSION);\n  return true;\n}\n\nvoid FlutterWindow::OnDestroy() {\n  if (flutter_controller_) {\n    flutter_controller_ = nullptr;\n  }\n\n  Win32Window::OnDestroy();\n}\n\nLRESULT\nFlutterWindow::MessageHandler(HWND hwnd, UINT const message,\n                              WPARAM const wparam,\n                              LPARAM const lparam) noexcept {\n  // Give Flutter, including plugins, an opportunity to handle window messages.\n  if (flutter_controller_) {\n    std::optional\u003cLRESULT\u003e result =\n        flutter_controller_-\u003eHandleTopLevelWindowProc(hwnd, message, wparam,\n                                                      lparam);\n    if (result) {\n      return *result;\n    }\n  }\n\n  switch (message) {\n    case WM_FONTCHANGE:\n      flutter_controller_-\u003eengine()-\u003eReloadSystemFonts();\n      break;\n  }\n\n  return Win32Window::MessageHandler(hwnd, message, wparam, lparam);\n}\n```\n### Linux\nThis plugin relies on the gnome-screensaver to provide screen state information.\n\n#### Linux Important Note:\nIf gnome-screensaver is not installed on your Linux system, please install it before using this plugin. The functionality of the plugin depends on the presence of gnome-screensaver.\n```\nsudo apt-get install gnome-screensaver\n```\n\n## Getting Started\n\n1. Add `desktop_screenstate` to your `pubspec.yaml`.\n\n```yaml\n  desktop_screenstate: $latest_version\n```\n\n2. **Linux ONLY** - Only needed if your app will run on Linux.\n\nIn your main() function, select the monitor service type to use. By default, the `dbus-monitor` service is used. However, you may find that the `gdbus` service is more reliable.\n\nThe `dbus-monitor` service is included in the standard D-Bus package (`dbus-utils` or equivalent). The `gdbus` requires GLib 2.26+ (typically installed via the `glib2` package).\n```\nsudo apt-get install glib2\n```\n\nIn your `main.dart` file, add the following to your `main()` function. The process exit cleanup code is needed regardless of which type of monitor service you select. If this cleanup code is not added, then background processes will be left running, and they will accumulate over time as your application is started and stopped.\n```dart\nimport 'package:desktop_screenstate/desktop_screenstate.dart';\n\nvoid main() {\n  DesktopScreenState.linuxMonitor = ScreenStateMonitor.gdbus;\n  /// Hook into the process exit signals to clean up processes\n  ProcessSignal.sigint.watch().listen((_) =\u003e shutdownApp());\n  ProcessSignal.sigterm.watch().listen((_) =\u003e shutdownApp());\n\n  runApp(MyApp());\n}\n\nvoid shutdownApp() {\n  try {\n    DesktopScreenState.dispose();\n    // ... Add your custom cleanup logic here ...\n  } finally {\n    exit(0);\n  }\n}\n```\n\n3. Then you can use `DesktopScreenState.instance.isActive` to listen window active event.\n\n```dart\nfinal ValueListenable\u003cbool\u003e event = DesktopScreenState.instance.isActive;\n\nfinal bool active = event.value;\n\nevent.addListener(() {\n  debugPrint(\"screen is on or off: ${event.value}\");\n});\n\n```\n4. You can now utilize `DesktopScreenState.instance.state` to get the current state of the screen:\n\n```dart\nfinal ScreenState state = DesktopScreenState.instance.state;\n\nswitch (state) {\n  case ScreenState.awaked:\n    debugPrint(\"Screen is on\");\n    break;\n  case ScreenState.sleep:\n    debugPrint(\"Screen is sleep\");\n    break;\n  case ScreenState.locked:\n    debugPrint(\"Screen is locked\");\n    break;\n  case ScreenState.unlocked:\n    debugPrint(\"Screen is unlocked\");\n    break;\n}\nThe DesktopScreenState instance provides an enum ScreenState with the following possible values:\n\n\n\n```\n\nsee LICENSE file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falihassan143%2Fscreenstate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falihassan143%2Fscreenstate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falihassan143%2Fscreenstate/lists"}