🥅 Clean exit if XOpenDisplay fails
This commit is contained in:
		
							parent
							
								
									e2830d6659
								
							
						
					
					
						commit
						599610fd6f
					
				
					 1 changed files with 10 additions and 5 deletions
				
			
		|  | @ -17,14 +17,20 @@ | ||||||
| Aswm _aswm; | Aswm _aswm; | ||||||
| 
 | 
 | ||||||
| void aswm_open(const char* zlog_conf) { | void aswm_open(const char* zlog_conf) { | ||||||
|  | 	atexit(aswm_close); | ||||||
|  | 
 | ||||||
| 	set_up_logger(zlog_conf); | 	set_up_logger(zlog_conf); | ||||||
| 
 | 
 | ||||||
|  | 	XSetErrorHandler(aswm_error_handler); | ||||||
|  | 
 | ||||||
| 	_aswm.display = XOpenDisplay(NULL); | 	_aswm.display = XOpenDisplay(NULL); | ||||||
| 	_aswm.desktops = malloc(0); | 	_aswm.desktops = malloc(0); | ||||||
| 	_aswm.desktops_count = 0; | 	_aswm.desktops_count = 0; | ||||||
| 
 | 
 | ||||||
| 	XSetErrorHandler(aswm_error_handler); | 	if(_aswm.display == NULL) { | ||||||
| 
 | 		aswm_error("Cannot open X Display. Check the DISPLAY environement variable, and ensure an X server is running for the corresponding DISPLAY."); | ||||||
|  | 		exit(1); | ||||||
|  | 	} | ||||||
| 	Window x_root_window = DefaultRootWindow(_aswm.display); | 	Window x_root_window = DefaultRootWindow(_aswm.display); | ||||||
| 	XWindowAttributes x_root_attributes; | 	XWindowAttributes x_root_attributes; | ||||||
| 	XGetWindowAttributes(_aswm.display, x_root_window, &x_root_attributes); | 	XGetWindowAttributes(_aswm.display, x_root_window, &x_root_attributes); | ||||||
|  | @ -50,8 +56,6 @@ void aswm_open(const char* zlog_conf) { | ||||||
| 	aswm_debug("ASWM Root window %lu", _aswm.root_window); | 	aswm_debug("ASWM Root window %lu", _aswm.root_window); | ||||||
| 
 | 
 | ||||||
| 	aswm_log_tree(aswm_debug, &_aswm, DefaultRootWindow(_aswm.display), 1); | 	aswm_log_tree(aswm_debug, &_aswm, DefaultRootWindow(_aswm.display), 1); | ||||||
| 
 |  | ||||||
| 	atexit(aswm_close); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void aswm_create_workspace() { | void aswm_create_workspace() { | ||||||
|  | @ -153,7 +157,8 @@ void aswm_event_loop() { | ||||||
| void aswm_close() { | void aswm_close() { | ||||||
| 	free(_aswm.desktops); | 	free(_aswm.desktops); | ||||||
| 	tear_down_logger(); | 	tear_down_logger(); | ||||||
| 	XCloseDisplay(_aswm.display); | 	if(_aswm.display != NULL) | ||||||
|  | 		XCloseDisplay(_aswm.display); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Window aswm_currently_active() { | Window aswm_currently_active() { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Paul Breugnot
						Paul Breugnot