Skip to content

Commit 67b3755

Browse files
committed
opt: ensure auto schedule next frame when animaiton not end
1 parent d2894f0 commit 67b3755

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/animation/client.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,7 @@ void init_fadeout_client(Client *c) {
840840
wl_list_insert(&fadeout_clients, &fadeout_cient->fadeout_link);
841841

842842
// 请求刷新屏幕
843-
if (c->mon)
844-
wlr_output_schedule_frame(c->mon->wlr_output);
843+
request_fresh_all_monitors();
845844
}
846845

847846
void client_commit(Client *c) {
@@ -860,8 +859,7 @@ void client_commit(Client *c) {
860859
c->animation.should_animate = false;
861860
}
862861
// 请求刷新屏幕
863-
if (c->mon)
864-
wlr_output_schedule_frame(c->mon->wlr_output);
862+
request_fresh_all_monitors();
865863
}
866864

867865
void client_set_pending_state(Client *c) {

src/animation/common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,13 @@ struct wlr_scene_tree *wlr_scene_tree_snapshot(struct wlr_scene_node *node,
250250

251251
return snapshot;
252252
}
253+
254+
void request_fresh_all_monitors(void) {
255+
Monitor *m = NULL;
256+
wl_list_for_each(m, &mons, link) {
257+
if (!m->wlr_output->enabled) {
258+
continue;
259+
}
260+
wlr_output_schedule_frame(m->wlr_output);
261+
}
262+
}

src/dispatch/bind_define.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,28 @@ int32_t bind_to_view(const Arg *arg) {
3131
}
3232

3333
int32_t chvt(const Arg *arg) {
34+
struct timespec ts;
3435

36+
// prevent the animation to rquest the new frame
37+
allow_frame_scheduling = false;
38+
39+
// backup current tag and monitor name
3540
if (selmon) {
3641
chvt_backup_tag = selmon->pertag->curtag;
3742
strncpy(chvt_backup_selmon, selmon->wlr_output->name,
3843
sizeof(chvt_backup_selmon) - 1);
3944
}
45+
4046
wlr_session_change_vt(session, arg->ui);
47+
48+
// wait for DRM device to stabilize and ensure the session state is inactive
49+
ts.tv_sec = 0;
50+
ts.tv_nsec = 100000000; // 200ms
51+
nanosleep(&ts, NULL);
52+
53+
// allow frame scheduling,
54+
// because session state is now inactive, rendermon will not enter
55+
allow_frame_scheduling = true;
4156
return 1;
4257
}
4358

src/mango.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ static void refresh_monitors_workspaces_status(Monitor *m);
761761
static void init_client_properties(Client *c);
762762
static float *get_border_color(Client *c);
763763
static void clear_fullscreen_and_maximized_state(Monitor *m);
764+
static void request_fresh_all_monitors(void);
764765

765766
#include "data/static_keymap.h"
766767
#include "dispatch/bind_declare.h"
@@ -845,6 +846,7 @@ static double swipe_dy = 0;
845846
bool render_border = true;
846847

847848
uint32_t chvt_backup_tag = 0;
849+
bool allow_frame_scheduling = true;
848850
char chvt_backup_selmon[32] = {0};
849851

850852
struct dvec2 *baked_points_move;
@@ -4237,7 +4239,7 @@ void rendermon(struct wl_listener *listener, void *data) {
42374239
return;
42384240
}
42394241

4240-
if (!m->wlr_output->enabled)
4242+
if (!m->wlr_output->enabled || !allow_frame_scheduling)
42414243
return;
42424244

42434245
frame_allow_tearing = check_tearing_frame_allow(m);
@@ -4258,11 +4260,6 @@ void rendermon(struct wl_listener *listener, void *data) {
42584260
need_more_frames = layer_draw_fadeout_frame(l) || need_more_frames;
42594261
}
42604262

4261-
// 如果需要更多帧,确保安排下一帧
4262-
if (need_more_frames) {
4263-
wlr_output_schedule_frame(m->wlr_output);
4264-
}
4265-
42664263
// 绘制客户端
42674264
wl_list_for_each(c, &clients, link) {
42684265
need_more_frames = client_draw_frame(c) || need_more_frames;
@@ -4289,6 +4286,11 @@ void rendermon(struct wl_listener *listener, void *data) {
42894286
wlr_scene_output_send_frame_done(m->scene_output, &now);
42904287
wlr_output_state_finish(&pending);
42914288
}
4289+
4290+
// 如果需要更多帧,确保安排下一帧
4291+
if (need_more_frames && allow_frame_scheduling) {
4292+
request_fresh_all_monitors();
4293+
}
42924294
}
42934295

42944296
void requestdecorationmode(struct wl_listener *listener, void *data) {

0 commit comments

Comments
 (0)