summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2015-01-22 12:40:32 -0500
committerChris Michael <cp.michael@samsung.com>2015-01-26 08:37:08 -0500
commit81a47310369ac964d5c06f876960717b04f31fc8 (patch)
treeb5da889cd0c3d72b36003f8f43f3a4b8a1ff1e2b /src/lib/ecore_drm
parentc7d557cf4e1cf2b5d4278141363c02ec01d98dfc (diff)
ecore-drm: Cleanup launcher code
Summary: This moves the VT switch handling code to the tty file, and sets the proper flags on the VT when opened. @fix Signed-off-by: Chris Michael <cp.michael@samsung.com>
Diffstat (limited to 'src/lib/ecore_drm')
-rw-r--r--src/lib/ecore_drm/ecore_drm_launcher.c170
1 files changed, 41 insertions, 129 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_launcher.c b/src/lib/ecore_drm/ecore_drm_launcher.c
index 41f2fe1b50..860cc84666 100644
--- a/src/lib/ecore_drm/ecore_drm_launcher.c
+++ b/src/lib/ecore_drm/ecore_drm_launcher.c
@@ -1,9 +1,8 @@
1#include "ecore_drm_private.h" 1#include "ecore_drm_private.h"
2#include "ecore_drm_logind.h"
3 2
4static Eina_Bool logind = EINA_FALSE; 3static Eina_Bool logind = EINA_FALSE;
5 4
6static Eina_Bool 5static Eina_Bool
7_ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event) 6_ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
8{ 7{
9 Ecore_Drm_Device *dev; 8 Ecore_Drm_Device *dev;
@@ -28,167 +27,80 @@ _ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
28 return ECORE_CALLBACK_PASS_ON; 27 return ECORE_CALLBACK_PASS_ON;
29} 28}
30 29
31 30int
32static Eina_Bool 31_ecore_drm_launcher_device_flags_set(int fd, int flags)
33_ecore_drm_launcher_cb_vt_signal(void *data, int type EINA_UNUSED, void *event)
34{ 32{
35 Ecore_Drm_Device *dev; 33 int fl;
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 34
69 _ecore_drm_event_activate_send(EINA_FALSE); 35 fl = fcntl(fd, F_GETFL);
70 } 36 if (fl < 0) return -1;
71 37
72 /* issue ioctl to release vt */ 38 if (flags & O_NONBLOCK)
73 if (!ecore_drm_tty_release(dev)) 39 fl |= O_NONBLOCK;
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 40
84 /* set drm master */ 41 if (fcntl(fd, F_SETFL, fl) < 0)
85 if (!ecore_drm_device_master_set(dev)) 42 return -1;
86 ERR("Could not set drm master: %m");
87 43
88 /* set output mode */ 44 fl = fcntl(fd, F_GETFD);
89 EINA_LIST_FOREACH(dev->outputs, l, output) 45 if (fl < 0) return -1;
90 ecore_drm_output_enable(output);
91 46
92 /* enable inputs */ 47 if (!(flags & O_CLOEXEC))
93 EINA_LIST_FOREACH(dev->inputs, l, input) 48 fl &= ~FD_CLOEXEC;
94 ecore_drm_inputs_enable(input);
95 49
96 if (ecore_drm_tty_acquire(dev)) 50 if (fcntl(fd, F_SETFD, fl) < 0)
97 _ecore_drm_event_activate_send(EINA_TRUE); 51 return -1;
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 52
108 return ECORE_CALLBACK_RENEW; 53 return fd;
109} 54}
110 55
111EAPI Eina_Bool 56EAPI Eina_Bool
112ecore_drm_launcher_connect(Ecore_Drm_Device *dev) 57ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
113{ 58{
59 /* try to connect to logind */
114 if (!(logind = _ecore_drm_logind_connect(dev))) 60 if (!(logind = _ecore_drm_logind_connect(dev)))
115 { 61 {
116 DBG("Launcher: Not Support logind\n"); 62 DBG("Launcher: Logind not supported");
117 if (geteuid() == 0) 63 if (geteuid() == 0)
118 DBG("Launcher: Try to keep going with root privilege\n"); 64 {
65 DBG("Launcher: Trying to continue with root privileges");
66 if (!ecore_drm_tty_open(dev, NULL))
67 {
68 ERR("Launcher: Could not setup tty");
69 return EINA_FALSE;
70 }
71 }
119 else 72 else
120 { 73 {
121 ERR("Launcher: Need Root Privilege or logind\n"); 74 ERR("Launcher: Root privileges needed");
122 return EINA_FALSE; 75 return EINA_FALSE;
123 } 76 }
124 } 77 }
125 78
126 if (!ecore_drm_tty_open(dev, NULL)) 79 dev->tty.switch_hdlr =
127 { 80 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
128 ERR("Launcher: failed to open tty\n"); 81 _ecore_drm_launcher_cb_vt_switch, dev);
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
142 DBG("Launcher: Success Connect\n");
143 82
144 return EINA_TRUE; 83 return EINA_TRUE;
145} 84}
146 85
147EAPI void 86EAPI void
148ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev) 87ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev)
149{ 88{
150 if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
151 dev->tty.event_hdlr = NULL;
152
153 if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr); 89 if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
154 dev->tty.switch_hdlr = NULL; 90 dev->tty.switch_hdlr = NULL;
155 91
156 if (!ecore_drm_tty_close(dev)) 92 if (!logind)
157 ERR("Launcher: failed to close tty\n"); 93 {
158 94 if (!ecore_drm_tty_close(dev))
159 if (logind) 95 ERR("Launcher: Could not close tty");
96 }
97 else
160 { 98 {
161 logind = EINA_FALSE;
162 _ecore_drm_logind_disconnect(dev); 99 _ecore_drm_logind_disconnect(dev);
100 logind = EINA_FALSE;
163 } 101 }
164} 102}
165 103
166static int
167_device_flags_set(int fd, int flags)
168{
169 int fl;
170
171 fl = fcntl(fd, F_GETFL);
172 if (fl < 0) return -1;
173
174 if (flags & O_NONBLOCK)
175 fl |= O_NONBLOCK;
176
177 if (fcntl(fd, F_SETFL, fl) < 0)
178 return -1;
179
180 fl = fcntl(fd, F_GETFD);
181 if (fl < 0) return -1;
182
183 if (!(flags & O_CLOEXEC))
184 fl &= ~FD_CLOEXEC;
185
186 if (fcntl(fd, F_SETFD, fl) < 0)
187 return -1;
188
189 return fd;
190}
191
192Eina_Bool 104Eina_Bool
193_ecore_drm_launcher_device_open(const char *device, Ecore_Drm_Open_Cb callback, void *data, int flags) 105_ecore_drm_launcher_device_open(const char *device, Ecore_Drm_Open_Cb callback, void *data, int flags)
194{ 106{
@@ -226,7 +138,7 @@ _ecore_drm_launcher_device_open_no_pending(const char *device, int flags)
226 if (logind) 138 if (logind)
227 { 139 {
228 fd = _ecore_drm_logind_device_open_no_pending(device); 140 fd = _ecore_drm_logind_device_open_no_pending(device);
229 if ((fd = _device_flags_set(fd, flags)) == -1) 141 if ((fd = _ecore_drm_launcher_device_flags_set(fd, flags)) < 0)
230 { 142 {
231 _ecore_drm_logind_device_close(device); 143 _ecore_drm_logind_device_close(device);
232 return -1; 144 return -1;