Skip to content

Commit

Permalink
fixed non-update pinned stats overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed May 16, 2024
1 parent 0e714cb commit 1fd2dc6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/app/stream/video/session_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void vdec_stat_submit(const struct VIDEO_STATS *src, unsigned long now) {
dst->receivedFps = (float) dst->receivedFrames / ((float) delta / 1000);
dst->decodedFps = (float) dst->submittedFrames / ((float) delta / 1000);
LiGetEstimatedRttInfo(&dst->rtt, &dst->rttVariance);
if (!streaming_overlay_shown()) {
if (!streaming_stats_shown()) {
return;
}
int latencyUs = 0;
Expand Down
30 changes: 25 additions & 5 deletions src/app/ui/streaming/streaming.controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void overlay_key_cb(lv_event_t *e);

static void update_buttons_layout(streaming_controller_t *controller);

bool stats_showing(streaming_controller_t *controller);
static void pin_toggle(lv_event_t *e);

const lv_fragment_class_t streaming_controller_class = {
.constructor_cb = constructor,
Expand All @@ -51,21 +51,21 @@ const lv_fragment_class_t streaming_controller_class = {
.instance_size = sizeof(streaming_controller_t),
};

static bool overlay_showing;
static bool overlay_showing = false, overlay_pinned = false;
static streaming_controller_t *current_controller = NULL;

bool streaming_overlay_shown() {
return overlay_showing;
}

bool stats_showing(streaming_controller_t *controller) {
return streaming_overlay_shown() || controller->stats->parent != controller->overlay;
bool streaming_stats_shown() {
return overlay_showing || overlay_pinned;
}

bool streaming_refresh_stats() {
streaming_controller_t *controller = current_controller;
if (!controller) { return false; }
if (!stats_showing(controller)) {
if (!streaming_stats_shown()) {
return false;
}
app_t *app = controller->global;
Expand Down Expand Up @@ -222,6 +222,8 @@ static void on_view_created(lv_fragment_t *self, lv_obj_t *view) {
controller->notice = notice;
controller->notice_label = notice_label;

lv_obj_add_event_cb(controller->stats_pin, pin_toggle, LV_EVENT_VALUE_CHANGED, controller->stats);

#if !defined(TARGET_WEBOS)
const app_settings_t *settings = &controller->global->settings;
if (settings->syskey_capture) {
Expand Down Expand Up @@ -330,3 +332,21 @@ static void update_buttons_layout(streaming_controller_t *controller) {
lv_area_center(&coords, &controller->button_points[4]);
app_input_set_button_points(&controller->global->ui.input, controller->button_points);
}

static void pin_toggle(lv_event_t *e) {
lv_obj_t *toggle_view = lv_event_get_user_data(e);
lv_fragment_t *fragment = lv_obj_get_user_data(toggle_view);
bool checked = lv_obj_has_state(lv_event_get_current_target(e), LV_STATE_CHECKED);
bool pinned = toggle_view->parent != fragment->obj;
overlay_pinned = checked;
if (checked == pinned) {
return;
}
if (checked) {
lv_obj_set_parent(toggle_view, lv_layer_top());
lv_obj_add_state(toggle_view, LV_STATE_USER_1);
} else {
lv_obj_set_parent(toggle_view, fragment->obj);
lv_obj_clear_state(toggle_view, LV_STATE_USER_1);
}
}
3 changes: 3 additions & 0 deletions src/app/ui/streaming/streaming.controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct {
lv_obj_t *host_latency;
lv_obj_t *vdec_latency;
} stats_items;
lv_obj_t *stats_pin;
lv_obj_t *notice, *notice_label;
lv_style_t overlay_button_style;
lv_style_t overlay_button_style_focused;
Expand All @@ -56,6 +57,8 @@ void streaming_overlay_resized(streaming_controller_t *controller);

bool streaming_overlay_shown();

bool streaming_stats_shown();

bool streaming_refresh_stats();

void streaming_notice_show(const char *message);
31 changes: 6 additions & 25 deletions src/app/ui/streaming/streaming.view.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include "streaming.controller.h"

#include "lvgl/ext/lv_child_group.h"

#include "util/i18n.h"
#include "util/font.h"
#include "hints.h"

#include "lvgl/ext/lv_child_group.h"
#include "lvgl/theme/lv_theme_moonlight.h"

static lv_obj_t *stat_label(lv_obj_t *parent, const char *title);

static lv_obj_t *overlay_title(lv_obj_t *parent, const char *title);

static void pin_toggle(lv_event_t *e);
static lv_obj_t *overlay_title(lv_obj_t *parent, const char *title, streaming_controller_t *controller);

lv_obj_t *streaming_scene_create(lv_fragment_t *self, lv_obj_t *parent) {
streaming_controller_t *controller = (streaming_controller_t *) self;
Expand Down Expand Up @@ -119,7 +117,7 @@ lv_obj_t *streaming_scene_create(lv_fragment_t *self, lv_obj_t *parent) {
lv_obj_align(stats, LV_ALIGN_TOP_RIGHT, -LV_DPX(20), LV_DPX(20));
lv_obj_set_user_data(stats, controller);

overlay_title(stats, locstr("Performance"));
overlay_title(stats, locstr("Performance"), controller);

controller->stats_items.resolution = stat_label(stats, "Resolution");
controller->stats_items.decoder = stat_label(stats, "Decoder");
Expand Down Expand Up @@ -192,7 +190,7 @@ static lv_obj_t *stat_label(lv_obj_t *parent, const char *title) {
return value;
}

static lv_obj_t *overlay_title(lv_obj_t *parent, const char *title) {
static lv_obj_t *overlay_title(lv_obj_t *parent, const char *title, streaming_controller_t *controller) {
lv_obj_t *stats_title = lv_label_create(parent);
lv_label_set_text_static(stats_title, title);
lv_obj_set_width(stats_title, LV_PCT(100));
Expand Down Expand Up @@ -226,23 +224,6 @@ static lv_obj_t *overlay_title(lv_obj_t *parent, const char *title) {
lv_img_set_src(stat_pin_content, MAT_SYMBOL_PUSH_PIN);

lv_obj_align(stats_pin, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(stats_pin, pin_toggle, LV_EVENT_VALUE_CHANGED, parent);
controller->stats_pin = stats_pin;
return stats_title;
}

static void pin_toggle(lv_event_t *e) {
lv_obj_t *toggle_view = lv_event_get_user_data(e);
lv_fragment_t *fragment = lv_obj_get_user_data(toggle_view);
bool checked = lv_obj_has_state(lv_event_get_current_target(e), LV_STATE_CHECKED);
bool pinned = toggle_view->parent != fragment->obj;
if (checked == pinned) {
return;
}
if (checked) {
lv_obj_set_parent(toggle_view, lv_layer_top());
lv_obj_add_state(toggle_view, LV_STATE_USER_1);
} else {
lv_obj_set_parent(toggle_view, fragment->obj);
lv_obj_clear_state(toggle_view, LV_STATE_USER_1);
}
}

0 comments on commit 1fd2dc6

Please sign in to comment.