SHIFT is an open source shell built on KDE Plasma Mobile, designed to adapt fluidly to your computing needs across devices
Find a file
Florian RICHER 5c6a97caa5 Flashlight : Use udev instead of hardcoded pinephone device file
# Goal of this patch

Use udev to change or detect flash device instead of hardcoded pinephone device file.
Inspired by phosh flash manager because it works in many devices. https://gitlab.gnome.org/World/Phosh/phosh/-/blob/main/src/torch-manager.c?ref_type=heads#L168-198

# Remaining work

- [x] Minimal project for testing
- [x] Try to build for pmOS to test in my device (OP6)
- [x] Need udev rules to work (Require write permission in brightness)

# Stabilization

- [x] read permission removed in max_brightness to check if no crash
> "Failed to read max_brightness from udev device" in log
- [x] read permission removed in brightness to check if no crash
> "Failed to read brightness from udev device" in log
- [x] "Break" match in my side to check if no crash occured when no device found
> "No flashlight found" in log

# Minimal project

It run in my device perfectly, it find device, get current value and max value and toggle flashlight. It require **root** permissions to write in device file.

```cpp
#include <iostream>
#include <cstring>
#include <libudev.h>

#define TORCH_SUBSYSTEM "leds"

int main() {
    struct udev* udev = udev_new();
    struct udev_enumerate* enumerate = udev_enumerate_new(udev);

    // Use to find all devices in subsystem "leds"
    // And use match sysname to filter only flash or torch
    // Example:
    //  - /sys/devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:led-controller@d300/leds/white:flash On OP6
    //  - /sys/devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:led-controller@d300/leds/yellow:flash On OP6
    //  - /sys/devices/platform/led-controller/leds/white:flash/brightness On pinephone
    udev_enumerate_add_match_subsystem(enumerate, TORCH_SUBSYSTEM);
    udev_enumerate_add_match_sysname(enumerate, "*:torch");
    udev_enumerate_add_match_sysname(enumerate, "*:flash");
    udev_enumerate_scan_devices(enumerate);

    struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate);
    struct udev_list_entry *entry = udev_list_entry_get_next(devices);

    if (entry == nullptr) {
        std::cout << "No flashlight found" << std::endl;
        return 1;
    }

    const char *path = udev_list_entry_get_name(entry);
    struct udev_device *torch = udev_device_new_from_syspath(udev, path);

    const char *max_brightness = udev_device_get_sysattr_value(torch, "max_brightness");

    const char *brightness = udev_device_get_sysattr_value(torch, "brightness");

    bool enabled = std::strcmp(brightness, "0") != 0;
    udev_device_set_sysattr_value(torch, "brightness", const_cast<char*>(enabled ? "0" : max_brightness));

    udev_device_unref(torch);
    udev_enumerate_unref(enumerate);
    udev_unref(udev);
    return 0;
}
```

Build with `g++ torch.cpp -ludev -o torch`
Run with `sudo ./torch`

# Important info

- **udev** dependencies added
- destructor for flashlightutil added to unref udev_device

# Require udev rules

Files `/etc/udev/rules.d/99-flashlight.rules`
```bash
# Allow everyone to set brightness of flashlight (Required for plasma-mobile flashlightplugin)
SUBSYSTEMS=="leds", KERNEL=="*:flash|*:torch", RUN+="/bin/chmod 666 %S%p/brightness"
```

pmOS : See to add depends `eudev` and makedepends `eudev-dev`
2023-12-31 17:11:28 +00:00
.reuse Add dep5 file for setting license of json files 2022-07-21 19:30:11 +00:00
bin SVN_SILENT made messages (.desktop file) - always resolve ours 2023-12-17 02:07:26 +00:00
components Add hotspot in quicksettings list 2023-12-25 12:52:50 +01:00
containments SVN_SILENT made messages (.desktop file) - always resolve ours 2023-12-22 02:13:13 +00:00
envmanager envmanager: Explicitly enable kdecoration plugin 2023-12-29 15:44:26 -05:00
initialstart initialstart/wifi: Update to card based design 2023-12-27 18:17:16 -05:00
kcms kcms: time: Avoid calling waitForFinished 2023-12-30 17:53:34 +00:00
kded SVN_SILENT made messages (.desktop file) - always resolve ours 2023-12-17 02:07:26 +00:00
kwin kwin/mobiletaskswitcher: Ensure that touch borders are registered 2023-12-28 15:24:35 -05:00
LICENSES components/hapticsplugin: Introduce direct haptics API for hfd-service 2023-11-15 08:13:25 -08:00
lookandfeel SVN_SILENT made messages (.desktop file) - always resolve ours 2023-12-22 02:13:13 +00:00
po GIT_SILENT Sync po/docbooks with svn 2023-12-31 02:51:15 +00:00
quicksettings Flashlight : Use udev instead of hardcoded pinephone device file 2023-12-31 17:11:28 +00:00
screenshots screenshots: Add licenses 2022-08-31 15:54:11 -04:00
shell shell: Fix WallpaperSelector 2023-12-29 12:13:52 -05:00
tests Port mobileshell plugins to ecm_add_qml_module 2023-11-02 11:08:17 +00:00
.git-blame-ignore-revs REUSE compliance, add check to CI, drop unused components 2021-12-23 16:02:41 +00:00
.gitignore Ignore dir 2022-05-13 08:36:05 +02:00
.gitlab-ci.yml GIT_SILENT: Port to new CI template 2023-11-19 16:23:46 +01:00
.kde-ci.yml Adapt to plasma-framework being renamed to libplasma 2023-11-25 15:43:49 +01:00
CMakeLists.txt kcms: time: Avoid calling waitForFinished 2023-12-30 17:53:34 +00:00
logo.png Add repository icon 2021-12-23 22:37:54 +00:00
logo.png.license Fix license header 2021-12-23 22:41:04 +00:00
README.md shell: Change id to org.kde.plasma.mobileshell 2023-11-23 00:05:44 -08:00

Plasma Mobile

This repository contains shell components for Plasma Mobile.

Reporting issues

Locations

  • components/mobileshell - private shell component library (API not guaranteed to be stable!)
  • containments - shell panels (homescreens, status bar, task panel)
  • kcms - settings module
  • look-and-feel - Plasma look-and-feel packages (ex. lockscreen, logout, etc.)
  • shell - Plasma shell package, provides implementations for applet and containment configuration dialogs
  • quicksettings - quick settings packages for the action drawer
  • tests - small runnable snippets that can be used to test parts of the shell without loading all of Plasma

Test on a development machine

See the documentation page for more details.

It is recommended to use kdesrc-build to build this from source. See this page in order to set it up.

Dependencies:

  • KDE Frameworks 6 setup (plasma-framework and its dependencies)
  • plasma-nano
  • plasma-workspace
  • plasma-nm
  • plasma-pa
  • bluez-qt
  • Milou (for search)
  • Kirigami
  • Kirigami Addons
  • hfd-service (optional: for vibrations)

To start the phone homescreen in a window, run:

QT_QPA_PLATFORM=wayland dbus-run-session kwin_wayland --xwayland "plasmashell -p org.kde.plasma.mobileshell"