1 /*
2  * This software is licensed under the terms of the MIT License.
3  * See COPYING for further information.
4  * ---
5  * Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
6  * Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
7 */
8 
9 #include "taisei.h"
10 
11 #include "gamemode.h"
12 #include "util.h"
13 #include "taskmanager.h"
14 
15 #include <gamemode_client.h>
16 
17 // NOTE: These dbus requests may block, so proxy them off to a background worker thread to not affect load times.
18 
gamemode_init_task(void * a)19 static void *gamemode_init_task(void *a) {
20 	if(gamemode_request_start() < 0) {
21 		log_error("gamemode_request_start() failed: %s", gamemode_error_string());
22 	}
23 
24 	return NULL;
25 }
26 
gamemode_shutdown_task(void * a)27 static void *gamemode_shutdown_task(void *a) {
28 	if(gamemode_request_end() < 0) {
29 		log_error("gamemode_request_end() failed: %s", gamemode_error_string());
30 	}
31 
32 	return NULL;
33 }
34 
gamemode_control_enabled(void)35 static inline bool gamemode_control_enabled(void) {
36 	return env_get_int("TAISEI_GAMEMODE", true);
37 }
38 
gamemode_init(void)39 void gamemode_init(void) {
40 	if(gamemode_control_enabled()) {
41 		task_detach(taskmgr_global_submit((TaskParams) { .callback = gamemode_init_task }));
42 	}
43 }
44 
gamemode_shutdown(void)45 void gamemode_shutdown(void) {
46 	if(gamemode_control_enabled()) {
47 		task_detach(taskmgr_global_submit((TaskParams) { .callback = gamemode_shutdown_task }));
48 	}
49 }
50