diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-11-18 17:48:10 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-11-18 17:48:10 +0100 |
commit | 71f95e4b12b0a79e7ff9fc4239af87b1380ad3cd (patch) | |
tree | ee9f0cd5e02338878b985889ec171d3c331aa50a | |
parent | d6b4fb5ba9aa4329859ad79d612a39fc97e1b7db (diff) |
Add option to start replay when power supply is connected
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | include/Overlay.hpp | 5 | ||||
-rw-r--r-- | src/Overlay.cpp | 53 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 1 |
4 files changed, 55 insertions, 6 deletions
@@ -87,3 +87,5 @@ gsr ui window has _NET_WM_STATE _NET_WM_STATE_ABOVE, not _NET_WM_STATE_FULLSCREE For replay on fullscreen detect focused fullscreen window by checking if the window size is the same as the monitor size instead of _NET_WM_STATE_FULLSCREEN. Add audio devices/app refresh button. + +Play camera shutter sound when saving recording. When another sound when starting recording. diff --git a/include/Overlay.hpp b/include/Overlay.hpp index de27bf3..a31f9dd 100644 --- a/include/Overlay.hpp +++ b/include/Overlay.hpp @@ -59,7 +59,9 @@ namespace gsr { void update_notification_process_status(); void update_gsr_process_status(); + void replay_status_update_status(); void update_focused_fullscreen_status(); + void update_power_supply_status(); void update_ui_recording_paused(); void update_ui_recording_unpaused(); @@ -117,7 +119,8 @@ namespace gsr { RecordingStatus recording_status = RecordingStatus::NONE; bool paused = false; - mgl::Clock focused_fullscreen_clock; + mgl::Clock replay_status_update_clock; + std::string power_supply_online_filepath; std::array<KeyBinding, 1> key_bindings; }; diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 79e7bdc..f06ea3b 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -14,6 +14,7 @@ #include <assert.h> #include <sys/wait.h> #include <limits.h> +#include <fcntl.h> #include <stdexcept> #include <X11/Xlib.h> @@ -30,7 +31,7 @@ extern "C" { namespace gsr { static const mgl::Color bg_color(0, 0, 0, 100); static const double force_window_on_top_timeout_seconds = 1.0; - static const double focused_window_fullscreen_check_timeout_seconds = 1.0; + static const double replay_status_update_check_timeout_seconds = 1.0; static bool window_has_atom(Display *dpy, Window window, Atom atom) { Atom type; @@ -291,6 +292,28 @@ namespace gsr { return XGetSelectionOwner(dpy, prop_atom) != None; } + static std::string get_power_supply_online_filepath() { + std::string result; + if(access("/sys/class/power_supply/ADP1/online", F_OK) == 0) + result = "/sys/class/power_supply/ADP1/online"; + else if(access("/sys/class/power_supply/AC/online", F_OK) == 0) + result = "/sys/class/power_supply/AC/online"; + else if(access("/sys/class/power_supply/ACAD/online", F_OK) == 0) + result = "/sys/class/power_supply/ACAD/online"; + return result; + } + + static bool power_supply_is_connected(const char *power_supply_online_filepath) { + int fd = open(power_supply_online_filepath, O_RDONLY); + if(fd == -1) + return false; + + char buf[1]; + const bool is_connected = read(fd, buf, 1) == 1 && buf[0] == '1'; + close(fd); + return is_connected; + } + Overlay::Overlay(std::string resources_path, GsrInfo gsr_info, egl_functions egl_funcs) : resources_path(std::move(resources_path)), gsr_info(gsr_info), @@ -320,6 +343,8 @@ namespace gsr { const std::string notify_bg_color_str = color_to_hex_str(get_color_theme().tint_color); setenv("GSR_NOTIFY_BG_COLOR", notify_bg_color_str.c_str(), true); + power_supply_online_filepath = get_power_supply_online_filepath(); + if(config.replay_config.turn_on_replay_automatically_mode == "turn_on_at_system_startup") on_press_start_replay(true); } @@ -389,7 +414,7 @@ namespace gsr { bool Overlay::draw() { update_notification_process_status(); update_gsr_process_status(); - update_focused_fullscreen_status(); + replay_status_update_status(); if(!visible) return false; @@ -854,11 +879,16 @@ namespace gsr { recording_status = RecordingStatus::NONE; } - void Overlay::update_focused_fullscreen_status() { - if(focused_fullscreen_clock.get_elapsed_time_seconds() < focused_window_fullscreen_check_timeout_seconds) + void Overlay::replay_status_update_status() { + if(replay_status_update_clock.get_elapsed_time_seconds() < replay_status_update_check_timeout_seconds) return; - focused_fullscreen_clock.restart(); + replay_status_update_clock.restart(); + update_focused_fullscreen_status(); + update_power_supply_status(); + } + + void Overlay::update_focused_fullscreen_status() { if(config.replay_config.turn_on_replay_automatically_mode != "turn_on_at_fullscreen") return; @@ -878,6 +908,19 @@ namespace gsr { } } + void Overlay::update_power_supply_status() { + if(config.replay_config.turn_on_replay_automatically_mode != "turn_on_at_power_supply_connected") + return; + + if(recording_status == RecordingStatus::NONE) { + if(power_supply_online_filepath.empty() || power_supply_is_connected(power_supply_online_filepath.c_str())) + on_press_start_replay(true); + } else if(recording_status == RecordingStatus::REPLAY) { + if(!power_supply_online_filepath.empty() && !power_supply_is_connected(power_supply_online_filepath.c_str())) + on_press_start_replay(true); + } + } + void Overlay::update_ui_recording_paused() { if(!visible || recording_status != RecordingStatus::RECORD) return; diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index 51951dd..fad02fa 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -664,6 +664,7 @@ namespace gsr { radiobutton->add_item("Don't turn on replay automatically", "dont_turn_on_automatically"); radiobutton->add_item("Turn on replay at system startup", "turn_on_at_system_startup"); radiobutton->add_item("Turn on replay when starting a fullscreen application", "turn_on_at_fullscreen"); + radiobutton->add_item("Turn on replay when power supply is connected", "turn_on_at_power_supply_connected"); turn_on_replay_automatically_mode_ptr = radiobutton.get(); return radiobutton; } |