summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm
diff options
context:
space:
mode:
authorSeunghun Lee <shiin.lee@samsung.com>2015-01-05 09:08:27 -0500
committerChris Michael <cp.michael@samsung.com>2015-01-05 09:08:27 -0500
commit2db6ed09456e433877c5be191a18c84d216ae3f6 (patch)
treedac97eb8cdc676d9a72504bee65a15f739fbca75 /src/lib/ecore_drm
parenta5183ee424d65cf37343ea46f7982c74f60d6fbc (diff)
ecore-drm: remove duplicated code from logind and tty.
Summary: integrates the code used in common. Reviewers: devilhorns Reviewed By: devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1796
Diffstat (limited to 'src/lib/ecore_drm')
-rw-r--r--src/lib/ecore_drm/ecore_drm_launcher.c142
-rw-r--r--src/lib/ecore_drm/ecore_drm_logind.c228
-rw-r--r--src/lib/ecore_drm/ecore_drm_private.h2
-rw-r--r--src/lib/ecore_drm/ecore_drm_tty.c119
4 files changed, 147 insertions, 344 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_launcher.c b/src/lib/ecore_drm/ecore_drm_launcher.c
index dbe7303854..e6309328a5 100644
--- a/src/lib/ecore_drm/ecore_drm_launcher.c
+++ b/src/lib/ecore_drm/ecore_drm_launcher.c
@@ -3,6 +3,111 @@
3 3
4static Eina_Bool logind = EINA_FALSE; 4static Eina_Bool logind = EINA_FALSE;
5 5
6static Eina_Bool
7_ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
8{
9 Ecore_Drm_Device *dev;
10 Ecore_Event_Key *ev;
11 int keycode;
12 int vt;
13
14 dev = data;
15 ev = event;
16 keycode = ev->keycode - 8;
17
18 if ((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
19 (ev->modifiers & ECORE_EVENT_MODIFIER_ALT) &&
20 (keycode >= KEY_F1) && (keycode <= KEY_F8))
21 {
22 vt = (keycode - KEY_F1 + 1);
23
24 if (!_ecore_drm_tty_switch(dev, vt))
25 ERR("Failed to activate vt: %m");
26 }
27
28 return ECORE_CALLBACK_PASS_ON;
29}
30
31
32static Eina_Bool
33_ecore_drm_launcher_cb_vt_signal(void *data, int type EINA_UNUSED, void *event)
34{
35 Ecore_Drm_Device *dev;
36 Ecore_Event_Signal_User *ev;
37 siginfo_t sigdata;
38
39 dev = data;
40 ev = event;
41
42 sigdata = ev->data;
43 if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
44
45 if (ev->number == 1)
46 {
47 if (!logind)
48 {
49 Ecore_Drm_Input *input;
50 Ecore_Drm_Output *output;
51 Ecore_Drm_Sprite *sprite;
52 Eina_List *l;
53
54 /* disable inputs (suspends) */
55 EINA_LIST_FOREACH(dev->inputs, l, input)
56 ecore_drm_inputs_disable(input);
57
58 /* disable hardware cursor */
59 EINA_LIST_FOREACH(dev->outputs, l, output)
60 ecore_drm_output_cursor_size_set(output, 0, 0, 0);
61
62 /* disable sprites */
63 EINA_LIST_FOREACH(dev->sprites, l, sprite)
64 ecore_drm_sprites_fb_set(sprite, 0, 0);
65
66 /* drop drm master */
67 ecore_drm_device_master_drop(dev);
68
69 _ecore_drm_event_activate_send(EINA_FALSE);
70 }
71
72 /* issue ioctl to release vt */
73 if (!ecore_drm_tty_release(dev))
74 ERR("Could not release VT: %m");
75 }
76 else if (ev->number == 2)
77 {
78 if (!logind)
79 {
80 Ecore_Drm_Output *output;
81 Ecore_Drm_Input *input;
82 Eina_List *l;
83
84 /* set drm master */
85 if (!ecore_drm_device_master_set(dev))
86 ERR("Could not set drm master: %m");
87
88 /* set output mode */
89 EINA_LIST_FOREACH(dev->outputs, l, output)
90 ecore_drm_output_enable(output);
91
92 /* enable inputs */
93 EINA_LIST_FOREACH(dev->inputs, l, input)
94 ecore_drm_inputs_enable(input);
95
96 if (ecore_drm_tty_acquire(dev))
97 _ecore_drm_event_activate_send(EINA_TRUE);
98 else
99 ERR("Could not acquire VT: %m");
100 }
101 else
102 {
103 if (!ecore_drm_tty_acquire(dev))
104 ERR("Could not acquire VT: %m");
105 }
106 }
107
108 return ECORE_CALLBACK_RENEW;
109}
110
6EAPI Eina_Bool 111EAPI Eina_Bool
7ecore_drm_launcher_connect(Ecore_Drm_Device *dev) 112ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
8{ 113{
@@ -10,20 +115,30 @@ ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
10 { 115 {
11 DBG("Launcher: Not Support logind\n"); 116 DBG("Launcher: Not Support logind\n");
12 if (geteuid() == 0) 117 if (geteuid() == 0)
13 { 118 DBG("Launcher: Try to keep going with root privilege\n");
14 DBG("Launcher: Try to keep going with root privilege\n");
15 if (!ecore_drm_tty_open(dev, NULL))
16 {
17 ERR("Launcher: failed to open tty with root privilege\n");
18 return EINA_FALSE;
19 }
20 }
21 else 119 else
22 { 120 {
23 ERR("Launcher: Need Root Privilege or logind\n"); 121 ERR("Launcher: Need Root Privilege or logind\n");
24 return EINA_FALSE; 122 return EINA_FALSE;
25 } 123 }
26 } 124 }
125
126 if (!ecore_drm_tty_open(dev, NULL))
127 {
128 ERR("Launcher: failed to open tty\n");
129 return EINA_FALSE;
130 }
131
132 /* setup handler for signals */
133 dev->tty.event_hdlr =
134 ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
135 _ecore_drm_launcher_cb_vt_signal, dev);
136
137 /* setup handler for key event of vt switch */
138 dev->tty.switch_hdlr =
139 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
140 _ecore_drm_launcher_cb_vt_switch, dev);
141
27 DBG("Launcher: Success Connect\n"); 142 DBG("Launcher: Success Connect\n");
28 143
29 return EINA_TRUE; 144 return EINA_TRUE;
@@ -37,8 +152,15 @@ ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev)
37 logind = EINA_FALSE; 152 logind = EINA_FALSE;
38 _ecore_drm_logind_disconnect(dev); 153 _ecore_drm_logind_disconnect(dev);
39 } 154 }
40 else 155
41 ecore_drm_tty_close(dev); 156 if (!ecore_drm_tty_close(dev))
157 ERR("Launcher: failed to close tty\n");
158
159 if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
160 dev->tty.event_hdlr = NULL;
161
162 if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
163 dev->tty.switch_hdlr = NULL;
42} 164}
43 165
44static int 166static int
diff --git a/src/lib/ecore_drm/ecore_drm_logind.c b/src/lib/ecore_drm/ecore_drm_logind.c
index 2e1110261c..9a8d7f1357 100644
--- a/src/lib/ecore_drm/ecore_drm_logind.c
+++ b/src/lib/ecore_drm/ecore_drm_logind.c
@@ -14,58 +14,6 @@ static Ecore_Event_Handler *active_hdl;
14static char *sid; 14static char *sid;
15 15
16static Eina_Bool 16static Eina_Bool
17_ecore_drm_logind_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
18{
19 Ecore_Drm_Device *dev;
20 Ecore_Event_Key *ev;
21 int keycode;
22 int vt;
23
24 dev = data;
25 ev = event;
26 keycode = ev->keycode - 8;
27
28 if ((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
29 (ev->modifiers & ECORE_EVENT_MODIFIER_ALT) &&
30 (keycode >= KEY_F1) && (keycode <= KEY_F8))
31 {
32 vt = (keycode - KEY_F1 + 1);
33
34 if (ioctl(dev->tty.fd, VT_ACTIVATE, vt) < 0)
35 ERR("Failed to activate vt: %m");
36 }
37
38 return ECORE_CALLBACK_PASS_ON;
39}
40
41static Eina_Bool
42_ecore_drm_logind_cb_vt_signal(void *data, int type EINA_UNUSED, void *event)
43{
44 Ecore_Drm_Device *dev;
45 Ecore_Event_Signal_User *ev;
46 siginfo_t sigdata;
47
48 dev = data;
49 ev = event;
50
51 sigdata = ev->data;
52 if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
53
54 if (ev->number == 1)
55 {
56 if (!ecore_drm_tty_release(dev))
57 ERR("Could not release VT: %m");
58 }
59 else if (ev->number == 2)
60 {
61 if (!ecore_drm_tty_acquire(dev))
62 ERR("Could not acquire VT: %m");
63 }
64
65 return ECORE_CALLBACK_PASS_ON;
66}
67
68static Eina_Bool
69_ecore_drm_logind_cb_activate(void *data, int type EINA_UNUSED, void *event) 17_ecore_drm_logind_cb_activate(void *data, int type EINA_UNUSED, void *event)
70{ 18{
71 Ecore_Drm_Event_Activate *e; 19 Ecore_Drm_Event_Activate *e;
@@ -100,163 +48,6 @@ _ecore_drm_logind_cb_activate(void *data, int type EINA_UNUSED, void *event)
100 return ECORE_CALLBACK_PASS_ON; 48 return ECORE_CALLBACK_PASS_ON;
101} 49}
102 50
103static Eina_Bool
104_ecore_drm_logind_tty_setup(Ecore_Drm_Device *dev)
105{
106 struct stat st;
107 int kmode;
108 struct vt_mode vtmode = { 0 };
109
110 if (fstat(dev->tty.fd, &st) == -1)
111 {
112 ERR("Failed to get stats for tty: %m");
113 return EINA_FALSE;
114 }
115
116 if (ioctl(dev->tty.fd, KDGETMODE, &kmode))
117 {
118 ERR("Could not get tty mode: %m");
119 return EINA_FALSE;
120 }
121
122 if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0)
123 {
124 ERR("Failed to activate vt: %m");
125 return EINA_FALSE;
126 }
127
128 if (ioctl(dev->tty.fd, VT_WAITACTIVE, minor(st.st_rdev)) < 0)
129 {
130 ERR("Failed to wait active: %m");
131 return EINA_FALSE;
132 }
133
134 /* NB: Don't set this. This Turns OFF keyboard on the VT */
135 /* if (ioctl(dev->tty.fd, KDSKBMUTE, 1) && */
136 /* ioctl(dev->tty.fd, KDSKBMODE, K_OFF)) */
137 /* { */
138 /* ERR("Could not set K_OFF keyboard mode: %m"); */
139 /* return EINA_FALSE; */
140 /* } */
141
142 if (kmode != KD_GRAPHICS)
143 {
144 if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS))
145 {
146 ERR("Could not set graphics mode: %m");
147 goto err_kmode;
148 }
149 }
150
151 vtmode.mode = VT_PROCESS;
152 vtmode.waitv = 0;
153 vtmode.relsig = SIGUSR1;
154 vtmode.acqsig = SIGUSR2;
155 if (ioctl(dev->tty.fd, VT_SETMODE, &vtmode) < 0)
156 {
157 ERR("Could not set Terminal Mode: %m");
158 goto err_setmode;
159 }
160
161 return EINA_TRUE;
162err_setmode:
163 ioctl(dev->tty.fd, KDSETMODE, KD_TEXT);
164err_kmode:
165 return EINA_FALSE;
166}
167
168static Eina_Bool
169_ecore_drm_logind_vt_open(Ecore_Drm_Device *dev, const char *name)
170{
171 char tty[32] = "<stdin>";
172
173 /* check for valid device */
174 if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
175
176 /* assign default tty fd of -1 */
177 dev->tty.fd = -1;
178
179 if (!name)
180 {
181 char *env;
182
183 if ((env = getenv("ECORE_DRM_TTY")))
184 snprintf(tty, sizeof(tty), "%s", env);
185 else
186 dev->tty.fd = dup(STDIN_FILENO);
187 }
188 else
189 snprintf(tty, sizeof(tty), "%s", name);
190
191 if (dev->tty.fd < 0)
192 {
193 DBG("Trying to Open Tty: %s", tty);
194
195 dev->tty.fd = open(tty, O_RDWR | O_NOCTTY);
196 if (dev->tty.fd < 0)
197 {
198 DBG("Failed to Open Tty: %m");
199 return EINA_FALSE;
200 }
201 }
202
203 /* save tty name */
204 dev->tty.name = eina_stringshare_add(tty);
205
206 /* FIXME */
207 if (!_ecore_drm_logind_tty_setup(dev))
208 {
209 close(dev->tty.fd);
210 dev->tty.fd = -1;
211 if (dev->tty.name)
212 {
213 eina_stringshare_del(dev->tty.name);
214 dev->tty.name = NULL;
215 }
216 return EINA_FALSE;
217 }
218
219 /* setup handler for signals */
220 dev->tty.event_hdlr =
221 ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
222 _ecore_drm_logind_cb_vt_signal, dev);
223
224 /* setup handler for key event of vt switch */
225 dev->tty.switch_hdlr =
226 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
227 _ecore_drm_logind_cb_vt_switch, dev);
228
229 active_hdl =
230 ecore_event_handler_add(ECORE_DRM_EVENT_ACTIVATE,
231 _ecore_drm_logind_cb_activate, dev);
232
233 /* set current tty into env */
234 setenv("ECORE_DRM_TTY", tty, 1);
235
236 return EINA_TRUE;
237}
238
239static void
240_ecore_drm_logind_vt_close(Ecore_Drm_Device *dev)
241{
242 struct vt_mode mode = { 0 };
243
244 ioctl(dev->tty.fd, KDSETMODE, KD_TEXT);
245 mode.mode = VT_AUTO;
246 ioctl(dev->tty.fd, VT_SETMODE, &mode);
247
248 if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
249 dev->tty.event_hdlr = NULL;
250
251 if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
252 dev->tty.switch_hdlr = NULL;
253
254 if (dev->tty.name) eina_stringshare_del(dev->tty.name);
255 dev->tty.name = NULL;
256
257 unsetenv("ECORE_DRM_TTY");
258}
259
260Eina_Bool 51Eina_Bool
261_ecore_drm_logind_connect(Ecore_Drm_Device *dev) 52_ecore_drm_logind_connect(Ecore_Drm_Device *dev)
262{ 53{
@@ -267,24 +58,21 @@ _ecore_drm_logind_connect(Ecore_Drm_Device *dev)
267 58
268 /* try to init dbus */ 59 /* try to init dbus */
269 if (!_ecore_drm_dbus_init(sid)) 60 if (!_ecore_drm_dbus_init(sid))
270 goto dbus_err; 61 {
62 free(sid);
63 return EINA_FALSE;
64 }
271 65
272 if (!_ecore_drm_logind_vt_open(dev, NULL)) 66 active_hdl =
273 goto vt_err; 67 ecore_event_handler_add(ECORE_DRM_EVENT_ACTIVATE,
68 _ecore_drm_logind_cb_activate, dev);
274 69
275 return EINA_TRUE; 70 return EINA_TRUE;
276
277vt_err:
278 _ecore_drm_dbus_shutdown();
279dbus_err:
280 free(sid);
281 return EINA_FALSE;
282} 71}
283 72
284void 73void
285_ecore_drm_logind_disconnect(Ecore_Drm_Device *dev) 74_ecore_drm_logind_disconnect(Ecore_Drm_Device *dev EINA_UNUSED)
286{ 75{
287 _ecore_drm_logind_vt_close(dev);
288 _ecore_drm_dbus_shutdown(); 76 _ecore_drm_dbus_shutdown();
289 77
290 if (active_hdl) 78 if (active_hdl)
diff --git a/src/lib/ecore_drm/ecore_drm_private.h b/src/lib/ecore_drm/ecore_drm_private.h
index 151303fe53..8b907b5311 100644
--- a/src/lib/ecore_drm/ecore_drm_private.h
+++ b/src/lib/ecore_drm/ecore_drm_private.h
@@ -235,6 +235,8 @@ Eina_Bool _ecore_drm_launcher_device_open(const char *device, Ecore_Drm_Open_Cb
235int _ecore_drm_launcher_device_open_no_pending(const char *device, int flags); 235int _ecore_drm_launcher_device_open_no_pending(const char *device, int flags);
236void _ecore_drm_launcher_device_close(const char *device, int fd); 236void _ecore_drm_launcher_device_close(const char *device, int fd);
237 237
238Eina_Bool _ecore_drm_tty_switch(Ecore_Drm_Device *dev, int activate_vt);
239
238void _ecore_drm_inputs_update_output(Ecore_Drm_Device *dev, int w, int h); 240void _ecore_drm_inputs_update_output(Ecore_Drm_Device *dev, int w, int h);
239 241
240Ecore_Drm_Evdev *_ecore_drm_evdev_device_create(Ecore_Drm_Seat *seat, struct libinput_device *device); 242Ecore_Drm_Evdev *_ecore_drm_evdev_device_create(Ecore_Drm_Seat *seat, struct libinput_device *device);
diff --git a/src/lib/ecore_drm/ecore_drm_tty.c b/src/lib/ecore_drm/ecore_drm_tty.c
index 11a074e0d6..2bf7027f9f 100644
--- a/src/lib/ecore_drm/ecore_drm_tty.c
+++ b/src/lib/ecore_drm/ecore_drm_tty.c
@@ -12,103 +12,12 @@
12# define KDSKBMUTE 0x4B51 12# define KDSKBMUTE 0x4B51
13#endif 13#endif
14 14
15static Eina_Bool 15Eina_Bool
16_ecore_drm_tty_cb_vt_switch(void *data, int type EINA_UNUSED, void *event) 16_ecore_drm_tty_switch(Ecore_Drm_Device *dev, int activate_vt)
17{ 17{
18 Ecore_Drm_Device *dev; 18 if (!ioctl(dev->tty.fd, VT_ACTIVATE, activate_vt) < 0)
19 Ecore_Event_Key *ev; 19 return EINA_FALSE;
20 int keycode; 20 return EINA_TRUE;
21 int vt;
22
23 dev = data;
24 ev = event;
25 keycode = ev->keycode - 8;
26
27 if ((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
28 (ev->modifiers & ECORE_EVENT_MODIFIER_ALT) &&
29 (keycode >= KEY_F1) && (keycode <= KEY_F8))
30 {
31 vt = (keycode - KEY_F1 + 1);
32
33 if (ioctl(dev->tty.fd, VT_ACTIVATE, vt) < 0)
34 ERR("Failed to activate vt: %m");
35 }
36
37 return ECORE_CALLBACK_PASS_ON;
38}
39
40static Eina_Bool
41_ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, void *event)
42{
43 Ecore_Drm_Device *dev;
44 Ecore_Event_Signal_User *ev;
45 siginfo_t sigdata;
46
47 dev = data;
48 ev = event;
49
50 sigdata = ev->data;
51 if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
52
53 if (ev->number == 1)
54 {
55 Ecore_Drm_Input *input;
56 Ecore_Drm_Output *output;
57 Ecore_Drm_Sprite *sprite;
58 Eina_List *l;
59
60 /* disable inputs (suspends) */
61 EINA_LIST_FOREACH(dev->inputs, l, input)
62 ecore_drm_inputs_disable(input);
63
64 /* disable hardware cursor */
65 EINA_LIST_FOREACH(dev->outputs, l, output)
66 ecore_drm_output_cursor_size_set(output, 0, 0, 0);
67
68 /* disable sprites */
69 EINA_LIST_FOREACH(dev->sprites, l, sprite)
70 ecore_drm_sprites_fb_set(sprite, 0, 0);
71
72 /* drop drm master */
73 if (ecore_drm_device_master_drop(dev))
74 {
75 /* issue ioctl to release vt */
76 if (!ecore_drm_tty_release(dev))
77 ERR("Could not release VT: %m");
78 }
79 else
80 ERR("Could not drop drm master: %m");
81
82 _ecore_drm_event_activate_send(EINA_FALSE);
83 }
84 else if (ev->number == 2)
85 {
86 /* issue ioctl to acquire vt */
87 if (ecore_drm_tty_acquire(dev))
88 {
89 Ecore_Drm_Output *output;
90 Ecore_Drm_Input *input;
91 Eina_List *l;
92
93 /* set drm master */
94 if (!ecore_drm_device_master_set(dev))
95 ERR("Could not set drm master: %m");
96
97 /* set output mode */
98 EINA_LIST_FOREACH(dev->outputs, l, output)
99 ecore_drm_output_enable(output);
100
101 /* enable inputs */
102 EINA_LIST_FOREACH(dev->inputs, l, input)
103 ecore_drm_inputs_enable(input);
104
105 _ecore_drm_event_activate_send(EINA_TRUE);
106 }
107 else
108 ERR("Could not acquire VT: %m");
109 }
110
111 return ECORE_CALLBACK_RENEW;
112} 21}
113 22
114static Eina_Bool 23static Eina_Bool
@@ -246,16 +155,6 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
246 return EINA_FALSE; 155 return EINA_FALSE;
247 } 156 }
248 157
249 /* setup handler for signals */
250 dev->tty.event_hdlr =
251 ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
252 _ecore_drm_tty_cb_signal, dev);
253
254 /* setup handler for key event of vt switch */
255 dev->tty.switch_hdlr =
256 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
257 _ecore_drm_tty_cb_vt_switch, dev);
258
259 /* set current tty into env */ 158 /* set current tty into env */
260 setenv("ECORE_DRM_TTY", tty, 1); 159 setenv("ECORE_DRM_TTY", tty, 1);
261 160
@@ -301,14 +200,6 @@ ecore_drm_tty_close(Ecore_Drm_Device *dev)
301 200
302 dev->tty.fd = -1; 201 dev->tty.fd = -1;
303 202
304 /* destroy the event handler */
305 if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
306 dev->tty.event_hdlr = NULL;
307
308 /* destroy the event handler */
309 if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
310 dev->tty.switch_hdlr = NULL;
311
312 /* clear the tty name */ 203 /* clear the tty name */
313 if (dev->tty.name) eina_stringshare_del(dev->tty.name); 204 if (dev->tty.name) eina_stringshare_del(dev->tty.name);
314 dev->tty.name = NULL; 205 dev->tty.name = NULL;