summaryrefslogtreecommitdiff
path: root/src/lib/ecore_wl2/ecore_wl2.c
blob: ceb6dce80feafdeaad1db225f1c08f9927c36703 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "ecore_wl2_private.h"

/* local variables */
static int _ecore_wl2_init_count = 0;

/* external variables */
Eina_Bool no_session_recovery;
int _ecore_wl2_log_dom = -1;

/* public API variables */
EAPI int ECORE_WL2_EVENT_CONNECT = 0;
EAPI int ECORE_WL2_EVENT_DISCONNECT = 0;
EAPI int ECORE_WL2_EVENT_GLOBAL_ADDED = 0;
EAPI int ECORE_WL2_EVENT_GLOBAL_REMOVED = 0;
EAPI int ECORE_WL2_EVENT_FOCUS_IN = 0;
EAPI int ECORE_WL2_EVENT_FOCUS_OUT = 0;
EAPI int ECORE_WL2_EVENT_DND_ENTER = 0;
EAPI int ECORE_WL2_EVENT_DND_LEAVE = 0;
EAPI int ECORE_WL2_EVENT_DND_MOTION = 0;
EAPI int ECORE_WL2_EVENT_DND_DROP = 0;
EAPI int ECORE_WL2_EVENT_DND_END = 0;
EAPI int ECORE_WL2_EVENT_DATA_SOURCE_END = 0;
EAPI int ECORE_WL2_EVENT_DATA_SOURCE_DROP = 0;
EAPI int ECORE_WL2_EVENT_DATA_SOURCE_ACTION = 0;
EAPI int ECORE_WL2_EVENT_DATA_SOURCE_TARGET = 0;
EAPI int ECORE_WL2_EVENT_DATA_SOURCE_SEND = 0;
EAPI int ECORE_WL2_EVENT_WINDOW_CONFIGURE = 0;
EAPI int ECORE_WL2_EVENT_SYNC_DONE = 0;
EAPI int ECORE_WL2_EVENT_OFFER_DATA_READY = 0;
EAPI int ECORE_WL2_EVENT_SEAT_NAME_CHANGED = 0;

EAPI int _ecore_wl2_event_window_www = -1;
EAPI int _ecore_wl2_event_window_www_drag = -1;

/* public API functions */
EAPI int
ecore_wl2_init(void)
{
   if (++_ecore_wl2_init_count != 1) return _ecore_wl2_init_count;

   /* try to initialize Eina */
   if (!eina_init()) return --_ecore_wl2_init_count;

   /* try to create Eina logging domain */
   _ecore_wl2_log_dom =
     eina_log_domain_register("ecore_wl2", ECORE_WL2_DEFAULT_LOG_COLOR);
   if (_ecore_wl2_log_dom < 0)
     {
        EINA_LOG_ERR("Cannot create a log domain for Ecore Wl2");
        goto eina_err;
     }

   /* try to initialize Ecore */
   if (!ecore_init())
     {
        ERR("Could not initialize Ecore");
        goto ecore_err;
     }

   /* try to initialize Ecore_Event */
   if (!ecore_event_init())
     {
        ERR("Could not initialize Ecore_Event");
        goto ecore_event_err;
     }

   /* handle creating new Ecore_Wl2 event types */
   if (!ECORE_WL2_EVENT_GLOBAL_ADDED)
     {
        ECORE_WL2_EVENT_CONNECT = ecore_event_type_new();
        ECORE_WL2_EVENT_DISCONNECT = ecore_event_type_new();
        ECORE_WL2_EVENT_GLOBAL_ADDED = ecore_event_type_new();
        ECORE_WL2_EVENT_GLOBAL_REMOVED = ecore_event_type_new();
        ECORE_WL2_EVENT_FOCUS_IN = ecore_event_type_new();
        ECORE_WL2_EVENT_FOCUS_OUT = ecore_event_type_new();
        ECORE_WL2_EVENT_DND_ENTER = ecore_event_type_new();
        ECORE_WL2_EVENT_DND_LEAVE = ecore_event_type_new();
        ECORE_WL2_EVENT_DND_MOTION = ecore_event_type_new();
        ECORE_WL2_EVENT_DND_DROP = ecore_event_type_new();
        ECORE_WL2_EVENT_DND_END = ecore_event_type_new();
        ECORE_WL2_EVENT_DATA_SOURCE_END = ecore_event_type_new();
        ECORE_WL2_EVENT_DATA_SOURCE_DROP = ecore_event_type_new();
        ECORE_WL2_EVENT_DATA_SOURCE_ACTION = ecore_event_type_new();
        ECORE_WL2_EVENT_DATA_SOURCE_TARGET = ecore_event_type_new();
        ECORE_WL2_EVENT_DATA_SOURCE_SEND = ecore_event_type_new();
        ECORE_WL2_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
        ECORE_WL2_EVENT_SYNC_DONE = ecore_event_type_new();
        ECORE_WL2_EVENT_OFFER_DATA_READY = ecore_event_type_new();
        ECORE_WL2_EVENT_SEAT_NAME_CHANGED = ecore_event_type_new();
        _ecore_wl2_event_window_www = ecore_event_type_new();
        _ecore_wl2_event_window_www_drag = ecore_event_type_new();
     }
   if (!no_session_recovery)
     no_session_recovery = !!getenv("EFL_NO_WAYLAND_SESSION_RECOVERY");

   return _ecore_wl2_init_count;

ecore_event_err:
   ecore_shutdown();

ecore_err:
   eina_log_domain_unregister(_ecore_wl2_log_dom);
   _ecore_wl2_log_dom = -1;

eina_err:
   eina_shutdown();
   return --_ecore_wl2_init_count;
}

EAPI int
ecore_wl2_shutdown(void)
{
   if (_ecore_wl2_init_count < 1)
     {
        ERR("Ecore_Wl2 shutdown called without Ecore_Wl2 Init");
        return 0;
     }

   if (--_ecore_wl2_init_count != 0) return _ecore_wl2_init_count;

   /* reset events */
   ECORE_WL2_EVENT_CONNECT = 0;
   ECORE_WL2_EVENT_DISCONNECT = 0;
   ECORE_WL2_EVENT_GLOBAL_ADDED = 0;
   ECORE_WL2_EVENT_GLOBAL_REMOVED = 0;
   ECORE_WL2_EVENT_FOCUS_IN = 0;
   ECORE_WL2_EVENT_FOCUS_OUT = 0;
   ECORE_WL2_EVENT_DND_ENTER = 0;
   ECORE_WL2_EVENT_DND_LEAVE = 0;
   ECORE_WL2_EVENT_DND_MOTION = 0;
   ECORE_WL2_EVENT_DND_DROP = 0;
   ECORE_WL2_EVENT_DND_END = 0;
   ECORE_WL2_EVENT_DATA_SOURCE_END = 0;
   ECORE_WL2_EVENT_DATA_SOURCE_DROP = 0;
   ECORE_WL2_EVENT_DATA_SOURCE_ACTION = 0;
   ECORE_WL2_EVENT_DATA_SOURCE_TARGET = 0;
   ECORE_WL2_EVENT_DATA_SOURCE_SEND = 0;
   ECORE_WL2_EVENT_WINDOW_CONFIGURE = 0;
   ECORE_WL2_EVENT_SYNC_DONE = 0;
   ECORE_WL2_EVENT_OFFER_DATA_READY = 0;
   ECORE_WL2_EVENT_SEAT_NAME_CHANGED = 0;

   /* shutdown Ecore_Event */
   ecore_event_shutdown();

   /* shutdown Ecore */
   ecore_shutdown();

   /* unregister logging domain */
   eina_log_domain_unregister(_ecore_wl2_log_dom);
   _ecore_wl2_log_dom = -1;

   /* shutdown eina */
   eina_shutdown();

   return _ecore_wl2_init_count;
}

EAPI void
ecore_wl2_session_recovery_disable(void)
{
   no_session_recovery = EINA_TRUE;
}