From cd4e1c612f9c78b1fd9081e28914dfd58087ccac Mon Sep 17 00:00:00 2001 From: Igor Demyanov Date: Sat, 3 May 2025 17:49:24 +0300 Subject: [PATCH 1/6] add linux_dpms package --- packages/linux_dpms/.gitignore | 7 ++ packages/linux_dpms/LICENSE | 21 +++++ packages/linux_dpms/analysis_options.yaml | 30 +++++++ packages/linux_dpms/lib/linux_dpms.dart | 3 + .../linux_dpms/lib/src/dpms_power_state.dart | 17 ++++ packages/linux_dpms/lib/src/linux_dpms.dart | 83 +++++++++++++++++++ .../linux_dpms/lib/src/linux_dpms_stub.dart | 15 ++++ .../linux_dpms/lib/src/linux_dpms_web.dart | 13 +++ packages/linux_dpms/pubspec.yaml | 13 +++ 9 files changed, 202 insertions(+) create mode 100644 packages/linux_dpms/.gitignore create mode 100644 packages/linux_dpms/LICENSE create mode 100644 packages/linux_dpms/analysis_options.yaml create mode 100644 packages/linux_dpms/lib/linux_dpms.dart create mode 100644 packages/linux_dpms/lib/src/dpms_power_state.dart create mode 100644 packages/linux_dpms/lib/src/linux_dpms.dart create mode 100644 packages/linux_dpms/lib/src/linux_dpms_stub.dart create mode 100644 packages/linux_dpms/lib/src/linux_dpms_web.dart create mode 100644 packages/linux_dpms/pubspec.yaml diff --git a/packages/linux_dpms/.gitignore b/packages/linux_dpms/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/packages/linux_dpms/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/packages/linux_dpms/LICENSE b/packages/linux_dpms/LICENSE new file mode 100644 index 0000000..20ca2e3 --- /dev/null +++ b/packages/linux_dpms/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Klaralvdalens Datakonsult AB + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/linux_dpms/analysis_options.yaml b/packages/linux_dpms/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/packages/linux_dpms/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/packages/linux_dpms/lib/linux_dpms.dart b/packages/linux_dpms/lib/linux_dpms.dart new file mode 100644 index 0000000..d3862d6 --- /dev/null +++ b/packages/linux_dpms/lib/linux_dpms.dart @@ -0,0 +1,3 @@ +export 'src/linux_dpms_stub.dart' + if (dart.library.io) 'src/linux_dpms.dart' + if (dart.library.js) 'src/linux_dpms_web.dart'; diff --git a/packages/linux_dpms/lib/src/dpms_power_state.dart b/packages/linux_dpms/lib/src/dpms_power_state.dart new file mode 100644 index 0000000..4b48aae --- /dev/null +++ b/packages/linux_dpms/lib/src/dpms_power_state.dart @@ -0,0 +1,17 @@ +/* +https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_mode.h#L143 +/* bit compatible with the xorg definitions. */ +#define DRM_MODE_DPMS_ON 0 +#define DRM_MODE_DPMS_STANDBY 1 +#define DRM_MODE_DPMS_SUSPEND 2 +#define DRM_MODE_DPMS_OFF 3 +*/ +enum DpmsPowerState { + on(0), + standby(1), + suspend(2), + off(3); + + final int value; + const DpmsPowerState(this.value); +} diff --git a/packages/linux_dpms/lib/src/linux_dpms.dart b/packages/linux_dpms/lib/src/linux_dpms.dart new file mode 100644 index 0000000..ba1e1ad --- /dev/null +++ b/packages/linux_dpms/lib/src/linux_dpms.dart @@ -0,0 +1,83 @@ +import 'dart:ffi' as ffi; +import 'package:linux_dpms/src/dpms_power_state.dart'; + +/* +uint32_t dpms_isAvailable(); +void dpms_setProperty(uint64_t value); +uint64_t dpms_getProperty(); +*/ + +typedef DpmsGetPropertyFuncType = ffi.Uint64 Function(); +typedef DpmsGetPropertyType = int Function(); + +typedef DpmsSetPropertyFuncType = ffi.Void Function(ffi.Uint64 value); +typedef DpmsSetPropertyType = void Function(int value); + +typedef DpmsIsAvailableFuncType = ffi.Uint32 Function(); +typedef DpmsIsAvailableType = int Function(); + +class DpmsLinux { + final _DpmsLinux _service = _DpmsLinux.instance; + bool isAvailable() { + if (_service.dpmsIsAvailable == null || _service.dpmsSetProperty == null) { + return false; + } + return true; + } + + void setPowerState(DpmsPowerState state) { + if (_service.dpmsSetProperty != null) { + _service.dpmsSetProperty!(state.value); + } + return; + } + + DpmsPowerState getPowerState() { + if (_service.dpmsGetProperty != null) { + final value = _service.dpmsGetProperty!(); + return DpmsPowerState.values.firstWhere((item) => item.value == value); + } + return DpmsPowerState.on; + } +} + +class _DpmsLinux { + final DpmsIsAvailableType? dpmsIsAvailable; + final DpmsGetPropertyType? dpmsGetProperty; + final DpmsSetPropertyType? dpmsSetProperty; + + _DpmsLinux._constructor({ + required this.dpmsIsAvailable, + required this.dpmsGetProperty, + required this.dpmsSetProperty, + }); + + factory _DpmsLinux._() { + final lib = ffi.DynamicLibrary.process(); + + try { + final dpmsIsAvailable = lib.lookupFunction("dpms_isAvailable"); + final dpmsGetProperty = lib.lookupFunction("dpms_getProperty"); + final dpmsSetProperty = lib.lookupFunction("dpms_setProperty"); + + return _DpmsLinux._constructor( + dpmsIsAvailable: dpmsIsAvailable, + dpmsGetProperty: dpmsGetProperty, + dpmsSetProperty: dpmsSetProperty, + ); + } on ArgumentError { + return _DpmsLinux._constructor( + dpmsIsAvailable: null, + dpmsGetProperty: null, + dpmsSetProperty: null, + ); + } + } + + static _DpmsLinux? _instance; + + static _DpmsLinux get instance { + _instance ??= _DpmsLinux._(); + return _instance!; + } +} diff --git a/packages/linux_dpms/lib/src/linux_dpms_stub.dart b/packages/linux_dpms/lib/src/linux_dpms_stub.dart new file mode 100644 index 0000000..afca0c3 --- /dev/null +++ b/packages/linux_dpms/lib/src/linux_dpms_stub.dart @@ -0,0 +1,15 @@ +import 'package:linux_dpms/src/dpms_power_state.dart'; + +class DpmsLinux { + bool isAvailable() { + throw UnimplementedError(); + } + + void setPowerState(DpmsPowerState state) { + throw UnimplementedError(); + } + + DpmsPowerState getPowerState() { + throw UnimplementedError(); + } +} diff --git a/packages/linux_dpms/lib/src/linux_dpms_web.dart b/packages/linux_dpms/lib/src/linux_dpms_web.dart new file mode 100644 index 0000000..aaac0b6 --- /dev/null +++ b/packages/linux_dpms/lib/src/linux_dpms_web.dart @@ -0,0 +1,13 @@ +import 'package:linux_dpms/src/dpms_power_state.dart'; + +class DpmsLinux { + bool isAvailable() { + return false; + } + + void setPowerState(DpmsPowerState state) {} + + DpmsPowerState getPowerState() { + return DpmsPowerState.on; + } +} diff --git a/packages/linux_dpms/pubspec.yaml b/packages/linux_dpms/pubspec.yaml new file mode 100644 index 0000000..26e0d5e --- /dev/null +++ b/packages/linux_dpms/pubspec.yaml @@ -0,0 +1,13 @@ +name: linux_dpms +description: Package for using DPMS on linux. +version: 0.1.0+1 +repository: https://github.com/ardera/flutter_packages + +environment: + sdk: '>=3.0.0 <4.0.0' + +dev_dependencies: + lints: ^3.0.0 + test: ^1.21.0 + + \ No newline at end of file From c0945b4e7eef3201a93f868f0262222ae19315f0 Mon Sep 17 00:00:00 2001 From: Igor Demyanov Date: Sat, 3 May 2025 17:56:34 +0300 Subject: [PATCH 2/6] export DpmsPowerState --- packages/linux_dpms/lib/linux_dpms.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/linux_dpms/lib/linux_dpms.dart b/packages/linux_dpms/lib/linux_dpms.dart index d3862d6..b7b149b 100644 --- a/packages/linux_dpms/lib/linux_dpms.dart +++ b/packages/linux_dpms/lib/linux_dpms.dart @@ -1,3 +1,4 @@ export 'src/linux_dpms_stub.dart' if (dart.library.io) 'src/linux_dpms.dart' if (dart.library.js) 'src/linux_dpms_web.dart'; +export 'src/dpms_power_state.dart'; From 4234e44ae1f2f2d8c523326fd987f61df2cc42f1 Mon Sep 17 00:00:00 2001 From: Igor Demyanov Date: Tue, 30 Dec 2025 23:25:02 +0300 Subject: [PATCH 3/6] rename package to dpms, rename set\get methods --- packages/linux_dpms/.gitignore | 7 -- packages/linux_dpms/LICENSE | 21 ----- packages/linux_dpms/analysis_options.yaml | 30 ------- packages/linux_dpms/lib/linux_dpms.dart | 4 - .../linux_dpms/lib/src/dpms_power_state.dart | 17 ---- packages/linux_dpms/lib/src/linux_dpms.dart | 83 ------------------- .../linux_dpms/lib/src/linux_dpms_stub.dart | 15 ---- .../linux_dpms/lib/src/linux_dpms_web.dart | 13 --- packages/linux_dpms/pubspec.yaml | 13 --- 9 files changed, 203 deletions(-) delete mode 100644 packages/linux_dpms/.gitignore delete mode 100644 packages/linux_dpms/LICENSE delete mode 100644 packages/linux_dpms/analysis_options.yaml delete mode 100644 packages/linux_dpms/lib/linux_dpms.dart delete mode 100644 packages/linux_dpms/lib/src/dpms_power_state.dart delete mode 100644 packages/linux_dpms/lib/src/linux_dpms.dart delete mode 100644 packages/linux_dpms/lib/src/linux_dpms_stub.dart delete mode 100644 packages/linux_dpms/lib/src/linux_dpms_web.dart delete mode 100644 packages/linux_dpms/pubspec.yaml diff --git a/packages/linux_dpms/.gitignore b/packages/linux_dpms/.gitignore deleted file mode 100644 index 3cceda5..0000000 --- a/packages/linux_dpms/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ - -# Avoid committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock diff --git a/packages/linux_dpms/LICENSE b/packages/linux_dpms/LICENSE deleted file mode 100644 index 20ca2e3..0000000 --- a/packages/linux_dpms/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 Klaralvdalens Datakonsult AB - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/linux_dpms/analysis_options.yaml b/packages/linux_dpms/analysis_options.yaml deleted file mode 100644 index dee8927..0000000 --- a/packages/linux_dpms/analysis_options.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - -include: package:lints/recommended.yaml - -# Uncomment the following section to specify additional rules. - -# linter: -# rules: -# - camel_case_types - -# analyzer: -# exclude: -# - path/to/excluded/files/** - -# For more information about the core and recommended set of lints, see -# https://dart.dev/go/core-lints - -# For additional information about configuring this file, see -# https://dart.dev/guides/language/analysis-options diff --git a/packages/linux_dpms/lib/linux_dpms.dart b/packages/linux_dpms/lib/linux_dpms.dart deleted file mode 100644 index b7b149b..0000000 --- a/packages/linux_dpms/lib/linux_dpms.dart +++ /dev/null @@ -1,4 +0,0 @@ -export 'src/linux_dpms_stub.dart' - if (dart.library.io) 'src/linux_dpms.dart' - if (dart.library.js) 'src/linux_dpms_web.dart'; -export 'src/dpms_power_state.dart'; diff --git a/packages/linux_dpms/lib/src/dpms_power_state.dart b/packages/linux_dpms/lib/src/dpms_power_state.dart deleted file mode 100644 index 4b48aae..0000000 --- a/packages/linux_dpms/lib/src/dpms_power_state.dart +++ /dev/null @@ -1,17 +0,0 @@ -/* -https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_mode.h#L143 -/* bit compatible with the xorg definitions. */ -#define DRM_MODE_DPMS_ON 0 -#define DRM_MODE_DPMS_STANDBY 1 -#define DRM_MODE_DPMS_SUSPEND 2 -#define DRM_MODE_DPMS_OFF 3 -*/ -enum DpmsPowerState { - on(0), - standby(1), - suspend(2), - off(3); - - final int value; - const DpmsPowerState(this.value); -} diff --git a/packages/linux_dpms/lib/src/linux_dpms.dart b/packages/linux_dpms/lib/src/linux_dpms.dart deleted file mode 100644 index ba1e1ad..0000000 --- a/packages/linux_dpms/lib/src/linux_dpms.dart +++ /dev/null @@ -1,83 +0,0 @@ -import 'dart:ffi' as ffi; -import 'package:linux_dpms/src/dpms_power_state.dart'; - -/* -uint32_t dpms_isAvailable(); -void dpms_setProperty(uint64_t value); -uint64_t dpms_getProperty(); -*/ - -typedef DpmsGetPropertyFuncType = ffi.Uint64 Function(); -typedef DpmsGetPropertyType = int Function(); - -typedef DpmsSetPropertyFuncType = ffi.Void Function(ffi.Uint64 value); -typedef DpmsSetPropertyType = void Function(int value); - -typedef DpmsIsAvailableFuncType = ffi.Uint32 Function(); -typedef DpmsIsAvailableType = int Function(); - -class DpmsLinux { - final _DpmsLinux _service = _DpmsLinux.instance; - bool isAvailable() { - if (_service.dpmsIsAvailable == null || _service.dpmsSetProperty == null) { - return false; - } - return true; - } - - void setPowerState(DpmsPowerState state) { - if (_service.dpmsSetProperty != null) { - _service.dpmsSetProperty!(state.value); - } - return; - } - - DpmsPowerState getPowerState() { - if (_service.dpmsGetProperty != null) { - final value = _service.dpmsGetProperty!(); - return DpmsPowerState.values.firstWhere((item) => item.value == value); - } - return DpmsPowerState.on; - } -} - -class _DpmsLinux { - final DpmsIsAvailableType? dpmsIsAvailable; - final DpmsGetPropertyType? dpmsGetProperty; - final DpmsSetPropertyType? dpmsSetProperty; - - _DpmsLinux._constructor({ - required this.dpmsIsAvailable, - required this.dpmsGetProperty, - required this.dpmsSetProperty, - }); - - factory _DpmsLinux._() { - final lib = ffi.DynamicLibrary.process(); - - try { - final dpmsIsAvailable = lib.lookupFunction("dpms_isAvailable"); - final dpmsGetProperty = lib.lookupFunction("dpms_getProperty"); - final dpmsSetProperty = lib.lookupFunction("dpms_setProperty"); - - return _DpmsLinux._constructor( - dpmsIsAvailable: dpmsIsAvailable, - dpmsGetProperty: dpmsGetProperty, - dpmsSetProperty: dpmsSetProperty, - ); - } on ArgumentError { - return _DpmsLinux._constructor( - dpmsIsAvailable: null, - dpmsGetProperty: null, - dpmsSetProperty: null, - ); - } - } - - static _DpmsLinux? _instance; - - static _DpmsLinux get instance { - _instance ??= _DpmsLinux._(); - return _instance!; - } -} diff --git a/packages/linux_dpms/lib/src/linux_dpms_stub.dart b/packages/linux_dpms/lib/src/linux_dpms_stub.dart deleted file mode 100644 index afca0c3..0000000 --- a/packages/linux_dpms/lib/src/linux_dpms_stub.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:linux_dpms/src/dpms_power_state.dart'; - -class DpmsLinux { - bool isAvailable() { - throw UnimplementedError(); - } - - void setPowerState(DpmsPowerState state) { - throw UnimplementedError(); - } - - DpmsPowerState getPowerState() { - throw UnimplementedError(); - } -} diff --git a/packages/linux_dpms/lib/src/linux_dpms_web.dart b/packages/linux_dpms/lib/src/linux_dpms_web.dart deleted file mode 100644 index aaac0b6..0000000 --- a/packages/linux_dpms/lib/src/linux_dpms_web.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:linux_dpms/src/dpms_power_state.dart'; - -class DpmsLinux { - bool isAvailable() { - return false; - } - - void setPowerState(DpmsPowerState state) {} - - DpmsPowerState getPowerState() { - return DpmsPowerState.on; - } -} diff --git a/packages/linux_dpms/pubspec.yaml b/packages/linux_dpms/pubspec.yaml deleted file mode 100644 index 26e0d5e..0000000 --- a/packages/linux_dpms/pubspec.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: linux_dpms -description: Package for using DPMS on linux. -version: 0.1.0+1 -repository: https://github.com/ardera/flutter_packages - -environment: - sdk: '>=3.0.0 <4.0.0' - -dev_dependencies: - lints: ^3.0.0 - test: ^1.21.0 - - \ No newline at end of file From 868075d48945a4642c3a350845b4a891eaf53bb8 Mon Sep 17 00:00:00 2001 From: Igor Demyanov Date: Tue, 30 Dec 2025 23:25:31 +0300 Subject: [PATCH 4/6] rename package to dpms, rename set\get methods --- packages/dpms/.gitignore | 7 +++ packages/dpms/LICENSE | 21 +++++++ packages/dpms/analysis_options.yaml | 30 ++++++++++ packages/dpms/lib/dpms.dart | 2 + packages/dpms/lib/src/dpms.dart | 42 ++++++++++++++ packages/dpms/lib/src/dpms_stub.dart | 15 +++++ packages/dpms/lib/src/dpms_web.dart | 13 +++++ packages/dpms/lib/src/platform/flutterpi.dart | 57 +++++++++++++++++++ packages/dpms/lib/src/power_mode.dart | 4 ++ packages/dpms/pubspec.yaml | 13 +++++ 10 files changed, 204 insertions(+) create mode 100644 packages/dpms/.gitignore create mode 100644 packages/dpms/LICENSE create mode 100644 packages/dpms/analysis_options.yaml create mode 100644 packages/dpms/lib/dpms.dart create mode 100644 packages/dpms/lib/src/dpms.dart create mode 100644 packages/dpms/lib/src/dpms_stub.dart create mode 100644 packages/dpms/lib/src/dpms_web.dart create mode 100644 packages/dpms/lib/src/platform/flutterpi.dart create mode 100644 packages/dpms/lib/src/power_mode.dart create mode 100644 packages/dpms/pubspec.yaml diff --git a/packages/dpms/.gitignore b/packages/dpms/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/packages/dpms/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/packages/dpms/LICENSE b/packages/dpms/LICENSE new file mode 100644 index 0000000..c4b6a63 --- /dev/null +++ b/packages/dpms/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Igor Demyanov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/dpms/analysis_options.yaml b/packages/dpms/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/packages/dpms/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/packages/dpms/lib/dpms.dart b/packages/dpms/lib/dpms.dart new file mode 100644 index 0000000..c1d0960 --- /dev/null +++ b/packages/dpms/lib/dpms.dart @@ -0,0 +1,2 @@ +export 'src/dpms_stub.dart' if (dart.library.io) 'src/linux_dpms.dart' if (dart.library.js) 'src/linux_dpms_web.dart'; +export 'src/power_mode.dart'; diff --git a/packages/dpms/lib/src/dpms.dart b/packages/dpms/lib/src/dpms.dart new file mode 100644 index 0000000..1ae3169 --- /dev/null +++ b/packages/dpms/lib/src/dpms.dart @@ -0,0 +1,42 @@ +import 'package:dpms/src/platform/flutterpi.dart'; +import 'package:dpms/src/power_mode.dart'; + +class Dpms { + final FlutterpiDPMS _service = FlutterpiDPMS.instance; + /* +https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_mode.h#L143 +/* bit compatible with the xorg definitions. */ +#define DRM_MODE_DPMS_ON 0 +#define DRM_MODE_DPMS_STANDBY 1 +#define DRM_MODE_DPMS_SUSPEND 2 +#define DRM_MODE_DPMS_OFF 3 +*/ + // ignore: constant_identifier_names + static const DRM_MODE_DPMS_ON = 0; + // ignore: constant_identifier_names + static const DRM_MODE_DPMS_OFF = 3; + bool isAvailable() { + if (_service.dpmsIsAvailable == null || _service.dpmsSetProperty == null) { + return false; + } + return true; + } + + void setMode(PowerMode state) { + if (_service.dpmsSetProperty != null) { + _service.dpmsSetProperty!(state == PowerMode.on ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); + } + return; + } + + PowerMode getMode() { + if (_service.dpmsGetProperty != null) { + final value = _service.dpmsGetProperty!(); + if (value == DRM_MODE_DPMS_ON) { + return PowerMode.on; + } + PowerMode.off; + } + return PowerMode.on; + } +} diff --git a/packages/dpms/lib/src/dpms_stub.dart b/packages/dpms/lib/src/dpms_stub.dart new file mode 100644 index 0000000..281b4a7 --- /dev/null +++ b/packages/dpms/lib/src/dpms_stub.dart @@ -0,0 +1,15 @@ +import 'package:dpms/src/power_mode.dart'; + +class Dpms { + bool isAvailable() { + throw UnimplementedError(); + } + + void setMode(PowerMode mode) { + throw UnimplementedError(); + } + + PowerMode getMode() { + throw UnimplementedError(); + } +} diff --git a/packages/dpms/lib/src/dpms_web.dart b/packages/dpms/lib/src/dpms_web.dart new file mode 100644 index 0000000..b1c811a --- /dev/null +++ b/packages/dpms/lib/src/dpms_web.dart @@ -0,0 +1,13 @@ +import 'package:dpms/src/power_mode.dart'; + +class Dpms { + bool isAvailable() { + return false; + } + + void setMode(PowerMode mode) {} + + PowerMode getMode() { + return PowerMode.on; + } +} diff --git a/packages/dpms/lib/src/platform/flutterpi.dart b/packages/dpms/lib/src/platform/flutterpi.dart new file mode 100644 index 0000000..2b113f8 --- /dev/null +++ b/packages/dpms/lib/src/platform/flutterpi.dart @@ -0,0 +1,57 @@ +import 'dart:ffi' as ffi; + +/* +uint32_t dpms_isAvailable(); +void dpms_setProperty(uint64_t value); +uint64_t dpms_getProperty(); +*/ + +typedef DpmsGetPropertyFuncType = ffi.Uint64 Function(); +typedef DpmsGetPropertyType = int Function(); + +typedef DpmsSetPropertyFuncType = ffi.Void Function(ffi.Uint64 value); +typedef DpmsSetPropertyType = void Function(int value); + +typedef DpmsIsAvailableFuncType = ffi.Uint32 Function(); +typedef DpmsIsAvailableType = int Function(); + +class FlutterpiDPMS { + final DpmsIsAvailableType? dpmsIsAvailable; + final DpmsGetPropertyType? dpmsGetProperty; + final DpmsSetPropertyType? dpmsSetProperty; + + FlutterpiDPMS._constructor({ + required this.dpmsIsAvailable, + required this.dpmsGetProperty, + required this.dpmsSetProperty, + }); + + factory FlutterpiDPMS._() { + final lib = ffi.DynamicLibrary.process(); + + try { + final dpmsIsAvailable = lib.lookupFunction("dpms_isAvailable"); + final dpmsGetProperty = lib.lookupFunction("dpms_getProperty"); + final dpmsSetProperty = lib.lookupFunction("dpms_setProperty"); + + return FlutterpiDPMS._constructor( + dpmsIsAvailable: dpmsIsAvailable, + dpmsGetProperty: dpmsGetProperty, + dpmsSetProperty: dpmsSetProperty, + ); + } on ArgumentError { + return FlutterpiDPMS._constructor( + dpmsIsAvailable: null, + dpmsGetProperty: null, + dpmsSetProperty: null, + ); + } + } + + static FlutterpiDPMS? _instance; + + static FlutterpiDPMS get instance { + _instance ??= FlutterpiDPMS._(); + return _instance!; + } +} diff --git a/packages/dpms/lib/src/power_mode.dart b/packages/dpms/lib/src/power_mode.dart new file mode 100644 index 0000000..56eb9ca --- /dev/null +++ b/packages/dpms/lib/src/power_mode.dart @@ -0,0 +1,4 @@ +enum PowerMode { + on, + off, +} diff --git a/packages/dpms/pubspec.yaml b/packages/dpms/pubspec.yaml new file mode 100644 index 0000000..57c5022 --- /dev/null +++ b/packages/dpms/pubspec.yaml @@ -0,0 +1,13 @@ +name: dpms +description: Package for using DPMS (Display Power Management Signaling) on linux. +version: 0.1.0+1 +repository: https://github.com/ardera/flutter_packages + +environment: + sdk: '>=3.0.0 <4.0.0' + +dev_dependencies: + lints: ^3.0.0 + test: ^1.21.0 + + \ No newline at end of file From 4f2eabf9f7f47c44c169dc56d261b6e374a68fb7 Mon Sep 17 00:00:00 2001 From: Igor Demyanov Date: Tue, 30 Dec 2025 23:26:24 +0300 Subject: [PATCH 5/6] dpms bump version --- packages/dpms/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dpms/pubspec.yaml b/packages/dpms/pubspec.yaml index 57c5022..b1c0bd8 100644 --- a/packages/dpms/pubspec.yaml +++ b/packages/dpms/pubspec.yaml @@ -1,6 +1,6 @@ name: dpms description: Package for using DPMS (Display Power Management Signaling) on linux. -version: 0.1.0+1 +version: 1.0.0+1 repository: https://github.com/ardera/flutter_packages environment: From 407a39d332c8bf14e3aec332a47d42925e44dee8 Mon Sep 17 00:00:00 2001 From: Igor Demyanov Date: Tue, 30 Dec 2025 23:38:22 +0300 Subject: [PATCH 6/6] fix dpms import --- packages/dpms/lib/dpms.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dpms/lib/dpms.dart b/packages/dpms/lib/dpms.dart index c1d0960..af63ee8 100644 --- a/packages/dpms/lib/dpms.dart +++ b/packages/dpms/lib/dpms.dart @@ -1,2 +1,2 @@ -export 'src/dpms_stub.dart' if (dart.library.io) 'src/linux_dpms.dart' if (dart.library.js) 'src/linux_dpms_web.dart'; +export 'src/dpms_stub.dart' if (dart.library.io) 'src/dpms.dart' if (dart.library.js) 'src/dpms_web.dart'; export 'src/power_mode.dart';