From 8131a4518a5438ba7512548ea34aa80fe9e397b2 Mon Sep 17 00:00:00 2001 From: Carter Prince Date: Mon, 15 Jan 2024 21:50:07 -0500 Subject: [PATCH 1/4] battery: make scroll change brightness --- metadata/panel.xml | 5 ++++ src/panel/widgets/battery.cpp | 56 +++++++++++++++++++++++++++++++++++ src/panel/widgets/battery.hpp | 2 ++ 3 files changed, 63 insertions(+) diff --git a/metadata/panel.xml b/metadata/panel.xml index ca7241b8..0a919736 100644 --- a/metadata/panel.xml +++ b/metadata/panel.xml @@ -125,6 +125,11 @@ 32 1 + - + + <_short>Network diff --git a/src/panel/widgets/battery.cpp b/src/panel/widgets/battery.cpp index 949aa25a..3cb437cf 100644 --- a/src/panel/widgets/battery.cpp +++ b/src/panel/widgets/battery.cpp @@ -2,8 +2,6 @@ #include #include #include -#include -#include #define UPOWER_NAME "org.freedesktop.UPower" #define DISPLAY_DEVICE "/org/freedesktop/UPower/devices/DisplayDevice" @@ -16,13 +14,6 @@ #define TIMETOEMPTY "TimeToEmpty" #define SHOULD_DISPLAY "IsPresent" -std::string backlight = std::filesystem::directory_iterator{"/sys/class/backlight"}->path().string(); - -int max_brightness; -std::string brightness_file = backlight + "/brightness"; -std::string max_brightness_file = backlight + "/max_brightness"; -std::ifstream max_brightness_stream(max_brightness_file); - static std::string get_device_type_description(uint32_t type) { if (type == 2) @@ -38,35 +29,6 @@ static std::string get_device_type_description(uint32_t type) return ""; } -// this works as long as the owner of the wf-panel process is in the video group -// sudo usermod -a -G video USER -void change_brightness(int change) { - std::ifstream brightness_stream(brightness_file); - int current_brightness; - - if (brightness_stream >> current_brightness) - { - int new_brightness = current_brightness + (change*max_brightness)/100.0; // change by change% - if (new_brightness > max_brightness) - { - new_brightness = max_brightness; - } - else if (new_brightness <= 0) - { - new_brightness = 1; - } - std::cout << new_brightness << "\n"; - - std::ofstream brightness_output(brightness_file); - brightness_output << new_brightness; - - return; - } - - std::cerr << "battery.cpp: Failed to change brightness\n"; -} - - void WayfireBatteryInfo::on_properties_changed( const Gio::DBus::Proxy::MapChangedProperties& properties, const std::vector& invalidated) @@ -214,14 +176,19 @@ void WayfireBatteryInfo::update_details() void WayfireBatteryInfo::on_battery_scroll(GdkEventScroll *event) { - if (event->delta_y < 0) - { - change_brightness(sensitivity_opt); - } - else if (0 < event->delta_y) - { - change_brightness(-sensitivity_opt); + if (scroll_counter <= 0) { + if (event->delta_y < 0) + { + std::system(battery_scrollup_command.value().c_str()); + } else if (0 < event->delta_y) + { + std::system(battery_scrolldown_command.value().c_str()); + } + + scroll_counter = 3; } + + scroll_counter--; } void WayfireBatteryInfo::update_state() @@ -272,11 +239,10 @@ bool WayfireBatteryInfo::setup_dbus() } // TODO: simplify config loading - static const std::string default_font = "default"; void WayfireBatteryInfo::init(Gtk::HBox *container) { - max_brightness_stream >> max_brightness; + scroll_counter = 0; if (!setup_dbus()) { diff --git a/src/panel/widgets/battery.hpp b/src/panel/widgets/battery.hpp index ab3267f9..15428e86 100644 --- a/src/panel/widgets/battery.hpp +++ b/src/panel/widgets/battery.hpp @@ -23,14 +23,17 @@ class WayfireBatteryInfo : public WayfireWidget { WfOption status_opt{"panel/battery_status"}; WfOption font_opt{"panel/battery_font"}; + WfOption battery_scrollup_command{"panel/battery_scrollup_command"}; + WfOption battery_scrolldown_command{"panel/battery_scrolldown_command"}; WfOption size_opt{"panel/battery_icon_size"}; - WfOption sensitivity_opt{"panel/battery_scroll_sensitivity"}; WfOption invert_opt{"panel/battery_icon_invert"}; Gtk::Button button; Gtk::Label label; Gtk::HBox button_box; + int scroll_counter; + Gtk::Image icon; DBusConnection connection;