mirror of
				https://github.com/DreamMaoMao/maomaowm.git
				synced 2025-11-03 09:01:47 -05:00 
			
		
		
		
	opt: Reduce unnecessary layout calculations
This commit is contained in:
		
							parent
							
								
									c9843ec05a
								
							
						
					
					
						commit
						62a569d756
					
				
					 2 changed files with 23 additions and 44 deletions
				
			
		| 
						 | 
					@ -11,8 +11,7 @@ void fibonacci(Monitor *mon, int s) {
 | 
				
			||||||
	cur_gappoh = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
						cur_gappoh = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
				
			||||||
	cur_gappov = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
						cur_gappov = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
				
			||||||
	// Count visible clients
 | 
						// Count visible clients
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && ISTILED(c))
 | 
						n = mon->visible_tiling_clients;
 | 
				
			||||||
		n++;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0)
 | 
						if (n == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -133,13 +132,7 @@ void grid(Monitor *m) {
 | 
				
			||||||
	Client *c;
 | 
						Client *c;
 | 
				
			||||||
	n = 0;
 | 
						n = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 第一次遍历,计算 n 的值
 | 
						n = m->isoverview ? m->visible_clients : m->visible_tiling_clients;
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) {
 | 
					 | 
				
			||||||
		if (VISIBLEON(c, m) && !c->isunglobal &&
 | 
					 | 
				
			||||||
			((m->isoverview && !client_should_ignore_focus(c)) || ISTILED(c))) {
 | 
					 | 
				
			||||||
			n++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0) {
 | 
						if (n == 0) {
 | 
				
			||||||
		return; // 没有需要处理的客户端,直接返回
 | 
							return; // 没有需要处理的客户端,直接返回
 | 
				
			||||||
| 
						 | 
					@ -252,7 +245,8 @@ void deck(Monitor *m) {
 | 
				
			||||||
	cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
						cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
				
			||||||
	cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
						cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
 | 
						n = m->visible_tiling_clients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0)
 | 
						if (n == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -298,11 +292,10 @@ void deck(Monitor *m) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 滚动布局
 | 
					// 滚动布局
 | 
				
			||||||
void scroller(Monitor *m) {
 | 
					void scroller(Monitor *m) {
 | 
				
			||||||
	unsigned int i, n;
 | 
						unsigned int i, n, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Client *c, *root_client = NULL;
 | 
						Client *c, *root_client = NULL;
 | 
				
			||||||
	Client **tempClients = NULL; // 初始化为 NULL
 | 
						Client **tempClients = NULL; // 初始化为 NULL
 | 
				
			||||||
	n = 0;
 | 
					 | 
				
			||||||
	struct wlr_box target_geom;
 | 
						struct wlr_box target_geom;
 | 
				
			||||||
	int focus_client_index = 0;
 | 
						int focus_client_index = 0;
 | 
				
			||||||
	bool need_scroller = false;
 | 
						bool need_scroller = false;
 | 
				
			||||||
| 
						 | 
					@ -317,12 +310,7 @@ void scroller(Monitor *m) {
 | 
				
			||||||
	unsigned int max_client_width =
 | 
						unsigned int max_client_width =
 | 
				
			||||||
		m->w.width - 2 * scroller_structs - cur_gappih;
 | 
							m->w.width - 2 * scroller_structs - cur_gappih;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 第一次遍历,计算 n 的值
 | 
						n = m->visible_tiling_clients;
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) {
 | 
					 | 
				
			||||||
		if (VISIBLEON(c, m) && ISTILED(c)) {
 | 
					 | 
				
			||||||
			n++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0) {
 | 
						if (n == 0) {
 | 
				
			||||||
		return; // 没有需要处理的客户端,直接返回
 | 
							return; // 没有需要处理的客户端,直接返回
 | 
				
			||||||
| 
						 | 
					@ -336,11 +324,11 @@ void scroller(Monitor *m) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 第二次遍历,填充 tempClients
 | 
						// 第二次遍历,填充 tempClients
 | 
				
			||||||
	n = 0;
 | 
						j = 0;
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) {
 | 
						wl_list_for_each(c, &clients, link) {
 | 
				
			||||||
		if (VISIBLEON(c, m) && ISTILED(c)) {
 | 
							if (VISIBLEON(c, m) && ISTILED(c)) {
 | 
				
			||||||
			tempClients[n] = c;
 | 
								tempClients[j] = c;
 | 
				
			||||||
			n++;
 | 
								j++;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -436,7 +424,8 @@ void tile(Monitor *m) {
 | 
				
			||||||
	unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty;
 | 
						unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty;
 | 
				
			||||||
	Client *c;
 | 
						Client *c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
 | 
						n = m->visible_tiling_clients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0)
 | 
						if (n == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,9 +10,8 @@ void vertical_fibonacci(Monitor *mon, int s) {
 | 
				
			||||||
	cur_gappiv = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappiv;
 | 
						cur_gappiv = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappiv;
 | 
				
			||||||
	cur_gappoh = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
						cur_gappoh = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
				
			||||||
	cur_gappov = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
						cur_gappov = smartgaps && mon->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
				
			||||||
	// Count visible clients
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && ISTILED(c))
 | 
						n = mon->visible_tiling_clients;
 | 
				
			||||||
		n++;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0)
 | 
						if (n == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -130,14 +129,8 @@ void vertical_grid(Monitor *m) {
 | 
				
			||||||
	unsigned int dy;
 | 
						unsigned int dy;
 | 
				
			||||||
	unsigned int rows, cols, overrows;
 | 
						unsigned int rows, cols, overrows;
 | 
				
			||||||
	Client *c;
 | 
						Client *c;
 | 
				
			||||||
	n = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) {
 | 
						n = m->isoverview ? m->visible_clients : m->visible_tiling_clients;
 | 
				
			||||||
		if (VISIBLEON(c, m) && !c->isunglobal &&
 | 
					 | 
				
			||||||
			((m->isoverview && !client_should_ignore_focus(c)) || ISTILED(c))) {
 | 
					 | 
				
			||||||
			n++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0) {
 | 
						if (n == 0) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -247,7 +240,8 @@ void vertical_deck(Monitor *m) {
 | 
				
			||||||
	cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
						cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh;
 | 
				
			||||||
	cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
						cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
 | 
						n = m->visible_tiling_clients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0)
 | 
						if (n == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -288,10 +282,9 @@ void vertical_deck(Monitor *m) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vertical_scroller(Monitor *m) {
 | 
					void vertical_scroller(Monitor *m) {
 | 
				
			||||||
	unsigned int i, n;
 | 
						unsigned int i, n, j;
 | 
				
			||||||
	Client *c, *root_client = NULL;
 | 
						Client *c, *root_client = NULL;
 | 
				
			||||||
	Client **tempClients = NULL;
 | 
						Client **tempClients = NULL;
 | 
				
			||||||
	n = 0;
 | 
					 | 
				
			||||||
	struct wlr_box target_geom;
 | 
						struct wlr_box target_geom;
 | 
				
			||||||
	int focus_client_index = 0;
 | 
						int focus_client_index = 0;
 | 
				
			||||||
	bool need_scroller = false;
 | 
						bool need_scroller = false;
 | 
				
			||||||
| 
						 | 
					@ -306,11 +299,7 @@ void vertical_scroller(Monitor *m) {
 | 
				
			||||||
	unsigned int max_client_height =
 | 
						unsigned int max_client_height =
 | 
				
			||||||
		m->w.height - 2 * scroller_structs - cur_gappiv;
 | 
							m->w.height - 2 * scroller_structs - cur_gappiv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) {
 | 
						n = m->visible_tiling_clients;
 | 
				
			||||||
		if (VISIBLEON(c, m) && ISTILED(c)) {
 | 
					 | 
				
			||||||
			n++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0) {
 | 
						if (n == 0) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -321,11 +310,11 @@ void vertical_scroller(Monitor *m) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	n = 0;
 | 
						j = 0;
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) {
 | 
						wl_list_for_each(c, &clients, link) {
 | 
				
			||||||
		if (VISIBLEON(c, m) && ISTILED(c)) {
 | 
							if (VISIBLEON(c, m) && ISTILED(c)) {
 | 
				
			||||||
			tempClients[n] = c;
 | 
								tempClients[j] = c;
 | 
				
			||||||
			n++;
 | 
								j++;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -421,7 +410,8 @@ void vertical_tile(Monitor *m) {
 | 
				
			||||||
	unsigned int i, n = 0, w, r, ie = enablegaps, mh, mx, tx;
 | 
						unsigned int i, n = 0, w, r, ie = enablegaps, mh, mx, tx;
 | 
				
			||||||
	Client *c;
 | 
						Client *c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
 | 
						n = m->visible_tiling_clients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n == 0)
 | 
						if (n == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue