mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Add support for running swaybar_command
This commit is contained in:
		
							parent
							
								
									2ab4e5676e
								
							
						
					
					
						commit
						207678e809
					
				
					 1 changed files with 26 additions and 9 deletions
				
			
		| 
						 | 
					@ -371,6 +371,10 @@ static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i
 | 
				
			||||||
	snprintf(output_id, bufsize, "%d", output_i);
 | 
						snprintf(output_id, bufsize, "%d", output_i);
 | 
				
			||||||
	output_id[bufsize-1] = 0;
 | 
						output_id[bufsize-1] = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pid_t *pid = malloc(sizeof(pid_t));
 | 
				
			||||||
 | 
						*pid = fork();
 | 
				
			||||||
 | 
						if (*pid == 0) {
 | 
				
			||||||
 | 
							if (!bar->swaybar_command) {
 | 
				
			||||||
			char *const cmd[] = {
 | 
								char *const cmd[] = {
 | 
				
			||||||
				"swaybar",
 | 
									"swaybar",
 | 
				
			||||||
				"-b",
 | 
									"-b",
 | 
				
			||||||
| 
						 | 
					@ -379,10 +383,23 @@ static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i
 | 
				
			||||||
				NULL,
 | 
									NULL,
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pid_t *pid = malloc(sizeof(pid_t));
 | 
					 | 
				
			||||||
	*pid = fork();
 | 
					 | 
				
			||||||
	if (*pid == 0) {
 | 
					 | 
				
			||||||
			execvp(cmd[0], cmd);
 | 
								execvp(cmd[0], cmd);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								// run custom swaybar
 | 
				
			||||||
 | 
								int len = strlen(bar->swaybar_command) + strlen(bar->id) + strlen(output_id) + 6;
 | 
				
			||||||
 | 
								char *command = malloc(len * sizeof(char));
 | 
				
			||||||
 | 
								snprintf(command, len, "%s -b %s %s", bar->swaybar_command, bar->id, output_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								char *const cmd[] = {
 | 
				
			||||||
 | 
									"sh",
 | 
				
			||||||
 | 
									"-c",
 | 
				
			||||||
 | 
									command,
 | 
				
			||||||
 | 
									NULL,
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								execvp(cmd[0], cmd);
 | 
				
			||||||
 | 
								free(command);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// add swaybar pid to output
 | 
						// add swaybar pid to output
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue