mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	workspaces: Hide menu if there is only a single workspace
This commit is contained in:
		
							parent
							
								
									ff69988347
								
							
						
					
					
						commit
						282620589d
					
				
					 1 changed files with 46 additions and 3 deletions
				
			
		| 
						 | 
					@ -208,6 +208,15 @@ fill_item(char *nodename, char *content)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					item_destroy(struct menuitem *item)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						wl_list_remove(&item->link);
 | 
				
			||||||
 | 
						action_list_free(&item->actions);
 | 
				
			||||||
 | 
						wlr_scene_node_destroy(&item->tree->node);
 | 
				
			||||||
 | 
						free(item);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
entry(xmlNode *node, char *nodename, char *content)
 | 
					entry(xmlNode *node, char *nodename, char *content)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -449,6 +458,38 @@ menu_configure(struct menu *menu, int lx, int ly, enum menu_align align)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					menu_hide_submenu(const char *id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct menu *menu, *hide_menu;
 | 
				
			||||||
 | 
						hide_menu = menu_get_by_id(id);
 | 
				
			||||||
 | 
						if (!hide_menu) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for (int i = 0; i < nr_menus; ++i) {
 | 
				
			||||||
 | 
							menu = menus + i;
 | 
				
			||||||
 | 
							size_t item_index = 0;
 | 
				
			||||||
 | 
							size_t items_destroyed = 0;
 | 
				
			||||||
 | 
							struct menuitem *item, *item_tmp;
 | 
				
			||||||
 | 
							wl_list_for_each_reverse_safe(item, item_tmp, &menu->menuitems, link) {
 | 
				
			||||||
 | 
								if (item->submenu == hide_menu) {
 | 
				
			||||||
 | 
									item_destroy(item);
 | 
				
			||||||
 | 
									items_destroyed++;
 | 
				
			||||||
 | 
									item_index++;
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (items_destroyed) {
 | 
				
			||||||
 | 
									int y = (item_index - items_destroyed) * menu->item_height;
 | 
				
			||||||
 | 
									wlr_scene_node_set_position(&item->tree->node, 0, y);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								item_index++;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (items_destroyed) {
 | 
				
			||||||
 | 
								menu->size.height -= items_destroyed * menu->item_height;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
menu_init_rootmenu(struct server *server)
 | 
					menu_init_rootmenu(struct server *server)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -508,6 +549,10 @@ menu_init_windowmenu(struct server *server)
 | 
				
			||||||
		current_item = item_create(menu, _("Close"));
 | 
							current_item = item_create(menu, _("Close"));
 | 
				
			||||||
		fill_item("name.action", "Close");
 | 
							fill_item("name.action", "Close");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (wl_list_length(&rc.workspace_config.workspaces) == 1) {
 | 
				
			||||||
 | 
							menu_hide_submenu("workspaces");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					@ -518,9 +563,7 @@ menu_finish(void)
 | 
				
			||||||
		menu = menus + i;
 | 
							menu = menus + i;
 | 
				
			||||||
		struct menuitem *item, *next;
 | 
							struct menuitem *item, *next;
 | 
				
			||||||
		wl_list_for_each_safe(item, next, &menu->menuitems, link) {
 | 
							wl_list_for_each_safe(item, next, &menu->menuitems, link) {
 | 
				
			||||||
			wl_list_remove(&item->link);
 | 
								item_destroy(item);
 | 
				
			||||||
			action_list_free(&item->actions);
 | 
					 | 
				
			||||||
			free(item);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		/**
 | 
							/**
 | 
				
			||||||
		 * Destroying the root node will destroy everything,
 | 
							 * Destroying the root node will destroy everything,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue