commit 8377032

Michael Forney  ·  2019-08-29 07:25:17 +0000 UTC
parent 1f26824
data_device_manager: Move away from global state
4 files changed,  +14, -26
+4, -17
 1@@ -1,6 +1,6 @@
 2 /* swc: data_device_manager.c
 3  *
 4- * Copyright (c) 2013 Michael Forney
 5+ * Copyright (c) 2013-2019 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -27,10 +27,6 @@
10 #include "internal.h"
11 #include "seat.h"
12 
13-static struct {
14-	struct wl_global *global;
15-} data_device_manager;
16-
17 static void
18 create_data_source(struct wl_client *client, struct wl_resource *resource, uint32_t id)
19 {
20@@ -65,17 +61,8 @@ bind_data_device_manager(struct wl_client *client, void *data, uint32_t version,
21 	wl_resource_set_implementation(resource, &data_device_manager_implementation, NULL, NULL);
22 }
23 
24-bool
25-data_device_manager_initialize(void)
26-{
27-	data_device_manager.global = wl_global_create(swc.display, &wl_data_device_manager_interface, 1,
28-	                                              NULL, &bind_data_device_manager);
29-
30-	return data_device_manager.global != NULL;
31-}
32-
33-void
34-data_device_manager_finalize(void)
35+struct wl_global *
36+data_device_manager_create(struct wl_display *display)
37 {
38-	wl_global_destroy(data_device_manager.global);
39+	return wl_global_create(display, &wl_data_device_manager_interface, 1, NULL, &bind_data_device_manager);
40 }
+3, -4
 1@@ -1,6 +1,6 @@
 2 /* swc: data_device_manager.h
 3  *
 4- * Copyright (c) 2013 Michael Forney
 5+ * Copyright (c) 2013-2019 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -24,9 +24,8 @@
10 #ifndef SWC_DATA_DEVICE_MANAGER_H
11 #define SWC_DATA_DEVICE_MANAGER_H
12 
13-#include <stdbool.h>
14+struct wl_display;
15 
16-bool data_device_manager_initialize(void);
17-void data_device_manager_finalize(void);
18+struct wl_global *data_device_manager_create(struct wl_display *display);
19 
20 #endif
+2, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: swc/internal.h
 3  *
 4- * Copyright (c) 2013 Michael Forney
 5+ * Copyright (c) 2013-2019 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -45,6 +45,7 @@ struct swc {
10 	struct swc_compositor *const compositor;
11 	struct swc_shm *const shm;
12 	struct swc_drm *const drm;
13+	struct wl_global *data_device_manager;
14 };
15 
16 extern struct swc swc;
+5, -4
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/swc.c
 3  *
 4- * Copyright (c) 2013, 2014, 2018 Michael Forney
 5+ * Copyright (c) 2013-2019 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -145,7 +145,8 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con
10 		goto error6;
11 	}
12 
13-	if (!data_device_manager_initialize()) {
14+	swc.data_device_manager = data_device_manager_create(display);
15+	if (!swc.data_device_manager) {
16 		ERROR("Could not initialize data device manager\n");
17 		goto error7;
18 	}
19@@ -181,7 +182,7 @@ error10:
20 error9:
21 	seat_finalize();
22 error8:
23-	data_device_manager_finalize();
24+	wl_global_destroy(swc.data_device_manager);
25 error7:
26 	subcompositor_finalize();
27 error6:
28@@ -206,7 +207,7 @@ swc_finalize(void)
29 	panel_manager_finalize();
30 	shell_finalize();
31 	seat_finalize();
32-	data_device_manager_finalize();
33+	wl_global_destroy(swc.data_device_manager);
34 	compositor_finalize();
35 	screens_finalize();
36 	bindings_finalize();