summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm/ecore_drm_launcher.c
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/ecore_drm_launcher.c
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/ecore_drm_launcher.c')
-rw-r--r--src/lib/ecore_drm/ecore_drm_launcher.c142
1 files changed, 132 insertions, 10 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